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:
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user