Test invalid syntax on oxc-ts parser (#17593)

This commit is contained in:
fisker Cheung authored and GitHub committed 2025-09-23 05:12:51 +08:00
1 parent fc3565dbd5
commit 74744dc568
22 files changed
+1501 -11

No files matched your search

@@ -11,6 +11,16 @@ exports[`catch-clause-with-initializer.ts [babel-ts] format 1`] = `
Cause: Unexpected token, expected ")" (3:9)"
`;
exports[`catch-clause-with-initializer.ts [oxc-ts] format 1`] = `
"Expected \`)\` but found \`=\` (3:10)
1 | try {
2 | }
> 3 | catch (e = 1) {
| ^
4 | }
5 |"
`;
exports[`catch-clause-with-initializer.ts [typescript] format 1`] = `
"Catch clause variable cannot have an initializer. (3:12)
1 | try {
@@ -1 +1 @@
runFormatTest(import.meta, ["babel-ts", "typescript"]);
runFormatTest(import.meta, ["babel-ts", "typescript", "oxc-ts"]);
@@ -7,6 +7,12 @@ exports[`snippet: #0 [babel-ts] format 1`] = `
Cause: An implementation cannot be declared in ambient contexts. (1:0)"
`;
exports[`snippet: #0 [oxc-ts] format 1`] = `
"An implementation cannot be declared in ambient contexts. (1:24)
> 1 | declare function foo() {}
| ^"
`;
exports[`snippet: #0 [typescript] format 1`] = `
"An implementation cannot be declared in ambient contexts. (1:1)
> 1 | declare function foo() {}
@@ -3,5 +3,5 @@ runFormatTest(
importMeta: import.meta,
snippets: ["declare function foo() {}"],
},
["babel-ts", "typescript"],
["babel-ts", "typescript", "oxc-ts"],
);
@@ -7,6 +7,12 @@ exports[`snippet: #0 [babel-ts] format 1`] = `
Cause: Invalid left-hand side in postfix operation. (1:0)"
`;
exports[`snippet: #0 [oxc-ts] format 1`] = `
"Cannot assign to this expression (1:1)
> 1 | 1 ++
| ^"
`;
exports[`snippet: #0 [typescript] format 1`] = `
"Invalid left-hand side expression in unary operation (1:1)
> 1 | 1 ++
@@ -21,6 +27,12 @@ exports[`snippet: #1 [babel-ts] format 1`] = `
Cause: Invalid left-hand side in postfix operation. (1:1)"
`;
exports[`snippet: #1 [oxc-ts] format 1`] = `
"Cannot assign to this expression (1:2)
> 1 | (1)++
| ^"
`;
exports[`snippet: #1 [typescript] format 1`] = `
"Invalid left-hand side expression in unary operation (1:1)
> 1 | (1)++
@@ -35,6 +47,12 @@ exports[`snippet: #2 [babel-ts] format 1`] = `
Cause: Invalid left-hand side in postfix operation. (1:1)"
`;
exports[`snippet: #2 [oxc-ts] format 1`] = `
"Cannot assign to this expression (1:2)
> 1 | (1)--
| ^"
`;
exports[`snippet: #2 [typescript] format 1`] = `
"Invalid left-hand side expression in unary operation (1:1)
> 1 | (1)--
@@ -49,6 +67,12 @@ exports[`snippet: #3 [babel-ts] format 1`] = `
Cause: Invalid left-hand side in prefix operation. (1:3)"
`;
exports[`snippet: #3 [oxc-ts] format 1`] = `
"Cannot assign to this expression (1:4)
> 1 | ++(1)
| ^"
`;
exports[`snippet: #3 [typescript] format 1`] = `
"Invalid left-hand side expression in unary operation (1:3)
> 1 | ++(1)
@@ -63,6 +87,12 @@ exports[`snippet: #4 [babel-ts] format 1`] = `
Cause: Invalid left-hand side in prefix operation. (1:3)"
`;
exports[`snippet: #4 [oxc-ts] format 1`] = `
"Cannot assign to this expression (1:4)
> 1 | --(1)
| ^"
`;
exports[`snippet: #4 [typescript] format 1`] = `
"Invalid left-hand side expression in unary operation (1:3)
> 1 | --(1)
@@ -77,6 +107,12 @@ exports[`snippet: #5 [babel-ts] format 1`] = `
Cause: Invalid left-hand side in postfix operation. (1:1)"
`;
exports[`snippet: #5 [oxc-ts] format 1`] = `
"Cannot assign to this expression (1:2)
> 1 | (1 + 2)++
| ^^^^^"
`;
exports[`snippet: #5 [typescript] format 1`] = `
"Invalid left-hand side expression in unary operation (1:1)
> 1 | (1 + 2)++
@@ -91,6 +127,12 @@ exports[`snippet: #6 [babel-ts] format 1`] = `
Cause: Invalid left-hand side in postfix operation. (1:1)"
`;
exports[`snippet: #6 [oxc-ts] format 1`] = `
"Cannot assign to this expression (1:2)
> 1 | (1 + 2)--
| ^^^^^"
`;
exports[`snippet: #6 [typescript] format 1`] = `
"Invalid left-hand side expression in unary operation (1:1)
> 1 | (1 + 2)--
@@ -105,6 +147,12 @@ exports[`snippet: #7 [babel-ts] format 1`] = `
Cause: Invalid left-hand side in prefix operation. (1:3)"
`;
exports[`snippet: #7 [oxc-ts] format 1`] = `
"Cannot assign to this expression (1:4)
> 1 | ++(1 + 2)
| ^^^^^"
`;
exports[`snippet: #7 [typescript] format 1`] = `
"Invalid left-hand side expression in unary operation (1:3)
> 1 | ++(1 + 2)
@@ -119,6 +167,12 @@ exports[`snippet: #8 [babel-ts] format 1`] = `
Cause: Invalid left-hand side in prefix operation. (1:3)"
`;
exports[`snippet: #8 [oxc-ts] format 1`] = `
"Cannot assign to this expression (1:4)
> 1 | --(1 + 2)
| ^^^^^"
`;
exports[`snippet: #8 [typescript] format 1`] = `
"Invalid left-hand side expression in unary operation (1:3)
> 1 | --(1 + 2)
@@ -133,6 +187,12 @@ exports[`snippet: #9 [babel-ts] format 1`] = `
Cause: Invalid left-hand side in postfix operation. (1:1)"
`;
exports[`snippet: #9 [oxc-ts] format 1`] = `
"Cannot assign to this expression (1:2)
> 1 | (x + x)++
| ^^^^^"
`;
exports[`snippet: #9 [typescript] format 1`] = `
"Invalid left-hand side expression in unary operation (1:1)
> 1 | (x + x)++
@@ -147,6 +207,12 @@ exports[`snippet: #10 [babel-ts] format 1`] = `
Cause: Invalid left-hand side in postfix operation. (1:1)"
`;
exports[`snippet: #10 [oxc-ts] format 1`] = `
"Cannot assign to this expression (1:2)
> 1 | (x + x)--
| ^^^^^"
`;
exports[`snippet: #10 [typescript] format 1`] = `
"Invalid left-hand side expression in unary operation (1:1)
> 1 | (x + x)--
@@ -161,6 +227,12 @@ exports[`snippet: #11 [babel-ts] format 1`] = `
Cause: Invalid left-hand side in prefix operation. (1:3)"
`;
exports[`snippet: #11 [oxc-ts] format 1`] = `
"Cannot assign to this expression (1:4)
> 1 | ++(x + x)
| ^^^^^"
`;
exports[`snippet: #11 [typescript] format 1`] = `
"Invalid left-hand side expression in unary operation (1:3)
> 1 | ++(x + x)
@@ -175,6 +247,12 @@ exports[`snippet: #12 [babel-ts] format 1`] = `
Cause: Invalid left-hand side in prefix operation. (1:3)"
`;
exports[`snippet: #12 [oxc-ts] format 1`] = `
"Cannot assign to this expression (1:4)
> 1 | --(x + x)
| ^^^^^"
`;
exports[`snippet: #12 [typescript] format 1`] = `
"Invalid left-hand side expression in unary operation (1:3)
> 1 | --(x + x)
@@ -189,6 +267,12 @@ exports[`snippet: #13 [babel-ts] format 1`] = `
Cause: Invalid left-hand side in postfix operation. (1:0)"
`;
exports[`snippet: #13 [oxc-ts] format 1`] = `
"Cannot assign to this expression (1:1)
> 1 | a()++
| ^^^"
`;
exports[`snippet: #13 [typescript] format 1`] = `
"Invalid left-hand side expression in unary operation (1:1)
> 1 | a()++
@@ -203,6 +287,12 @@ exports[`snippet: #14 [babel-ts] format 1`] = `
Cause: Invalid optional chaining in the left-hand side of postfix operation. (1:0)"
`;
exports[`snippet: #14 [oxc-ts] format 1`] = `
"Cannot assign to this expression (1:1)
> 1 | x?.y++
| ^^^^"
`;
exports[`snippet: #14 [typescript] format 1`] = `
"Invalid left-hand side expression in unary operation (1:1)
> 1 | x?.y++
@@ -217,6 +307,12 @@ exports[`snippet: #15 [babel-ts] format 1`] = `
Cause: Invalid optional chaining in the left-hand side of postfix operation. (1:0)"
`;
exports[`snippet: #15 [oxc-ts] format 1`] = `
"Cannot assign to this expression (1:1)
> 1 | x?.y.z++
| ^^^^^^"
`;
exports[`snippet: #15 [typescript] format 1`] = `
"Invalid left-hand side expression in unary operation (1:1)
> 1 | x?.y.z++
@@ -231,6 +327,12 @@ exports[`snippet: #16 [babel-ts] format 1`] = `
Cause: Invalid optional chaining in the left-hand side of postfix operation. (1:0)"
`;
exports[`snippet: #16 [oxc-ts] format 1`] = `
"Cannot assign to this expression (1:1)
> 1 | x?.y().z++
| ^^^^^^^^"
`;
exports[`snippet: #16 [typescript] format 1`] = `
"Invalid left-hand side expression in unary operation (1:1)
> 1 | x?.y().z++
@@ -245,6 +347,12 @@ exports[`snippet: #17 [babel-ts] format 1`] = `
Cause: Invalid left-hand side in postfix operation. (1:1)"
`;
exports[`snippet: #17 [oxc-ts] format 1`] = `
"Cannot assign to this expression (1:2)
> 1 | (a())++
| ^^^"
`;
exports[`snippet: #17 [typescript] format 1`] = `
"Invalid left-hand side expression in unary operation (1:1)
> 1 | (a())++
@@ -29,5 +29,5 @@ runFormatTest(
"(a())++",
],
},
["babel-ts", "typescript"],
["babel-ts", "typescript", "oxc-ts"],
);
@@ -7,6 +7,12 @@ exports[`snippet: #0 [babel-ts] format 1`] = `
Cause: Accessibility modifier already seen: 'protected'. (1:17)"
`;
exports[`snippet: #0 [oxc-ts] format 1`] = `
"Accessibility modifier already seen. (1:18)
> 1 | class A {private protected method(){}}
| ^^^^^^^^^"
`;
exports[`snippet: #0 [typescript] format 1`] = `
"Accessibility modifier already seen. (1:18)
> 1 | class A {private protected method(){}}
@@ -21,6 +27,12 @@ exports[`snippet: #1 [babel-ts] format 1`] = `
Cause: Accessibility modifier already seen: 'public'. (1:19)"
`;
exports[`snippet: #1 [oxc-ts] format 1`] = `
"Accessibility modifier already seen. (1:20)
> 1 | class A {protected public method(){}}
| ^^^^^^"
`;
exports[`snippet: #1 [typescript] format 1`] = `
"Accessibility modifier already seen. (1:20)
> 1 | class A {protected public method(){}}
@@ -35,6 +47,12 @@ exports[`snippet: #2 [babel-ts] format 1`] = `
Cause: Accessibility modifier already seen: 'private'. (1:17)"
`;
exports[`snippet: #2 [oxc-ts] format 1`] = `
"Accessibility modifier already seen. (1:18)
> 1 | class A {private private method(){}}
| ^^^^^^^"
`;
exports[`snippet: #2 [typescript] format 1`] = `
"Accessibility modifier already seen. (1:18)
> 1 | class A {private private method(){}}
@@ -49,6 +67,12 @@ exports[`snippet: #3 [babel-ts] format 1`] = `
Cause: Accessibility modifier already seen: 'protected'. (1:17)"
`;
exports[`snippet: #3 [oxc-ts] format 1`] = `
"Accessibility modifier already seen. (1:18)
> 1 | class A {private protected property}
| ^^^^^^^^^"
`;
exports[`snippet: #3 [typescript] format 1`] = `
"Accessibility modifier already seen. (1:18)
> 1 | class A {private protected property}
@@ -63,6 +87,12 @@ exports[`snippet: #4 [babel-ts] format 1`] = `
Cause: Accessibility modifier already seen: 'public'. (1:19)"
`;
exports[`snippet: #4 [oxc-ts] format 1`] = `
"Accessibility modifier already seen. (1:20)
> 1 | class A {protected public property}
| ^^^^^^"
`;
exports[`snippet: #4 [typescript] format 1`] = `
"Accessibility modifier already seen. (1:20)
> 1 | class A {protected public property}
@@ -77,6 +107,12 @@ exports[`snippet: #5 [babel-ts] format 1`] = `
Cause: Accessibility modifier already seen: 'private'. (1:17)"
`;
exports[`snippet: #5 [oxc-ts] format 1`] = `
"Accessibility modifier already seen. (1:18)
> 1 | class A {private private property}
| ^^^^^^^"
`;
exports[`snippet: #5 [typescript] format 1`] = `
"Accessibility modifier already seen. (1:18)
> 1 | class A {private private property}
@@ -10,5 +10,5 @@ runFormatTest(
"class A {private private property}",
],
},
["typescript", "babel-ts"],
["typescript", "babel-ts", "oxc-ts"],
);
@@ -1,5 +1,21 @@
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
exports[`valid-flow-default-import.mts [babel-ts] format 1`] = `
"Unexpected token. (1:8)
> 1 | import module foo from "./module.wasm";
| ^
2 | import bar from "./module.wasm";
3 |"
`;
exports[`valid-flow-default-import.mts [oxc-ts] format 1`] = `
"Expected \`from\` but found \`Identifier\` (1:15)
> 1 | import module foo from "./module.wasm";
| ^^^
2 | import bar from "./module.wasm";
3 |"
`;
exports[`valid-flow-default-import.mts [typescript] format 1`] = `
"'=' expected. (1:15)
> 1 | import module foo from "./module.wasm";
@@ -9,6 +25,22 @@ exports[`valid-flow-default-import.mts [typescript] format 1`] = `
Cause: '=' expected."
`;
exports[`valid-ts-default-import.mts [babel-ts] format 1`] = `
"Unexpected token. (1:8)
> 1 | import module foo from "./module.wasm";
| ^
2 | import bar from "./module.wasm";
3 |"
`;
exports[`valid-ts-default-import.mts [oxc-ts] format 1`] = `
"Expected \`from\` but found \`Identifier\` (1:15)
> 1 | import module foo from "./module.wasm";
| ^^^
2 | import bar from "./module.wasm";
3 |"
`;
exports[`valid-ts-default-import.mts [typescript] format 1`] = `
"'=' expected. (1:15)
> 1 | import module foo from "./module.wasm";
@@ -1 +1 @@
runFormatTest(import.meta, ["typescript"]);
runFormatTest(import.meta, ["typescript", "babel-ts", "oxc-ts"]);
@@ -7,6 +7,12 @@ exports[`snippet: #0 [babel-ts] format 1`] = `
Cause: Unexpected token, expected ";" (1:24)"
`;
exports[`snippet: #0 [oxc-ts] format 1`] = `
"Unexpected token (1:25)
> 1 | interface I { x: number = 1;}
| ^"
`;
exports[`snippet: #0 [typescript] format 1`] = `
"A property signature cannot have an initializer. (1:27)
> 1 | interface I { x: number = 1;}
@@ -21,6 +27,12 @@ exports[`snippet: #1 [babel-ts] format 1`] = `
Cause: Unexpected token, expected "{" (1:12)"
`;
exports[`snippet: #1 [oxc-ts] format 1`] = `
"Expected \`{\` but found \`Identifier\` (1:13)
> 1 | interface A mixins B {}
| ^^^^^^"
`;
exports[`snippet: #1 [typescript] format 1`] = `
"'{' expected. (1:13)
> 1 | interface A mixins B {}
@@ -35,6 +47,12 @@ exports[`snippet: #2 [babel-ts] format 1`] = `
Cause: Unexpected token, expected "{" (1:12)"
`;
exports[`snippet: #2 [oxc-ts] format 1`] = `
"Interface declaration cannot have 'implements' clause. (1:13)
> 1 | interface A implements B {}
| ^^^^^^^^^^"
`;
exports[`snippet: #2 [typescript] format 1`] = `
"Interface declaration cannot have 'implements' clause. (1:13)
> 1 | interface A implements B {}
@@ -9,5 +9,5 @@ runFormatTest(
"interface A implements B {}",
],
},
["babel-ts", "typescript"],
["babel-ts", "typescript", "oxc-ts"],
);
@@ -7,6 +7,12 @@ exports[`snippet: #0 [babel-ts] format 1`] = `
Cause: Missing semicolon. (1:11)"
`;
exports[`snippet: #0 [oxc-ts] format 1`] = `
"Expected \`;\` but found \`Identifier\` (1:13)
> 1 | for (var of X);
| ^"
`;
exports[`snippet: #0 [typescript] format 1`] = `
"Only a single variable declaration is allowed in a 'for...of' statement. (1:6)
> 1 | for (var of X);
@@ -21,6 +27,12 @@ exports[`snippet: #1 [babel-ts] format 1`] = `
Cause: Unexpected token (1:14)"
`;
exports[`snippet: #1 [oxc-ts] format 1`] = `
"Unexpected token (1:15)
> 1 | for (var of of);
| ^"
`;
exports[`snippet: #1 [typescript] format 1`] = `
"Only a single variable declaration is allowed in a 'for...of' statement. (1:6)
> 1 | for (var of of);
@@ -35,6 +47,12 @@ exports[`snippet: #2 [babel-ts] format 1`] = `
Cause: Unexpected keyword 'in'. (1:9)"
`;
exports[`snippet: #2 [oxc-ts] format 1`] = `
"Identifier expected. 'in' is a reserved word that cannot be used here. (1:10)
> 1 | for (var in X);
| ^^"
`;
exports[`snippet: #2 [typescript] format 1`] = `
"Only a single variable declaration is allowed in a 'for...in' statement. (1:6)
> 1 | for (var in X);
@@ -3,5 +3,5 @@ runFormatTest(
importMeta: import.meta,
snippets: ["for (var of X);", "for (var of of);", "for (var in X);"],
},
["babel-ts", "typescript"],
["babel-ts", "typescript", "oxc-ts"],
);
@@ -11,6 +11,16 @@ exports[`mapped-type.ts [babel-ts] format 1`] = `
Cause: Unexpected token, expected "}" (3:2)"
`;
exports[`mapped-type.ts [oxc-ts] format 1`] = `
"Expected \`}\` but found \`Identifier\` (3:3)
1 | type Mapped = {
2 | [key in keyof O]: number;
> 3 | extra_member: should_not_allowed
| ^^^^^^^^^^^^
4 | };
5 |"
`;
exports[`mapped-type.ts [typescript] format 1`] = `
"A mapped type may not declare properties or methods. (3:3)
1 | type Mapped = {
@@ -1 +1 @@
runFormatTest(import.meta, ["babel-ts", "typescript"]);
runFormatTest(import.meta, ["babel-ts", "typescript", "oxc-ts"]);
File diff suppressed because it is too large. Load diff
@@ -140,5 +140,5 @@ runFormatTest(
`,
],
},
["babel-ts", "typescript"],
["babel-ts", "typescript", "oxc-ts"],
);
@@ -7,6 +7,12 @@ exports[`snippet: #0 [babel-ts] format 1`] = `
Cause: Missing semicolon. (1:9)"
`;
exports[`snippet: #0 [oxc-ts] format 1`] = `
"Unexpected token (1:11)
> 1 | namespace "a" {}
| ^^^"
`;
exports[`snippet: #0 [typescript] format 1`] = `
"Identifier expected. (1:11)
> 1 | namespace "a" {}
@@ -21,6 +27,12 @@ exports[`snippet: #1 [babel-ts] format 1`] = `
Cause: Missing semicolon. (1:9)"
`;
exports[`snippet: #1 [oxc-ts] format 1`] = `
"Unexpected token (1:11)
> 1 | namespace "a";
| ^^^"
`;
exports[`snippet: #1 [typescript] format 1`] = `
"Identifier expected. (1:11)
> 1 | namespace "a";
@@ -35,6 +47,12 @@ exports[`snippet: #2 [babel-ts] format 1`] = `
Cause: Unexpected token, expected "{" (1:11)"
`;
exports[`snippet: #2 [oxc-ts] format 1`] = `
"Expected \`{\` but found \`;\` (1:12)
> 1 | namespace a;
| ^"
`;
exports[`snippet: #2 [typescript] format 1`] = `
"'{' expected. (1:12)
> 1 | namespace a;
@@ -3,5 +3,5 @@ runFormatTest(
importMeta: import.meta,
snippets: ['namespace "a" {}', 'namespace "a";', "namespace a;"],
},
["babel-ts", "typescript"],
["babel-ts", "typescript", "oxc-ts"],
);
@@ -7,6 +7,12 @@ exports[`snippet: #0 [babel-ts] format 1`] = `
Cause: Tuple members must be labeled with a simple identifier. (1:10)"
`;
exports[`snippet: #0 [oxc-ts] format 1`] = `
"Expected \`,\` but found \`:\` (1:14)
> 1 | type T = [x.y: A];
| ^"
`;
exports[`snippet: #0 [typescript] format 1`] = `
"',' expected. (1:14)
> 1 | type T = [x.y: A];
@@ -21,6 +27,12 @@ exports[`snippet: #1 [babel-ts] format 1`] = `
Cause: Tuple members must be labeled with a simple identifier. (1:10)"
`;
exports[`snippet: #1 [oxc-ts] format 1`] = `
"Expected \`,\` but found \`:\` (1:15)
> 1 | type T = [x<y>: A];
| ^"
`;
exports[`snippet: #1 [typescript] format 1`] = `
"',' expected. (1:15)
> 1 | type T = [x<y>: A];
@@ -8,5 +8,5 @@ runFormatTest(
"type T = [x<y>: A];",
],
},
["babel-ts", "typescript"],
["babel-ts", "typescript", "oxc-ts"],
);