case statement with multiple values does not work #358
Replies: 3 comments 1 reply
-
It's supported since v1.9.1, check your version please. See the playground demo: https://liquidjs.com/playground.html#eyUgY2FzZSAiYXNkIiAlfQ0KeyUgd2hlbiAgInRlc3QiLCAiYXNkIiAlfQ0Kc2hvdWxkIHdvcmssIGJ1dCBpdHMgbm90DQp7JSBlbmRjYXNlICV9 |
Beta Was this translation helpful? Give feedback.
-
Interesting. I'm seeing errors in liquidjs@6.4.3 (the current version in Eleventy v0.12). v6.4.3const Liquid = require('liquidjs'); // v6.4.3
const engine = new Liquid();
const {name, version} = require("liquidjs/package.json");
console.log("DEBUG:", `${name}@${version}`);
const tmpl = `
{% case "asd" %}
{% when "test", "asd" %}
"test" or "asd"
{% when "foo" %}
"foo"
{% else %}
"else"
{% endcase %}
`;
engine
.parseAndRender(tmpl)
.then(res => console.log(res.trim())); > node foo.liquid.js
DEBUG: liquidjs@6.4.3
(node:12273) UnhandledPromiseRejectionWarning: 1|
>> 2| {% case "asd" %}
3| {% when "test", "asd" %}
4| "test" or "asd"
5| {% when "foo" %}
RenderError: cannot eval '"test", "asd"' as value, line:2
at Object._callee2$ (/private/tmp/liquid-case/node_modules/liquidjs/dist/liquid.common.js:1681:21)
at tryCatch (/private/tmp/liquid-case/node_modules/liquidjs/dist/liquid.common.js:108:40)
at Generator.invoke [as _invoke] (/private/tmp/liquid-case/node_modules/liquidjs/dist/liquid.common.js:319:22)
at Generator.prototype.<computed> [as throw] (/private/tmp/liquid-case/node_modules/liquidjs/dist/liquid.common.js:156:21)
at step (/private/tmp/liquid-case/node_modules/liquidjs/dist/liquid.common.js:25:30)
at /private/tmp/liquid-case/node_modules/liquidjs/dist/liquid.common.js:38:13
at processTicksAndRejections (internal/process/task_queues.js:95:5)
From TypeError: cannot eval '"test", "asd"' as value
at evalValue (/private/tmp/liquid-case/node_modules/liquidjs/dist/liquid.common.js:1580:9)
at Function.evalExp (/private/tmp/liquid-case/node_modules/liquidjs/dist/liquid.common.js:1567:10)
at Object.render (/private/tmp/liquid-case/node_modules/liquidjs/dist/liquid.common.js:2351:26)
at Object._callee$ (/private/tmp/liquid-case/node_modules/liquidjs/dist/liquid.common.js:1851:55)
at tryCatch (/private/tmp/liquid-case/node_modules/liquidjs/dist/liquid.common.js:108:40)
at Generator.invoke [as _invoke] (/private/tmp/liquid-case/node_modules/liquidjs/dist/liquid.common.js:319:22)
at Generator.prototype.<computed> [as next] (/private/tmp/liquid-case/node_modules/liquidjs/dist/liquid.common.js:156:21)
at step (/private/tmp/liquid-case/node_modules/liquidjs/dist/liquid.common.js:25:30)
at /private/tmp/liquid-case/node_modules/liquidjs/dist/liquid.common.js:43:14
at new Promise (<anonymous>)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:12273) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:12273) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. v7.5.1If I run npm i liquidjs@7.5.1 (I believe the last in the 7.x branch), it doesn't throw errors, but also seems to return an unexpected result: DEBUG: liquidjs@7.5.1
"else" {% case "asd" %}
{% when "test", "asd" %}
"test" or "asd"
{% when "foo" %}
"foo"
{% else %}
"else"
{% endcase %} v8.5.3Same as v7.x results. DEBUG: liquidjs@8.5.3
"else" v9.25.0But, it does seem to work in liquidjs@9.25.0 (current latest stable): const {Liquid} = require('liquidjs');
const engine = new Liquid();
const {name, version} = require("liquidjs/package.json");
console.log("DEBUG:", `${name}@${version}`);
const tmpl = `
{% case "asd" %}
{% when "test", "asd" %}
"test" or "asd"
{% when "foo" %}
"foo"
{% else %}
"else"
{% endcase %}
`;
engine
.parseAndRender(tmpl)
.then(res => console.log(res.trim())); DEBUG: liquidjs@9.25.0
"test" or "asd" |
Beta Was this translation helpful? Give feedback.
-
Ah, it looks like the multiple "when" clause support was added in 9.25.0, per #343. |
Beta Was this translation helpful? Give feedback.
-
See following example:
Produces:
ParseError: unexpected token at ", \"asd\"", line:1, col:1
But actually it should be supported to add multiple values: https://liquidjs.com/tags/case.html
Beta Was this translation helpful? Give feedback.
All reactions