diff --git a/.github/workflows/prod-test.yml b/.github/workflows/prod-test.yml index d6f83c5ad..7bbe8bf04 100644 --- a/.github/workflows/prod-test.yml +++ b/.github/workflows/prod-test.yml @@ -123,11 +123,21 @@ jobs: path: dist - name: Run Tests + if: matrix.node != '14' run: yarn test:production + - name: Run Tests (Node.js 14) + if: matrix.node == '14' + run: yarn test:production-node14 + - name: Run Format Tests (standalone) + if: matrix.node != '14' run: yarn test:production-standalone + - name: Run Format Tests (standalone, Node.js 14) + if: matrix.node == '14' + run: yarn test:production-standalone-node14 + cli: name: CLI runs-on: ubuntu-latest diff --git a/package.json b/package.json index 90776bca8..96c8dc090 100644 --- a/package.json +++ b/package.json @@ -43,9 +43,9 @@ ], "dependencies": { "@angular/compiler": "20.3.1", - "@babel/code-frame": "7.27.1", - "@babel/parser": "7.28.4", - "@babel/types": "7.28.4", + "@babel/code-frame": "8.0.0-beta.2", + "@babel/parser": "8.0.0-beta.2", + "@babel/types": "8.0.0-beta.2", "@glimmer/syntax": "0.95.0", "@prettier/cli": "0.9.0", "@prettier/html-event-attributes": "0.0.1", @@ -123,7 +123,7 @@ "yaml-unist-parser": "2.0.5" }, "devDependencies": { - "@babel/generator": "7.28.3", + "@babel/generator": "8.0.0-beta.2", "@eslint-react/eslint-plugin": "1.53.1", "@eslint/js": "9.35.0", "@stylistic/eslint-plugin": "5.3.1", @@ -178,9 +178,12 @@ "scripts": { "prepublishOnly": "echo \"Error: must publish from dist/\" && exit 1", "test": "jest", + "test:node14": "cross-env NODE_OPTIONS=\"--experimental-loader=$PWD/scripts/nodejs-14-test-loader.js --no-warnings=ExperimentalWarning\" jest --runInBand", "test:dev-package": "cross-env INSTALL_PACKAGE=1 yarn test", "test:production": "cross-env NODE_ENV=production yarn test", + "test:production-node14": "cross-env NODE_ENV=production yarn test:node14", "test:production-standalone": "cross-env TEST_STANDALONE=1 yarn test:production", + "test:production-standalone-node14": "cross-env TEST_STANDALONE=1 yarn test:production-node14", "test:production-lint": "eslint dist/prettier --config=./scripts/bundle-eslint-config.js --quiet --format friendly", "perf": "yarn && yarn build && cross-env NODE_ENV=production node ./dist/prettier/bin/prettier.cjs", "perf:inspect": "yarn && yarn build && cross-env NODE_ENV=production node --inspect-brk ./dist/prettier/bin/prettier.cjs", diff --git a/scripts/build/shims/colors.js b/scripts/build/shims/colors.js index 239a7d54a..36bbfdb30 100644 --- a/scripts/build/shims/colors.js +++ b/scripts/build/shims/colors.js @@ -1,3 +1,4 @@ const colors = new Proxy(String, { get: () => colors }); export default colors; +export const createColors = () => colors; diff --git a/scripts/build/transform/index.js b/scripts/build/transform/index.js index 377294aa8..a112169f2 100644 --- a/scripts/build/transform/index.js +++ b/scripts/build/transform/index.js @@ -1,13 +1,11 @@ import path from "node:path"; -import babelGenerator from "@babel/generator"; +import generate from "@babel/generator"; import { parse } from "@babel/parser"; import { traverseFast as traverse } from "@babel/types"; import { outdent } from "outdent"; import { PROJECT_ROOT, SOURCE_DIR } from "../../utils/index.js"; import allTransforms from "./transforms/index.js"; -const generate = babelGenerator.default; - /* Doesn't work for dependencies, optional call, computed property, and spread arguments */ function transform(original, file) { @@ -20,6 +18,7 @@ function transform(original, file) { ) || file.startsWith(path.join(PROJECT_ROOT, "node_modules/jest-docblock/")) || file.startsWith(path.join(PROJECT_ROOT, "node_modules/espree/")) || + file.startsWith(path.join(PROJECT_ROOT, "node_modules/@babel/parser/")) || file.startsWith( path.join( PROJECT_ROOT, diff --git a/scripts/nodejs-14-test-loader.js b/scripts/nodejs-14-test-loader.js new file mode 100644 index 000000000..5e952883a --- /dev/null +++ b/scripts/nodejs-14-test-loader.js @@ -0,0 +1,26 @@ +import { readFile } from "node:fs/promises"; +import { fileURLToPath } from "node:url"; +import esbuild from "esbuild"; + +// `@babel/code-frame` and `@babel/highlight` use syntax that is not available in Node.js 14, +// such as `??=`. When bundled into dist/ they are compiled to be compatible with Node.js 14, +// however we also need to load them at runtime from node_modules to run our tests. +// 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)/u.test(url) || + context.format !== "module" + ) { + return defaultGetSource(url, context, defaultGetSource); + } + + 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; + } +} diff --git a/scripts/prepare-test-for-legacy-nodejs.js b/scripts/prepare-test-for-legacy-nodejs.js index b9c255787..a2a5a2794 100644 --- a/scripts/prepare-test-for-legacy-nodejs.js +++ b/scripts/prepare-test-for-legacy-nodejs.js @@ -22,75 +22,85 @@ if (nodeVersion === 14) { throw new Error("Unexpected `--node-version`."); } -// Script to get dependencies -// console.log( -// Object.fromEntries( -// Array.from( -// fs -// .readFileSync("./yarn.lock", "utf8") -// .matchAll(/"(.*?)@npm:30\.0\.0-alpha\.3[",]/g), -// (match) => match[1], -// ) -// .sort() -// .map((dependency) => [dependency, "30.0.0-alpha.2"]), -// ), -// ); +/* +Script to get dependencies -fs.writeFileSync( - packageJsonFile, - JSON.stringify( - { - ...packageJson, - resolutions: { - ...packageJson.resolutions, - "@jest/console": jestVersion, - "@jest/core": jestVersion, - "@jest/environment": jestVersion, - "@jest/expect": jestVersion, - "@jest/expect-utils": jestVersion, - "@jest/fake-timers": jestVersion, - "@jest/globals": jestVersion, - "@jest/reporters": jestVersion, - "@jest/schemas": jestVersion, - "@jest/source-map": jestVersion, - "@jest/test-result": jestVersion, - "@jest/test-sequencer": jestVersion, - "@jest/transform": jestVersion, - // "@jest/types": jestVersion, - "babel-jest": jestVersion, - "babel-plugin-jest-hoist": jestVersion, - "babel-preset-jest": jestVersion, - "diff-sequences": jestVersion, - expect: jestVersion, - jest: jestVersion, - "jest-changed-files": jestVersion, - "jest-circus": jestVersion, - "jest-cli": jestVersion, - "jest-config": jestVersion, - "jest-diff": jestVersion, - // "jest-docblock": jestVersion, - "jest-each": jestVersion, - "jest-environment-node": jestVersion, - "jest-get-type": jestVersion, - "jest-haste-map": jestVersion, - "jest-leak-detector": jestVersion, - "jest-matcher-utils": jestVersion, - "jest-message-util": jestVersion, - "jest-mock": jestVersion, - "jest-regex-util": jestVersion, - "jest-resolve": jestVersion, - "jest-resolve-dependencies": jestVersion, - "jest-runner": jestVersion, - "jest-runtime": jestVersion, - "jest-snapshot": jestVersion, - "jest-util": jestVersion, - "jest-validate": jestVersion, - "jest-watcher": jestVersion, - "jest-worker": jestVersion, - "pretty-format": jestVersion, - }, - }, - undefined, - 2, - ), +```js +console.log( + Array.from( + fs + .readFileSync("./yarn.lock", "utf8") + .matchAll(/"(.*?)@npm:30\.0\.0-alpha\.3[",]/g), + (match) => match[1], + ).sort(), ); +``` +*/ + +const jestDependencies = [ + "@jest/console", + "@jest/core", + "@jest/environment", + "@jest/expect", + "@jest/expect-utils", + "@jest/fake-timers", + "@jest/globals", + "@jest/reporters", + "@jest/schemas", + "@jest/source-map", + "@jest/test-result", + "@jest/test-sequencer", + "@jest/transform", + // "@jest/types", + "babel-jest", + "babel-plugin-jest-hoist", + "babel-preset-jest", + "diff-sequences", + "expect", + "jest", + "jest-changed-files", + "jest-circus", + "jest-cli", + "jest-config", + "jest-diff", + // "jest-docblock", + "jest-each", + "jest-environment-node", + "jest-get-type", + "jest-haste-map", + "jest-leak-detector", + "jest-matcher-utils", + "jest-message-util", + "jest-mock", + "jest-regex-util", + "jest-resolve", + "jest-resolve-dependencies", + "jest-runner", + "jest-runtime", + "jest-snapshot", + "jest-util", + "jest-validate", + "jest-watcher", + "jest-worker", + "pretty-format", +]; + +let content = JSON.stringify( + { + ...packageJson, + resolutions: { + ...packageJson.resolutions, + ...Object.fromEntries( + jestDependencies.map((name) => [name, jestVersion]), + ), + }, + }, + undefined, + 2, +); + +if (process.platform === "win32") { + content = content.replace("$PWD/", new URL("../", import.meta.url).href); +} + +fs.writeFileSync(packageJsonFile, content); diff --git a/src/language-js/clean.js b/src/language-js/clean.js index 39dfc0b2f..6fc821c41 100644 --- a/src/language-js/clean.js +++ b/src/language-js/clean.js @@ -31,13 +31,6 @@ function clean(original, cloned) { delete cloned.sourceType; } - if ( - (original.type === "BigIntLiteral" || - original.type === "BigIntLiteralTypeAnnotation") && - original.value - ) { - cloned.value = original.value.toLowerCase(); - } if ( (original.type === "BigIntLiteral" || original.type === "Literal") && original.bigint diff --git a/src/language-js/parse/babel.js b/src/language-js/parse/babel.js index 8586a1ff1..452913f35 100644 --- a/src/language-js/parse/babel.js +++ b/src/language-js/parse/babel.js @@ -198,7 +198,6 @@ const allowedReasonCodes = new Set([ "NonAbstractClassHasAbstractMethod", "OptionalTypeBeforeRequired", "PatternIsOptional", - "OptionalBindingPattern", "DeclareClassFieldHasInitializer", "TypeImportCannotSpecifyDefaultAndNamed", diff --git a/src/language-js/parse/postprocess/index.js b/src/language-js/parse/postprocess/index.js index 4bd30d313..c189567ab 100644 --- a/src/language-js/parse/postprocess/index.js +++ b/src/language-js/parse/postprocess/index.js @@ -2,7 +2,6 @@ import * as assert from "#universal/assert"; import { locEnd, locStart } from "../../loc.js"; import createTypeCheckFunction from "../../utils/create-type-check-function.js"; import getRaw from "../../utils/get-raw.js"; -import getTextWithoutComments from "../../utils/get-text-without-comments.js"; import isBlockComment from "../../utils/is-block-comment.js"; import isLineComment from "../../utils/is-line-comment.js"; import isTypeCastComment from "../../utils/is-type-cast-comment.js"; @@ -47,22 +46,6 @@ function postprocess(ast, options) { let typeCastCommentsEnds; ast = visitNode(ast, { - onEnter(node) { - switch (node.type) { - // Remove this when update `@babel/parser` to v8 - // https://github.com/typescript-eslint/typescript-eslint/pull/7065 - case "TSMappedType": - if (!node.constraint && !node.key) { - const { name: key, constraint } = fixBabelTSTypeParameter( - node.typeParameter, - ); - node.constraint = constraint; - node.key = key; - delete node.typeParameter; - } - break; - } - }, onLeave(node) { switch (node.type) { case "ParenthesizedExpression": { @@ -149,11 +132,6 @@ function postprocess(ast, options) { case "TSParenthesizedType": return node.typeAnnotation; - case "TSTypeParameter": - // babel-ts - fixBabelTSTypeParameter(node); - break; - // For hack-style pipeline case "TopicReference": ast.extra = { ...ast.extra, __isUsingHackPipeline: true }; @@ -167,30 +145,6 @@ function postprocess(ast, options) { } break; - // Remove this when update `@babel/parser` to v8 - // https://github.com/typescript-eslint/typescript-eslint/pull/8920 - case "TSEnumDeclaration": - if (!node.body) { - const idEnd = locEnd(node.id); - const { members } = node; - const textWithoutComments = getTextWithoutComments( - { - originalText: text, - [Symbol.for("comments")]: comments, - }, - idEnd, - members[0] ? locStart(members[0]) : locEnd(node), - ); - const start = idEnd + textWithoutComments.indexOf("{"); - node.body = { - type: "TSEnumBody", - members, - range: [start, locEnd(node)], - }; - delete node.members; - } - break; - // https://github.com/facebook/hermes/issues/1712 case "ImportExpression": if (parser === "hermes" && node.attributes && !node.options) { @@ -233,19 +187,6 @@ function postprocess(ast, options) { return ast; } -function fixBabelTSTypeParameter(node) { - if (node.type === "TSTypeParameter" && typeof node.name === "string") { - const start = locStart(node); - node.name = { - type: "Identifier", - name: node.name, - range: [start, start + node.name.length], - }; - } - - return node; -} - function isUnbalancedLogicalTree(node) { return ( node.type === "LogicalExpression" && diff --git a/src/language-js/parse/postprocess/visit-node.js b/src/language-js/parse/postprocess/visit-node.js index e29fe0a6d..ed550df1c 100644 --- a/src/language-js/parse/postprocess/visit-node.js +++ b/src/language-js/parse/postprocess/visit-node.js @@ -15,7 +15,9 @@ function visitNode(node, options) { return node; } - node = options.onEnter(node) || node; + if (options.onEnter) { + node = options.onEnter(node) || node; + } const keys = getVisitorKeys(node); for (let i = 0; i < keys.length; i++) { diff --git a/src/language-js/parse/utils/create-babel-parse-error.js b/src/language-js/parse/utils/create-babel-parse-error.js index 1c7856969..c5e2f9419 100644 --- a/src/language-js/parse/utils/create-babel-parse-error.js +++ b/src/language-js/parse/utils/create-babel-parse-error.js @@ -6,7 +6,7 @@ const parseExpressionErrorMessagePrefix = function createBabelParseError(error) { let { message, loc, reasonCode } = error; - /* c8 ignore next 3 */ + /* c8 ignore next 3 -- not a babel parse error */ if (!loc) { return error; } diff --git a/src/language-js/print/assignment.js b/src/language-js/print/assignment.js index 11f929c76..f014f6969 100644 --- a/src/language-js/print/assignment.js +++ b/src/language-js/print/assignment.js @@ -456,10 +456,7 @@ function shouldBreakBeforeConditionalType(node) { case "TSFunctionType": return Boolean(subNode.typeParameters); case "TSTypeReference": - return Boolean( - // TODO: Use `typeArguments` only when babel align with TS. - subNode.typeArguments ?? subNode.typeParameters, - ); + return Boolean(subNode.typeArguments); default: return false; } diff --git a/src/language-js/print/object.js b/src/language-js/print/object.js index 32fcd58a8..3f45bc793 100644 --- a/src/language-js/print/object.js +++ b/src/language-js/print/object.js @@ -238,10 +238,7 @@ function printObject(path, options, print) { function shouldHugTheOnlyParameter(node, name) { return ( - (name === "params" || - name === "parameters" || - name === "this" || - name === "rest") && + (name === "params" || name === "this" || name === "rest") && shouldHugTheOnlyFunctionParameter(node) ); } diff --git a/src/language-js/print/template-literal.js b/src/language-js/print/template-literal.js index 3a8d1ecc1..ecebecc85 100644 --- a/src/language-js/print/template-literal.js +++ b/src/language-js/print/template-literal.js @@ -154,7 +154,7 @@ function printTaggedTemplateLiteral(path, options, print) { return label(quasiDoc.label && { tagged: true, ...quasiDoc.label }, [ print("tag"), - print(node.typeArguments ? "typeArguments" : "typeParameters"), + print("typeArguments"), space, lineSuffixBoundary, quasiDoc, diff --git a/src/language-js/print/type-annotation.js b/src/language-js/print/type-annotation.js index 915047e30..0aedc88c9 100644 --- a/src/language-js/print/type-annotation.js +++ b/src/language-js/print/type-annotation.js @@ -328,13 +328,7 @@ function printFunctionType(path, options, print) { print("returnType"), ); } else { - returnTypeDoc.push( - printTypeAnnotationProperty( - path, - print, - node.returnType ? "returnType" : "typeAnnotation", - ), - ); + returnTypeDoc.push(printTypeAnnotationProperty(path, print, "returnType")); } if (shouldGroupFunctionParameters(node, returnTypeDoc)) { @@ -568,12 +562,7 @@ function printArrayType(print) { function printTypeQuery({ node }, print) { const argumentPropertyName = node.type === "TSTypeQuery" ? "exprName" : "argument"; - const typeArgsPropertyName = - // TODO: Use `typeArguments` only when babel align with TS. - node.type === "TypeofTypeAnnotation" || node.typeArguments - ? "typeArguments" - : "typeParameters"; - return ["typeof ", print(argumentPropertyName), print(typeArgsPropertyName)]; + return ["typeof ", print(argumentPropertyName), print("typeArguments")]; } /* diff --git a/src/language-js/print/typescript.js b/src/language-js/print/typescript.js index 619cf97b2..41cb2ebb1 100644 --- a/src/language-js/print/typescript.js +++ b/src/language-js/print/typescript.js @@ -127,15 +127,8 @@ function printTypescript(path, options, print) { return printClassProperty(path, options, print); case "TSInterfaceHeritage": case "TSClassImplements": - case "TSExpressionWithTypeArguments": // Babel AST case "TSInstantiationExpression": - return [ - print("expression"), - print( - // TODO: Use `typeArguments` only when babel align with TS. - node.typeArguments ? "typeArguments" : "typeParameters", - ), - ]; + return [print("expression"), print("typeArguments")]; case "TSTemplateLiteralType": return printTemplateLiteral(path, options, print); case "TSNamedTupleMember": @@ -217,12 +210,7 @@ function printTypescript(path, options, print) { return [ printCallExpression(path, options, print), !node.qualifier ? "" : [".", print("qualifier")], - printTypeParameters( - path, - options, - print, - node.typeArguments ? "typeArguments" : "typeParameters", - ), + printTypeParameters(path, options, print, "typeArguments"), ]; case "TSLiteralType": return print("literal"); @@ -254,13 +242,11 @@ function printTypescript(path, options, print) { /* printTypeParams */ true, ); - const returnTypePropertyName = node.returnType - ? "returnType" - : "typeAnnotation"; - const returnTypeNode = node[returnTypePropertyName]; - const returnTypeDoc = returnTypeNode - ? printTypeAnnotationProperty(path, print, returnTypePropertyName) - : ""; + const returnTypeDoc = printTypeAnnotationProperty( + path, + print, + "returnType", + ); const shouldGroupParameters = shouldGroupFunctionParameters( node, returnTypeDoc, @@ -268,7 +254,7 @@ function printTypescript(path, options, print) { parts.push(shouldGroupParameters ? group(parametersDoc) : parametersDoc); - if (returnTypeNode) { + if (node.returnType) { parts.push(group(returnTypeDoc)); } @@ -342,13 +328,7 @@ function printTypescript(path, options, print) { case "TSTypeReference": return [ print("typeName"), - printTypeParameters( - path, - options, - print, - // TODO: Use `typeArguments` only when babel align with TS. - node.typeArguments ? "typeArguments" : "typeParameters", - ), + printTypeParameters(path, options, print, "typeArguments"), ]; case "TSTypeAnnotation": return printTypeAnnotation(path, options, print); diff --git a/src/language-js/utils/index.js b/src/language-js/utils/index.js index f2ac298e7..ea6f7d1bd 100644 --- a/src/language-js/utils/index.js +++ b/src/language-js/utils/index.js @@ -846,12 +846,9 @@ function getFunctionParameters(node) { if (node.this) { parameters.push(node.this); } - // `params` vs `parameters` - see https://github.com/babel/babel/issues/9231 - if (Array.isArray(node.parameters)) { - parameters.push(...node.parameters); - } else if (Array.isArray(node.params)) { - parameters.push(...node.params); - } + + parameters.push(...node.params); + if (node.rest) { parameters.push(node.rest); } @@ -866,11 +863,9 @@ function iterateFunctionParametersPath(path, iteratee) { if (node.this) { path.call(callback, "this"); } - if (Array.isArray(node.parameters)) { - path.each(callback, "parameters"); - } else if (Array.isArray(node.params)) { - path.each(callback, "params"); - } + + path.each(callback, "params"); + if (node.rest) { path.call(callback, "rest"); } diff --git a/src/language-js/utils/is-node-matches.js b/src/language-js/utils/is-node-matches.js index ac4e99c71..91ca793a2 100644 --- a/src/language-js/utils/is-node-matches.js +++ b/src/language-js/utils/is-node-matches.js @@ -32,6 +32,7 @@ function isNodeMatchesNameOrPath(node, nameOrPath) { if ( node.type === "MemberExpression" && + // @ts-expect-error -- Don't know why !node.optional && !node.computed && node.property.type === "Identifier" && diff --git a/tests/format/misc/errors/babel-missing-plugins/__snapshots__/format.test.js.snap b/tests/format/misc/errors/babel-missing-plugins/__snapshots__/format.test.js.snap index 652d7b071..64118e114 100644 --- a/tests/format/misc/errors/babel-missing-plugins/__snapshots__/format.test.js.snap +++ b/tests/format/misc/errors/babel-missing-plugins/__snapshots__/format.test.js.snap @@ -7,13 +7,15 @@ exports[`snippet: #0 [babel] format 1`] = ` `; exports[`snippet: #1 [babel] format 1`] = ` -"Unexpected token. (1:4) +"Identifier directly after number. (1:4) > 1 | 100m; - | ^" + | ^ +Cause: Identifier directly after number. (1:3)" `; exports[`snippet: #2 [babel] format 1`] = ` -"Unexpected token. (1:8) +"Unexpected token, expected "from" (1:15) > 1 | import module foo from "./module.wasm"; - | ^" + | ^ +Cause: Unexpected token, expected "from" (1:14)" `; diff --git a/tests/format/misc/errors/invalid-interface-extends/__snapshots__/format.test.js.snap b/tests/format/misc/errors/invalid-interface-extends/__snapshots__/format.test.js.snap index 07af0134c..b166185e8 100644 --- a/tests/format/misc/errors/invalid-interface-extends/__snapshots__/format.test.js.snap +++ b/tests/format/misc/errors/invalid-interface-extends/__snapshots__/format.test.js.snap @@ -1,10 +1,10 @@ // Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing exports[`snippet: #0 [babel-ts] format 1`] = ` -"Unexpected token (1:21) +"'extends' list can only include identifiers or qualified-names with optional type arguments. (1:21) > 1 | interface A extends (typeof fs) { } | ^ -Cause: Unexpected token (1:20)" +Cause: 'extends' list can only include identifiers or qualified-names with optional type arguments. (1:20)" `; exports[`snippet: #0 [typescript] format 1`] = ` @@ -15,10 +15,10 @@ Cause: Interface declaration can only extend an identifier/qualified name with o `; exports[`snippet: #1 [babel-ts] format 1`] = ` -"Unexpected token, expected "," (1:22) +"'extends' list can only include identifiers or qualified-names with optional type arguments. (1:21) > 1 | interface B extends C['D'] { } - | ^ -Cause: Unexpected token, expected "," (1:21)" + | ^ +Cause: 'extends' list can only include identifiers or qualified-names with optional type arguments. (1:20)" `; exports[`snippet: #1 [typescript] format 1`] = ` @@ -29,10 +29,10 @@ Cause: Interface declaration can only extend an identifier/qualified name with o `; exports[`snippet: #2 [babel-ts] format 1`] = ` -"Unexpected token, expected "," (1:22) +"'extends' list can only include identifiers or qualified-names with optional type arguments. (1:21) > 1 | interface E extends F?.G { } - | ^ -Cause: Unexpected token, expected "," (1:21)" + | ^ +Cause: 'extends' list can only include identifiers or qualified-names with optional type arguments. (1:20)" `; exports[`snippet: #2 [typescript] format 1`] = ` @@ -57,10 +57,10 @@ Cause: 'extends' clause already seen." `; exports[`snippet: #4 [babel-ts] format 1`] = ` -"Unexpected token (1:21) +"'extends' list can only include identifiers or qualified-names with optional type arguments. (1:21) > 1 | interface K extends 2 { } | ^ -Cause: Unexpected token (1:20)" +Cause: 'extends' list can only include identifiers or qualified-names with optional type arguments. (1:20)" `; exports[`snippet: #4 [typescript] format 1`] = ` @@ -71,10 +71,10 @@ Cause: Interface declaration can only extend an identifier/qualified name with o `; exports[`snippet: #5 [babel-ts] format 1`] = ` -"Unexpected token, expected "," (1:22) +"'extends' list can only include identifiers or qualified-names with optional type arguments. (1:21) > 1 | interface L extends M().N { } - | ^ -Cause: Unexpected token, expected "," (1:21)" + | ^ +Cause: 'extends' list can only include identifiers or qualified-names with optional type arguments. (1:20)" `; exports[`snippet: #5 [typescript] format 1`] = ` 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 f23b08610..ac62dacba 100644 --- a/tests/format/misc/errors/js/__snapshots__/format.test.js.snap +++ b/tests/format/misc/errors/js/__snapshots__/format.test.js.snap @@ -145,9 +145,10 @@ Cause: Unexpected token (5:11)" `; exports[`snippet: #7 [babel] format 1`] = ` -"Unexpected token. (1:7) +"Unexpected token (1:7) > 1 | const #{ a, b } = #{ a: 1, b: 2 }; - | ^" + | ^ +Cause: Unexpected token (1:6)" `; exports[`snippet: #8 [babel] format 1`] = ` diff --git a/tests/format/misc/errors/js/record/__snapshots__/format.test.js.snap b/tests/format/misc/errors/js/record/__snapshots__/format.test.js.snap index d2bd279f3..c260f1a22 100644 --- a/tests/format/misc/errors/js/record/__snapshots__/format.test.js.snap +++ b/tests/format/misc/errors/js/record/__snapshots__/format.test.js.snap @@ -8,9 +8,10 @@ Cause: Unexpected character '{' (1:1)" `; exports[`snippet: #0 [babel] format 1`] = ` -"Unexpected token. (1:1) +"Unexpected token (1:1) > 1 | #{a() {}} - | ^" + | ^ +Cause: Unexpected token (1:0)" `; exports[`snippet: #0 [espree] format 1`] = ` @@ -35,9 +36,10 @@ Cause: Unexpected character '{' (1:1)" `; exports[`snippet: #1 [babel] format 1`] = ` -"Unexpected token. (1:1) +"Unexpected token (1:1) > 1 | #{async b() {}} - | ^" + | ^ +Cause: Unexpected token (1:0)" `; exports[`snippet: #1 [espree] format 1`] = ` @@ -62,9 +64,10 @@ Cause: Unexpected character '{' (1:1)" `; exports[`snippet: #2 [babel] format 1`] = ` -"Unexpected token. (1:1) +"Unexpected token (1:1) > 1 | #{get c() {}} - | ^" + | ^ +Cause: Unexpected token (1:0)" `; exports[`snippet: #2 [espree] format 1`] = ` @@ -89,9 +92,10 @@ Cause: Unexpected character '{' (1:1)" `; exports[`snippet: #3 [babel] format 1`] = ` -"Unexpected token. (1:1) +"Unexpected token (1:1) > 1 | #{set d(_) {}} - | ^" + | ^ +Cause: Unexpected token (1:0)" `; exports[`snippet: #3 [espree] format 1`] = ` @@ -116,9 +120,10 @@ Cause: Unexpected character '{' (1:1)" `; exports[`snippet: #4 [babel] format 1`] = ` -"Unexpected token. (1:1) +"Unexpected token (1:1) > 1 | #{*e() {}} - | ^" + | ^ +Cause: Unexpected token (1:0)" `; exports[`snippet: #4 [espree] format 1`] = ` diff --git a/tests/format/misc/errors/json/__snapshots__/format.test.js.snap b/tests/format/misc/errors/json/__snapshots__/format.test.js.snap index a770e1fbc..b8983897e 100644 --- a/tests/format/misc/errors/json/__snapshots__/format.test.js.snap +++ b/tests/format/misc/errors/json/__snapshots__/format.test.js.snap @@ -572,7 +572,7 @@ exports[`snippet: #11 [json] format 1`] = ` `; exports[`snippet: #11 [json] format 2`] = ` -"'CallExpression' is not allowed in JSON. (1:2) +"'ImportExpression' is not allowed in JSON. (1:2) > 1 | [import('a', {type:'json'})] | ^^^^^^^^^^^^^^^^^^^^^^^^^^" `; @@ -596,9 +596,10 @@ exports[`snippet: #12 [json] format 1`] = ` `; exports[`snippet: #12 [json] format 2`] = ` -"Unexpected token. (1:3) +"Identifier directly after number. (1:3) > 1 | [1m] - | ^" + | ^ +Cause: Identifier directly after number. (1:2)" `; exports[`snippet: #12 [json-stringify] format 1`] = ` @@ -740,7 +741,7 @@ exports[`snippet: #18 [json] format 1`] = ` `; exports[`snippet: #18 [json] format 2`] = ` -"'CallExpression' is not allowed in JSON. (1:2) +"'ImportExpression' is not allowed in JSON. (1:2) > 1 | [import('a', {reflect: 'module'})] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" `; @@ -876,9 +877,10 @@ Cause: Unexpected parseExpression() input: The input is empty or contains only c `; exports[`snippet: #23 [json] format 2`] = ` -"Unexpected token. (1:2) +"Unexpected token (1:2) > 1 | [#{}] - | ^" + | ^ +Cause: Unexpected token (1:1)" `; exports[`snippet: #23 [json-stringify] format 1`] = ` diff --git a/tests/format/misc/errors/typescript/import-reflection/__snapshots__/format.test.js.snap b/tests/format/misc/errors/typescript/import-reflection/__snapshots__/format.test.js.snap index 57c53f0c8..7cd478aef 100644 --- a/tests/format/misc/errors/typescript/import-reflection/__snapshots__/format.test.js.snap +++ b/tests/format/misc/errors/typescript/import-reflection/__snapshots__/format.test.js.snap @@ -1,11 +1,12 @@ // Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing exports[`valid-flow-default-import.mts [babel-ts] format 1`] = ` -"Unexpected token. (1:8) +"Unexpected token, expected "from" (1:15) > 1 | import module foo from "./module.wasm"; - | ^ + | ^ 2 | import bar from "./module.wasm"; - 3 |" + 3 | +Cause: Unexpected token, expected "from" (1:14)" `; exports[`valid-flow-default-import.mts [oxc-ts] format 1`] = ` @@ -26,11 +27,12 @@ Cause: '=' expected." `; exports[`valid-ts-default-import.mts [babel-ts] format 1`] = ` -"Unexpected token. (1:8) +"Unexpected token, expected "from" (1:15) > 1 | import module foo from "./module.wasm"; - | ^ + | ^ 2 | import bar from "./module.wasm"; - 3 |" + 3 | +Cause: Unexpected token, expected "from" (1:14)" `; exports[`valid-ts-default-import.mts [oxc-ts] format 1`] = ` diff --git a/tests/unit/__snapshots__/visitor-keys.js.snap b/tests/unit/__snapshots__/visitor-keys.js.snap index 2ca397243..c7dc92f73 100644 --- a/tests/unit/__snapshots__/visitor-keys.js.snap +++ b/tests/unit/__snapshots__/visitor-keys.js.snap @@ -73,7 +73,6 @@ exports[`visitor keys estree 1`] = ` "arguments", "callee", "typeArguments", - "typeParameters", ], "CatchClause": [ "body", @@ -636,9 +635,7 @@ exports[`visitor keys estree 1`] = ` "arguments", "callee", "typeArguments", - "typeParameters", ], - "Noop": [], "NullLiteral": [], "NullLiteralTypeAnnotation": [], "NullableTypeAnnotation": [ @@ -713,7 +710,6 @@ exports[`visitor keys estree 1`] = ` "arguments", "callee", "typeArguments", - "typeParameters", ], "OptionalIndexedAccessType": [ "indexType", @@ -823,10 +819,8 @@ exports[`visitor keys estree 1`] = ` "TSBigIntKeyword": [], "TSBooleanKeyword": [], "TSCallSignatureDeclaration": [ - "parameters", "params", "returnType", - "typeAnnotation", "typeParameters", ], "TSClassImplements": [ @@ -841,17 +835,13 @@ exports[`visitor keys estree 1`] = ` "trueType", ], "TSConstructSignatureDeclaration": [ - "parameters", "params", "returnType", - "typeAnnotation", "typeParameters", ], "TSConstructorType": [ - "parameters", "params", "returnType", - "typeAnnotation", "typeParameters", ], "TSDeclareFunction": [ @@ -890,18 +880,12 @@ exports[`visitor keys estree 1`] = ` "expression", ], "TSExportKeyword": [], - "TSExpressionWithTypeArguments": [ - "expression", - "typeParameters", - ], "TSExternalModuleReference": [ "expression", ], "TSFunctionType": [ - "parameters", "params", "returnType", - "typeAnnotation", "typeParameters", ], "TSImportEqualsDeclaration": [ @@ -913,7 +897,6 @@ exports[`visitor keys estree 1`] = ` "options", "qualifier", "typeArguments", - "typeParameters", ], "TSIndexSignature": [ "parameters", @@ -929,7 +912,6 @@ exports[`visitor keys estree 1`] = ` "TSInstantiationExpression": [ "expression", "typeArguments", - "typeParameters", ], "TSInterfaceBody": [ "body", @@ -968,10 +950,8 @@ exports[`visitor keys estree 1`] = ` ], "TSMethodSignature": [ "key", - "parameters", "params", "returnType", - "typeAnnotation", "typeParameters", ], "TSModuleBlock": [ @@ -1071,12 +1051,10 @@ exports[`visitor keys estree 1`] = ` "TSTypeQuery": [ "exprName", "typeArguments", - "typeParameters", ], "TSTypeReference": [ "typeArguments", "typeName", - "typeParameters", ], "TSUndefinedKeyword": [], "TSUnionType": [ @@ -1088,7 +1066,6 @@ exports[`visitor keys estree 1`] = ` "quasi", "tag", "typeArguments", - "typeParameters", ], "TemplateElement": [], "TemplateLiteral": [ diff --git a/yarn.lock b/yarn.lock index 8e6b0fca6..e46ecbc41 100644 --- a/yarn.lock +++ b/yarn.lock @@ -23,7 +23,18 @@ __metadata: languageName: node linkType: hard -"@babel/code-frame@npm:7.27.1, @babel/code-frame@npm:^7.0.0, @babel/code-frame@npm:^7.12.13, @babel/code-frame@npm:^7.26.2, @babel/code-frame@npm:^7.27.1": +"@babel/code-frame@npm:8.0.0-beta.2": + version: 8.0.0-beta.2 + resolution: "@babel/code-frame@npm:8.0.0-beta.2" + dependencies: + "@babel/helper-validator-identifier": "npm:^8.0.0-beta.2" + js-tokens: "npm:^8.0.0" + picocolors: "npm:^1.1.1" + checksum: 10/8a735166b733b8b38eb2739d5316e7d63a16ac09f997ac52ffcc876e1473961f1ff91510b1c4e8d754de7b36f9d637e8947a1bcfe3e50177911466d3d01af67d + languageName: node + linkType: hard + +"@babel/code-frame@npm:^7.0.0, @babel/code-frame@npm:^7.12.13, @babel/code-frame@npm:^7.26.2, @babel/code-frame@npm:^7.27.1": version: 7.27.1 resolution: "@babel/code-frame@npm:7.27.1" dependencies: @@ -64,7 +75,21 @@ __metadata: languageName: node linkType: hard -"@babel/generator@npm:7.28.3, @babel/generator@npm:^7.27.5, @babel/generator@npm:^7.28.3, @babel/generator@npm:^7.7.2": +"@babel/generator@npm:8.0.0-beta.2": + version: 8.0.0-beta.2 + resolution: "@babel/generator@npm:8.0.0-beta.2" + dependencies: + "@babel/parser": "npm:^8.0.0-beta.2" + "@babel/types": "npm:^8.0.0-beta.2" + "@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/7aa16c71a5c0c8f925590b090b595955024ec7cd3c0900b3579da04d51a38a914c9fd199d3105354518faffa0852ffb914b746617931c392a5529cf9f11decb1 + languageName: node + linkType: hard + +"@babel/generator@npm:^7.27.5, @babel/generator@npm:^7.28.3, @babel/generator@npm:^7.7.2": version: 7.28.3 resolution: "@babel/generator@npm:7.28.3" dependencies: @@ -134,6 +159,13 @@ __metadata: languageName: node linkType: hard +"@babel/helper-string-parser@npm:^8.0.0-beta.2": + version: 8.0.0-beta.2 + resolution: "@babel/helper-string-parser@npm:8.0.0-beta.2" + checksum: 10/43d51311d965e4488953e6a79a7c2b666c0aad23eca85a7afc6af3a66fec07bcda0e5d4b85d528fbcb07fce9894664f2f787c8efeb2e9a9a73743d5405b1ba0e + languageName: node + linkType: hard + "@babel/helper-validator-identifier@npm:^7.25.9, @babel/helper-validator-identifier@npm:^7.27.1": version: 7.27.1 resolution: "@babel/helper-validator-identifier@npm:7.27.1" @@ -141,6 +173,13 @@ __metadata: languageName: node linkType: hard +"@babel/helper-validator-identifier@npm:^8.0.0-beta.2": + version: 8.0.0-beta.2 + resolution: "@babel/helper-validator-identifier@npm:8.0.0-beta.2" + checksum: 10/4862e26d18c99be1f3cbb1973846f48a084f7b9e68ca12e08de8dd06c3acab0b53e2e2a937c03d89a064239f251d3576b1ae2c3d2dbffbecb4e3f6ab42978943 + languageName: node + linkType: hard + "@babel/helper-validator-option@npm:^7.27.1": version: 7.27.1 resolution: "@babel/helper-validator-option@npm:7.27.1" @@ -170,7 +209,18 @@ __metadata: languageName: node linkType: hard -"@babel/parser@npm:7.28.4, @babel/parser@npm:^7.1.0, @babel/parser@npm:^7.14.7, @babel/parser@npm:^7.20.7, @babel/parser@npm:^7.23.9, @babel/parser@npm:^7.27.2, @babel/parser@npm:^7.28.3, @babel/parser@npm:^7.28.4": +"@babel/parser@npm:8.0.0-beta.2, @babel/parser@npm:^8.0.0-beta.2": + version: 8.0.0-beta.2 + resolution: "@babel/parser@npm:8.0.0-beta.2" + dependencies: + "@babel/types": "npm:^8.0.0-beta.2" + bin: + parser: ./bin/babel-parser.js + checksum: 10/b6d8c7952c890c3b1a8d1560c5332d0ea8276997bde27febe8ecfbc9d4429e78163c3ed27911126a2d0706ebfe67fdfe761770f6c155fab0984e576033ca2e7e + languageName: node + linkType: hard + +"@babel/parser@npm:^7.1.0, @babel/parser@npm:^7.14.7, @babel/parser@npm:^7.20.7, @babel/parser@npm:^7.23.9, @babel/parser@npm:^7.27.2, @babel/parser@npm:^7.28.3, @babel/parser@npm:^7.28.4": version: 7.28.4 resolution: "@babel/parser@npm:7.28.4" dependencies: @@ -394,7 +444,17 @@ __metadata: languageName: node linkType: hard -"@babel/types@npm:7.28.4, @babel/types@npm:^7.0.0, @babel/types@npm:^7.20.7, @babel/types@npm:^7.27.1, @babel/types@npm:^7.27.3, @babel/types@npm:^7.28.2, @babel/types@npm:^7.28.4, @babel/types@npm:^7.3.3": +"@babel/types@npm:8.0.0-beta.2, @babel/types@npm:^8.0.0-beta.2": + version: 8.0.0-beta.2 + resolution: "@babel/types@npm:8.0.0-beta.2" + dependencies: + "@babel/helper-string-parser": "npm:^8.0.0-beta.2" + "@babel/helper-validator-identifier": "npm:^8.0.0-beta.2" + checksum: 10/2a1e060816bcaab4ae00a153c9259769d622454c99289e421e72029242ff30dc0a5fb6c6586eb40668029ced68384168c175bc19f3dc4c9fad378083b794126f + languageName: node + linkType: hard + +"@babel/types@npm:^7.0.0, @babel/types@npm:^7.20.7, @babel/types@npm:^7.27.1, @babel/types@npm:^7.27.3, @babel/types@npm:^7.28.2, @babel/types@npm:^7.28.4, @babel/types@npm:^7.3.3": version: 7.28.4 resolution: "@babel/types@npm:7.28.4" dependencies: @@ -2463,6 +2523,13 @@ __metadata: languageName: node linkType: hard +"@types/jsesc@npm:^2.5.0": + version: 2.5.1 + resolution: "@types/jsesc@npm:2.5.1" + checksum: 10/25407775ed621790d2eec0cc51e194bd0d67a82e39204fd9748899c249ef965e17d9e6560f6c658773714f6d45a259465f3639790bb55750ebb168ee23801596 + languageName: node + linkType: hard + "@types/json-schema@npm:^7.0.15": version: 7.0.15 resolution: "@types/json-schema@npm:7.0.15" @@ -6353,6 +6420,13 @@ __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.1 resolution: "js-yaml@npm:3.14.1" @@ -7535,10 +7609,10 @@ __metadata: resolution: "prettier@workspace:." dependencies: "@angular/compiler": "npm:20.3.1" - "@babel/code-frame": "npm:7.27.1" - "@babel/generator": "npm:7.28.3" - "@babel/parser": "npm:7.28.4" - "@babel/types": "npm:7.28.4" + "@babel/code-frame": "npm:8.0.0-beta.2" + "@babel/generator": "npm:8.0.0-beta.2" + "@babel/parser": "npm:8.0.0-beta.2" + "@babel/types": "npm:8.0.0-beta.2" "@eslint-react/eslint-plugin": "npm:1.53.1" "@eslint/js": "npm:9.35.0" "@glimmer/syntax": "npm:0.95.0"