Test all invalid syntax on oxc-ts parser (#17933)

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
fisker Cheungandautofix-ci[bot] authored and GitHub committed 2025-10-09 14:14:56 +08:00
1 parent 73a9a5205c
commit 4eb0f86ab6
19 files changed
+259 -25

No files matched your search

@@ -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"]
@@ -0,0 +1,7 @@
class A {
[constructor]
}
class B {
["constructor"]
}
@@ -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 {
@@ -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"],
);
@@ -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 \`&gt;\` or \`{'>'}\`? (3:44)"
`;
exports[`invalid-jsx-1.tsx [oxc-ts] format 1`] = `
"Unexpected token. Did you mean \`{'>'}\` or \`&gt;\`? (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 = <div>Navigate to: Menu Bar > Tools > Options</div>
| ^
4 |"
`;
exports[`invalid-jsx-1.tsx [typescript] format 1`] = `
"Unexpected token. Did you mean \`{'>'}\` or \`&gt;\`? (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 {
@@ -16,5 +16,5 @@ runFormatTest(
`,
],
},
["babel-ts", "typescript", "oxc-ts"],
["typescript", "babel-ts", "oxc-ts"],
);
@@ -11,5 +11,5 @@ runFormatTest(
`,
],
},
["babel-ts", "typescript", "oxc-ts"],
["typescript", "babel-ts", "oxc-ts"],
);
@@ -1 +1 @@
runFormatTest(import.meta, ["babel-ts", "typescript", "oxc-ts"]);
runFormatTest(import.meta, ["typescript", "babel-ts", "oxc-ts"]);
@@ -3,5 +3,5 @@ runFormatTest(
importMeta: import.meta,
snippets: ["declare function foo() {}"],
},
["babel-ts", "typescript", "oxc-ts"],
["typescript", "babel-ts", "oxc-ts"],
);
@@ -29,5 +29,5 @@ runFormatTest(
"(a())++",
],
},
["babel-ts", "typescript", "oxc-ts"],
["typescript", "babel-ts", "oxc-ts"],
);
@@ -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 {
@@ -28,5 +28,5 @@ runFormatTest(
`,
),
},
["typescript", "babel-ts"],
["typescript", "babel-ts", "oxc-ts"],
);
@@ -1,5 +1 @@
runFormatTest(import.meta, [
"typescript",
"babel-ts",
// "oxc-ts"
]);
runFormatTest(import.meta, ["typescript", "babel-ts", "oxc-ts"]);
@@ -9,5 +9,5 @@ runFormatTest(
"interface A implements B {}",
],
},
["babel-ts", "typescript", "oxc-ts"],
["typescript", "babel-ts", "oxc-ts"],
);
@@ -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"],
);
@@ -1 +1 @@
runFormatTest(import.meta, ["babel-ts", "typescript", "oxc-ts"]);
runFormatTest(import.meta, ["typescript", "babel-ts", "oxc-ts"]);
@@ -144,5 +144,5 @@ runFormatTest(
...["abstract"].map((modifier) => `({${modifier} method(){}})`),
],
},
["babel-ts", "typescript", "oxc-ts"],
["typescript", "babel-ts", "oxc-ts"],
);
@@ -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"],
);
@@ -8,5 +8,5 @@ runFormatTest(
"type T = [x<y>: A];",
],
},
["babel-ts", "typescript", "oxc-ts"],
["typescript", "babel-ts", "oxc-ts"],
);