From 98b7dd03ab0eacbe144fca42c199a20662cd3d0a Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Thu, 12 Jun 2025 04:52:36 +0800 Subject: [PATCH] Add `checkPrivateFields: false` to acorn parser (#17594) --- src/language-js/parse/acorn.js | 6 +++++ .../__snapshots__/format.test.js.snap | 22 +------------------ .../js/classes-private-fields/format.test.js | 1 - .../__snapshots__/format.test.js.snap | 12 +--------- tests/format/js/private-in/format.test.js | 2 +- .../__snapshots__/format.test.js.snap | 8 +++---- 6 files changed, 13 insertions(+), 38 deletions(-) diff --git a/src/language-js/parse/acorn.js b/src/language-js/parse/acorn.js index 6b194e618..abe7dd12c 100644 --- a/src/language-js/parse/acorn.js +++ b/src/language-js/parse/acorn.js @@ -16,9 +16,15 @@ import { const parseOptions = { ecmaVersion: "latest", // sourceType: "module", + // onInsertedSemicolon: null, + // onTrailingComma: null, + allowReserved: true, allowReturnOutsideFunction: true, // allowImportExportEverywhere: true, + // allowAwaitOutsideFunction: null, allowSuperOutsideMethod: true, + // allowHashBang: true, + checkPrivateFields: false, locations: false, ranges: true, preserveParens: true, diff --git a/tests/format/js/classes-private-fields/__snapshots__/format.test.js.snap b/tests/format/js/classes-private-fields/__snapshots__/format.test.js.snap index 9fc05ae4e..97d8101fd 100644 --- a/tests/format/js/classes-private-fields/__snapshots__/format.test.js.snap +++ b/tests/format/js/classes-private-fields/__snapshots__/format.test.js.snap @@ -1,14 +1,4 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`optional-chaining.js [acorn] format 1`] = ` -"Private field '#x' must be declared in an enclosing class (3:13) - 1 | // https://github.com/babel/babel/pull/11669 - 2 | -> 3 | delete obj?.#x.a - | ^ - 4 | -Cause: Private field '#x' must be declared in an enclosing class (3:12)" -`; +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing exports[`optional-chaining.js [espree] format 1`] = ` "Private field '#x' must be declared in an enclosing class (3:13) @@ -20,16 +10,6 @@ exports[`optional-chaining.js [espree] format 1`] = ` Cause: Private field '#x' must be declared in an enclosing class" `; -exports[`optional-chaining.js - {"semi":false} [acorn] format 1`] = ` -"Private field '#x' must be declared in an enclosing class (3:13) - 1 | // https://github.com/babel/babel/pull/11669 - 2 | -> 3 | delete obj?.#x.a - | ^ - 4 | -Cause: Private field '#x' must be declared in an enclosing class (3:12)" -`; - exports[`optional-chaining.js - {"semi":false} [espree] format 1`] = ` "Private field '#x' must be declared in an enclosing class (3:13) 1 | // https://github.com/babel/babel/pull/11669 diff --git a/tests/format/js/classes-private-fields/format.test.js b/tests/format/js/classes-private-fields/format.test.js index 6cee9ccd6..8a7838c28 100644 --- a/tests/format/js/classes-private-fields/format.test.js +++ b/tests/format/js/classes-private-fields/format.test.js @@ -1,5 +1,4 @@ const errors = { - acorn: ["optional-chaining.js"], espree: ["optional-chaining.js"], }; runFormatTest(import.meta, ["babel"], { diff --git a/tests/format/js/private-in/__snapshots__/format.test.js.snap b/tests/format/js/private-in/__snapshots__/format.test.js.snap index a0bd23767..7d52da1b5 100644 --- a/tests/format/js/private-in/__snapshots__/format.test.js.snap +++ b/tests/format/js/private-in/__snapshots__/format.test.js.snap @@ -1,14 +1,4 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`private-in.js [acorn] format 1`] = ` -"Unexpected token (1:5) -> 1 | if (#prop in obj) { - | ^ - 2 | } - 3 | - 4 | #prop in obj; -Cause: Unexpected token (1:4)" -`; +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing exports[`private-in.js [espree] format 1`] = ` "Unexpected token #prop (1:5) diff --git a/tests/format/js/private-in/format.test.js b/tests/format/js/private-in/format.test.js index 9f8d910e6..0a93f8d29 100644 --- a/tests/format/js/private-in/format.test.js +++ b/tests/format/js/private-in/format.test.js @@ -1,3 +1,3 @@ runFormatTest(import.meta, ["babel"], { - errors: { acorn: true, espree: true }, + errors: { espree: true }, }); diff --git a/tests/format/misc/errors/js/async-await/__snapshots__/format.test.js.snap b/tests/format/misc/errors/js/async-await/__snapshots__/format.test.js.snap index 4e3f738a0..442081ec4 100644 --- a/tests/format/misc/errors/js/async-await/__snapshots__/format.test.js.snap +++ b/tests/format/misc/errors/js/async-await/__snapshots__/format.test.js.snap @@ -1,12 +1,12 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing exports[`snippet: #0 [acorn] format 1`] = ` -"Cannot use keyword 'await' outside an async function (2:20) +"Unexpected token (2:26) 1 | async function foo() { > 2 | function bar(x = await 2) {} - | ^ + | ^ 3 | } -Cause: Cannot use keyword 'await' outside an async function (2:19)" +Cause: Unexpected token (2:25)" `; exports[`snippet: #0 [acorn] format 2`] = `