Skip to content

Commit

Permalink
Merge pull request #16065 from webpack/fix/issue-16054
Browse files Browse the repository at this point in the history
support es2022
  • Loading branch information
sokra committed Jul 25, 2022
2 parents d4cab5b + 8bfcb69 commit 555915b
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 7 deletions.
9 changes: 7 additions & 2 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 Expand Up @@ -1903,7 +1908,7 @@ class JavascriptParser extends Parser {
!this.hooks.importSpecifier.call(
statement,
source,
specifier.imported.name,
specifier.imported.name || specifier.imported.value,
name
)
) {
Expand Down Expand Up @@ -1973,7 +1978,7 @@ class JavascriptParser extends Parser {
const specifier = statement.specifiers[specifierIndex];
switch (specifier.type) {
case "ExportSpecifier": {
const name = specifier.exported.name;
const name = specifier.exported.name || specifier.exported.value;
if (source) {
this.hooks.exportImportSpecifier.call(
statement,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -10,7 +10,7 @@
"@webassemblyjs/ast": "1.11.1",
"@webassemblyjs/wasm-edit": "1.11.1",
"@webassemblyjs/wasm-parser": "1.11.1",
"acorn": "^8.4.1",
"acorn": "^8.7.1",
"acorn-import-assertions": "^1.7.6",
"browserslist": "^4.14.5",
"chrome-trace-event": "^1.0.2",
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 { "\0 add" as add } from './reexport';

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);
});
1 change: 1 addition & 0 deletions test/cases/parsing/es2022/reexport.js
@@ -0,0 +1 @@
export { add as "\0 add" } from "./counter";
11 changes: 11 additions & 0 deletions test/cases/parsing/es2022/test.filter.js
@@ -0,0 +1,11 @@
module.exports = function(config) {
// terser doesn't support static {}
if (config.mode === "production") return false;

try {
eval("class A { static {} }");
return true;
} catch {
return false;
}
};
8 changes: 4 additions & 4 deletions yarn.lock
Expand Up @@ -1230,10 +1230,10 @@ acorn@^7.1.1, acorn@^7.4.0:
resolved "https://registry.yarnpkg.com/acorn/-/acorn-7.4.1.tgz#feaed255973d2e77555b83dbc08851a6c63520fa"
integrity sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==

acorn@^8.2.4, acorn@^8.4.1:
version "8.7.0"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.7.0.tgz#90951fde0f8f09df93549481e5fc141445b791cf"
integrity sha512-V/LGr1APy+PXIwKebEWrkZPwoeoF+w1jiOBUmuxuiUIaOHtob8Qc9BTrYo7VuI5fR8tqsy+buA2WFooR5olqvQ==
acorn@^8.2.4, acorn@^8.7.1:
version "8.7.1"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.7.1.tgz#0197122c843d1bf6d0a5e83220a788f278f63c30"
integrity sha512-Xx54uLJQZ19lKygFXOWsscKUbsBZW0CPykPhVQdhIeIwrbPmJzqeASDInc8nKBnp/JT6igTs82qPXz069H8I/A==

agent-base@6:
version "6.0.2"
Expand Down

0 comments on commit 555915b

Please sign in to comment.