Fix await binding error within static block (#13088)

* fix: allow await within SCOPE_FUNCTION under static block

* perf: scan scopeStack for once

* add new test case

* chore: update allowlist
This commit is contained in:
Huáng Jùnliàng
2021-07-16 10:35:19 -04:00
committed by GitHub
parent 1c7da020e4
commit 6e57617138
15 changed files with 1198 additions and 507 deletions

View File

@@ -2385,7 +2385,7 @@ export default class ExpressionParser extends LValParser {
if (this.prodParam.hasAwait) {
this.raise(startLoc, Errors.AwaitBindingIdentifier);
return;
} else if (this.scope.inStaticBlock && !this.scope.inNonArrowFunction) {
} else if (this.scope.inStaticBlock) {
this.raise(startLoc, Errors.AwaitBindingIdentifierInStaticBlock);
return;
} else {

View File

@@ -65,7 +65,16 @@ export default class ScopeHandler<IScope: Scope = Scope> {
return (flags & SCOPE_CLASS) > 0 && (flags & SCOPE_FUNCTION) === 0;
}
get inStaticBlock() {
return (this.currentThisScopeFlags() & SCOPE_STATIC_BLOCK) > 0;
for (let i = this.scopeStack.length - 1; ; i--) {
const { flags } = this.scopeStack[i];
if (flags & SCOPE_STATIC_BLOCK) {
return true;
}
if (flags & (SCOPE_VAR | SCOPE_CLASS)) {
// function body, module body, class property initializers
return false;
}
}
}
get inNonArrowFunction() {
return (this.currentThisScopeFlags() & SCOPE_FUNCTION) > 0;