diff --git a/changelog_unreleased/javascript/18611.md b/changelog_unreleased/javascript/18611.md new file mode 100644 index 000000000..b36912ace --- /dev/null +++ b/changelog_unreleased/javascript/18611.md @@ -0,0 +1,23 @@ +#### Drop support for the old "import assertions" syntax (#18611 by @fisker) + +`import assertions` (using the `assert` keyword) is an old version of the current [import attributes proposal](https://github.com/tc39/proposal-import-attributes). + +```js +// Old (deprecated) +import foo from "./foo.json" assert { type: "json" }; + +// Current standard +import foo from "./foo.json" with { type: "json" }; +``` + +Babel 8 completely removed support for the legacy `assert` syntax (the old parser plugin is gone). +Without Babel parser support, Prettier can no longer reliably parse or format code using `import ... assert { ... }`. + +Please migrate to the `with` syntax. + +```diff +- import foo from "./foo.json" assert { type: "json" }; ++ import foo from "./foo.json" with { type: "json" }; +``` + +See also Prettier's [disclaimer about non-standard syntax](https://prettier.io/docs/rationale.html#disclaimer-about-non-standard-syntax). diff --git a/package.json b/package.json index cdf627be6..caafc79d0 100644 --- a/package.json +++ b/package.json @@ -43,9 +43,9 @@ ], "dependencies": { "@angular/compiler": "21.1.0", - "@babel/code-frame": "8.0.0-beta.3", - "@babel/parser": "8.0.0-beta.3", - "@babel/types": "8.0.0-beta.3", + "@babel/code-frame": "8.0.0-beta.4", + "@babel/parser": "8.0.0-beta.4", + "@babel/types": "8.0.0-beta.4", "@glimmer/syntax": "0.95.0", "@prettier/cli": "0.10.0", "@prettier/html-event-attributes": "0.0.1", @@ -135,7 +135,7 @@ "yaml-unist-parser": "2.2.1" }, "devDependencies": { - "@babel/generator": "8.0.0-beta.3", + "@babel/generator": "8.0.0-beta.4", "@eslint/js": "9.39.2", "@stylistic/eslint-plugin": "5.6.1", "@types/jsesc": "3.0.3", diff --git a/scripts/nodejs-14-test-loader.js b/scripts/nodejs-14-test-loader.js index b3cb380e0..d577b6d16 100644 --- a/scripts/nodejs-14-test-loader.js +++ b/scripts/nodejs-14-test-loader.js @@ -8,19 +8,29 @@ import esbuild from "esbuild"; // We can use an `--experimental-loader` to compile them on-the-fly with esbuild. export async function getSource(url, context, defaultGetSource) { - if ( - !/node_modules\/@babel\/(?:code-frame|highlight)/.test(url) || - context.format !== "module" - ) { - return defaultGetSource(url, context, defaultGetSource); + if (context.format === "module") { + if (url.includes("/node_modules/js-tokens/")) { + const text = await readFile(fileURLToPath(url), "utf8"); + const commonJsExport = 'export { jsTokens as "module.exports" };'; + if (text.includes(commonJsExport)) { + return { source: text.replace(commonJsExport, "") }; + } + } + + if ( + url.includes("/node_modules/@babel/code-frame/") || + url.includes("/node_modules/@babel/highlight/") + ) { + const raw = await readFile(fileURLToPath(url)); + try { + const result = await esbuild.transform(raw, { target: "node14" }); + return { source: result.code }; + } catch (error) { + error.message += ` (in ${url})`; + throw error; + } + } } - const raw = await readFile(fileURLToPath(url)); - try { - const result = await esbuild.transform(raw, { target: "node14" }); - return { source: result.code }; - } catch (error) { - error.message += ` (in ${url})`; - throw error; - } + return defaultGetSource(url, context, defaultGetSource); } diff --git a/src/language-js/parse/babel.js b/src/language-js/parse/babel.js index 5693ce601..7e6c7cd43 100644 --- a/src/language-js/parse/babel.js +++ b/src/language-js/parse/babel.js @@ -212,15 +212,6 @@ const allowedReasonCodes = new Set([ "InvalidPrivateFieldResolution", "DuplicateExport", - /* - Legacy syntax - - ```js - import json from "./json.json" assert {type: "json"}; - ``` - */ - "ImportAttributesUseAssert", - /* Allow const without initializer in `.d.ts` files https://github.com/prettier/prettier/issues/17649 diff --git a/src/language-js/parse/postprocess/index.js b/src/language-js/parse/postprocess/index.js index 03191e92c..08fa714b9 100644 --- a/src/language-js/parse/postprocess/index.js +++ b/src/language-js/parse/postprocess/index.js @@ -151,7 +151,9 @@ function postprocess(ast, options) { // For hack-style pipeline case "TopicReference": ast.extra = { ...ast.extra, __isUsingHackPipeline: true }; - break; // In Flow parser, it doesn't generate union/intersection types for single type + break; + + // In Flow parser, it doesn't generate union/intersection types for single type case "TSUnionType": case "TSIntersectionType": if (node.types.length === 1) { @@ -159,10 +161,9 @@ function postprocess(ast, options) { } break; - // https://github.com/facebook/hermes/issues/1712 - case "ImportExpression": - if (parser === "hermes" && node.attributes && !node.options) { - node.options = node.attributes; + case "ImportDeclaration": + if (parser === "hermes" && node.assertions && !node.attributes) { + node.attributes = node.assertions; } break; @@ -183,15 +184,6 @@ function postprocess(ast, options) { return rebalanceLogicalTree(node); } break; - - // https://github.com/babel/babel/issues/17506 - // It's possible to have parenthesized `argument`, need do this in `onLeave` - case "TSImportType": - if (!node.source && node.argument.type === "TSLiteralType") { - node.source = node.argument.literal; - delete node.argument; - } - break; } /* c8 ignore next 3 */ diff --git a/src/language-js/print/module.js b/src/language-js/print/module.js index 648b9c3bb..41da353cf 100644 --- a/src/language-js/print/module.js +++ b/src/language-js/print/module.js @@ -254,11 +254,6 @@ function shouldPrintSpecifiers(node, options) { } function getImportAttributesKeyword(node, options) { - // Babel parser add this property to indicate the keyword is `assert` - if (node.extra?.deprecatedAssertSyntax) { - return "assert"; - } - const textBetweenSourceAndAttributes = getTextWithoutComments( options, locEnd(node.source), diff --git a/src/language-js/traverse/visitor-keys.evaluate.js b/src/language-js/traverse/visitor-keys.evaluate.js index 9869179e9..50f079c80 100644 --- a/src/language-js/traverse/visitor-keys.evaluate.js +++ b/src/language-js/traverse/visitor-keys.evaluate.js @@ -38,16 +38,9 @@ const excludeVisitorKeys = { // Flow node from Babel TupleTypeAnnotation: ["types"], - - // https://github.com/babel/babel/issues/17506 - TSImportType: ["argument"], }; -// https://github.com/babel/babel/issues/17524 const excludeNodeTypes = [ - // Babel will remove in v8 - // https://github.com/babel/babel/pull/17242 - "TupleExpression", // Babel, Won't exist since we use `createImportExpressions` when parsing with babel "Import", diff --git a/tests/config/utilities/check-parsers.js b/tests/config/utilities/check-parsers.js index 7673cd70f..3a8dbb27c 100644 --- a/tests/config/utilities/check-parsers.js +++ b/tests/config/utilities/check-parsers.js @@ -57,7 +57,7 @@ const categoryParsers = new Map([ [ "js", { - parsers: ["babel", "acorn", "espree", "meriyah", "oxc", "oxc-ts"], + parsers: ["babel", "acorn", "espree", "meriyah", "oxc"], verifyParsers: [ "babel", "acorn", @@ -69,6 +69,7 @@ const categoryParsers = new Map([ "babel-flow", "typescript", "babel-ts", + "hermes", ], extensions: [".js", ".cjs", ".mjs"], }, diff --git a/tests/format/js/babel-plugins/__snapshots__/format.test.js.snap b/tests/format/js/babel-plugins/__snapshots__/format.test.js.snap index fb1323814..547da233a 100644 --- a/tests/format/js/babel-plugins/__snapshots__/format.test.js.snap +++ b/tests/format/js/babel-plugins/__snapshots__/format.test.js.snap @@ -1247,44 +1247,6 @@ import("./foo.json", { assert: { type: "json" } }); ================================================================================ `; -exports[`import-assertions-static.js [acorn] format 1`] = ` -"Unexpected token (1:31) -> 1 | import json from "./foo.json" assert { type: "json" }; - | ^ - 2 | -Cause: Unexpected token (1:30)" -`; - -exports[`import-assertions-static.js [espree] format 1`] = ` -"Unexpected token assert (1:31) -> 1 | import json from "./foo.json" assert { type: "json" }; - | ^ - 2 | -Cause: Unexpected token assert" -`; - -exports[`import-assertions-static.js [meriyah] format 1`] = ` -"Unexpected token: 'identifier' (1:31) -> 1 | import json from "./foo.json" assert { type: "json" }; - | ^^^^^^ - 2 | -Cause: [1:30-1:36]: Unexpected token: 'identifier'" -`; - -exports[`import-assertions-static.js format 1`] = ` -====================================options===================================== -parsers: ["babel", "babel-ts", "babel-flow"] -printWidth: 80 - | printWidth -=====================================input====================================== -import json from "./foo.json" assert { type: "json" }; - -=====================================output===================================== -import json from "./foo.json" assert { type: "json" }; - -================================================================================ -`; - exports[`import-attributes-dynamic.js format 1`] = ` ====================================options===================================== parsers: ["babel", "babel-ts", "babel-flow"] diff --git a/tests/format/js/babel-plugins/format.test.js b/tests/format/js/babel-plugins/format.test.js index 438e34a0b..15206ad89 100644 --- a/tests/format/js/babel-plugins/format.test.js +++ b/tests/format/js/babel-plugins/format.test.js @@ -11,7 +11,6 @@ runFormatTest(import.meta, ["babel", "babel-ts", "babel-flow"], { "flow.js", "function-bind.js", "function-sent.js", - "import-assertions-static.js", "partial-application.js", "pipeline-operator-fsharp.js", "pipeline-operator-minimal.js", @@ -35,7 +34,6 @@ runFormatTest(import.meta, ["babel", "babel-ts", "babel-flow"], { "flow.js", "function-bind.js", "function-sent.js", - "import-assertions-static.js", "partial-application.js", "pipeline-operator-fsharp.js", "pipeline-operator-minimal.js", @@ -67,7 +65,6 @@ runFormatTest(import.meta, ["babel", "babel-ts", "babel-flow"], { "throw-expressions.js", "typescript.js", "v8intrinsic.js", - "import-assertions-static.js", "module-blocks.js", "async-do-expressions.js", "explicit-resource-management.js", diff --git a/tests/format/js/babel-plugins/import-assertions-static.js b/tests/format/js/babel-plugins/import-assertions-static.js deleted file mode 100644 index 890e42900..000000000 --- a/tests/format/js/babel-plugins/import-assertions-static.js +++ /dev/null @@ -1 +0,0 @@ -import json from "./foo.json" assert { type: "json" }; diff --git a/tests/format/js/import-assertions/__snapshots__/format.test.js.snap b/tests/format/js/import-assertions/__snapshots__/format.test.js.snap index 3e1ad8cc6..a84bb05e3 100644 --- a/tests/format/js/import-assertions/__snapshots__/format.test.js.snap +++ b/tests/format/js/import-assertions/__snapshots__/format.test.js.snap @@ -2,7 +2,7 @@ exports[`dynamic-import.js format 1`] = ` ====================================options===================================== -parsers: ["babel", "typescript"] +parsers: ["oxc", "typescript", "hermes"] printWidth: 80 | printWidth =====================================input====================================== @@ -14,42 +14,33 @@ import("./foo.json", { assert: { type: "json" } }); ================================================================================ `; -exports[`empty.js [acorn] format 1`] = ` -"Unexpected token (2:33) +exports[`empty.js [babel-ts] format 1`] = ` +"Missing semicolon. (2:32) 1 | export * as foo from "foo.json" > 2 | export * as bar from "bar.json" assert { } - | ^ + | ^ 3 | export * as baz from "baz.json" assert { /* comment */ } 4 | 5 | import * as foo from "foo.json" -Cause: Unexpected token (2:32)" +Cause: Missing semicolon. (2:31)" `; -exports[`empty.js [espree] format 1`] = ` -"Unexpected token assert (2:33) +exports[`empty.js [hermes] format 1`] = ` +"';' expected (2:32) 1 | export * as foo from "foo.json" > 2 | export * as bar from "bar.json" assert { } - | ^ + | ^ 3 | export * as baz from "baz.json" assert { /* comment */ } 4 | 5 | import * as foo from "foo.json" -Cause: Unexpected token assert" -`; - -exports[`empty.js [meriyah] format 1`] = ` -"Unexpected token: 'identifier' (2:33) - 1 | export * as foo from "foo.json" -> 2 | export * as bar from "bar.json" assert { } - | ^^^^^^ - 3 | export * as baz from "baz.json" assert { /* comment */ } - 4 | - 5 | import * as foo from "foo.json" -Cause: [2:32-2:38]: Unexpected token: 'identifier'" +Cause: ';' expected (2:32) +export * as bar from "bar.json" assert { } + ^" `; exports[`empty.js format 1`] = ` ====================================options===================================== -parsers: ["babel", "typescript"] +parsers: ["oxc", "typescript", "hermes"] printWidth: 80 | printWidth =====================================input====================================== @@ -72,39 +63,33 @@ import * as baz from "baz.json" /* comment */ assert {}; ================================================================================ `; -exports[`keyword-detect.js [acorn] format 1`] = ` -"Unexpected token (1:33) +exports[`keyword-detect.js [babel-ts] format 1`] = ` +"Missing semicolon. (1:21) > 1 | import "./test.json" /* with */ assert /* with */ { type: "json" } - | ^ + | ^ 2 | import {default as b} from "./test.json" /* with */ assert /* with */ { type: "json" } 3 | 4 | export {default as e} from "./test.json" /* with */ assert /* with */ { type: "json" } -Cause: Unexpected token (1:32)" +Cause: Missing semicolon. (1:20)" `; -exports[`keyword-detect.js [espree] format 1`] = ` -"Unexpected token assert (1:33) -> 1 | import "./test.json" /* with */ assert /* with */ { type: "json" } - | ^ +exports[`keyword-detect.js [hermes] format 1`] = ` +"';' expected (4:52) 2 | import {default as b} from "./test.json" /* with */ assert /* with */ { type: "json" } 3 | - 4 | export {default as e} from "./test.json" /* with */ assert /* with */ { type: "json" } -Cause: Unexpected token assert" -`; - -exports[`keyword-detect.js [meriyah] format 1`] = ` -"Unexpected token: 'identifier' (1:33) -> 1 | import "./test.json" /* with */ assert /* with */ { type: "json" } - | ^^^^^^ - 2 | import {default as b} from "./test.json" /* with */ assert /* with */ { type: "json" } - 3 | - 4 | export {default as e} from "./test.json" /* with */ assert /* with */ { type: "json" } -Cause: [1:32-1:38]: Unexpected token: 'identifier'" +> 4 | export {default as e} from "./test.json" /* with */ assert /* with */ { type: "json" } + | ^ + 5 | + 6 | export * from "./test.json" /* with */ assert /* with */ { type: "json" } + 7 | +Cause: ';' expected (4:52) +export {default as e} from "./test.json" /* with */ assert /* with */ { type: "json" } + ^" `; exports[`keyword-detect.js format 1`] = ` ====================================options===================================== -parsers: ["babel", "typescript"] +parsers: ["oxc", "typescript", "hermes"] printWidth: 80 | printWidth =====================================input====================================== @@ -126,33 +111,17 @@ export * from "./test.json" /* with */ /* with */ assert { type: "json" }; ================================================================================ `; -exports[`multi-types.js [acorn] format 1`] = ` -"Unexpected token (1:31) +exports[`multi-types.js [babel-ts] format 1`] = ` +"Unexpected token (1:58) > 1 | import json from "./foo.json" assert { type: "json", type: "bar" }; - | ^ + | ^ 2 | -Cause: Unexpected token (1:30)" -`; - -exports[`multi-types.js [espree] format 1`] = ` -"Unexpected token assert (1:31) -> 1 | import json from "./foo.json" assert { type: "json", type: "bar" }; - | ^ - 2 | -Cause: Unexpected token assert" -`; - -exports[`multi-types.js [meriyah] format 1`] = ` -"Unexpected token: 'identifier' (1:31) -> 1 | import json from "./foo.json" assert { type: "json", type: "bar" }; - | ^^^^^^ - 2 | -Cause: [1:30-1:36]: Unexpected token: 'identifier'" +Cause: Unexpected token (1:57)" `; exports[`multi-types.js format 1`] = ` ====================================options===================================== -parsers: ["babel", "typescript"] +parsers: ["oxc", "typescript", "hermes"] printWidth: 80 | printWidth =====================================input====================================== @@ -164,33 +133,17 @@ import json from "./foo.json" assert { type: "json", type: "bar" }; ================================================================================ `; -exports[`non-type.js [acorn] format 1`] = ` -"Unexpected token (1:28) +exports[`non-type.js [babel-ts] format 1`] = ` +"Missing semicolon. (1:27) > 1 | import foo from "foo.json" assert { lazy: "true" }; - | ^ + | ^ 2 | -Cause: Unexpected token (1:27)" -`; - -exports[`non-type.js [espree] format 1`] = ` -"Unexpected token assert (1:28) -> 1 | import foo from "foo.json" assert { lazy: "true" }; - | ^ - 2 | -Cause: Unexpected token assert" -`; - -exports[`non-type.js [meriyah] format 1`] = ` -"Unexpected token: 'identifier' (1:28) -> 1 | import foo from "foo.json" assert { lazy: "true" }; - | ^^^^^^ - 2 | -Cause: [1:27-1:33]: Unexpected token: 'identifier'" +Cause: Missing semicolon. (1:26)" `; exports[`non-type.js format 1`] = ` ====================================options===================================== -parsers: ["babel", "typescript"] +parsers: ["oxc", "typescript", "hermes"] printWidth: 80 | printWidth =====================================input====================================== @@ -204,7 +157,7 @@ import foo from "foo.json" assert { lazy: "true" }; exports[`not-import-assertions.js format 1`] = ` ====================================options===================================== -parsers: ["babel", "typescript"] +parsers: ["oxc", "typescript", "hermes"] printWidth: 80 | printWidth =====================================input====================================== @@ -218,39 +171,31 @@ assert({ type: "json" }); ================================================================================ `; -exports[`re-export.js [acorn] format 1`] = ` -"Unexpected token (1:44) +exports[`re-export.js [babel-ts] format 1`] = ` +"Missing semicolon. (1:43) > 1 | export { default as foo2 } from "foo.json" assert { type: "json" }; - | ^ + | ^ 2 | export * from "foo.json" assert { type: "json" }; 3 | export * as foo3 from "foo.json" assert { type: "json" }; 4 | -Cause: Unexpected token (1:43)" +Cause: Missing semicolon. (1:42)" `; -exports[`re-export.js [espree] format 1`] = ` -"Unexpected token assert (1:44) +exports[`re-export.js [hermes] format 1`] = ` +"';' expected (1:43) > 1 | export { default as foo2 } from "foo.json" assert { type: "json" }; - | ^ + | ^ 2 | export * from "foo.json" assert { type: "json" }; 3 | export * as foo3 from "foo.json" assert { type: "json" }; 4 | -Cause: Unexpected token assert" -`; - -exports[`re-export.js [meriyah] format 1`] = ` -"Unexpected token: 'identifier' (1:44) -> 1 | export { default as foo2 } from "foo.json" assert { type: "json" }; - | ^^^^^^ - 2 | export * from "foo.json" assert { type: "json" }; - 3 | export * as foo3 from "foo.json" assert { type: "json" }; - 4 | -Cause: [1:43-1:49]: Unexpected token: 'identifier'" +Cause: ';' expected (1:43) +export { default as foo2 } from "foo.json" assert { type: "json" }; + ^" `; exports[`re-export.js format 1`] = ` ====================================options===================================== -parsers: ["babel", "typescript"] +parsers: ["oxc", "typescript", "hermes"] printWidth: 80 | printWidth =====================================input====================================== @@ -266,33 +211,17 @@ export * as foo3 from "foo.json" assert { type: "json" }; ================================================================================ `; -exports[`static-import.js [acorn] format 1`] = ` -"Unexpected token (1:31) +exports[`static-import.js [babel-ts] format 1`] = ` +"Missing semicolon. (1:30) > 1 | import json from "./foo.json" assert { type: "json" }; - | ^ + | ^ 2 | -Cause: Unexpected token (1:30)" -`; - -exports[`static-import.js [espree] format 1`] = ` -"Unexpected token assert (1:31) -> 1 | import json from "./foo.json" assert { type: "json" }; - | ^ - 2 | -Cause: Unexpected token assert" -`; - -exports[`static-import.js [meriyah] format 1`] = ` -"Unexpected token: 'identifier' (1:31) -> 1 | import json from "./foo.json" assert { type: "json" }; - | ^^^^^^ - 2 | -Cause: [1:30-1:36]: Unexpected token: 'identifier'" +Cause: Missing semicolon. (1:29)" `; exports[`static-import.js format 1`] = ` ====================================options===================================== -parsers: ["babel", "typescript"] +parsers: ["oxc", "typescript", "hermes"] printWidth: 80 | printWidth =====================================input====================================== @@ -304,33 +233,17 @@ import json from "./foo.json" assert { type: "json" }; ================================================================================ `; -exports[`without-from.js [acorn] format 1`] = ` -"Unexpected token (1:14) +exports[`without-from.js [babel-ts] format 1`] = ` +"Missing semicolon. (1:13) > 1 | import "foo" assert { type: "json" } - | ^ + | ^ 2 | -Cause: Unexpected token (1:13)" -`; - -exports[`without-from.js [espree] format 1`] = ` -"Unexpected token assert (1:14) -> 1 | import "foo" assert { type: "json" } - | ^ - 2 | -Cause: Unexpected token assert" -`; - -exports[`without-from.js [meriyah] format 1`] = ` -"Unexpected token: 'identifier' (1:14) -> 1 | import "foo" assert { type: "json" } - | ^^^^^^ - 2 | -Cause: [1:13-1:19]: Unexpected token: 'identifier'" +Cause: Missing semicolon. (1:12)" `; exports[`without-from.js format 1`] = ` ====================================options===================================== -parsers: ["babel", "typescript"] +parsers: ["oxc", "typescript", "hermes"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/js/import-assertions/bracket-spacing/__snapshots__/format.test.js.snap b/tests/format/js/import-assertions/bracket-spacing/__snapshots__/format.test.js.snap index 50a8d2f20..4859d0cc9 100644 --- a/tests/format/js/import-assertions/bracket-spacing/__snapshots__/format.test.js.snap +++ b/tests/format/js/import-assertions/bracket-spacing/__snapshots__/format.test.js.snap @@ -3,7 +3,7 @@ exports[`dynamic-import.js - {"bracketSpacing":false} format 1`] = ` ====================================options===================================== bracketSpacing: false -parsers: ["babel"] +parsers: ["oxc", "typescript", "hermes"] printWidth: 80 | printWidth =====================================input====================================== @@ -15,31 +15,26 @@ import("./foo.json", {assert: {type: "json"}}); ================================================================================ `; -exports[`empty.js - {"bracketSpacing":false} [acorn] format 1`] = ` -"Unexpected token (1:33) +exports[`empty.js - {"bracketSpacing":false} [babel-ts] format 1`] = ` +"Missing semicolon. (1:32) > 1 | export * as bar from "bar.json" assert { } - | ^ -Cause: Unexpected token (1:32)" + | ^ +Cause: Missing semicolon. (1:31)" `; -exports[`empty.js - {"bracketSpacing":false} [espree] format 1`] = ` -"Unexpected token assert (1:33) +exports[`empty.js - {"bracketSpacing":false} [hermes] format 1`] = ` +"';' expected (1:32) > 1 | export * as bar from "bar.json" assert { } - | ^ -Cause: Unexpected token assert" -`; - -exports[`empty.js - {"bracketSpacing":false} [meriyah] format 1`] = ` -"Unexpected token: 'identifier' (1:33) -> 1 | export * as bar from "bar.json" assert { } - | ^^^^^^ -Cause: [1:32-1:38]: Unexpected token: 'identifier'" + | ^ +Cause: ';' expected (1:32) +export * as bar from "bar.json" assert { } + ^" `; exports[`empty.js - {"bracketSpacing":false} format 1`] = ` ====================================options===================================== bracketSpacing: false -parsers: ["babel"] +parsers: ["oxc", "typescript", "hermes"] printWidth: 80 | printWidth =====================================input====================================== @@ -50,34 +45,28 @@ export * as bar from "bar.json" assert {}; ================================================================================ `; -exports[`re-export.js - {"bracketSpacing":false} [acorn] format 1`] = ` -"Unexpected token (1:44) +exports[`re-export.js - {"bracketSpacing":false} [babel-ts] format 1`] = ` +"Missing semicolon. (1:43) > 1 | export { default as foo2 } from "foo.json" assert { type: "json" }; - | ^ + | ^ 2 | -Cause: Unexpected token (1:43)" +Cause: Missing semicolon. (1:42)" `; -exports[`re-export.js - {"bracketSpacing":false} [espree] format 1`] = ` -"Unexpected token assert (1:44) +exports[`re-export.js - {"bracketSpacing":false} [hermes] format 1`] = ` +"';' expected (1:43) > 1 | export { default as foo2 } from "foo.json" assert { type: "json" }; - | ^ + | ^ 2 | -Cause: Unexpected token assert" -`; - -exports[`re-export.js - {"bracketSpacing":false} [meriyah] format 1`] = ` -"Unexpected token: 'identifier' (1:44) -> 1 | export { default as foo2 } from "foo.json" assert { type: "json" }; - | ^^^^^^ - 2 | -Cause: [1:43-1:49]: Unexpected token: 'identifier'" +Cause: ';' expected (1:43) +export { default as foo2 } from "foo.json" assert { type: "json" }; + ^" `; exports[`re-export.js - {"bracketSpacing":false} format 1`] = ` ====================================options===================================== bracketSpacing: false -parsers: ["babel"] +parsers: ["oxc", "typescript", "hermes"] printWidth: 80 | printWidth =====================================input====================================== @@ -89,34 +78,18 @@ export {default as foo2} from "foo.json" assert {type: "json"}; ================================================================================ `; -exports[`static-import.js - {"bracketSpacing":false} [acorn] format 1`] = ` -"Unexpected token (1:31) +exports[`static-import.js - {"bracketSpacing":false} [babel-ts] format 1`] = ` +"Missing semicolon. (1:30) > 1 | import json from "./foo.json" assert { type: "json" }; - | ^ + | ^ 2 | -Cause: Unexpected token (1:30)" -`; - -exports[`static-import.js - {"bracketSpacing":false} [espree] format 1`] = ` -"Unexpected token assert (1:31) -> 1 | import json from "./foo.json" assert { type: "json" }; - | ^ - 2 | -Cause: Unexpected token assert" -`; - -exports[`static-import.js - {"bracketSpacing":false} [meriyah] format 1`] = ` -"Unexpected token: 'identifier' (1:31) -> 1 | import json from "./foo.json" assert { type: "json" }; - | ^^^^^^ - 2 | -Cause: [1:30-1:36]: Unexpected token: 'identifier'" +Cause: Missing semicolon. (1:29)" `; exports[`static-import.js - {"bracketSpacing":false} format 1`] = ` ====================================options===================================== bracketSpacing: false -parsers: ["babel"] +parsers: ["oxc", "typescript", "hermes"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/js/import-assertions/bracket-spacing/format.test.js b/tests/format/js/import-assertions/bracket-spacing/format.test.js index 22128e084..38e1da333 100644 --- a/tests/format/js/import-assertions/bracket-spacing/format.test.js +++ b/tests/format/js/import-assertions/bracket-spacing/format.test.js @@ -1,8 +1,7 @@ -runFormatTest(import.meta, ["babel"], { +runFormatTest(import.meta, ["oxc", "typescript", "hermes"], { bracketSpacing: false, errors: { - acorn: ["static-import.js", "re-export.js", "empty.js"], - espree: ["static-import.js", "re-export.js", "empty.js"], - meriyah: ["static-import.js", "re-export.js", "empty.js"], + "babel-ts": ["static-import.js", "re-export.js", "empty.js"], + hermes: ["empty.js", "re-export.js"], }, }); diff --git a/tests/format/js/import-assertions/format.test.js b/tests/format/js/import-assertions/format.test.js index 65202051a..2cf6fe4bc 100644 --- a/tests/format/js/import-assertions/format.test.js +++ b/tests/format/js/import-assertions/format.test.js @@ -1,24 +1,6 @@ -runFormatTest(import.meta, ["babel", "typescript"], { +runFormatTest(import.meta, ["oxc", "typescript", "hermes"], { errors: { - acorn: [ - "empty.js", - "multi-types.js", - "static-import.js", - "re-export.js", - "without-from.js", - "non-type.js", - "keyword-detect.js", - ], - espree: [ - "empty.js", - "multi-types.js", - "static-import.js", - "re-export.js", - "without-from.js", - "non-type.js", - "keyword-detect.js", - ], - meriyah: [ + "babel-ts": [ "empty.js", "multi-types.js", "static-import.js", @@ -27,5 +9,6 @@ runFormatTest(import.meta, ["babel", "typescript"], { "non-type.js", "keyword-detect.js", ], + hermes: ["keyword-detect.js", "empty.js", "re-export.js"], }, }); diff --git a/tests/format/misc/errors/js/__snapshots__/format.test.js.snap b/tests/format/misc/errors/js/__snapshots__/format.test.js.snap index ac62dacba..e76caa372 100644 --- a/tests/format/misc/errors/js/__snapshots__/format.test.js.snap +++ b/tests/format/misc/errors/js/__snapshots__/format.test.js.snap @@ -12,22 +12,6 @@ exports[`html-like-comments.js [babel] format 1`] = ` Cause: Unexpected token (3:0)" `; -exports[`import-assertions-for-export-without-from.js [babel] format 1`] = ` -"Missing semicolon. (1:26) -> 1 | export { default as foo } assert { type: "json" }; - | ^ - 2 | -Cause: Missing semicolon. (1:25)" -`; - -exports[`import-assertions-with-parens.js [babel] format 1`] = ` -"Unexpected token, expected "{" (1:19) -> 1 | import "x" assert ({type: 'json'}); - | ^ - 2 | -Cause: Unexpected token, expected "{" (1:18)" -`; - exports[`import-attributes-for-export-without-from.js [babel] format 1`] = ` "Unexpected token, expected "(" (1:32) > 1 | export { default as foo } with { type: "json" }; @@ -166,24 +150,24 @@ Cause: Unexpected token (1:1)" `; exports[`snippet: #10 [babel] format 1`] = ` -"Invalid decimal. (1:1) +"Identifier directly after number. (1:12) > 1 | 0b101011101m; - | ^ -Cause: Invalid decimal. (1:0)" + | ^ +Cause: Identifier directly after number. (1:11)" `; exports[`snippet: #11 [babel] format 1`] = ` -"Invalid decimal. (1:1) +"Identifier directly after number. (1:8) > 1 | 0x16432m; - | ^ -Cause: Invalid decimal. (1:0)" + | ^ +Cause: Identifier directly after number. (1:7)" `; exports[`snippet: #12 [babel] format 1`] = ` -"Invalid decimal. (1:1) +"Identifier directly after number. (1:8) > 1 | 0o16432m; - | ^ -Cause: Invalid decimal. (1:0)" + | ^ +Cause: Identifier directly after number. (1:7)" `; exports[`static-import-source-should-not-has-extra-token.js [babel] format 1`] = ` diff --git a/tests/format/misc/errors/js/import-assertions-for-export-without-from.js b/tests/format/misc/errors/js/import-assertions-for-export-without-from.js deleted file mode 100644 index 6c36a8437..000000000 --- a/tests/format/misc/errors/js/import-assertions-for-export-without-from.js +++ /dev/null @@ -1 +0,0 @@ -export { default as foo } assert { type: "json" }; diff --git a/tests/format/misc/errors/js/import-assertions-with-parens.js b/tests/format/misc/errors/js/import-assertions-with-parens.js deleted file mode 100644 index f20676b37..000000000 --- a/tests/format/misc/errors/js/import-assertions-with-parens.js +++ /dev/null @@ -1 +0,0 @@ -import "x" assert ({type: 'json'}); diff --git a/yarn.lock b/yarn.lock index 5e5330f5e..eed2a6c00 100644 --- a/yarn.lock +++ b/yarn.lock @@ -23,14 +23,14 @@ __metadata: languageName: node linkType: hard -"@babel/code-frame@npm:8.0.0-beta.3": - version: 8.0.0-beta.3 - resolution: "@babel/code-frame@npm:8.0.0-beta.3" +"@babel/code-frame@npm:8.0.0-beta.4": + version: 8.0.0-beta.4 + resolution: "@babel/code-frame@npm:8.0.0-beta.4" dependencies: - "@babel/helper-validator-identifier": "npm:^8.0.0-beta.3" - js-tokens: "npm:^8.0.0" + "@babel/helper-validator-identifier": "npm:^8.0.0-beta.4" + js-tokens: "npm:^10.0.0" picocolors: "npm:^1.1.1" - checksum: 10/64a99c5a31e11bdebac002db93ef0484b766165d841f966fcd03657ddc86a764e80ccdb8375e6b950ab0ecf4eac5ee2812866f4fee8a15da1d0ce7ca5b4e3329 + checksum: 10/11bfcf81136ee40a4ed74e9ed363c798415196b0ca5b1636364819f0fcb2425ef729732536f0145a75d8db3297f2ea7913a17e331ba29cc3d3775967bc9fb4e4 languageName: node linkType: hard @@ -75,17 +75,17 @@ __metadata: languageName: node linkType: hard -"@babel/generator@npm:8.0.0-beta.3": - version: 8.0.0-beta.3 - resolution: "@babel/generator@npm:8.0.0-beta.3" +"@babel/generator@npm:8.0.0-beta.4": + version: 8.0.0-beta.4 + resolution: "@babel/generator@npm:8.0.0-beta.4" dependencies: - "@babel/parser": "npm:^8.0.0-beta.3" - "@babel/types": "npm:^8.0.0-beta.3" + "@babel/parser": "npm:^8.0.0-beta.4" + "@babel/types": "npm:^8.0.0-beta.4" "@jridgewell/gen-mapping": "npm:^0.3.12" "@jridgewell/trace-mapping": "npm:^0.3.28" "@types/jsesc": "npm:^2.5.0" jsesc: "npm:^3.0.2" - checksum: 10/949c6fce42edccc30950ac1370162426e9750be122c078da07d029d065b4da18b21f362b2c944543ef57ffcc62827be9612c20c97aa3b6aa5bf95e199598d547 + checksum: 10/79a2130a454f43f80c4d4289eaa3b83afd7ed27e62878c0b070108ee321a3602e3edbcff213a80b16c2b0a7913ef3150ccb14cef3cdccc155c296d0fbb96cac6 languageName: node linkType: hard @@ -159,10 +159,10 @@ __metadata: languageName: node linkType: hard -"@babel/helper-string-parser@npm:^8.0.0-beta.3": - version: 8.0.0-beta.3 - resolution: "@babel/helper-string-parser@npm:8.0.0-beta.3" - checksum: 10/c3f172fc4724ee0ed3c1fc14daa8840a12592cbb7dce77d82beee5eed7598ac827a3c3f2f52691e9607d23a02c0824228f17d1f48621e5ecbec38b1154dd0117 +"@babel/helper-string-parser@npm:^8.0.0-beta.4": + version: 8.0.0-beta.4 + resolution: "@babel/helper-string-parser@npm:8.0.0-beta.4" + checksum: 10/39fe9a7a2fcb7418d40248e515e7e40bc63a9f4320d7dc5e748094fa96cc20646a4e48e8492d507bdefcb94c558fefeb4acdc29cd510a1fd87c7a33f3f77d0d7 languageName: node linkType: hard @@ -173,10 +173,10 @@ __metadata: languageName: node linkType: hard -"@babel/helper-validator-identifier@npm:^8.0.0-beta.3": - version: 8.0.0-beta.3 - resolution: "@babel/helper-validator-identifier@npm:8.0.0-beta.3" - checksum: 10/0953ca90fa0657d6cc60653a95cdbbac89696784087e571d77d8e6f91d26a56aa98f5bbca856c992d216bf615f07fb934a640d93eab87fcbc714e4aa19fda5bd +"@babel/helper-validator-identifier@npm:^8.0.0-beta.4": + version: 8.0.0-beta.4 + resolution: "@babel/helper-validator-identifier@npm:8.0.0-beta.4" + checksum: 10/f011422956084af1f4ce51a1453083b77b20abb48eb95aef33df52d3328460c95848aaa92e59b618a9f334f58fb50d27f3fd66235fbfdd77e0a382c2a9aa650c languageName: node linkType: hard @@ -209,14 +209,14 @@ __metadata: languageName: node linkType: hard -"@babel/parser@npm:8.0.0-beta.3, @babel/parser@npm:^8.0.0-beta.3": - version: 8.0.0-beta.3 - resolution: "@babel/parser@npm:8.0.0-beta.3" +"@babel/parser@npm:8.0.0-beta.4, @babel/parser@npm:^8.0.0-beta.4": + version: 8.0.0-beta.4 + resolution: "@babel/parser@npm:8.0.0-beta.4" dependencies: - "@babel/types": "npm:^8.0.0-beta.3" + "@babel/types": "npm:^8.0.0-beta.4" bin: parser: ./bin/babel-parser.js - checksum: 10/4ddc4112a8f5888c4f0ccc1c187ef0a8736de5f079dcf4e7bcd246a378eec83a37106ea16c08ae948b939be8cedbeeeb32ae97a6be5bede8bf6e59837d2c43a8 + checksum: 10/41ea150c87ad2153efa245013fc6f6fa5be303403e2de0c4f2547f8529b92f242ae7a8a19f076a0bf63c494595fe40924421a6fbf4bc944378570d9df7849b82 languageName: node linkType: hard @@ -451,13 +451,13 @@ __metadata: languageName: node linkType: hard -"@babel/types@npm:8.0.0-beta.3, @babel/types@npm:^8.0.0-beta.3": - version: 8.0.0-beta.3 - resolution: "@babel/types@npm:8.0.0-beta.3" +"@babel/types@npm:8.0.0-beta.4, @babel/types@npm:^8.0.0-beta.4": + version: 8.0.0-beta.4 + resolution: "@babel/types@npm:8.0.0-beta.4" dependencies: - "@babel/helper-string-parser": "npm:^8.0.0-beta.3" - "@babel/helper-validator-identifier": "npm:^8.0.0-beta.3" - checksum: 10/162784ece3223284dec9f97b08cf741ce07564cc25a563f47892c445b449e87c4b46864af4965814bc007e1ed5a73231031b7de80771572a5ecf3897fcf4169a + "@babel/helper-string-parser": "npm:^8.0.0-beta.4" + "@babel/helper-validator-identifier": "npm:^8.0.0-beta.4" + checksum: 10/31222a70050c3845c44c1339a7bc75bc6bcea48da754f8e8d59e36605d3bac9ce29707078a6ef44ddb102f6493aea508e73e35ea849683d3844cb412f35f85ce languageName: node linkType: hard @@ -6483,6 +6483,13 @@ __metadata: languageName: node linkType: hard +"js-tokens@npm:^10.0.0": + version: 10.0.0 + resolution: "js-tokens@npm:10.0.0" + checksum: 10/88f536ec89f076fc230d29df255b3c55531237669d746d1868fca716b1e3f5f2e4abf8e5b8701903216e3f00d2dc3918d078b35da87772d433ab6a513c3bf76d + languageName: node + linkType: hard + "js-tokens@npm:^4.0.0": version: 4.0.0 resolution: "js-tokens@npm:4.0.0" @@ -6490,13 +6497,6 @@ __metadata: languageName: node linkType: hard -"js-tokens@npm:^8.0.0": - version: 8.0.3 - resolution: "js-tokens@npm:8.0.3" - checksum: 10/af5ed8ddbc446a868c026599214f4a482ab52461edb82e547949255f98910a14bd81ddab88a8d570d74bd7dc96c6d4df7f963794ec5aaf13c53918cc46b9caa6 - languageName: node - linkType: hard - "js-yaml@npm:^3.13.1": version: 3.14.2 resolution: "js-yaml@npm:3.14.2" @@ -8360,10 +8360,10 @@ __metadata: resolution: "prettier@workspace:." dependencies: "@angular/compiler": "npm:21.1.0" - "@babel/code-frame": "npm:8.0.0-beta.3" - "@babel/generator": "npm:8.0.0-beta.3" - "@babel/parser": "npm:8.0.0-beta.3" - "@babel/types": "npm:8.0.0-beta.3" + "@babel/code-frame": "npm:8.0.0-beta.4" + "@babel/generator": "npm:8.0.0-beta.4" + "@babel/parser": "npm:8.0.0-beta.4" + "@babel/types": "npm:8.0.0-beta.4" "@eslint/js": "npm:9.39.2" "@glimmer/syntax": "npm:0.95.0" "@prettier/cli": "npm:0.10.0"