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

Using operator as variable name fails in some case #649

Open
ericmorand opened this issue Jun 25, 2019 · 2 comments
Open

Using operator as variable name fails in some case #649

ericmorand opened this issue Jun 25, 2019 · 2 comments

Comments

@ericmorand
Copy link
Contributor

ericmorand commented Jun 25, 2019

Twig allows using operators as variable names - this is expected since it is possible to add operators to the language and it would make the language extremely unreliable to forbid calling a variable like an operator.

But twig.js doesn't seem to support that feature for all operators.

The following template fails for example:

{% for in in in %}
    {{ in }}
{% endfor %}

TypeError: Cannot read property 'length' of undefined

{{ in }}

TypeError: Cannot read property 'length' of undefined

{{ matches }}

TypeError: Cannot read property 'test' of undefined

The following one succeed:

{{ is }}

Here is the script I use to test the templates above:

const Twig = require('twig');

Twig.renderFile('./index.twig', {in: [1, 2], matches: 'foo', is: 'bar'}, (err, html) => {
    console.warn(html);
});
@willrowe
Copy link
Collaborator

Examples in twig.js: https://codepen.io/willrowe/pen/JjLONqP

@willrowe
Copy link
Collaborator

All examples in one Twigfiddle: https://twigfiddle.com/tbav9k

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

No branches or pull requests

2 participants