diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 762dc818b..a95a75c29 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -48,7 +48,7 @@ function runFormatTest( Parameters: - **`fixtures`**: Must be set to `import.meta` or to an object of the shape `{ importMeta: import.meta, ... }`. The object may have the `snippets` property to specify an array of extra input entries in addition to the files in the current directory. For each input entry (a file or a snippet), `runFormatTest` configures and runs a number of tests. The main check is that for a given input the output should match the snapshot (for snippets, the expected output can also be specified directly). [Additional checks](#deeper-testing) are controlled by options and environment variables. -- **`parsers`**: A list of parser names. The tests verify that the parsers in this list produce the same output. If the list includes `typescript`, then `babel-ts` is included implicitly. If the list includes `flow`, then `babel-flow` is included implicitly. If the list includes `babel`, and the current directory is inside `tests/format/js` or `tests/format/jsx`, then `acorn`, `espree`, `meriyah`, and `oxc` are included implicitly. +- **`parsers`**: A list of parser names. The tests verify that the parsers in this list produce the same output. If the list includes `typescript`, then `babel-ts`, and `oxc-ts` is included implicitly. If the list includes `flow`, then `babel-flow` is included implicitly. If the list includes `babel`, and the current directory is inside `tests/format/js` or `tests/format/jsx`, then `acorn`, `espree`, `meriyah`, and `oxc` are included implicitly. - **`options`**: In addition to Prettier's formatting options, can contain the `errors` property to specify that it's expected that the formatting shouldn't be successful and an error should be thrown for all (`errors: true`) or some combinations of input entries and parsers. The implementation of `runFormatTest` can be found in [`tests/config/run-format-test.js`](tests/config/run-format-test.js). diff --git a/package.json b/package.json index 00c021859..80558179c 100644 --- a/package.json +++ b/package.json @@ -189,9 +189,9 @@ "build": "node ./scripts/build/build.js", "build:website": "node ./scripts/build-website.js", "gen:changelog": "node ./scripts/generate-changelog.js", - "debug": "node bin/prettier.js --ignore-path=.prettierignore", - "debug:watch": "node --watch bin/prettier.js --ignore-path=.prettierignore", - "debug:inspect": "node --inspect-brk bin/prettier.js --ignore-path=.prettierignore" + "debug": "node bin/prettier.js --ignore-path=.prettierignore --plugin=./packages/plugin-oxc/index.js", + "debug:watch": "node --watch bin/prettier.js --ignore-path=.prettierignore --plugin=./packages/plugin-oxc/index.js", + "debug:inspect": "node --inspect-brk bin/prettier.js --ignore-path=.prettierignore --plugin=./packages/plugin-oxc/index.js" }, "c8": { "reporter": [ diff --git a/packages/plugin-oxc/README.md b/packages/plugin-oxc/README.md index f7cec954d..cdcf9c1b2 100644 --- a/packages/plugin-oxc/README.md +++ b/packages/plugin-oxc/README.md @@ -16,11 +16,18 @@ Create or modify your [prettier configuration file](https://prettier.io/docs/en/ { "overrides": [ { - "files": ["**/*.{js,mjs,cjs}"], + "files": ["**/*.{js,mjs,cjs,jsx}"], "options": { "plugins": ["@prettier/plugin-oxc"], "parser": "oxc" } + }, + { + "files": ["**/*.{ts,mts,cts,tsx}"], + "options": { + "plugins": ["@prettier/plugin-oxc"], + "parser": "oxc-ts" + } } ] } diff --git a/packages/plugin-oxc/index.js b/packages/plugin-oxc/index.js index d81d6defb..f830f22b6 100644 --- a/packages/plugin-oxc/index.js +++ b/packages/plugin-oxc/index.js @@ -1,3 +1 @@ -import { oxc } from "../../src/language-js/parse/oxc.js"; - -export const parsers = { oxc }; +export * as parsers from "../../src/language-js/parse/oxc.js"; diff --git a/src/language-js/comments/printer-methods.js b/src/language-js/comments/printer-methods.js index ed8d74880..9884f4b78 100644 --- a/src/language-js/comments/printer-methods.js +++ b/src/language-js/comments/printer-methods.js @@ -46,6 +46,7 @@ function getCommentChildNodes(node, options) { options.parser === "flow" || options.parser === "acorn" || options.parser === "oxc" || + options.parser === "oxc-ts" || options.parser === "espree" || options.parser === "meriyah" || options.parser === "__babel_estree") && diff --git a/src/language-js/parse/oxc.js b/src/language-js/parse/oxc.js index 87c397675..44b9fdc96 100644 --- a/src/language-js/parse/oxc.js +++ b/src/language-js/parse/oxc.js @@ -31,13 +31,11 @@ const isRawTransferSupported = () => { return cachedIsRawTransferSupported; }; -async function parseWithOptions(filename, text, sourceType) { +async function parseWithOptions(filename, text, options) { const result = await oxcParse(filename, text, { - sourceType, - lang: "jsx", preserveParens: true, - // @ts-expect-error -- missing experimentalRawTransfer: isRawTransferSupported(), + ...options, }); const { errors } = result; @@ -56,7 +54,7 @@ async function parseWithOptions(filename, text, sourceType) { return result; } -async function parse(text, options = {}) { +async function parseJs(text, options = {}) { const sourceType = getSourceType(options); let { filepath } = options; if (typeof filepath !== "string") { @@ -64,7 +62,8 @@ async function parse(text, options = {}) { } const combinations = (sourceType ? [sourceType] : ["module", "script"]).map( - (sourceType) => () => parseWithOptions(filepath, text, sourceType), + (sourceType) => () => + parseWithOptions(filepath, text, { sourceType, lang: "jsx" }), ); let result; @@ -81,4 +80,75 @@ async function parse(text, options = {}) { return postprocess(ast, { text, parser: "oxc" }); } -export const oxc = createParser(parse); +function getTsParseOptionsCombinations(text, options) { + const sourceType = getSourceType(options); + /** @type {("module" | "script") []} */ + const sourceTypes = sourceType ? [sourceType] : ["module", "script"]; + const combinations = sourceTypes.map((sourceType) => ({ sourceType })); + + const extension = options.filepath?.toLowerCase().split(".").at(-1); + const isKnownJsx = extension === "jsx" || extension === "tsx"; + + if (isKnownJsx) { + return combinations.map((parseOptions) => ({ + ...parseOptions, + lang: "tsx", + })); + } + + const shouldEnableJsx = isProbablyJsx(text); + return combinations.flatMap((parseOptions) => + [shouldEnableJsx, !shouldEnableJsx].map((jsx) => + jsx ? { ...parseOptions, lang: "tsx" } : { ...parseOptions, lang: "ts" }, + ), + ); +} + +async function parseTs(text, options = {}) { + const parseOptionsCombinations = getTsParseOptionsCombinations(text, options); + let { filepath } = options; + if (typeof filepath !== "string") { + filepath = "prettier.tsx"; + } + + let result; + try { + result = await tryCombinationsAsync( + parseOptionsCombinations.map( + (parseOptions) => () => + parseWithOptions(filepath, text, { ...parseOptions, astType: "ts" }), + ), + ); + } catch ({ + // @ts-expect-error -- expected + errors: [error], + }) { + throw error; + } + + const { program: ast, comments } = result; + // @ts-expect-error -- expected + ast.comments = comments; + return postprocess(ast, { text, parser: "oxc", oxcAstType: "ts" }); +} + +/** + * Use a naive regular expression to detect JSX + * copied from typescript.js + */ +function isProbablyJsx(text) { + return new RegExp( + // eslint-disable-next-line regexp/no-useless-non-capturing-group -- possible bug + [ + "(?:^[^\"'`]*)", // Contains "/>" on line not starting with "//" + ].join(""), + "mu", + ).test(text); +} + +const oxc = createParser(parseJs); +const oxcTs = createParser(parseTs); + +export { oxc, oxcTs as "oxc-ts" }; diff --git a/src/language-js/parse/postprocess/index.js b/src/language-js/parse/postprocess/index.js index 7db0b0545..69dfe1069 100644 --- a/src/language-js/parse/postprocess/index.js +++ b/src/language-js/parse/postprocess/index.js @@ -34,6 +34,7 @@ const isNodeWithRaw = createTypeCheckFunction([ * @param {{ * text: string, * parser?: string, + * oxcAstType?: string, * }} options */ function postprocess(ast, options) { @@ -49,6 +50,12 @@ function postprocess(ast, options) { delete program.interpreter; } + if (parser === "oxc" && options.oxcAstType === "ts" && ast.hashbang) { + const { comments, hashbang } = ast; + comments.unshift(hashbang); + delete program.hashbang; + } + if (ast.comments.length > 0) { let followingComment; for (let i = ast.comments.length - 1; i >= 0; i--) { @@ -117,13 +124,23 @@ function postprocess(ast, options) { } break; + // This happens when use `oxc-parser` to parse `` `${foo satisfies bar}`; `` + // https://github.com/oxc-project/oxc/issues/11313 + case "TemplateLiteral": + /* c8 ignore next 3 */ + if (node.expressions.length !== node.quasis.length - 1) { + throw new Error("Malformed template literal."); + } + break; + case "TemplateElement": - // `flow` and `typescript` follows the `espree` style positions + // `flow`, `typescript`, and `oxc`(with `{astType: 'ts'}`) follows the `espree` style positions // https://github.com/eslint/js/blob/5826877f7b33548e5ba984878dd4a8eac8448f87/packages/espree/lib/espree.js#L213 if ( parser === "flow" || parser === "espree" || - parser === "typescript" + parser === "typescript" || + (parser === "oxc" && options.oxcAstType === "ts") ) { const start = locStart(node) + 1; const end = locEnd(node) - (node.tail ? 1 : 2); diff --git a/src/language-js/print/property.js b/src/language-js/print/property.js index 7d972946e..c6aabcaf3 100644 --- a/src/language-js/print/property.js +++ b/src/language-js/print/property.js @@ -56,7 +56,8 @@ function isStringKeySafeToUnquote(node, options) { // See https://github.com/microsoft/TypeScript/pull/20075 !( (options.parser === "babel-ts" && node.type === "ClassProperty") || - (options.parser === "typescript" && node.type === "PropertyDefinition") + ((options.parser === "typescript" || options.parser === "oxc-ts") && + node.type === "PropertyDefinition") ) ) { return true; @@ -90,7 +91,11 @@ function shouldQuotePropertyKey(path, options) { String(key.value) === printNumber(getRaw(key)) && // Quoting number keys is safe in JS and Flow, but not in TypeScript (as // mentioned in `isStringKeySafeToUnquote`). - !(options.parser === "typescript" || options.parser === "babel-ts"))) && + !( + options.parser === "typescript" || + options.parser === "babel-ts" || + options.parser === "oxc-ts" + ))) && (options.parser === "json" || options.parser === "jsonc" || (options.quoteProps === "consistent" && needsQuoteProps.get(path.parent))) diff --git a/src/language-js/utils/is-line-comment.js b/src/language-js/utils/is-line-comment.js index 9c99b038a..79aedac05 100644 --- a/src/language-js/utils/is-line-comment.js +++ b/src/language-js/utils/is-line-comment.js @@ -16,7 +16,7 @@ const isLineComment = createTypeCheckFunction([ "HashbangComment", "HTMLOpen", "HTMLClose", - // `espree` + // `espree`, and `oxc`(with `{astType: 'ts'}`) "Hashbang", // `babel` and `flow` hashbang "InterpreterDirective", diff --git a/src/main/range-util.js b/src/main/range-util.js index b2e2906a3..b4cb9acd6 100644 --- a/src/main/range-util.js +++ b/src/main/range-util.js @@ -178,6 +178,7 @@ function isSourceElement(opts, node, parentNode) { case "espree": case "meriyah": case "oxc": + case "oxc-ts": case "__babel_estree": return isJsSourceElement(node.type, parentNode?.type); case "json": diff --git a/tests/config/run-format-test.js b/tests/config/run-format-test.js index ccae14ca3..174f0b639 100644 --- a/tests/config/run-format-test.js +++ b/tests/config/run-format-test.js @@ -97,6 +97,12 @@ const oxcDisabledTests = new Set( "js/ignore/class-expression-decorator.js", ].map((file) => path.join(__dirname, "../format", file)), ); +const oxcTsDisabledTests = new Set( + [ + // https://github.com/oxc-project/oxc/issues/11029 + "typescript/decorators/abstract-method.ts", + ].map((file) => path.join(__dirname, "../format", file)), +); const isUnstable = (filename, options) => { const testFunction = unstableTests.get(filename); @@ -255,12 +261,13 @@ function runFormatTest(fixtures, parsers, options) { } } - if ( - parsers.includes("typescript") && - !parsers.includes("babel-ts") && - !IS_TYPESCRIPT_ONLY_TEST - ) { - allParsers.push("babel-ts"); + if (parsers.includes("typescript") && !IS_TYPESCRIPT_ONLY_TEST) { + if (!parsers.includes("babel-ts")) { + allParsers.push("babel-ts"); + } + if (!parsers.includes("oxc-ts")) { + allParsers.push("oxc-ts"); + } } if (parsers.includes("flow") && !parsers.includes("babel-flow")) { @@ -306,6 +313,7 @@ function runFormatTest(fixtures, parsers, options) { (currentParser === "espree" && espreeDisabledTests.has(filename)) || (currentParser === "meriyah" && meriyahDisabledTests.has(filename)) || (currentParser === "oxc" && oxcDisabledTests.has(filename)) || + (currentParser === "oxc-ts" && oxcTsDisabledTests.has(filename)) || (currentParser === "babel-ts" && babelTsDisabledTests.has(filename)) ) { continue; @@ -554,7 +562,7 @@ async function format(originalText, originalOptions) { } async function loadPlugins(options) { - if (options.parser === "oxc") { + if (options.parser === "oxc" || options.parser === "oxc-ts") { const plugins = options.plugins ?? []; const url = new URL( isProduction diff --git a/tests/config/utils/check-parsers.js b/tests/config/utils/check-parsers.js index 19dafab8f..bd3c82c80 100644 --- a/tests/config/utils/check-parsers.js +++ b/tests/config/utils/check-parsers.js @@ -57,13 +57,14 @@ const categoryParsers = new Map([ [ "js", { - parsers: ["babel", "acorn", "espree", "meriyah", "oxc"], + parsers: ["babel", "acorn", "espree", "meriyah", "oxc", "oxc-ts"], verifyParsers: [ "babel", "acorn", "espree", "meriyah", "oxc", + "oxc-ts", "flow", "babel-flow", "typescript", @@ -133,8 +134,8 @@ const categoryParsers = new Map([ [ "typescript", { - parsers: ["typescript", "babel-ts"], - verifyParsers: ["typescript", "babel-ts", "flow", "babel-flow"], + parsers: ["typescript", "babel-ts", "oxc-ts"], + verifyParsers: ["typescript", "babel-ts", "flow", "babel-flow", "oxc-ts"], extensions: [".ts", ".tsx", ".cts", ".mts"], }, ], diff --git a/tests/format/flow/mapped-types/__snapshots__/format.test.js.snap b/tests/format/flow/mapped-types/__snapshots__/format.test.js.snap index 24238bd30..88cccccba 100644 --- a/tests/format/flow/mapped-types/__snapshots__/format.test.js.snap +++ b/tests/format/flow/mapped-types/__snapshots__/format.test.js.snap @@ -24,6 +24,17 @@ exports[`comments.js [babel-ts] format 1`] = ` Cause: Unexpected token (3:2)" `; +exports[`comments.js [oxc-ts] format 1`] = ` +"Unexpected token (3:3) + 1 | type Type = { + 2 | // comment +> 3 | +[T in number]: number; + | ^ + 4 | }; + 5 | + 6 | type Type = {" +`; + exports[`comments.js [typescript] format 1`] = ` "Property or signature expected. (3:3) 1 | type Type = { @@ -151,6 +162,17 @@ exports[`mapped-types.js [babel-ts] format 1`] = ` Cause: Unexpected token (5:27)" `; +exports[`mapped-types.js [oxc-ts] format 1`] = ` +"Unexpected token (5:28) + 3 | type Mapped = {[key in keyof O]: O[key]}; + 4 | type MappedLong = {[key in keyof AReallyLongNameThatShouldReallyMostDefinitelyCauseALineWrap]: number}; +> 5 | type MappedWithVariance = {+[key in keyof O]: number}; + | ^ + 6 | type MappedWithVarianceLong = {-[key in keyof AReallyLongNameThatShouldReallyMostDefinitelyCauseALineWrap]: number}; + 7 | type MappedWithPlusOptional = {[key in keyof O]+?: number}; + 8 | type MappedWithMinusOptional = {[key in keyof O]-?: number};" +`; + exports[`mapped-types.js [typescript] format 1`] = ` "Property or signature expected. (5:28) 3 | type Mapped = {[key in keyof O]: O[key]}; diff --git a/tests/format/flow/mapped-types/format.test.js b/tests/format/flow/mapped-types/format.test.js index 797cbca40..912eeb33c 100644 --- a/tests/format/flow/mapped-types/format.test.js +++ b/tests/format/flow/mapped-types/format.test.js @@ -3,5 +3,6 @@ runFormatTest(import.meta, ["flow", "typescript"], { "babel-flow": ["comments.js", "mapped-types.js", "ts-compatibility.js"], "babel-ts": ["comments.js", "mapped-types.js"], typescript: ["comments.js", "mapped-types.js"], + "oxc-ts": ["comments.js", "mapped-types.js"], }, }); diff --git a/tests/format/js/arrows-bind/format.test.js b/tests/format/js/arrows-bind/format.test.js index 6e1f44b04..c0a7f0191 100644 --- a/tests/format/js/arrows-bind/format.test.js +++ b/tests/format/js/arrows-bind/format.test.js @@ -1,3 +1,9 @@ runFormatTest(import.meta, ["babel"], { - errors: { acorn: true, espree: true, meriyah: true, oxc: true }, + errors: { + acorn: true, + espree: true, + meriyah: true, + oxc: true, + "oxc-ts": true, + }, }); diff --git a/tests/format/js/async-do-expressions/format.test.js b/tests/format/js/async-do-expressions/format.test.js index 6e1f44b04..c0a7f0191 100644 --- a/tests/format/js/async-do-expressions/format.test.js +++ b/tests/format/js/async-do-expressions/format.test.js @@ -1,3 +1,9 @@ runFormatTest(import.meta, ["babel"], { - errors: { acorn: true, espree: true, meriyah: true, oxc: true }, + errors: { + acorn: true, + espree: true, + meriyah: true, + oxc: true, + "oxc-ts": true, + }, }); diff --git a/tests/format/js/babel-plugins/format.test.js b/tests/format/js/babel-plugins/format.test.js index 45f46217f..5faa3846e 100644 --- a/tests/format/js/babel-plugins/format.test.js +++ b/tests/format/js/babel-plugins/format.test.js @@ -94,6 +94,24 @@ runFormatTest(import.meta, ["babel", "babel-ts", "babel-flow"], { "typescript.js", "v8intrinsic.js", ], + "oxc-ts": [ + "async-do-expressions.js", + "destructuring-private.js", + "do-expressions.js", + "export-default-from.js", + "flow.js", + "function-bind.js", + "function-sent.js", + "module-blocks.js", + "optional-chaining-assignment.js", + "partial-application.js", + "pipeline-operator-fsharp.js", + "pipeline-operator-hack.js", + "pipeline-operator-minimal.js", + "throw-expressions.js", + "typescript.js", + "v8intrinsic.js", + ], babel: ["flow.js", "typescript.js"], __babel_estree: ["flow.js", "typescript.js"], }, diff --git a/tests/format/js/bind-expressions/format.test.js b/tests/format/js/bind-expressions/format.test.js index d2a87850b..ab36700a0 100644 --- a/tests/format/js/bind-expressions/format.test.js +++ b/tests/format/js/bind-expressions/format.test.js @@ -1,7 +1,10 @@ -runFormatTest(import.meta, ["babel"], { - errors: { acorn: true, espree: true, meriyah: true, oxc: true }, -}); -runFormatTest(import.meta, ["babel"], { - semi: false, - errors: { acorn: true, espree: true, meriyah: true, oxc: true }, -}); +const errors = { + acorn: true, + espree: true, + meriyah: true, + oxc: true, + "oxc-ts": true, +}; + +runFormatTest(import.meta, ["babel"], { errors }); +runFormatTest(import.meta, ["babel"], { semi: false, errors }); diff --git a/tests/format/js/call/invalid/format.test.js b/tests/format/js/call/invalid/format.test.js index 3e782ee1c..e3c45792c 100644 --- a/tests/format/js/call/invalid/format.test.js +++ b/tests/format/js/call/invalid/format.test.js @@ -6,5 +6,6 @@ runFormatTest(import.meta, ["babel"], { espree: true, meriyah: true, oxc: true, + "oxc-ts": true, }, }); diff --git a/tests/format/js/comments-pipeline-own-line/format.test.js b/tests/format/js/comments-pipeline-own-line/format.test.js index 6e1f44b04..c0a7f0191 100644 --- a/tests/format/js/comments-pipeline-own-line/format.test.js +++ b/tests/format/js/comments-pipeline-own-line/format.test.js @@ -1,3 +1,9 @@ runFormatTest(import.meta, ["babel"], { - errors: { acorn: true, espree: true, meriyah: true, oxc: true }, + errors: { + acorn: true, + espree: true, + meriyah: true, + oxc: true, + "oxc-ts": true, + }, }); diff --git a/tests/format/js/deferred-import-evaluation/format.test.js b/tests/format/js/deferred-import-evaluation/format.test.js index b785d5d78..d3fc06873 100644 --- a/tests/format/js/deferred-import-evaluation/format.test.js +++ b/tests/format/js/deferred-import-evaluation/format.test.js @@ -12,6 +12,7 @@ runFormatTest(import.meta, ["babel"], { espree: [...importDeferTests, ...invalidSyntaxTests], meriyah: [...importDeferTests, ...invalidSyntaxTests], oxc: invalidSyntaxTests, + "oxc-ts": invalidSyntaxTests, babel: invalidSyntaxTests, __babel_estree: invalidSyntaxTests, }, diff --git a/tests/format/js/destructuring-private-fields/format.test.js b/tests/format/js/destructuring-private-fields/format.test.js index 0d936213d..9ba1253eb 100644 --- a/tests/format/js/destructuring-private-fields/format.test.js +++ b/tests/format/js/destructuring-private-fields/format.test.js @@ -1,3 +1,9 @@ runFormatTest(import.meta, ["babel", "babel-flow", "babel-ts"], { - errors: { acorn: true, espree: true, meriyah: true, oxc: true }, + errors: { + acorn: true, + espree: true, + meriyah: true, + oxc: true, + "oxc-ts": true, + }, }); diff --git a/tests/format/js/do/format.test.js b/tests/format/js/do/format.test.js index 6e1f44b04..c0a7f0191 100644 --- a/tests/format/js/do/format.test.js +++ b/tests/format/js/do/format.test.js @@ -1,3 +1,9 @@ runFormatTest(import.meta, ["babel"], { - errors: { acorn: true, espree: true, meriyah: true, oxc: true }, + errors: { + acorn: true, + espree: true, + meriyah: true, + oxc: true, + "oxc-ts": true, + }, }); diff --git a/tests/format/js/explicit-resource-management/__snapshots__/format.test.js.snap b/tests/format/js/explicit-resource-management/__snapshots__/format.test.js.snap index 127ed7856..1801272ee 100644 --- a/tests/format/js/explicit-resource-management/__snapshots__/format.test.js.snap +++ b/tests/format/js/explicit-resource-management/__snapshots__/format.test.js.snap @@ -866,6 +866,15 @@ exports[`valid-module-block-top-level-await-using-binding.js [oxc] format 1`] = 4 |" `; +exports[`valid-module-block-top-level-await-using-binding.js [oxc-ts] format 1`] = ` +"Expected a semicolon or an implicit semicolon after a statement, but found none (1:17) +> 1 | const m = module { + | ^ + 2 | await using foo = bar(); + 3 | } + 4 |" +`; + exports[`valid-module-block-top-level-await-using-binding.js [typescript] format 1`] = ` "',' expected. (1:18) > 1 | const m = module { @@ -942,6 +951,15 @@ exports[`valid-module-block-top-level-using-binding.js [oxc] format 1`] = ` 4 |" `; +exports[`valid-module-block-top-level-using-binding.js [oxc-ts] format 1`] = ` +"Expected a semicolon or an implicit semicolon after a statement, but found none (1:7) +> 1 | module { + | ^ + 2 | using foo = bar(); + 3 | } + 4 |" +`; + exports[`valid-module-block-top-level-using-binding.js [typescript] format 1`] = ` "Namespace must be given a name. (1:8) > 1 | module { diff --git a/tests/format/js/explicit-resource-management/format.test.js b/tests/format/js/explicit-resource-management/format.test.js index b6b896aae..288bc5793 100644 --- a/tests/format/js/explicit-resource-management/format.test.js +++ b/tests/format/js/explicit-resource-management/format.test.js @@ -109,5 +109,11 @@ runFormatTest(import.meta, ["babel", "flow", "typescript"], { "valid-module-block-top-level-using-binding.js", "valid-module-block-top-level-await-using-binding.js", ], + "oxc-ts": [ + // "invalid-duplicate-using-bindings.js", + // "invalid-script-top-level-using-binding.js", + "valid-module-block-top-level-using-binding.js", + "valid-module-block-top-level-await-using-binding.js", + ], }, }); diff --git a/tests/format/js/export-default/escaped/format.test.js b/tests/format/js/export-default/escaped/format.test.js index 578b9300a..cc42d5f70 100644 --- a/tests/format/js/export-default/escaped/format.test.js +++ b/tests/format/js/export-default/escaped/format.test.js @@ -1,3 +1,10 @@ runFormatTest(import.meta, ["babel", "flow"], { - errors: { acorn: true, espree: true, meriyah: true, flow: true, oxc: true }, + errors: { + acorn: true, + espree: true, + meriyah: true, + flow: true, + oxc: true, + "oxc-ts": true, + }, }); diff --git a/tests/format/js/export-default/export-default-from/format.test.js b/tests/format/js/export-default/export-default-from/format.test.js index 6e1f44b04..c0a7f0191 100644 --- a/tests/format/js/export-default/export-default-from/format.test.js +++ b/tests/format/js/export-default/export-default-from/format.test.js @@ -1,3 +1,9 @@ runFormatTest(import.meta, ["babel"], { - errors: { acorn: true, espree: true, meriyah: true, oxc: true }, + errors: { + acorn: true, + espree: true, + meriyah: true, + oxc: true, + "oxc-ts": true, + }, }); diff --git a/tests/format/js/module-blocks/format.test.js b/tests/format/js/module-blocks/format.test.js index fadaccdf8..955083ef9 100644 --- a/tests/format/js/module-blocks/format.test.js +++ b/tests/format/js/module-blocks/format.test.js @@ -4,5 +4,6 @@ runFormatTest(import.meta, ["babel"], { espree: ["module-blocks.js", "range.js", "comments.js", "worker.js"], meriyah: ["module-blocks.js", "range.js", "comments.js", "worker.js"], oxc: ["module-blocks.js", "range.js", "comments.js", "worker.js"], + "oxc-ts": ["module-blocks.js", "range.js", "comments.js", "worker.js"], }, }); diff --git a/tests/format/js/multiparser-invalid/__snapshots__/format.test.js.snap b/tests/format/js/multiparser-invalid/__snapshots__/format.test.js.snap index 85c29a5cc..bff23f84f 100644 --- a/tests/format/js/multiparser-invalid/__snapshots__/format.test.js.snap +++ b/tests/format/js/multiparser-invalid/__snapshots__/format.test.js.snap @@ -56,6 +56,17 @@ exports[`text.js [oxc] format 1`] = ` 9 | foo = foo\`\\u{prettier}\${foo}pr\\u{0065}ttier\`;" `; +exports[`text.js [oxc-ts] format 1`] = ` +"Bad escape sequence in untagged template literal (6:18) + 4 | foo = markdown\`\\u{prettier}\\u{0065}\`; + 5 | foo = css\`\\u{prettier}\\u{0065}\`; +> 6 | foo = /* HTML */\`\\u{prettier}\\u{0065}\`; + | ^^^^^^^^^^^^^^^^^^^^ + 7 | foo = /* GraphQL */\`\\u{prettier}\\u{0065}\`; + 8 | + 9 | foo = foo\`\\u{prettier}\${foo}pr\\u{0065}ttier\`;" +`; + exports[`text.js [typescript] format 1`] = ` "Hexadecimal digit expected. (6:21) 4 | foo = markdown\`\\u{prettier}\\u{0065}\`; diff --git a/tests/format/js/multiparser-invalid/format.test.js b/tests/format/js/multiparser-invalid/format.test.js index 07531592d..848a44055 100644 --- a/tests/format/js/multiparser-invalid/format.test.js +++ b/tests/format/js/multiparser-invalid/format.test.js @@ -6,5 +6,6 @@ runFormatTest(import.meta, ["babel", "flow", "typescript"], { typescript: true, meriyah: true, oxc: true, + "oxc-ts": true, }, }); diff --git a/tests/format/js/no-semi-babylon-extensions/format.test.js b/tests/format/js/no-semi-babylon-extensions/format.test.js index d2a87850b..ad763c739 100644 --- a/tests/format/js/no-semi-babylon-extensions/format.test.js +++ b/tests/format/js/no-semi-babylon-extensions/format.test.js @@ -1,7 +1,9 @@ -runFormatTest(import.meta, ["babel"], { - errors: { acorn: true, espree: true, meriyah: true, oxc: true }, -}); -runFormatTest(import.meta, ["babel"], { - semi: false, - errors: { acorn: true, espree: true, meriyah: true, oxc: true }, -}); +const errors = { + acorn: true, + espree: true, + meriyah: true, + oxc: true, + "oxc-ts": true, +}; +runFormatTest(import.meta, ["babel"], { errors }); +runFormatTest(import.meta, ["babel"], { semi: false, errors }); diff --git a/tests/format/js/objects/__snapshots__/format.test.js.snap b/tests/format/js/objects/__snapshots__/format.test.js.snap index d021a3ff4..55cb812a3 100644 --- a/tests/format/js/objects/__snapshots__/format.test.js.snap +++ b/tests/format/js/objects/__snapshots__/format.test.js.snap @@ -128,6 +128,17 @@ exports[`expression.js [oxc] format 1`] = ` 8 | ({} = 0);" `; +exports[`expression.js [oxc-ts] format 1`] = ` +"Expected \`,\` but found \`:\` (5:4) + 3 | a = () => ({}).x; + 4 | ({} && a, b); +> 5 | ({}::b, 0); + | ^ + 6 | ({}::b()\`\`[''].c++ && 0 ? 0 : 0, 0); + 7 | ({}(), 0); + 8 | ({} = 0);" +`; + exports[`expression.js [typescript] format 1`] = ` "')' expected. (5:4) 3 | a = () => ({}).x; diff --git a/tests/format/js/objects/format.test.js b/tests/format/js/objects/format.test.js index c32eeca47..a6c9deb1f 100644 --- a/tests/format/js/objects/format.test.js +++ b/tests/format/js/objects/format.test.js @@ -5,6 +5,7 @@ runFormatTest(import.meta, ["babel", "typescript", "flow"], { typescript: ["expression.js"], meriyah: ["expression.js"], oxc: ["expression.js"], + "oxc-ts": ["expression.js"], flow: ["expression.js"], }, }); diff --git a/tests/format/js/optional-chaining-assignment/format.test.js b/tests/format/js/optional-chaining-assignment/format.test.js index 482d909d6..fd1452eb2 100644 --- a/tests/format/js/optional-chaining-assignment/format.test.js +++ b/tests/format/js/optional-chaining-assignment/format.test.js @@ -32,6 +32,7 @@ runFormatTest(import.meta, ["babel"], { ...invalidSyntaxTests, ], oxc: [...optionalChainingAssignTests, ...invalidSyntaxTests], + "oxc-ts": [...optionalChainingAssignTests, ...invalidSyntaxTests], babel: invalidSyntaxTests, __babel_estree: invalidSyntaxTests, }, diff --git a/tests/format/js/partial-application/format.test.js b/tests/format/js/partial-application/format.test.js index 6e1f44b04..c0a7f0191 100644 --- a/tests/format/js/partial-application/format.test.js +++ b/tests/format/js/partial-application/format.test.js @@ -1,3 +1,9 @@ runFormatTest(import.meta, ["babel"], { - errors: { acorn: true, espree: true, meriyah: true, oxc: true }, + errors: { + acorn: true, + espree: true, + meriyah: true, + oxc: true, + "oxc-ts": true, + }, }); diff --git a/tests/format/js/pipeline-operator/format.test.js b/tests/format/js/pipeline-operator/format.test.js index 6e1f44b04..c0a7f0191 100644 --- a/tests/format/js/pipeline-operator/format.test.js +++ b/tests/format/js/pipeline-operator/format.test.js @@ -1,3 +1,9 @@ runFormatTest(import.meta, ["babel"], { - errors: { acorn: true, espree: true, meriyah: true, oxc: true }, + errors: { + acorn: true, + espree: true, + meriyah: true, + oxc: true, + "oxc-ts": true, + }, }); diff --git a/tests/format/js/source-phase-imports/format.test.js b/tests/format/js/source-phase-imports/format.test.js index 512abb2ad..a02532b70 100644 --- a/tests/format/js/source-phase-imports/format.test.js +++ b/tests/format/js/source-phase-imports/format.test.js @@ -14,6 +14,7 @@ runFormatTest(import.meta, ["babel"], { espree: [...importSourceTests, ...invalidSyntaxTests], meriyah: [...importSourceTests, ...invalidSyntaxTests], oxc: invalidSyntaxTests, + "oxc-ts": invalidSyntaxTests, babel: invalidSyntaxTests, __babel_estree: invalidSyntaxTests, }, diff --git a/tests/format/js/throw_expressions/format.test.js b/tests/format/js/throw_expressions/format.test.js index 6e1f44b04..c0a7f0191 100644 --- a/tests/format/js/throw_expressions/format.test.js +++ b/tests/format/js/throw_expressions/format.test.js @@ -1,3 +1,9 @@ runFormatTest(import.meta, ["babel"], { - errors: { acorn: true, espree: true, meriyah: true, oxc: true }, + errors: { + acorn: true, + espree: true, + meriyah: true, + oxc: true, + "oxc-ts": true, + }, }); diff --git a/tests/format/js/v8_intrinsic/format.test.js b/tests/format/js/v8_intrinsic/format.test.js index 6e1f44b04..c0a7f0191 100644 --- a/tests/format/js/v8_intrinsic/format.test.js +++ b/tests/format/js/v8_intrinsic/format.test.js @@ -1,3 +1,9 @@ runFormatTest(import.meta, ["babel"], { - errors: { acorn: true, espree: true, meriyah: true, oxc: true }, + errors: { + acorn: true, + espree: true, + meriyah: true, + oxc: true, + "oxc-ts": true, + }, }); diff --git a/tests/format/jsx/do/format.test.js b/tests/format/jsx/do/format.test.js index f1e1a4294..ef7bd3702 100644 --- a/tests/format/jsx/do/format.test.js +++ b/tests/format/jsx/do/format.test.js @@ -4,5 +4,6 @@ runFormatTest(import.meta, ["babel"], { espree: ["do.js"], meriyah: ["do.js"], oxc: ["do.js"], + "oxc-ts": ["do.js"], }, }); diff --git a/tests/format/typescript/class/__snapshots__/format.test.js.snap b/tests/format/typescript/class/__snapshots__/format.test.js.snap index 4cdd099ac..a9676514c 100644 --- a/tests/format/typescript/class/__snapshots__/format.test.js.snap +++ b/tests/format/typescript/class/__snapshots__/format.test.js.snap @@ -34,6 +34,17 @@ abstract class Bar { ================================================================================ `; +exports[`constructor.ts [oxc-ts] format 1`] = ` +"Classes can't have a field named 'constructor' (8:5) + 6 | + 7 | class A { +> 8 | 'constructor': typeof A + | ^^^^^^^^^^^^^ + 9 | static Foo() { + 10 | return new A() + 11 | }" +`; + exports[`constructor.ts format 1`] = ` ====================================options===================================== parsers: ["typescript"] diff --git a/tests/format/typescript/class/format.test.js b/tests/format/typescript/class/format.test.js index 116dcbd78..3ed84d3b7 100644 --- a/tests/format/typescript/class/format.test.js +++ b/tests/format/typescript/class/format.test.js @@ -1 +1,8 @@ -runFormatTest(import.meta, ["typescript"]); +runFormatTest(import.meta, ["typescript"], { + errors: { + "oxc-ts": [ + // TODO: Ask typescript-eslint to throw + "constructor.ts", + ], + }, +}); diff --git a/tests/format/typescript/conformance/classes/constructorDeclarations/constructorParameters/__snapshots__/format.test.js.snap b/tests/format/typescript/conformance/classes/constructorDeclarations/constructorParameters/__snapshots__/format.test.js.snap index 82b0fe29c..356cedf93 100644 --- a/tests/format/typescript/conformance/classes/constructorDeclarations/constructorParameters/__snapshots__/format.test.js.snap +++ b/tests/format/typescript/conformance/classes/constructorDeclarations/constructorParameters/__snapshots__/format.test.js.snap @@ -509,6 +509,15 @@ exports[`readonlyReadonly.ts [babel-ts] format 1`] = ` Cause: Duplicate modifier: 'readonly'. (2:13)" `; +exports[`readonlyReadonly.ts [oxc-ts] format 1`] = ` +"readonly' modifier already seen. (2:14) + 1 | class C { +> 2 | readonly readonly x: number; + | ^^^^^^^^ + 3 | constructor(readonly readonly y: number) {} + 4 | }" +`; + exports[`readonlyReadonly.ts format 1`] = ` ====================================options===================================== parsers: ["typescript"] diff --git a/tests/format/typescript/conformance/classes/constructorDeclarations/constructorParameters/format.test.js b/tests/format/typescript/conformance/classes/constructorDeclarations/constructorParameters/format.test.js index 06972b9df..da58106e0 100644 --- a/tests/format/typescript/conformance/classes/constructorDeclarations/constructorParameters/format.test.js +++ b/tests/format/typescript/conformance/classes/constructorDeclarations/constructorParameters/format.test.js @@ -1,5 +1,6 @@ runFormatTest(import.meta, ["typescript"], { errors: { "babel-ts": ["readonlyInConstructorParameters.ts", "readonlyReadonly.ts"], + "oxc-ts": ["readonlyReadonly.ts"], }, }); diff --git a/tests/format/typescript/conformance/types/functions/__snapshots__/format.test.js.snap b/tests/format/typescript/conformance/types/functions/__snapshots__/format.test.js.snap index d2d346d99..c4efac423 100644 --- a/tests/format/typescript/conformance/types/functions/__snapshots__/format.test.js.snap +++ b/tests/format/typescript/conformance/types/functions/__snapshots__/format.test.js.snap @@ -603,6 +603,16 @@ exports[`functionOverloadErrorsSyntax.ts [babel-ts] format 1`] = ` Cause: Rest element must be last element. (9:35)" `; +exports[`functionOverloadErrorsSyntax.ts [oxc-ts] format 1`] = ` +"A rest parameter must be last in a parameter list (9:25) + 7 | + 8 | //Function overload signature with rest param followed by non-optional parameter +> 9 | function fn5(x: string, ...y: any[], z: string); + | ^^^^^^^^^^^ + 10 | function fn5() { } + 11 |" +`; + exports[`functionOverloadErrorsSyntax.ts format 1`] = ` ====================================options===================================== parsers: ["typescript"] diff --git a/tests/format/typescript/conformance/types/functions/format.test.js b/tests/format/typescript/conformance/types/functions/format.test.js index da8cbf3f1..3d703a140 100644 --- a/tests/format/typescript/conformance/types/functions/format.test.js +++ b/tests/format/typescript/conformance/types/functions/format.test.js @@ -1,3 +1,6 @@ runFormatTest(import.meta, ["typescript"], { - errors: { "babel-ts": ["functionOverloadErrorsSyntax.ts"] }, + errors: { + "babel-ts": ["functionOverloadErrorsSyntax.ts"], + "oxc-ts": ["functionOverloadErrorsSyntax.ts"], + }, }); diff --git a/tests/format/typescript/decorators/format.test.js b/tests/format/typescript/decorators/format.test.js index b25e0a3a1..91c4c595a 100644 --- a/tests/format/typescript/decorators/format.test.js +++ b/tests/format/typescript/decorators/format.test.js @@ -1,6 +1,7 @@ runFormatTest(import.meta, ["typescript"], { errors: { typescript: ["abstract-method.ts"], + "oxc-ts": ["abstract-method.ts"], "babel-ts": ["issue-9102.ts"], }, }); diff --git a/tests/format/typescript/enum/__snapshots__/format.test.js.snap b/tests/format/typescript/enum/__snapshots__/format.test.js.snap index 7433ffba4..73b3fafb3 100644 --- a/tests/format/typescript/enum/__snapshots__/format.test.js.snap +++ b/tests/format/typescript/enum/__snapshots__/format.test.js.snap @@ -11,6 +11,16 @@ exports[`computed-members.ts [babel-ts] format 1`] = ` Cause: Unexpected token (2:2)" `; +exports[`computed-members.ts [oxc-ts] format 1`] = ` +"Computed property names are not allowed in enums. (2:4) + 1 | enum A { +> 2 | [i++], + | ^^^ + 3 | } + 4 | + 5 | const bar = "bar"" +`; + exports[`computed-members.ts format 1`] = ` ====================================options===================================== parsers: ["typescript"] diff --git a/tests/format/typescript/enum/format.test.js b/tests/format/typescript/enum/format.test.js index a1cc3ad19..d5137df63 100644 --- a/tests/format/typescript/enum/format.test.js +++ b/tests/format/typescript/enum/format.test.js @@ -1,5 +1,6 @@ runFormatTest(import.meta, ["typescript"], { errors: { "babel-ts": ["computed-members.ts"], + "oxc-ts": ["computed-members.ts"], }, }); diff --git a/tests/format/typescript/error-recovery/__snapshots__/format.test.js.snap b/tests/format/typescript/error-recovery/__snapshots__/format.test.js.snap index f2b57844a..ee7164c2c 100644 --- a/tests/format/typescript/error-recovery/__snapshots__/format.test.js.snap +++ b/tests/format/typescript/error-recovery/__snapshots__/format.test.js.snap @@ -1,5 +1,27 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`generic.ts [oxc-ts] format 1`] = ` +"Type parameters cannot appear on a constructor declaration (8:16) + 6 | + 7 | class f4 { +> 8 | constructor<>() {} + | ^^ + 9 | } + 10 | + 11 | const f5 = function<>() {}" +`; + +exports[`generic.ts - {"trailingComma":"all"} [oxc-ts] format 1`] = ` +"Type parameters cannot appear on a constructor declaration (8:16) + 6 | + 7 | class f4 { +> 8 | constructor<>() {} + | ^^ + 9 | } + 10 | + 11 | const f5 = function<>() {}" +`; + exports[`generic.ts - {"trailingComma":"all"} format 1`] = ` ====================================options===================================== parsers: ["typescript"] @@ -51,6 +73,17 @@ class f7<> { ================================================================================ `; +exports[`generic.ts - {"trailingComma":"es5"} [oxc-ts] format 1`] = ` +"Type parameters cannot appear on a constructor declaration (8:16) + 6 | + 7 | class f4 { +> 8 | constructor<>() {} + | ^^ + 9 | } + 10 | + 11 | const f5 = function<>() {}" +`; + exports[`generic.ts - {"trailingComma":"es5"} format 1`] = ` ====================================options===================================== parsers: ["typescript"] @@ -164,6 +197,15 @@ exports[`index-signature.ts [babel-ts] format 1`] = ` Cause: Unexpected token, expected "]" (4:12)" `; +exports[`index-signature.ts [oxc-ts] format 1`] = ` +"Unexpected token (1:26) +> 1 | type A = { [key: string] }; + | ^ + 2 | + 3 | type TwoParams = { + 4 | [a: string, b: string]: string;" +`; + exports[`index-signature.ts - {"trailingComma":"all"} [babel-ts] format 1`] = ` "Unexpected token, expected "]" (4:13) 2 | @@ -176,6 +218,15 @@ exports[`index-signature.ts - {"trailingComma":"all"} [babel-ts] format 1`] = ` Cause: Unexpected token, expected "]" (4:12)" `; +exports[`index-signature.ts - {"trailingComma":"all"} [oxc-ts] format 1`] = ` +"Unexpected token (1:26) +> 1 | type A = { [key: string] }; + | ^ + 2 | + 3 | type TwoParams = { + 4 | [a: string, b: string]: string;" +`; + exports[`index-signature.ts - {"trailingComma":"all"} format 1`] = ` ====================================options===================================== parsers: ["typescript"] @@ -251,6 +302,15 @@ exports[`index-signature.ts - {"trailingComma":"es5"} [babel-ts] format 1`] = ` Cause: Unexpected token, expected "]" (4:12)" `; +exports[`index-signature.ts - {"trailingComma":"es5"} [oxc-ts] format 1`] = ` +"Unexpected token (1:26) +> 1 | type A = { [key: string] }; + | ^ + 2 | + 3 | type TwoParams = { + 4 | [a: string, b: string]: string;" +`; + exports[`index-signature.ts - {"trailingComma":"es5"} format 1`] = ` ====================================options===================================== parsers: ["typescript"] @@ -386,6 +446,15 @@ exports[`jsdoc_only_types.ts [babel-ts] format 1`] = ` Cause: Unexpected token (1:7)" `; +exports[`jsdoc_only_types.ts [oxc-ts] format 1`] = ` +"Unexpected token (1:8) +> 1 | let a: *; + | ^ + 2 | function b(x: ?) {} + 3 | let c: ?string; + 4 | let d: string?;" +`; + exports[`jsdoc_only_types.ts - {"trailingComma":"all"} [babel-ts] format 1`] = ` "Unexpected token (1:8) > 1 | let a: *; @@ -396,6 +465,15 @@ exports[`jsdoc_only_types.ts - {"trailingComma":"all"} [babel-ts] format 1`] = ` Cause: Unexpected token (1:7)" `; +exports[`jsdoc_only_types.ts - {"trailingComma":"all"} [oxc-ts] format 1`] = ` +"Unexpected token (1:8) +> 1 | let a: *; + | ^ + 2 | function b(x: ?) {} + 3 | let c: ?string; + 4 | let d: string?;" +`; + exports[`jsdoc_only_types.ts - {"trailingComma":"all"} format 1`] = ` ====================================options===================================== parsers: ["typescript"] @@ -435,6 +513,15 @@ exports[`jsdoc_only_types.ts - {"trailingComma":"es5"} [babel-ts] format 1`] = ` Cause: Unexpected token (1:7)" `; +exports[`jsdoc_only_types.ts - {"trailingComma":"es5"} [oxc-ts] format 1`] = ` +"Unexpected token (1:8) +> 1 | let a: *; + | ^ + 2 | function b(x: ?) {} + 3 | let c: ?string; + 4 | let d: string?;" +`; + exports[`jsdoc_only_types.ts - {"trailingComma":"es5"} format 1`] = ` ====================================options===================================== parsers: ["typescript"] diff --git a/tests/format/typescript/error-recovery/format.test.js b/tests/format/typescript/error-recovery/format.test.js index 735c1e93f..65ae7f88e 100644 --- a/tests/format/typescript/error-recovery/format.test.js +++ b/tests/format/typescript/error-recovery/format.test.js @@ -1,4 +1,12 @@ -const errors = { "babel-ts": ["jsdoc_only_types.ts", "index-signature.ts"] }; +const errors = { + "babel-ts": ["jsdoc_only_types.ts", "index-signature.ts"], + "oxc-ts": [ + "jsdoc_only_types.ts", + "index-signature.ts", + // TODO: Ask typescript-eslint to throw + "generic.ts", + ], +}; runFormatTest(import.meta, ["typescript"], { errors }); runFormatTest(import.meta, ["typescript"], { trailingComma: "es5", errors }); runFormatTest(import.meta, ["typescript"], { trailingComma: "all", errors }); diff --git a/tests/format/typescript/namespace/__snapshots__/format.test.js.snap b/tests/format/typescript/namespace/__snapshots__/format.test.js.snap index 169b88984..f76f739e4 100644 --- a/tests/format/typescript/namespace/__snapshots__/format.test.js.snap +++ b/tests/format/typescript/namespace/__snapshots__/format.test.js.snap @@ -10,6 +10,15 @@ exports[`invalid-await.ts [babel-ts] format 1`] = ` Cause: 'await' is only allowed within async functions and at the top levels of modules. (2:12)" `; +exports[`invalid-await.ts [oxc-ts] format 1`] = ` +"\`await\` is only allowed within async functions and at the top levels of modules (2:13) + 1 | namespace N { +> 2 | const x = await 42; + | ^^^^^ + 3 | } + 4 |" +`; + exports[`invalid-await.ts format 1`] = ` ====================================options===================================== parsers: ["typescript"] diff --git a/tests/format/typescript/namespace/format.test.js b/tests/format/typescript/namespace/format.test.js index 33a9fb791..a65268a06 100644 --- a/tests/format/typescript/namespace/format.test.js +++ b/tests/format/typescript/namespace/format.test.js @@ -1 +1,3 @@ -runFormatTest(import.meta, ["typescript"], { errors: { "babel-ts": true } }); +runFormatTest(import.meta, ["typescript"], { + errors: { "babel-ts": true, "oxc-ts": true }, +}); diff --git a/tests/format/typescript/trailing-comma/__snapshots__/format.test.js.snap b/tests/format/typescript/trailing-comma/__snapshots__/format.test.js.snap index ee42b39c7..953636cde 100644 --- a/tests/format/typescript/trailing-comma/__snapshots__/format.test.js.snap +++ b/tests/format/typescript/trailing-comma/__snapshots__/format.test.js.snap @@ -63,6 +63,16 @@ const f2 = < ================================================================================ `; +exports[`trailing.ts - {"trailingComma":"all"} [oxc-ts] format 1`] = ` +"Unexpected trailing comma after rest element (15:10) + 13 | longKeySoThisWillGoOnMultipleLines2, + 14 | longKeySoThisWillGoOnMultipleLines3, +> 15 | ...rest, + | ^ + 16 | } = something; + 17 |" +`; + exports[`trailing.ts - {"trailingComma":"all"} format 1`] = ` ====================================options===================================== parsers: ["typescript"] @@ -107,6 +117,16 @@ const { ================================================================================ `; +exports[`trailing.ts - {"trailingComma":"es5"} [oxc-ts] format 1`] = ` +"Unexpected trailing comma after rest element (15:10) + 13 | longKeySoThisWillGoOnMultipleLines2, + 14 | longKeySoThisWillGoOnMultipleLines3, +> 15 | ...rest, + | ^ + 16 | } = something; + 17 |" +`; + exports[`trailing.ts - {"trailingComma":"es5"} format 1`] = ` ====================================options===================================== parsers: ["typescript"] @@ -151,6 +171,16 @@ const { ================================================================================ `; +exports[`trailing.ts - {"trailingComma":"none"} [oxc-ts] format 1`] = ` +"Unexpected trailing comma after rest element (15:10) + 13 | longKeySoThisWillGoOnMultipleLines2, + 14 | longKeySoThisWillGoOnMultipleLines3, +> 15 | ...rest, + | ^ + 16 | } = something; + 17 |" +`; + exports[`trailing.ts - {"trailingComma":"none"} format 1`] = ` ====================================options===================================== parsers: ["typescript"] diff --git a/tests/format/typescript/trailing-comma/format.test.js b/tests/format/typescript/trailing-comma/format.test.js index 255526bea..0e2f7e8f3 100644 --- a/tests/format/typescript/trailing-comma/format.test.js +++ b/tests/format/typescript/trailing-comma/format.test.js @@ -1,3 +1,7 @@ -runFormatTest(import.meta, ["typescript"], { trailingComma: "all" }); -runFormatTest(import.meta, ["typescript"], { trailingComma: "es5" }); -runFormatTest(import.meta, ["typescript"], { trailingComma: "none" }); +const errors = { + "oxc-ts": ["trailing.ts"], +}; + +runFormatTest(import.meta, ["typescript"], { trailingComma: "all", errors }); +runFormatTest(import.meta, ["typescript"], { trailingComma: "es5", errors }); +runFormatTest(import.meta, ["typescript"], { trailingComma: "none", errors }); diff --git a/tests/format/typescript/type-arguments-bit-shift-left-like/__snapshots__/format.test.js.snap b/tests/format/typescript/type-arguments-bit-shift-left-like/__snapshots__/format.test.js.snap index e874eec0c..3baf0f903 100644 --- a/tests/format/typescript/type-arguments-bit-shift-left-like/__snapshots__/format.test.js.snap +++ b/tests/format/typescript/type-arguments-bit-shift-left-like/__snapshots__/format.test.js.snap @@ -42,6 +42,13 @@ printWidth: 80 ================================================================================ `; +exports[`3.ts [oxc-ts] format 1`] = ` +"Expected \`{\` but found \`<<\` (1:17) +> 1 | (class extends f<(v: T) => void> {}); + | ^^ + 2 |" +`; + exports[`3.ts [typescript] format 1`] = ` "',' expected. (1:17) > 1 | (class extends f<(v: T) => void> {}); @@ -81,6 +88,13 @@ printWidth: 80 ================================================================================ `; +exports[`5.tsx [oxc-ts] format 1`] = ` +"Unexpected token (1:11) +> 1 | (v: T) => void> /> + | ^^ + 2 |" +`; + exports[`5.tsx [typescript] format 1`] = ` "Identifier expected. (1:11) > 1 | (v: T) => void> /> diff --git a/tests/format/typescript/type-arguments-bit-shift-left-like/format.test.js b/tests/format/typescript/type-arguments-bit-shift-left-like/format.test.js index 8cf0c9559..c4908e90d 100644 --- a/tests/format/typescript/type-arguments-bit-shift-left-like/format.test.js +++ b/tests/format/typescript/type-arguments-bit-shift-left-like/format.test.js @@ -1,3 +1,3 @@ runFormatTest(import.meta, ["typescript"], { - errors: { typescript: ["3.ts", "5.tsx"] }, + errors: { typescript: ["3.ts", "5.tsx"], "oxc-ts": ["3.ts", "5.tsx"] }, });