Skip to content

Disallow await before exponential#12441

Merged
JLHwung merged 3 commits intobabel:mainfrom
JLHwung:disallow-await-before-exponential
Mar 25, 2021
Merged

Disallow await before exponential#12441
JLHwung merged 3 commits intobabel:mainfrom
JLHwung:disallow-await-before-exponential

Conversation

@JLHwung
Copy link
Copy Markdown
Contributor

@JLHwung JLHwung commented Dec 2, 2020

Q                       A
Fixed Issues? tc39/ecma262#2197
Tests Added + Pass? Yes
License MIT

Babel does not throw for await before exponential: async () => await -1 ** 1, REPL,

See here for the real diff.

This PR forbids await expression when it is the left of an exponential expression. In the first commit we refactor current check so we don't have to check node.left.type and extra.parenthesized, instead we check it when an AwaitExpression / UnaryExpression is parsed. Then we forbid exponential after an await is parsed.

This approach is also implemented in V8 (here) and acorn (here)

@JLHwung JLHwung added PR: Spec Compliance 👓 A type of pull request used for our changelog categories pkg: parser labels Dec 2, 2020
export type AwaitExpression = NodeBase & {
type: "AwaitExpression",
argument: ?Expression,
argument: Expression,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While yield is a yield expression, await is never valid and thus the argument here can not be null.

@babel-bot
Copy link
Copy Markdown
Collaborator

babel-bot commented Dec 2, 2020

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/44668/

@codesandbox-ci
Copy link
Copy Markdown

codesandbox-ci Bot commented Dec 2, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 7e186f0:

Sandbox Source
babel-repl-custom-plugin Configuration
babel-plugin-multi-config Configuration

@JLHwung JLHwung force-pushed the disallow-await-before-exponential branch from d1cf0c6 to cadadcc Compare December 3, 2020 15:43
@JLHwung JLHwung force-pushed the disallow-await-before-exponential branch from cadadcc to 7e186f0 Compare March 25, 2021 14:41
@JLHwung
Copy link
Copy Markdown
Contributor Author

JLHwung commented Mar 25, 2021

✔️

(After 3 months I have completely forgotten the context of this PR)

@JLHwung JLHwung merged commit 0067fd9 into babel:main Mar 25, 2021
@JLHwung JLHwung deleted the disallow-await-before-exponential branch March 25, 2021 15:20
@github-actions github-actions Bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Jun 25, 2021
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Jun 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: parser PR: Spec Compliance 👓 A type of pull request used for our changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants