Skip to content

Commit

Permalink
perf: scan scopeStack for once
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Jun 9, 2021
1 parent e92666f commit c9155bd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/babel-parser/src/parser/expression.js
Expand Up @@ -2415,7 +2415,7 @@ export default class ExpressionParser extends LValParser {
if (this.prodParam.hasAwait) {
this.raise(startLoc, Errors.AwaitBindingIdentifier);
return;
} else if (this.scope.inStaticBlock && !this.scope.inFunction) {
} else if (this.scope.inStaticBlock) {
this.raise(startLoc, Errors.AwaitBindingIdentifierInStaticBlock);
return;
} else {
Expand Down
15 changes: 14 additions & 1 deletion packages/babel-parser/src/util/scope.js
Expand Up @@ -65,7 +65,20 @@ 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_VAR) {
// function body, module body
return false;
}
if (flags & SCOPE_STATIC_BLOCK) {
return true;
}
if (flags & SCOPE_CLASS) {
// class property initializers
return false;
}
}
}
get inNonArrowFunction() {
return (this.currentThisScopeFlags() & SCOPE_FUNCTION) > 0;
Expand Down

0 comments on commit c9155bd

Please sign in to comment.