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

Unable to deconstruct an object that has a reserved keyword #4372

Closed
pushkine opened this issue Feb 5, 2020 · 8 comments · Fixed by #4390
Closed

Unable to deconstruct an object that has a reserved keyword #4372

pushkine opened this issue Feb 5, 2020 · 8 comments · Fixed by #4390
Assignees
Labels

Comments

@pushkine
Copy link
Contributor

pushkine commented Feb 5, 2020

https://svelte.dev/repl/8ec7ec1e072b405d90549a5277a9f235?version=3.18.1

@PatrickG
Copy link
Member

PatrickG commented Feb 5, 2020

That's not possible in plain JavaScript either.

@TehShrike TehShrike assigned TehShrike and unassigned TehShrike Feb 5, 2020
@TehShrike
Copy link
Member

@pushkine const { in: value } = { value: 12 } is a syntax error in JS: https://jsfiddle.net/uakgp9ho/

So, it will be a syntax error in Svelte too.

@pushkine
Copy link
Contributor Author

pushkine commented Feb 6, 2020

@TehShrike your fiddle makes no sense
here it is corrected : https://jsfiddle.net/2n8efqh0/
jsfiddle does underline the keyword but the console doesn't output any error, hinting this is not a javascript issue but a linter one
I see no reason why one couldn't use a reserved keyword as a object property name

@TehShrike
Copy link
Member

Hey, you're right

@TehShrike TehShrike reopened this Feb 6, 2020
@Conduitry Conduitry added the bug label Feb 6, 2020
@Conduitry
Copy link
Member

I believe we're currently using some custom parsing logic for the array/object destructuring in each blocks, and that probably doesn't realize that in can be used there in that way if it's trying to parse in by itself as an identifier. I'm not sure the reason we're not using Acorn to try to parse these (maybe because it wouldn't play nice with the parenthesized key afterwards?), but it seems like it would be nice if we could get that to happen.

@Conduitry
Copy link
Member

Apparently all the way back to 3.0.0, the compiler has never balked at doing something like {in} or {class}, which it definitely should, as that results in invalid code: text(in) or text(class).

@Conduitry
Copy link
Member

Actually that's probably just a matter of removing the special handling added way back in #385.

@Conduitry Conduitry self-assigned this Feb 8, 2020
Conduitry added a commit to Conduitry/sveltejs_svelte that referenced this issue Feb 8, 2020
@Conduitry
Copy link
Member

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

Successfully merging a pull request may close this issue.

4 participants