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

Fix import statement requiring a space afterwards #593

Open
FlyingDR opened this issue Nov 1, 2018 · 3 comments
Open

Fix import statement requiring a space afterwards #593

FlyingDR opened this issue Nov 1, 2018 · 3 comments

Comments

@FlyingDR
Copy link

FlyingDR commented Nov 1, 2018

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.

@ericmorand
Copy link
Contributor

I was sure it would at least throw a syntax error with TwigPHP but it actually works perfectly:

https://twigfiddle.com/v1f4cm

@FlyingDR
Copy link
Author

FlyingDR commented Nov 1, 2018

Yes, I forgot to mention a fact that PHP Twig parses this properly, sorry

@RobLoach RobLoach changed the title Incorrect parse of import statement Fix import statement requiring a space afterwards Jan 9, 2019
@willrowe
Copy link
Collaborator

Example of it not working in twig.js: https://codepen.io/willrowe/pen/VwXMgeo

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

3 participants