Skip to content

Commit

Permalink
fix: handle class name in properties and methods
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed May 20, 2023
1 parent b654bbd commit 0a2cef7
Showing 1 changed file with 27 additions and 20 deletions.
47 changes: 27 additions & 20 deletions lib/javascript/JavascriptParser.js
Expand Up @@ -1561,32 +1561,39 @@ class JavascriptParser extends Parser {
}
}
if (classy.body && classy.body.type === "ClassBody") {
for (const classElement of /** @type {TODO} */ (classy.body.body)) {
if (!this.hooks.classBodyElement.call(classElement, classy)) {
if (classElement.computed && classElement.key) {
this.walkExpression(classElement.key);
}
if (classElement.value) {
if (
!this.hooks.classBodyValue.call(
classElement.value,
classElement,
classy
)
) {
const scopeParams = [];
// Add class name in scope for recursive calls
if (classy.id) {
scopeParams.push(classy.id);
}
this.inFunctionScope(false, scopeParams, () => {
for (const classElement of /** @type {TODO} */ (classy.body.body)) {
if (!this.hooks.classBodyElement.call(classElement, classy)) {
if (classElement.computed && classElement.key) {
this.walkExpression(classElement.key);
}
if (classElement.value) {
if (
!this.hooks.classBodyValue.call(
classElement.value,
classElement,
classy
)
) {
const wasTopLevel = this.scope.topLevelScope;
this.scope.topLevelScope = false;
this.walkExpression(classElement.value);
this.scope.topLevelScope = wasTopLevel;
}
} else if (classElement.type === "StaticBlock") {
const wasTopLevel = this.scope.topLevelScope;
this.scope.topLevelScope = false;
this.walkExpression(classElement.value);
this.walkBlockStatement(classElement);
this.scope.topLevelScope = wasTopLevel;
}
} else if (classElement.type === "StaticBlock") {
const wasTopLevel = this.scope.topLevelScope;
this.scope.topLevelScope = false;
this.walkBlockStatement(classElement);
this.scope.topLevelScope = wasTopLevel;
}
}
}
});
}
}

Expand Down

0 comments on commit 0a2cef7

Please sign in to comment.