Skip to content

Commit

Permalink
support static block in parser
Browse files Browse the repository at this point in the history
  • Loading branch information
vankop committed Jul 18, 2022
1 parent 1132eb3 commit 12ba662
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/javascript/JavascriptParser.js
Expand Up @@ -1447,6 +1447,11 @@ class JavascriptParser extends Parser {
this.walkExpression(classElement.value);
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
4 changes: 4 additions & 0 deletions test/cases/parsing/es2022/counter.js
@@ -0,0 +1,4 @@
let value = 0;
const add = () => value++;

export { value, add }
20 changes: 20 additions & 0 deletions test/cases/parsing/es2022/es2022.js
@@ -0,0 +1,20 @@
import { add } from './counter';

export default class Foo {
static {
new Foo(add);
}

constructor(fn) {
this.#foo = fn;
this.#add();
}

#foo = undefined;

#add() {
if (#foo in this && this.#foo) {
this.#foo();
}
}
}
7 changes: 7 additions & 0 deletions test/cases/parsing/es2022/index.js
@@ -0,0 +1,7 @@
import { value, add } from "./counter";
import Foo from "./es2022";

it("should compile and run", () => {
new Foo(add);
expect(value).toBe(2);
});

0 comments on commit 12ba662

Please sign in to comment.