Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

if tag condition, the token args is empty after updating from 10.19.1 to 10.20.0 or later #796

Closed
sidneyprins opened this issue Feb 7, 2025 · 5 comments
Labels

Comments

@sidneyprins
Copy link

sidneyprins commented Feb 7, 2025

Hello,

We have a string

  • Hello, {% if name %} {{ name }} {% else %} user {% endif %}

When we update from 10.19.1 to 10.20.0 or later, our test starts to fail. We use the LiquidJS engine to read out all the different kinds of tokens and figure out which are required and optional.

The token if normally gets args filled with name in this case, but since updating it returns an empty string.

Version 10.19.1

See args

Image

Version 10.20.0 or higher

See args

Image

I have done some digging and found these changes.

Image

Link:
File tags/if.ts, line 15 till 21

If I revert these changes, it works again.

When I run that specific function item.token.tokenizer.readFilteredValue() I get the following error.

invalid value expression: "", line:1, col:18
>> 1| Hello, {% if name  %} {{ name }} {% else %} user {% endif %}
                       ^
TokenizationError: invalid value expression: "", line:1, col:18
    at Tokenizer.error (/private/var/www/vhosts/mailer/node_modules/liquidjs/dist/liquid.node.js:1999:16)
    at Tokenizer.assert (/private/var/www/vhosts/mailer/node_modules/liquidjs/dist/liquid.node.js:2003:24)
    at Tokenizer.readFilteredValue (/private/var/www/vhosts/mailer/node_modules/liquidjs/dist/liquid.node.js:1841:14)
    at eval (eval at <anonymous> (/private/var/www/vhosts/mailer/server/src/lib/helpers/liquid_helpers.ts:25:1), <anonymous>:1:22)
...

We have tried various versions of writing the strings, such as seen on https://liquidjs.com/tags/if.html, like

  • {% if customer.name == "kevin" %} blabla {% endif %}

We're not sure how to make a fix for this part, can you help us?

@jg-rp
Copy link
Contributor

jg-rp commented Feb 7, 2025

Hi @sidneyprins,

args was removed in version 10.20.0 and an arguments() methods was introduced, which returns a Value | ValueToken iterable (not all tags implement arguments(), it is optional).

@harttle might be willing to reintroduce args, but you might find some of the built-in static analysis features to be a useful alternative.

In this example globalFullVariablesSync returns an array of variable names that are not in scope from previous or enclosing tags.

import { Liquid } from "liquidjs";

const liquid = new Liquid();

const exampleTemplate = `\
Hello, {% if name %} {{ name }} {% else %} user {% endif %}

{%- assign you = 'Liquid' %}
G'day, {% if you %}{{ you }}{% else %}there{% endif %}!
`;

const context = {
  name: "World",
};

const template = liquid.parse(exampleTemplate);
console.log(liquid.globalFullVariablesSync(template)); // [ 'name' ]

@jg-rp
Copy link
Contributor

jg-rp commented Feb 7, 2025

Ah, sorry. IfTag.token.args has not been removed, but we do now advance TagToken.tokenizer.p, which breaks TagToken.args. So this might be a bug worth fixing after all.

@harttle harttle closed this as completed in 38a0f51 Feb 9, 2025
github-actions bot pushed a commit that referenced this issue Feb 9, 2025
## [10.20.3](v10.20.2...v10.20.3) (2025-02-09)

### Bug Fixes

* empty tagToken.args since 10.20.0, fixes [#796](#796) ([38a0f51](38a0f51))
Copy link

github-actions bot commented Feb 9, 2025

🎉 This issue has been resolved in version 10.20.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

@harttle
Copy link
Owner

harttle commented Feb 9, 2025

Thank you for the investigation @jg-rp, I released a fix just now @sidneyprins . Please let me know if args is still not working for 10.20.3

@sidneyprins
Copy link
Author

Thanks for making a fix, issue is resolved!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants