Skip to content
This repository was archived by the owner on Jun 23, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/referencer.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,14 @@ class Referencer extends esrecurse.Visitor {
}
}

StaticBlock(node) {
this.scopeManager.__nestClassStaticBlockScope(node);

this.visitChildren(node);

this.close(node);
}

MethodDefinition(node) {
this.visitProperty(node);
}
Expand Down
5 changes: 5 additions & 0 deletions lib/scope-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
BlockScope,
CatchScope,
ClassFieldInitializerScope,
ClassStaticBlockScope,
ClassScope,
ForScope,
FunctionExpressionNameScope,
Expand Down Expand Up @@ -228,6 +229,10 @@ class ScopeManager {
return this.__nestScope(new ClassFieldInitializerScope(this, this.__currentScope, node));
}

__nestClassStaticBlockScope(node) {
return this.__nestScope(new ClassStaticBlockScope(this, this.__currentScope, node));
}

__nestSwitchScope(node) {
return this.__nestScope(new SwitchScope(this, this.__currentScope, node));
}
Expand Down
20 changes: 17 additions & 3 deletions lib/scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ class Scope {
constructor(scopeManager, type, upperScope, block, isMethodDefinition) {

/**
* One of 'module', 'block', 'switch', 'function', 'catch', 'with', 'function', 'class', 'global'.
* One of "global", "module", "function", "function-expression-name", "block", "switch", "catch", "with", "for",
* "class", "class-field-initializer", "class-static-block".
* @member {string} Scope#type
*/
this.type = type;
Expand Down Expand Up @@ -225,7 +226,13 @@ class Scope {
* @member {Scope} Scope#variableScope
*/
this.variableScope =
(this.type === "global" || this.type === "function" || this.type === "module" || this.type === "class-field-initializer") ? this : upperScope.variableScope;
this.type === "global" ||
this.type === "module" ||
this.type === "function" ||
this.type === "class-field-initializer" ||
this.type === "class-static-block"
? this
: upperScope.variableScope;

/**
* Whether this scope is created by a FunctionExpression.
Expand Down Expand Up @@ -738,6 +745,12 @@ class ClassFieldInitializerScope extends Scope {
}
}

class ClassStaticBlockScope extends Scope {
constructor(scopeManager, upperScope, block) {
super(scopeManager, "class-static-block", upperScope, block, true);
}
}

export {
Scope,
GlobalScope,
Expand All @@ -750,7 +763,8 @@ export {
FunctionScope,
ForScope,
ClassScope,
ClassFieldInitializerScope
ClassFieldInitializerScope,
ClassStaticBlockScope
};

/* vim: set sw=4 ts=4 et tw=80 : */
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
"eslint-plugin-jsdoc": "^35.4.1",
"eslint-plugin-node": "^11.1.0",
"eslint-release": "^3.2.0",
"eslint-visitor-keys": "^3.0.0",
"espree": "^8.0.0",
"eslint-visitor-keys": "^3.1.0",
"espree": "^9.0.0",
"mocha": "^9.0.1",
"npm-license": "^0.3.3",
"rollup": "^2.52.7",
Expand Down
Loading