Using operator as variable name fails in some case
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:
- https://twigfiddle.com/coze8i
{% for in in in %}
{{ in }}
{% endfor %}
TypeError: Cannot read property 'length' of undefined
- https://twigfiddle.com/coze8i/2
{{ in }}
TypeError: Cannot read property 'length' of undefined
- https://twigfiddle.com/coze8i/3
{{ matches }}
TypeError: Cannot read property 'test' of undefined
The following one succeed:
- https://twigfiddle.com/coze8i/5
{{ 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);
});
Examples in twig.js: https://codepen.io/willrowe/pen/JjLONqP
All examples in one Twigfiddle: https://twigfiddle.com/tbav9k