More parsers on reserved word tests (#17959)

This commit is contained in:
fisker Cheung authored and GitHub committed 2025-09-25 03:51:07 +08:00
1 parent d8b26a69f1
commit 2ac07333b6
5 files changed
+182 -8

No files matched your search

@@ -1,5 +1,19 @@
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
exports[`snippet: #0 [acorn] format 1`] = `
"The keyword 'interface' is reserved (1:7)
> 1 | class interface {}
| ^
Cause: The keyword 'interface' is reserved (1:6)"
`;
exports[`snippet: #0 [acorn] format 2`] = `
"Unexpected token (1:8)
> 1 | export asyn\\u{63} from "async";
| ^
Cause: Unexpected token (1:7)"
`;
exports[`snippet: #0 [espree] format 1`] = `
"The keyword 'interface' is reserved (1:7)
> 1 | class interface {}
@@ -7,6 +21,34 @@ exports[`snippet: #0 [espree] format 1`] = `
Cause: The keyword 'interface' is reserved"
`;
exports[`snippet: #0 [espree] format 2`] = `
"Unexpected token asyn\\u{63} (1:8)
> 1 | export asyn\\u{63} from "async";
| ^
Cause: Unexpected token asyn\\u{63}"
`;
exports[`snippet: #0 [flow] format 1`] = `
"Use of reserved word in strict mode (1:7)
> 1 | class interface {}
| ^^^^^^^^^"
`;
exports[`snippet: #0 [flow] format 2`] = `
"Unexpected identifier, expected a declaration, statement or export specifiers (1:8)
> 1 | export asyn\\u{63} from "async";
| ^^^^^^^^^^"
`;
exports[`snippet: #0 [hermes] format 1`] = `
"expected declaration in export (1:7)
> 1 | export asyn\\u{63} from "async";
| ^
Cause: expected declaration in export (1:7)
export asyn\\u{63} from "async";
^~~~~~~~~~"
`;
exports[`snippet: #0 [meriyah] format 1`] = `
"Unexpected strict mode reserved word (1:7)
> 1 | class interface {}
@@ -14,6 +56,39 @@ exports[`snippet: #0 [meriyah] format 1`] = `
Cause: [1:6-1:15]: Unexpected strict mode reserved word"
`;
exports[`snippet: #0 [meriyah] format 2`] = `
"Unexpected token: 'reserved if strict' (1:8)
> 1 | export asyn\\u{63} from "async";
| ^^^^^^^^^^
Cause: [1:7-1:17]: Unexpected token: 'reserved if strict'"
`;
exports[`snippet: #0 [oxc] format 1`] = `
"Unexpected token (1:8)
> 1 | export asyn\\u{63} from "async";
| ^^^^^^^^^^"
`;
exports[`snippet: #0 [oxc-ts] format 1`] = `
"Keywords cannot contain escape characters (1:8)
> 1 | export asyn\\u{63} from "async";
| ^^^^^^^^^^"
`;
exports[`snippet: #0 [typescript] format 1`] = `
"Declaration or statement expected. (1:1)
> 1 | export asyn\\u{63} from "async";
| ^
Cause: Declaration or statement expected."
`;
exports[`snippet: #1 [acorn] format 1`] = `
"The keyword 'interface' is reserved (1:8)
> 1 | import interface from "foo";
| ^
Cause: The keyword 'interface' is reserved (1:7)"
`;
exports[`snippet: #1 [espree] format 1`] = `
"The keyword 'interface' is reserved (1:8)
> 1 | import interface from "foo";
@@ -21,6 +96,12 @@ exports[`snippet: #1 [espree] format 1`] = `
Cause: The keyword 'interface' is reserved"
`;
exports[`snippet: #1 [flow] format 1`] = `
"Use of reserved word in strict mode (1:8)
> 1 | import interface from "foo";
| ^^^^^^^^^"
`;
exports[`snippet: #1 [meriyah] format 1`] = `
"Unexpected strict mode reserved word (1:8)
> 1 | import interface from "foo";
@@ -3,5 +3,38 @@ runFormatTest(
importMeta: import.meta,
snippets: ["class interface {}", 'import interface from "foo";'],
},
["espree", "meriyah"],
[
// "babel",
// "babel-ts",
"acorn",
"espree",
"flow",
"meriyah",
// "typescript",
// "hermes",
// "oxc",
// "oxc-ts",
],
);
runFormatTest(
{
importMeta: import.meta,
snippets: [
// cspell:disable-next-line
String.raw`export asyn\u{63} from "async";`,
],
},
[
// "babel",
// "babel-ts",
"acorn",
"espree",
"flow",
"meriyah",
"typescript",
"hermes",
"oxc",
"oxc-ts",
],
);
@@ -1,5 +1,15 @@
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
exports[`declare-getter.ts [babel-ts] format 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 [typescript] format 1`] = `
"'declare' modifier cannot appear on class elements of this kind. (2:3)
1 | class Foo {
@@ -10,6 +20,16 @@ exports[`declare-getter.ts [typescript] format 1`] = `
Cause: 'declare' modifier cannot appear on class elements of this kind."
`;
exports[`declare-setter.ts [babel-ts] format 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 [typescript] format 1`] = `
"'declare' modifier cannot appear on class elements of this kind. (2:3)
1 | class Foo {
@@ -20,12 +40,12 @@ exports[`declare-setter.ts [typescript] format 1`] = `
Cause: 'declare' modifier cannot appear on class elements of this kind."
`;
exports[`default-escaped.ts [typescript] format 1`] = `
"Declaration or statement expected. (1:1)
> 1 | export asyn\\u{63} from "async";
| ^
exports[`export-declare.ts [babel-ts] format 1`] = `
"'export declare' must be followed by an ambient declaration. (1:16)
> 1 | export declare foo;
| ^
2 |
Cause: Declaration or statement expected."
Cause: 'export declare' must be followed by an ambient declaration. (1:15)"
`;
exports[`export-declare.ts [typescript] format 1`] = `
@@ -36,6 +56,16 @@ exports[`export-declare.ts [typescript] format 1`] = `
Cause: Declaration or statement expected."
`;
exports[`invalid-jsx-1.tsx [babel-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 = <div>Navigate to: Menu Bar > Tools > Options</div>
| ^
4 |
Cause: Unexpected token \`>\`. Did you mean \`&gt;\` or \`{'>'}\`? (3:44)"
`;
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
@@ -46,6 +76,14 @@ exports[`invalid-jsx-1.tsx [typescript] format 1`] = `
Cause: Unexpected token. Did you mean \`{'>'}\` or \`&gt;\`?"
`;
exports[`module-attributes-static.ts [babel-ts] format 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 [typescript] format 1`] = `
"'{' expected. (1:33)
> 1 | import foo from "foo.json" with type: "json";
@@ -54,6 +92,15 @@ exports[`module-attributes-static.ts [typescript] format 1`] = `
Cause: '{' expected."
`;
exports[`newline-before-arrow.ts [babel-ts] format 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 [typescript] format 1`] = `
"Unexpected keyword or identifier. (1:1)
> 1 | async x
@@ -63,6 +110,16 @@ exports[`newline-before-arrow.ts [typescript] format 1`] = `
Cause: Unexpected keyword or identifier."
`;
exports[`value-of-abstract-property.ts [babel-ts] format 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 [typescript] format 1`] = `
"Abstract property cannot have an initializer. (2:19)
1 | abstract class Foo {
@@ -1 +0,0 @@
export asyn\u{63} from "async";
@@ -1 +1,5 @@
runFormatTest(import.meta, ["typescript"]);
runFormatTest(import.meta, [
"typescript",
"babel-ts",
// "oxc-ts"
]);