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 await binding error within static block #13088
Conversation
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/47370/ |
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 0ce8c72:
|
ce0c08f
to
ebfc550
Compare
ebfc550
to
3886970
Compare
3886970
to
c9155bd
Compare
0aeebe9
to
c116d2f
Compare
@JLHwung Why not set 'this.scope.inStaticBlock' when you enter a static block, and unset this again every time you enter function body, arrow or block statement, and then for await check if this is set and if so, throw. |
@KFlash Besides function body, arrow, we should also take care of the class field initializers. A plain block statement I think the current approach is easier to maintain because we already have to push a lexical scope for static block, so an extra mark on the scope, compacted to bit arrays, does not introduce extra recording tasks. The worst scenario of current approach is an |
@JLHwung An easy solution for this is to "copy" what the author of this proposal did. Look at the open PR for implementation of static block in the Typescript repo. |
d5b9109
to
682682c
Compare
7122dfd
to
0ce8c72
Compare
* fix: allow await within SCOPE_FUNCTION under static block * perf: scan scopeStack for once * add new test case * chore: update allowlist
This PR aligns Babel behaviour to current V8 implementation, which follows Contains Static Semantics. However since this behaviour is not specified in that way, we have ongoing discussions in tc39/proposal-class-static-block#43I will mark this PR as ready when consensus is reached.This PR implements tc39/proposal-class-static-block#46. The spec now adds
[Await]
production parameter to static block and throw if it contains (specified in SDOcontainsAwait
) AwaitExpression andfor await
. However implementing the SDOcontainsAwait
requires scan of whole AST tree, which is not performant. Babel parses the StaticBlock in[~Await]
and uses parser scopes to throw if anawait
identifier is within the static block.See
scope#inStaticBlock
for current implementation detail.