diff --git a/tests/format/js/classes/__snapshots__/format.test.js.snap b/tests/format/js/classes/__snapshots__/format.test.js.snap index 65d840035..9b3b0b22b 100644 --- a/tests/format/js/classes/__snapshots__/format.test.js.snap +++ b/tests/format/js/classes/__snapshots__/format.test.js.snap @@ -177,6 +177,32 @@ class Foo { ================================================================================ `; +exports[`computed-constructor-property.js format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +class A { + [constructor] +} + +class B { + ["constructor"] +} + +=====================================output===================================== +class A { + [constructor]; +} + +class B { + ["constructor"]; +} + +================================================================================ +`; + exports[`constructor.js format 1`] = ` ====================================options===================================== parsers: ["babel", "flow", "typescript"] diff --git a/tests/format/js/classes/computed-constructor-property.js b/tests/format/js/classes/computed-constructor-property.js new file mode 100644 index 000000000..168e96dba --- /dev/null +++ b/tests/format/js/classes/computed-constructor-property.js @@ -0,0 +1,7 @@ +class A { + [constructor] +} + +class B { + ["constructor"] +} diff --git a/tests/format/misc/errors/js/class-property-named-constructor/__snapshots__/format.test.js.snap b/tests/format/misc/errors/js/class-property-named-constructor/__snapshots__/format.test.js.snap index 45b817783..121bb81a6 100644 --- a/tests/format/misc/errors/js/class-property-named-constructor/__snapshots__/format.test.js.snap +++ b/tests/format/misc/errors/js/class-property-named-constructor/__snapshots__/format.test.js.snap @@ -73,6 +73,30 @@ exports[`snippet: #0 [meriyah] format 1`] = ` Cause: [3:0-3:1]: Classes may not have a field called constructor" `; +exports[`snippet: #0 [oxc] format 1`] = ` +"Expected \`(\` but found \`}\` (3:1) + 1 | class Foo { + 2 | constructor +> 3 | } + | ^" +`; + +exports[`snippet: #0 [oxc-ts] format 1`] = ` +"Expected \`(\` but found \`}\` (3:1) + 1 | class Foo { + 2 | constructor +> 3 | } + | ^" +`; + +exports[`snippet: #0 [oxc-ts] format 2`] = ` +"Expected \`(\` but found \`}\` (3:1) + 1 | abstract class Foo { + 2 | constructor +> 3 | } + | ^" +`; + exports[`snippet: #0 [typescript] format 1`] = ` "'(' expected. (3:1) 1 | class Foo { @@ -164,6 +188,30 @@ exports[`snippet: #1 [meriyah] format 1`] = ` Cause: [3:0-3:1]: Classes may not have a field called constructor" `; +exports[`snippet: #1 [oxc] format 1`] = ` +"Classes can't have a field named 'constructor' (2:3) + 1 | class Foo { +> 2 | 'constructor' + | ^^^^^^^^^^^^^ + 3 | }" +`; + +exports[`snippet: #1 [oxc-ts] format 1`] = ` +"Classes can't have a field named 'constructor' (2:3) + 1 | class Foo { +> 2 | 'constructor' + | ^^^^^^^^^^^^^ + 3 | }" +`; + +exports[`snippet: #1 [oxc-ts] format 2`] = ` +"Classes can't have a field named 'constructor' (2:3) + 1 | abstract class Foo { +> 2 | 'constructor' + | ^^^^^^^^^^^^^ + 3 | }" +`; + exports[`snippet: #1 [typescript] format 1`] = ` "Classes may not have a field named 'constructor'. (2:3) 1 | class Foo { @@ -255,6 +303,30 @@ exports[`snippet: #2 [meriyah] format 1`] = ` Cause: [3:0-3:1]: Classes may not have a field called constructor" `; +exports[`snippet: #2 [oxc] format 1`] = ` +"Classes can't have a field named 'constructor' (2:3) + 1 | class Foo { +> 2 | 'constructor' + | ^^^^^^^^^^^^^ + 3 | }" +`; + +exports[`snippet: #2 [oxc-ts] format 1`] = ` +"Classes can't have a field named 'constructor' (2:3) + 1 | class Foo { +> 2 | 'constructor' + | ^^^^^^^^^^^^^ + 3 | }" +`; + +exports[`snippet: #2 [oxc-ts] format 2`] = ` +"Classes can't have a field named 'constructor' (2:3) + 1 | abstract class Foo { +> 2 | 'constructor' + | ^^^^^^^^^^^^^ + 3 | }" +`; + exports[`snippet: #2 [typescript] format 1`] = ` "Classes may not have a field named 'constructor'. (2:3) 1 | class Foo { @@ -346,6 +418,30 @@ exports[`snippet: #3 [meriyah] format 1`] = ` Cause: [3:0-3:1]: Classes may not have a field called constructor" `; +exports[`snippet: #3 [oxc] format 1`] = ` +"Classes may not have a field named 'constructor' (2:12) + 1 | class Foo { +> 2 | accessor 'constructor' + | ^^^^^^^^^^^^^ + 3 | }" +`; + +exports[`snippet: #3 [oxc-ts] format 1`] = ` +"Classes may not have a field named 'constructor' (2:12) + 1 | class Foo { +> 2 | accessor 'constructor' + | ^^^^^^^^^^^^^ + 3 | }" +`; + +exports[`snippet: #3 [oxc-ts] format 2`] = ` +"Classes may not have a field named 'constructor' (2:12) + 1 | abstract class Foo { +> 2 | accessor 'constructor' + | ^^^^^^^^^^^^^ + 3 | }" +`; + exports[`snippet: #3 [typescript] format 1`] = ` "Classes may not have a field named 'constructor'. (2:12) 1 | class Foo { @@ -437,6 +533,30 @@ exports[`snippet: #4 [meriyah] format 1`] = ` Cause: [3:0-3:1]: Classes may not have a field called constructor" `; +exports[`snippet: #4 [oxc] format 1`] = ` +"Classes may not have a field named 'constructor' (2:12) + 1 | class Foo { +> 2 | accessor 'constructor' + | ^^^^^^^^^^^^^ + 3 | }" +`; + +exports[`snippet: #4 [oxc-ts] format 1`] = ` +"Classes may not have a field named 'constructor' (2:12) + 1 | class Foo { +> 2 | accessor 'constructor' + | ^^^^^^^^^^^^^ + 3 | }" +`; + +exports[`snippet: #4 [oxc-ts] format 2`] = ` +"Classes may not have a field named 'constructor' (2:12) + 1 | abstract class Foo { +> 2 | accessor 'constructor' + | ^^^^^^^^^^^^^ + 3 | }" +`; + exports[`snippet: #4 [typescript] format 1`] = ` "Classes may not have a field named 'constructor'. (2:12) 1 | class Foo { @@ -528,6 +648,30 @@ exports[`snippet: #5 [meriyah] format 1`] = ` Cause: [3:0-3:1]: Classes may not have a field called constructor" `; +exports[`snippet: #5 [oxc] format 1`] = ` +"Expected \`(\` but found \`}\` (3:1) + 1 | class Foo { + 2 | accessor constructor +> 3 | } + | ^" +`; + +exports[`snippet: #5 [oxc-ts] format 1`] = ` +"Expected \`(\` but found \`}\` (3:1) + 1 | class Foo { + 2 | accessor constructor +> 3 | } + | ^" +`; + +exports[`snippet: #5 [oxc-ts] format 2`] = ` +"Expected \`(\` but found \`}\` (3:1) + 1 | abstract class Foo { + 2 | accessor constructor +> 3 | } + | ^" +`; + exports[`snippet: #5 [typescript] format 1`] = ` "'(' expected. (3:1) 1 | class Foo { diff --git a/tests/format/misc/errors/js/class-property-named-constructor/format.test.js b/tests/format/misc/errors/js/class-property-named-constructor/format.test.js index db70b617c..85bc53f2f 100644 --- a/tests/format/misc/errors/js/class-property-named-constructor/format.test.js +++ b/tests/format/misc/errors/js/class-property-named-constructor/format.test.js @@ -45,9 +45,8 @@ runFormatTest( "meriyah", "typescript", "babel-ts", - // https://github.com/oxc-project/oxc/issues/14014 - // "oxc", - // "oxc-ts", + "oxc", + "oxc-ts", "flow", "hermes", ], @@ -58,9 +57,5 @@ runFormatTest( importMeta: import.meta, snippets: cases.map((code) => `abstract ${code}`), }, - [ - "typescript", - "babel-ts", - // "oxc-ts", - ], + ["typescript", "babel-ts", "oxc-ts"], ); diff --git a/tests/format/misc/errors/typescript/__snapshots__/format.test.js.snap b/tests/format/misc/errors/typescript/__snapshots__/format.test.js.snap index 1a6fb55b2..ce2dc8cd3 100644 --- a/tests/format/misc/errors/typescript/__snapshots__/format.test.js.snap +++ b/tests/format/misc/errors/typescript/__snapshots__/format.test.js.snap @@ -10,6 +10,15 @@ exports[`declare-getter.ts [babel-ts] format 1`] = ` Cause: 'declare' is not allowed in getters. (2:2)" `; +exports[`declare-getter.ts [oxc-ts] format 1`] = ` +"'declare' modifier cannot be used here. (2:3) + 1 | class Foo { +> 2 | declare get foo() + | ^^^^^^^ + 3 | } + 4 |" +`; + exports[`declare-getter.ts [typescript] format 1`] = ` "'declare' modifier cannot appear on class elements of this kind. (2:3) 1 | class Foo { @@ -30,6 +39,15 @@ exports[`declare-setter.ts [babel-ts] format 1`] = ` Cause: 'declare' is not allowed in setters. (2:2)" `; +exports[`declare-setter.ts [oxc-ts] format 1`] = ` +"'declare' modifier cannot be used here. (2:3) + 1 | class Foo { +> 2 | declare set foo(v) + | ^^^^^^^ + 3 | } + 4 |" +`; + exports[`declare-setter.ts [typescript] format 1`] = ` "'declare' modifier cannot appear on class elements of this kind. (2:3) 1 | class Foo { @@ -48,6 +66,13 @@ exports[`export-declare.ts [babel-ts] format 1`] = ` Cause: 'export declare' must be followed by an ambient declaration. (1:15)" `; +exports[`export-declare.ts [oxc-ts] format 1`] = ` +"Unexpected token (1:16) +> 1 | export declare foo; + | ^^^ + 2 |" +`; + exports[`export-declare.ts [typescript] format 1`] = ` "Declaration or statement expected. (1:1) > 1 | export declare foo; @@ -66,6 +91,15 @@ exports[`invalid-jsx-1.tsx [babel-ts] format 1`] = ` Cause: Unexpected token \`>\`. Did you mean \`>\` or \`{'>'}\`? (3:44)" `; +exports[`invalid-jsx-1.tsx [oxc-ts] format 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 [typescript] format 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 @@ -84,6 +118,13 @@ exports[`module-attributes-static.ts [babel-ts] format 1`] = ` Cause: Unexpected token, expected "{" (1:32)" `; +exports[`module-attributes-static.ts [oxc-ts] format 1`] = ` +"Expected \`{\` but found \`type\` (1:33) +> 1 | import foo from "foo.json" with type: "json"; + | ^^^^ + 2 |" +`; + exports[`module-attributes-static.ts [typescript] format 1`] = ` "'{' expected. (1:33) > 1 | import foo from "foo.json" with type: "json"; @@ -101,6 +142,14 @@ exports[`newline-before-arrow.ts [babel-ts] format 1`] = ` Cause: No line break is allowed before '=>'. (2:2)" `; +exports[`newline-before-arrow.ts [oxc-ts] format 1`] = ` +"Line terminator not permitted before arrow (2:1) + 1 | async x +> 2 | => x + | ^^ + 3 |" +`; + exports[`newline-before-arrow.ts [typescript] format 1`] = ` "Unexpected keyword or identifier. (1:1) > 1 | async x @@ -120,6 +169,15 @@ exports[`value-of-abstract-property.ts [babel-ts] format 1`] = ` Cause: Property 'prop' cannot have an initializer because it is marked abstract. (2:16)" `; +exports[`value-of-abstract-property.ts [oxc-ts] format 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 [typescript] format 1`] = ` "Abstract property cannot have an initializer. (2:19) 1 | abstract class Foo { diff --git a/tests/format/misc/errors/typescript/abstract-accessor-with-implementation/format.test.js b/tests/format/misc/errors/typescript/abstract-accessor-with-implementation/format.test.js index 83b8d15f4..2b4879d5b 100644 --- a/tests/format/misc/errors/typescript/abstract-accessor-with-implementation/format.test.js +++ b/tests/format/misc/errors/typescript/abstract-accessor-with-implementation/format.test.js @@ -16,5 +16,5 @@ runFormatTest( `, ], }, - ["babel-ts", "typescript", "oxc-ts"], + ["typescript", "babel-ts", "oxc-ts"], ); diff --git a/tests/format/misc/errors/typescript/abstract-method-with-implementation/format.test.js b/tests/format/misc/errors/typescript/abstract-method-with-implementation/format.test.js index ab4c2f0d9..103ff63f9 100644 --- a/tests/format/misc/errors/typescript/abstract-method-with-implementation/format.test.js +++ b/tests/format/misc/errors/typescript/abstract-method-with-implementation/format.test.js @@ -11,5 +11,5 @@ runFormatTest( `, ], }, - ["babel-ts", "typescript", "oxc-ts"], + ["typescript", "babel-ts", "oxc-ts"], ); diff --git a/tests/format/misc/errors/typescript/catch-clause-with-initializer/format.test.js b/tests/format/misc/errors/typescript/catch-clause-with-initializer/format.test.js index edcbded1c..1831abd0d 100644 --- a/tests/format/misc/errors/typescript/catch-clause-with-initializer/format.test.js +++ b/tests/format/misc/errors/typescript/catch-clause-with-initializer/format.test.js @@ -1 +1 @@ -runFormatTest(import.meta, ["babel-ts", "typescript", "oxc-ts"]); +runFormatTest(import.meta, ["typescript", "babel-ts", "oxc-ts"]); diff --git a/tests/format/misc/errors/typescript/declare-function-with-body/format.test.js b/tests/format/misc/errors/typescript/declare-function-with-body/format.test.js index 862b4096d..399fe2561 100644 --- a/tests/format/misc/errors/typescript/declare-function-with-body/format.test.js +++ b/tests/format/misc/errors/typescript/declare-function-with-body/format.test.js @@ -3,5 +3,5 @@ runFormatTest( importMeta: import.meta, snippets: ["declare function foo() {}"], }, - ["babel-ts", "typescript", "oxc-ts"], + ["typescript", "babel-ts", "oxc-ts"], ); diff --git a/tests/format/misc/errors/typescript/decrement-and-increment-operators/format.test.js b/tests/format/misc/errors/typescript/decrement-and-increment-operators/format.test.js index 7d1d82e42..32f3d4c8d 100644 --- a/tests/format/misc/errors/typescript/decrement-and-increment-operators/format.test.js +++ b/tests/format/misc/errors/typescript/decrement-and-increment-operators/format.test.js @@ -29,5 +29,5 @@ runFormatTest( "(a())++", ], }, - ["babel-ts", "typescript", "oxc-ts"], + ["typescript", "babel-ts", "oxc-ts"], ); diff --git a/tests/format/misc/errors/typescript/enum/__snapshots__/format.test.js.snap b/tests/format/misc/errors/typescript/enum/__snapshots__/format.test.js.snap index 92fcd7611..e1d85e8e2 100644 --- a/tests/format/misc/errors/typescript/enum/__snapshots__/format.test.js.snap +++ b/tests/format/misc/errors/typescript/enum/__snapshots__/format.test.js.snap @@ -26,6 +26,14 @@ exports[`snippet: #0 [oxc-ts] format 1`] = ` 3 | }" `; +exports[`snippet: #0 [oxc-ts] format 2`] = ` +"Computed property names are not allowed in enums. (2:4) + 1 | enum Foo { +> 2 | [foo] = 1 + | ^^^ + 3 | }" +`; + exports[`snippet: #0 [typescript] format 1`] = ` "An enum member cannot have a numeric name. (2:3) 1 | enum Foo { diff --git a/tests/format/misc/errors/typescript/enum/format.test.js b/tests/format/misc/errors/typescript/enum/format.test.js index 14cc7fbb9..96b470445 100644 --- a/tests/format/misc/errors/typescript/enum/format.test.js +++ b/tests/format/misc/errors/typescript/enum/format.test.js @@ -28,5 +28,5 @@ runFormatTest( `, ), }, - ["typescript", "babel-ts"], + ["typescript", "babel-ts", "oxc-ts"], ); diff --git a/tests/format/misc/errors/typescript/format.test.js b/tests/format/misc/errors/typescript/format.test.js index 668580f5a..1831abd0d 100644 --- a/tests/format/misc/errors/typescript/format.test.js +++ b/tests/format/misc/errors/typescript/format.test.js @@ -1,5 +1 @@ -runFormatTest(import.meta, [ - "typescript", - "babel-ts", - // "oxc-ts" -]); +runFormatTest(import.meta, ["typescript", "babel-ts", "oxc-ts"]); diff --git a/tests/format/misc/errors/typescript/interface/format.test.js b/tests/format/misc/errors/typescript/interface/format.test.js index b4c1a0bdf..dc94f9e78 100644 --- a/tests/format/misc/errors/typescript/interface/format.test.js +++ b/tests/format/misc/errors/typescript/interface/format.test.js @@ -9,5 +9,5 @@ runFormatTest( "interface A implements B {}", ], }, - ["babel-ts", "typescript", "oxc-ts"], + ["typescript", "babel-ts", "oxc-ts"], ); diff --git a/tests/format/misc/errors/typescript/loop/format.test.js b/tests/format/misc/errors/typescript/loop/format.test.js index 548cd1db5..88d6f1300 100644 --- a/tests/format/misc/errors/typescript/loop/format.test.js +++ b/tests/format/misc/errors/typescript/loop/format.test.js @@ -3,5 +3,5 @@ runFormatTest( importMeta: import.meta, snippets: ["for (var of X);", "for (var of of);", "for (var in X);"], }, - ["babel-ts", "typescript", "oxc-ts"], + ["typescript", "babel-ts", "oxc-ts"], ); diff --git a/tests/format/misc/errors/typescript/mapped-type/format.test.js b/tests/format/misc/errors/typescript/mapped-type/format.test.js index edcbded1c..1831abd0d 100644 --- a/tests/format/misc/errors/typescript/mapped-type/format.test.js +++ b/tests/format/misc/errors/typescript/mapped-type/format.test.js @@ -1 +1 @@ -runFormatTest(import.meta, ["babel-ts", "typescript", "oxc-ts"]); +runFormatTest(import.meta, ["typescript", "babel-ts", "oxc-ts"]); diff --git a/tests/format/misc/errors/typescript/modifiers/format.test.js b/tests/format/misc/errors/typescript/modifiers/format.test.js index 6c09b9964..90c91221f 100644 --- a/tests/format/misc/errors/typescript/modifiers/format.test.js +++ b/tests/format/misc/errors/typescript/modifiers/format.test.js @@ -144,5 +144,5 @@ runFormatTest( ...["abstract"].map((modifier) => `({${modifier} method(){}})`), ], }, - ["babel-ts", "typescript", "oxc-ts"], + ["typescript", "babel-ts", "oxc-ts"], ); diff --git a/tests/format/misc/errors/typescript/module-declaration/format.test.js b/tests/format/misc/errors/typescript/module-declaration/format.test.js index 45581295a..c5ee6d3c3 100644 --- a/tests/format/misc/errors/typescript/module-declaration/format.test.js +++ b/tests/format/misc/errors/typescript/module-declaration/format.test.js @@ -3,5 +3,5 @@ runFormatTest( importMeta: import.meta, snippets: ['namespace "a" {}', 'namespace "a";', "namespace a;"], }, - ["babel-ts", "typescript", "oxc-ts"], + ["typescript", "babel-ts", "oxc-ts"], ); diff --git a/tests/format/misc/errors/typescript/tuple/format.test.js b/tests/format/misc/errors/typescript/tuple/format.test.js index 7512bc2ea..c89886025 100644 --- a/tests/format/misc/errors/typescript/tuple/format.test.js +++ b/tests/format/misc/errors/typescript/tuple/format.test.js @@ -8,5 +8,5 @@ runFormatTest( "type T = [x: A];", ], }, - ["babel-ts", "typescript", "oxc-ts"], + ["typescript", "babel-ts", "oxc-ts"], );