twig.js
twig.js copied to clipboard
Fix import statement requiring a space afterwards
Twig.js v1.12.0 is failed to properly parse import
statement in a case if there is no space between import
keyword and filename. Example test file:
{% include"test.twig" %}
(notice no space after include
) gives me:
Error compiling twig template index.twig:
TwigException: Unable to parse 'include"test.twig"'
node_modules/map-stream/index.js:103
throw err
^
TypeError: Cannot read property 'length' of undefined
at Object.e.async.forEach (node_modules/twig/twig.js:1:8309)
at e.Template.e.parse (node_modules/twig/twig.js:1:77630)
at e.Template.e.parseAsync (node_modules/twig/twig.js:1:5510)
at e.Template.<anonymous> (node_modules/twig/twig.js:1:81286)
at node_modules/twig/twig.js:1:5951
at Object.e.async.potentiallyAsync (node_modules/twig/twig.js:1:6181)
at e.Template.render (node_modules/twig/twig.js:1:81231)
at modifyContents (node_modules/gulp-twig/index.js:90:49)
at wrappedMapper (node_modules/map-stream/index.js:84:19)
at Stream.stream.write (node_modules/map-stream/index.js:96:21)
if test file get changed by adding space after import
:
{% include "test.twig" %}
it get parsed successfully.
I was sure it would at least throw a syntax error with TwigPHP but it actually works perfectly:
https://twigfiddle.com/v1f4cm
Yes, I forgot to mention a fact that PHP Twig parses this properly, sorry
Example of it not working in twig.js: https://codepen.io/willrowe/pen/VwXMgeo