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

[parser] `arguments` and `eval` as object shorthand should be valid in strict mode #10411

Open
pvdz opened this issue Sep 7, 2019 · 4 comments

Comments

@pvdz
Copy link

commented Sep 7, 2019

Bug Report

The object key shorthand syntax is checking the ident for being a keyword and triggers an error. This is not correct for eval and arguments, which are only read (which is legal).

Current Behavior

It will throw a syntax error Unexpected keyword 'eval' (1:2)

Input Code

https://astexplorer.net/#/gist/15eb31fbb1024faa6f42a4940d8beb4a/06e20b27a9291d5356faa340e430c0ded986ccb8

It will properly apply sloppy/strict mode exceptions (script vs module goal). So eval won't throw with script goal.

({arguments})
({eval})

Not sure if same bug, but definitely related is the next one, where the eval identifier is a regular object key, not a assignment destructuring pattern (because it assigns to .x of the object literal). Let me know if this is the same cause, otherwise I'll file a separate issue for this.

({...{eval}.x} = {});

Expected behavior/code

It should not throw an error because it's a regular object key and a read from eval / arguments, which is allowed.

Environment

Babel 7.5.5

Possible Solution

Add exception path for eval and arguments when doing the keyword check.

@babel-bot

This comment has been minimized.

Copy link
Collaborator

commented Sep 7, 2019

Hey @pvdz! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite.

@nicolo-ribaudo

This comment has been minimized.

Copy link
Member

commented Sep 7, 2019

({break}) is a syntax error because it's the same as ({break: break})

@pvdz

This comment has been minimized.

Copy link
Author

commented Sep 7, 2019

Oh wow, thanks for that. I completely missed that detail.

Looking explicitly at it now, https://tc39.es/ecma262/#prod-PropertyDefinition uses https://tc39.es/ecma262/#prod-IdentifierReference for a shorthand. This leads to https://tc39.es/ecma262/#prod-Identifier which forbids "keywords". So you're absolutely correct; this is a syntax error.

@pvdz pvdz closed this Sep 7, 2019

@pvdz pvdz reopened this Sep 7, 2019

@pvdz

This comment has been minimized.

Copy link
Author

commented Sep 7, 2019

I will update the issue accordingly. I believe the bug here is that this would not apply to contextual value keywords like eval and arguments, which can be read in strict mode, just not written to. And this is just a read.

@pvdz pvdz changed the title [parser] Incorrectly considering paren wrapped object an arrow header [parser] `arguments` and `eval` as object shorthand should be valid in strict mode Sep 7, 2019

@JLHwung JLHwung added pkg: parser and removed i: needs triage labels Sep 11, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.