Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support es2022 #16065

Merged
merged 1 commit into from Jul 25, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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