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

Reserved keywords cause error when used in an expression with spaces around the keyword #1445

Closed
taylorzane opened this issue May 10, 2018 · 5 comments

Comments

@taylorzane
Copy link
Contributor

When using reserved JavaScript keywords in an expression, if the expression has spaces in between the curly brackets and the keyword, the parser will throw an error.

This throws: <div class="{ class }"></div>
But this does not: <div class="{class}"></div>

This goes for all JS keywords. I've tested import, export, and class at least.

REPL with failing test case: https://svelte.technology/repl?version=2.5.0&gist=9d4b8a0c733a48397d8a66feb9881fa5

REPL with passing test case: https://svelte.technology/repl?version=2.5.0&gist=6149f93a9af8cbc6286a335b8afbfaec

@Conduitry
Copy link
Member

I haven't tested this but I think we should be able to fix this with just a parser.allowWhitespace() inserted as the first line of the readExpression function here and have it not break sourcemaps.

@Conduitry
Copy link
Member

Actually, this is currently working with things like { export } appearing in HTML, just not when they're in an attribute value. These both use readExpression, so that suggests maybe the allowWhitespace() ought to be inserted elsewhere, but I'm not sure where.

@Conduitry
Copy link
Member

Ah, right here.

@taylorzane
Copy link
Contributor Author

How swift! Thank you for this.

Rich-Harris added a commit that referenced this issue May 11, 2018
allow spaces around reserved words used in tags in attributes
@Rich-Harris
Copy link
Member

released 2.5.1 with the fix — thanks

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

No branches or pull requests

3 participants