From a79dc0f20b21cdf298d32af1a7bfbb3d2c181316 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Thu, 13 Aug 2026 18:38:31 +0800 Subject: [PATCH] Move TS error tests (#19845) --- .../__snapshots__/format.test.js.snap | 189 ------------------ .../arrow/__snapshots__/format.test.js.snap | 27 +++ .../_errors_/{ => arrow}/format.test.js | 0 .../{ => arrow}/newline-before-arrow.ts | 0 .../__snapshots__/format.test.js.snap | 59 ++++++ .../{ => declare-accessor}/declare-getter.ts | 0 .../{ => declare-accessor}/declare-setter.ts | 0 .../_errors_/declare-accessor/format.test.js | 1 + .../__snapshots__/format.test.js.snap | 24 +++ .../{ => export-declare}/export-declare.ts | 0 .../_errors_/export-declare/format.test.js | 1 + .../__snapshots__/format.test.js.snap | 24 +++ .../_errors_/import-attributes/format.test.js | 1 + .../module-attributes-static.ts | 0 .../jsx/__snapshots__/format.test.js.snap | 30 +++ .../typescript/_errors_/jsx/format.test.js | 1 + .../_errors_/{ => jsx}/invalid-jsx-1.tsx | 0 .../__snapshots__/format.test.js.snap | 30 +++ .../value-of-abstract-property/format.test.js | 1 + .../value-of-abstract-property.ts | 0 20 files changed, 199 insertions(+), 189 deletions(-) delete mode 100644 tests/format/typescript/_errors_/__snapshots__/format.test.js.snap create mode 100644 tests/format/typescript/_errors_/arrow/__snapshots__/format.test.js.snap rename tests/format/typescript/_errors_/{ => arrow}/format.test.js (100%) rename tests/format/typescript/_errors_/{ => arrow}/newline-before-arrow.ts (100%) create mode 100644 tests/format/typescript/_errors_/declare-accessor/__snapshots__/format.test.js.snap rename tests/format/typescript/_errors_/{ => declare-accessor}/declare-getter.ts (100%) rename tests/format/typescript/_errors_/{ => declare-accessor}/declare-setter.ts (100%) create mode 100644 tests/format/typescript/_errors_/declare-accessor/format.test.js create mode 100644 tests/format/typescript/_errors_/export-declare/__snapshots__/format.test.js.snap rename tests/format/typescript/_errors_/{ => export-declare}/export-declare.ts (100%) create mode 100644 tests/format/typescript/_errors_/export-declare/format.test.js create mode 100644 tests/format/typescript/_errors_/import-attributes/__snapshots__/format.test.js.snap create mode 100644 tests/format/typescript/_errors_/import-attributes/format.test.js rename tests/format/typescript/_errors_/{ => import-attributes}/module-attributes-static.ts (100%) create mode 100644 tests/format/typescript/_errors_/jsx/__snapshots__/format.test.js.snap create mode 100644 tests/format/typescript/_errors_/jsx/format.test.js rename tests/format/typescript/_errors_/{ => jsx}/invalid-jsx-1.tsx (100%) create mode 100644 tests/format/typescript/_errors_/value-of-abstract-property/__snapshots__/format.test.js.snap create mode 100644 tests/format/typescript/_errors_/value-of-abstract-property/format.test.js rename tests/format/typescript/_errors_/{ => value-of-abstract-property}/value-of-abstract-property.ts (100%) diff --git a/tests/format/typescript/_errors_/__snapshots__/format.test.js.snap b/tests/format/typescript/_errors_/__snapshots__/format.test.js.snap deleted file mode 100644 index 8b7497fab..000000000 --- a/tests/format/typescript/_errors_/__snapshots__/format.test.js.snap +++ /dev/null @@ -1,189 +0,0 @@ -// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing - -exports[`declare-getter.ts format[babel-ts] 1`] = ` -"'declare' is not allowed in getters. (2:3) - 1 | class Foo { -> 2 | declare get foo() - | ^ - 3 | } - 4 | -Cause: 'declare' is not allowed in getters. (2:2)" -`; - -exports[`declare-getter.ts format[oxc-ts] 1`] = ` -"'declare' modifier cannot be used here. (2:3) - 1 | class Foo { -> 2 | declare get foo() - | ^^^^^^^ - 3 | } - 4 |" -`; - -exports[`declare-getter.ts format[typescript] 1`] = ` -"'declare' modifier cannot appear on class elements of this kind. (2:3) - 1 | class Foo { -> 2 | declare get foo() - | ^^^^^^^ - 3 | } - 4 | -Cause: 'declare' modifier cannot appear on class elements of this kind." -`; - -exports[`declare-setter.ts format[babel-ts] 1`] = ` -"'declare' is not allowed in setters. (2:3) - 1 | class Foo { -> 2 | declare set foo(v) - | ^ - 3 | } - 4 | -Cause: 'declare' is not allowed in setters. (2:2)" -`; - -exports[`declare-setter.ts format[oxc-ts] 1`] = ` -"'declare' modifier cannot be used here. (2:3) - 1 | class Foo { -> 2 | declare set foo(v) - | ^^^^^^^ - 3 | } - 4 |" -`; - -exports[`declare-setter.ts format[typescript] 1`] = ` -"'declare' modifier cannot appear on class elements of this kind. (2:3) - 1 | class Foo { -> 2 | declare set foo(v) - | ^^^^^^^ - 3 | } - 4 | -Cause: 'declare' modifier cannot appear on class elements of this kind." -`; - -exports[`export-declare.ts format[babel-ts] 1`] = ` -"'export declare' must be followed by an ambient declaration. (1:16) -> 1 | export declare foo; - | ^ - 2 | -Cause: 'export declare' must be followed by an ambient declaration. (1:15)" -`; - -exports[`export-declare.ts format[oxc-ts] 1`] = ` -"Unexpected token (1:16) -> 1 | export declare foo; - | ^^^ - 2 |" -`; - -exports[`export-declare.ts format[typescript] 1`] = ` -"Declaration or statement expected. (1:1) -> 1 | export declare foo; - | ^ - 2 | -Cause: Declaration or statement expected." -`; - -exports[`invalid-jsx-1.tsx format[babel-ts] 1`] = ` -"Unexpected token \`>\`. Did you mean \`>\` or \`{'>'}\`? (3:45) - 1 | // https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-9.html#-and--are-now-invalid-jsx-text-characters - 2 | -> 3 | let directions =
Navigate to: Menu Bar > Tools > Options
- | ^ - 4 | -Cause: Unexpected token \`>\`. Did you mean \`>\` or \`{'>'}\`? (3:44)" -`; - -exports[`invalid-jsx-1.tsx format[oxc-ts] 1`] = ` -"Unexpected token. Did you mean \`{'>'}\` or \`>\`? (3:45) - 1 | // https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-9.html#-and--are-now-invalid-jsx-text-characters - 2 | -> 3 | let directions =
Navigate to: Menu Bar > Tools > Options
- | ^ - 4 |" -`; - -exports[`invalid-jsx-1.tsx format[typescript] 1`] = ` -"Unexpected token. Did you mean \`{'>'}\` or \`>\`? (3:45) - 1 | // https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-9.html#-and--are-now-invalid-jsx-text-characters - 2 | -> 3 | let directions =
Navigate to: Menu Bar > Tools > Options
- | ^ - 4 | -Cause: Unexpected token. Did you mean \`{'>'}\` or \`>\`?" -`; - -exports[`module-attributes-static.ts format[babel-ts] 1`] = ` -"Unexpected token, expected "{" (1:33) -> 1 | import foo from "foo.json" with type: "json"; - | ^ - 2 | -Cause: Unexpected token, expected "{" (1:32)" -`; - -exports[`module-attributes-static.ts format[oxc-ts] 1`] = ` -"Expected \`{\` but found \`type\` (1:33) -> 1 | import foo from "foo.json" with type: "json"; - | ^^^^ - 2 |" -`; - -exports[`module-attributes-static.ts format[typescript] 1`] = ` -"'{' expected. (1:33) -> 1 | import foo from "foo.json" with type: "json"; - | ^ - 2 | -Cause: '{' expected." -`; - -exports[`newline-before-arrow.ts format[babel-ts] 1`] = ` -"No line break is allowed before '=>'. (2:3) - 1 | async x -> 2 | => x - | ^ - 3 | -Cause: No line break is allowed before '=>'. (2:2)" -`; - -exports[`newline-before-arrow.ts format[oxc-ts] 1`] = ` -"Line terminator not permitted before arrow (2:1) - 1 | async x -> 2 | => x - | ^^ - 3 |" -`; - -exports[`newline-before-arrow.ts format[typescript] 1`] = ` -"Unexpected keyword or identifier. (1:1) -> 1 | async x - | ^ - 2 | => x - 3 | -Cause: Unexpected keyword or identifier." -`; - -exports[`value-of-abstract-property.ts format[babel-ts] 1`] = ` -"Property 'prop' cannot have an initializer because it is marked abstract. (2:17) - 1 | abstract class Foo { -> 2 | abstract prop = 3; - | ^ - 3 | } - 4 | -Cause: Property 'prop' cannot have an initializer because it is marked abstract. (2:16)" -`; - -exports[`value-of-abstract-property.ts format[oxc-ts] 1`] = ` -"Property 'prop' cannot have an initializer because it is marked abstract. (2:12) - 1 | abstract class Foo { -> 2 | abstract prop = 3; - | ^^^^ - 3 | } - 4 |" -`; - -exports[`value-of-abstract-property.ts format[typescript] 1`] = ` -"Abstract property cannot have an initializer. (2:19) - 1 | abstract class Foo { -> 2 | abstract prop = 3; - | ^ - 3 | } - 4 | -Cause: Abstract property cannot have an initializer." -`; diff --git a/tests/format/typescript/_errors_/arrow/__snapshots__/format.test.js.snap b/tests/format/typescript/_errors_/arrow/__snapshots__/format.test.js.snap new file mode 100644 index 000000000..df6cbda10 --- /dev/null +++ b/tests/format/typescript/_errors_/arrow/__snapshots__/format.test.js.snap @@ -0,0 +1,27 @@ +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing + +exports[`newline-before-arrow.ts format[babel-ts] 1`] = ` +"No line break is allowed before '=>'. (2:3) + 1 | async x +> 2 | => x + | ^ + 3 | +Cause: No line break is allowed before '=>'. (2:2)" +`; + +exports[`newline-before-arrow.ts format[oxc-ts] 1`] = ` +"Line terminator not permitted before arrow (2:1) + 1 | async x +> 2 | => x + | ^^ + 3 |" +`; + +exports[`newline-before-arrow.ts format[typescript] 1`] = ` +"Unexpected keyword or identifier. (1:1) +> 1 | async x + | ^ + 2 | => x + 3 | +Cause: Unexpected keyword or identifier." +`; diff --git a/tests/format/typescript/_errors_/format.test.js b/tests/format/typescript/_errors_/arrow/format.test.js similarity index 100% rename from tests/format/typescript/_errors_/format.test.js rename to tests/format/typescript/_errors_/arrow/format.test.js diff --git a/tests/format/typescript/_errors_/newline-before-arrow.ts b/tests/format/typescript/_errors_/arrow/newline-before-arrow.ts similarity index 100% rename from tests/format/typescript/_errors_/newline-before-arrow.ts rename to tests/format/typescript/_errors_/arrow/newline-before-arrow.ts diff --git a/tests/format/typescript/_errors_/declare-accessor/__snapshots__/format.test.js.snap b/tests/format/typescript/_errors_/declare-accessor/__snapshots__/format.test.js.snap new file mode 100644 index 000000000..8ed932803 --- /dev/null +++ b/tests/format/typescript/_errors_/declare-accessor/__snapshots__/format.test.js.snap @@ -0,0 +1,59 @@ +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing + +exports[`declare-getter.ts format[babel-ts] 1`] = ` +"'declare' is not allowed in getters. (2:3) + 1 | class Foo { +> 2 | declare get foo() + | ^ + 3 | } + 4 | +Cause: 'declare' is not allowed in getters. (2:2)" +`; + +exports[`declare-getter.ts format[oxc-ts] 1`] = ` +"'declare' modifier cannot be used here. (2:3) + 1 | class Foo { +> 2 | declare get foo() + | ^^^^^^^ + 3 | } + 4 |" +`; + +exports[`declare-getter.ts format[typescript] 1`] = ` +"'declare' modifier cannot appear on class elements of this kind. (2:3) + 1 | class Foo { +> 2 | declare get foo() + | ^^^^^^^ + 3 | } + 4 | +Cause: 'declare' modifier cannot appear on class elements of this kind." +`; + +exports[`declare-setter.ts format[babel-ts] 1`] = ` +"'declare' is not allowed in setters. (2:3) + 1 | class Foo { +> 2 | declare set foo(v) + | ^ + 3 | } + 4 | +Cause: 'declare' is not allowed in setters. (2:2)" +`; + +exports[`declare-setter.ts format[oxc-ts] 1`] = ` +"'declare' modifier cannot be used here. (2:3) + 1 | class Foo { +> 2 | declare set foo(v) + | ^^^^^^^ + 3 | } + 4 |" +`; + +exports[`declare-setter.ts format[typescript] 1`] = ` +"'declare' modifier cannot appear on class elements of this kind. (2:3) + 1 | class Foo { +> 2 | declare set foo(v) + | ^^^^^^^ + 3 | } + 4 | +Cause: 'declare' modifier cannot appear on class elements of this kind." +`; diff --git a/tests/format/typescript/_errors_/declare-getter.ts b/tests/format/typescript/_errors_/declare-accessor/declare-getter.ts similarity index 100% rename from tests/format/typescript/_errors_/declare-getter.ts rename to tests/format/typescript/_errors_/declare-accessor/declare-getter.ts diff --git a/tests/format/typescript/_errors_/declare-setter.ts b/tests/format/typescript/_errors_/declare-accessor/declare-setter.ts similarity index 100% rename from tests/format/typescript/_errors_/declare-setter.ts rename to tests/format/typescript/_errors_/declare-accessor/declare-setter.ts diff --git a/tests/format/typescript/_errors_/declare-accessor/format.test.js b/tests/format/typescript/_errors_/declare-accessor/format.test.js new file mode 100644 index 000000000..1831abd0d --- /dev/null +++ b/tests/format/typescript/_errors_/declare-accessor/format.test.js @@ -0,0 +1 @@ +runFormatTest(import.meta, ["typescript", "babel-ts", "oxc-ts"]); diff --git a/tests/format/typescript/_errors_/export-declare/__snapshots__/format.test.js.snap b/tests/format/typescript/_errors_/export-declare/__snapshots__/format.test.js.snap new file mode 100644 index 000000000..5917b909c --- /dev/null +++ b/tests/format/typescript/_errors_/export-declare/__snapshots__/format.test.js.snap @@ -0,0 +1,24 @@ +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing + +exports[`export-declare.ts format[babel-ts] 1`] = ` +"'export declare' must be followed by an ambient declaration. (1:16) +> 1 | export declare foo; + | ^ + 2 | +Cause: 'export declare' must be followed by an ambient declaration. (1:15)" +`; + +exports[`export-declare.ts format[oxc-ts] 1`] = ` +"Unexpected token (1:16) +> 1 | export declare foo; + | ^^^ + 2 |" +`; + +exports[`export-declare.ts format[typescript] 1`] = ` +"Declaration or statement expected. (1:1) +> 1 | export declare foo; + | ^ + 2 | +Cause: Declaration or statement expected." +`; diff --git a/tests/format/typescript/_errors_/export-declare.ts b/tests/format/typescript/_errors_/export-declare/export-declare.ts similarity index 100% rename from tests/format/typescript/_errors_/export-declare.ts rename to tests/format/typescript/_errors_/export-declare/export-declare.ts diff --git a/tests/format/typescript/_errors_/export-declare/format.test.js b/tests/format/typescript/_errors_/export-declare/format.test.js new file mode 100644 index 000000000..1831abd0d --- /dev/null +++ b/tests/format/typescript/_errors_/export-declare/format.test.js @@ -0,0 +1 @@ +runFormatTest(import.meta, ["typescript", "babel-ts", "oxc-ts"]); diff --git a/tests/format/typescript/_errors_/import-attributes/__snapshots__/format.test.js.snap b/tests/format/typescript/_errors_/import-attributes/__snapshots__/format.test.js.snap new file mode 100644 index 000000000..b18e16ba6 --- /dev/null +++ b/tests/format/typescript/_errors_/import-attributes/__snapshots__/format.test.js.snap @@ -0,0 +1,24 @@ +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing + +exports[`module-attributes-static.ts format[babel-ts] 1`] = ` +"Unexpected token, expected "{" (1:33) +> 1 | import foo from "foo.json" with type: "json"; + | ^ + 2 | +Cause: Unexpected token, expected "{" (1:32)" +`; + +exports[`module-attributes-static.ts format[oxc-ts] 1`] = ` +"Expected \`{\` but found \`type\` (1:33) +> 1 | import foo from "foo.json" with type: "json"; + | ^^^^ + 2 |" +`; + +exports[`module-attributes-static.ts format[typescript] 1`] = ` +"'{' expected. (1:33) +> 1 | import foo from "foo.json" with type: "json"; + | ^ + 2 | +Cause: '{' expected." +`; diff --git a/tests/format/typescript/_errors_/import-attributes/format.test.js b/tests/format/typescript/_errors_/import-attributes/format.test.js new file mode 100644 index 000000000..1831abd0d --- /dev/null +++ b/tests/format/typescript/_errors_/import-attributes/format.test.js @@ -0,0 +1 @@ +runFormatTest(import.meta, ["typescript", "babel-ts", "oxc-ts"]); diff --git a/tests/format/typescript/_errors_/module-attributes-static.ts b/tests/format/typescript/_errors_/import-attributes/module-attributes-static.ts similarity index 100% rename from tests/format/typescript/_errors_/module-attributes-static.ts rename to tests/format/typescript/_errors_/import-attributes/module-attributes-static.ts diff --git a/tests/format/typescript/_errors_/jsx/__snapshots__/format.test.js.snap b/tests/format/typescript/_errors_/jsx/__snapshots__/format.test.js.snap new file mode 100644 index 000000000..94a9908a0 --- /dev/null +++ b/tests/format/typescript/_errors_/jsx/__snapshots__/format.test.js.snap @@ -0,0 +1,30 @@ +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing + +exports[`invalid-jsx-1.tsx format[babel-ts] 1`] = ` +"Unexpected token \`>\`. Did you mean \`>\` or \`{'>'}\`? (3:45) + 1 | // https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-9.html#-and--are-now-invalid-jsx-text-characters + 2 | +> 3 | let directions =
Navigate to: Menu Bar > Tools > Options
+ | ^ + 4 | +Cause: Unexpected token \`>\`. Did you mean \`>\` or \`{'>'}\`? (3:44)" +`; + +exports[`invalid-jsx-1.tsx format[oxc-ts] 1`] = ` +"Unexpected token. Did you mean \`{'>'}\` or \`>\`? (3:45) + 1 | // https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-9.html#-and--are-now-invalid-jsx-text-characters + 2 | +> 3 | let directions =
Navigate to: Menu Bar > Tools > Options
+ | ^ + 4 |" +`; + +exports[`invalid-jsx-1.tsx format[typescript] 1`] = ` +"Unexpected token. Did you mean \`{'>'}\` or \`>\`? (3:45) + 1 | // https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-9.html#-and--are-now-invalid-jsx-text-characters + 2 | +> 3 | let directions =
Navigate to: Menu Bar > Tools > Options
+ | ^ + 4 | +Cause: Unexpected token. Did you mean \`{'>'}\` or \`>\`?" +`; diff --git a/tests/format/typescript/_errors_/jsx/format.test.js b/tests/format/typescript/_errors_/jsx/format.test.js new file mode 100644 index 000000000..1831abd0d --- /dev/null +++ b/tests/format/typescript/_errors_/jsx/format.test.js @@ -0,0 +1 @@ +runFormatTest(import.meta, ["typescript", "babel-ts", "oxc-ts"]); diff --git a/tests/format/typescript/_errors_/invalid-jsx-1.tsx b/tests/format/typescript/_errors_/jsx/invalid-jsx-1.tsx similarity index 100% rename from tests/format/typescript/_errors_/invalid-jsx-1.tsx rename to tests/format/typescript/_errors_/jsx/invalid-jsx-1.tsx diff --git a/tests/format/typescript/_errors_/value-of-abstract-property/__snapshots__/format.test.js.snap b/tests/format/typescript/_errors_/value-of-abstract-property/__snapshots__/format.test.js.snap new file mode 100644 index 000000000..f97fe4389 --- /dev/null +++ b/tests/format/typescript/_errors_/value-of-abstract-property/__snapshots__/format.test.js.snap @@ -0,0 +1,30 @@ +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing + +exports[`value-of-abstract-property.ts format[babel-ts] 1`] = ` +"Property 'prop' cannot have an initializer because it is marked abstract. (2:17) + 1 | abstract class Foo { +> 2 | abstract prop = 3; + | ^ + 3 | } + 4 | +Cause: Property 'prop' cannot have an initializer because it is marked abstract. (2:16)" +`; + +exports[`value-of-abstract-property.ts format[oxc-ts] 1`] = ` +"Property 'prop' cannot have an initializer because it is marked abstract. (2:12) + 1 | abstract class Foo { +> 2 | abstract prop = 3; + | ^^^^ + 3 | } + 4 |" +`; + +exports[`value-of-abstract-property.ts format[typescript] 1`] = ` +"Abstract property cannot have an initializer. (2:19) + 1 | abstract class Foo { +> 2 | abstract prop = 3; + | ^ + 3 | } + 4 | +Cause: Abstract property cannot have an initializer." +`; diff --git a/tests/format/typescript/_errors_/value-of-abstract-property/format.test.js b/tests/format/typescript/_errors_/value-of-abstract-property/format.test.js new file mode 100644 index 000000000..1831abd0d --- /dev/null +++ b/tests/format/typescript/_errors_/value-of-abstract-property/format.test.js @@ -0,0 +1 @@ +runFormatTest(import.meta, ["typescript", "babel-ts", "oxc-ts"]); diff --git a/tests/format/typescript/_errors_/value-of-abstract-property.ts b/tests/format/typescript/_errors_/value-of-abstract-property/value-of-abstract-property.ts similarity index 100% rename from tests/format/typescript/_errors_/value-of-abstract-property.ts rename to tests/format/typescript/_errors_/value-of-abstract-property/value-of-abstract-property.ts