Skip to content

Commit 555915b

Browse files
authored
Merge pull request #16065 from webpack/fix/issue-16054
support es2022
2 parents d4cab5b + 8bfcb69 commit 555915b

8 files changed

Lines changed: 55 additions & 7 deletions

File tree

lib/javascript/JavascriptParser.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,6 +1447,11 @@ class JavascriptParser extends Parser {
14471447
this.walkExpression(classElement.value);
14481448
this.scope.topLevelScope = wasTopLevel;
14491449
}
1450+
} else if (classElement.type === "StaticBlock") {
1451+
const wasTopLevel = this.scope.topLevelScope;
1452+
this.scope.topLevelScope = false;
1453+
this.walkBlockStatement(classElement);
1454+
this.scope.topLevelScope = wasTopLevel;
14501455
}
14511456
}
14521457
}
@@ -1903,7 +1908,7 @@ class JavascriptParser extends Parser {
19031908
!this.hooks.importSpecifier.call(
19041909
statement,
19051910
source,
1906-
specifier.imported.name,
1911+
specifier.imported.name || specifier.imported.value,
19071912
name
19081913
)
19091914
) {
@@ -1973,7 +1978,7 @@ class JavascriptParser extends Parser {
19731978
const specifier = statement.specifiers[specifierIndex];
19741979
switch (specifier.type) {
19751980
case "ExportSpecifier": {
1976-
const name = specifier.exported.name;
1981+
const name = specifier.exported.name || specifier.exported.value;
19771982
if (source) {
19781983
this.hooks.exportImportSpecifier.call(
19791984
statement,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"@webassemblyjs/ast": "1.11.1",
1111
"@webassemblyjs/wasm-edit": "1.11.1",
1212
"@webassemblyjs/wasm-parser": "1.11.1",
13-
"acorn": "^8.4.1",
13+
"acorn": "^8.7.1",
1414
"acorn-import-assertions": "^1.7.6",
1515
"browserslist": "^4.14.5",
1616
"chrome-trace-event": "^1.0.2",
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
let value = 0;
2+
const add = () => value++;
3+
4+
export { value, add }
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { "\0 add" as add } from './reexport';
2+
3+
export default class Foo {
4+
static {
5+
new Foo(add);
6+
}
7+
8+
constructor(fn) {
9+
this.#foo = fn;
10+
this.#add();
11+
}
12+
13+
#foo = undefined;
14+
15+
#add() {
16+
if (#foo in this && this.#foo) {
17+
this.#foo();
18+
}
19+
}
20+
}

test/cases/parsing/es2022/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { value, add } from "./counter";
2+
import Foo from "./es2022";
3+
4+
it("should compile and run", () => {
5+
new Foo(add);
6+
expect(value).toBe(2);
7+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { add as "\0 add" } from "./counter";
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module.exports = function(config) {
2+
// terser doesn't support static {}
3+
if (config.mode === "production") return false;
4+
5+
try {
6+
eval("class A { static {} }");
7+
return true;
8+
} catch {
9+
return false;
10+
}
11+
};

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,10 +1230,10 @@ acorn@^7.1.1, acorn@^7.4.0:
12301230
resolved "https://registry.yarnpkg.com/acorn/-/acorn-7.4.1.tgz#feaed255973d2e77555b83dbc08851a6c63520fa"
12311231
integrity sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==
12321232

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

12381238
agent-base@6:
12391239
version "6.0.2"

0 commit comments

Comments
 (0)