From 8d3fe9b568f5b3330f053dec994f2fa9db761010 Mon Sep 17 00:00:00 2001 From: zoomdong <1344492820@qq.com> Date: Thu, 7 Nov 2024 14:40:28 +0800 Subject: [PATCH] chore: update code --- .../js_test_suite/error/import_type_error2.ts | 1 + .../error/import_type_error2.ts.snap | 102 ++++++++++++++++++ xtask/codegen/js.ungram | 11 +- 3 files changed, 107 insertions(+), 7 deletions(-) create mode 100644 crates/biome_js_parser/tests/js_test_suite/error/import_type_error2.ts create mode 100644 crates/biome_js_parser/tests/js_test_suite/error/import_type_error2.ts.snap diff --git a/crates/biome_js_parser/tests/js_test_suite/error/import_type_error2.ts b/crates/biome_js_parser/tests/js_test_suite/error/import_type_error2.ts new file mode 100644 index 000000000000..932f0ee1c1d2 --- /dev/null +++ b/crates/biome_js_parser/tests/js_test_suite/error/import_type_error2.ts @@ -0,0 +1 @@ +type A = typeof import("a.json",{ \ No newline at end of file diff --git a/crates/biome_js_parser/tests/js_test_suite/error/import_type_error2.ts.snap b/crates/biome_js_parser/tests/js_test_suite/error/import_type_error2.ts.snap new file mode 100644 index 000000000000..e31a1da4354f --- /dev/null +++ b/crates/biome_js_parser/tests/js_test_suite/error/import_type_error2.ts.snap @@ -0,0 +1,102 @@ +--- +source: crates/biome_js_parser/tests/spec_test.rs +expression: snapshot +--- +## Input + +```ts +type A = typeof import("a.json",{ +``` + + +## AST + +``` +JsModule { + bom_token: missing (optional), + interpreter_token: missing (optional), + directives: JsDirectiveList [], + items: JsModuleItemList [ + TsTypeAliasDeclaration { + type_token: TYPE_KW@0..5 "type" [] [Whitespace(" ")], + binding_identifier: TsIdentifierBinding { + name_token: IDENT@5..7 "A" [] [Whitespace(" ")], + }, + type_parameters: missing (optional), + eq_token: EQ@7..9 "=" [] [Whitespace(" ")], + ty: TsImportType { + typeof_token: TYPEOF_KW@9..16 "typeof" [] [Whitespace(" ")], + import_token: IMPORT_KW@16..22 "import" [] [], + arguments: TsImportTypeArguments { + l_paren_token: L_PAREN@22..23 "(" [] [], + argument: TsStringLiteralType { + literal_token: JS_STRING_LITERAL@23..31 "\"a.json\"" [] [], + }, + comma_token: COMMA@31..32 "," [] [], + ts_import_type_assertion_block: TsImportTypeAssertionBlock { + l_curly_token: L_CURLY@32..33 "{" [] [], + type_assertion: missing (required), + r_curly_token: missing (required), + }, + r_paren_token: missing (required), + }, + qualifier_clause: missing (optional), + type_arguments: missing (optional), + }, + semicolon_token: missing (optional), + }, + ], + eof_token: EOF@33..33 "" [] [], +} +``` + +## CST + +``` +0: JS_MODULE@0..33 + 0: (empty) + 1: (empty) + 2: JS_DIRECTIVE_LIST@0..0 + 3: JS_MODULE_ITEM_LIST@0..33 + 0: TS_TYPE_ALIAS_DECLARATION@0..33 + 0: TYPE_KW@0..5 "type" [] [Whitespace(" ")] + 1: TS_IDENTIFIER_BINDING@5..7 + 0: IDENT@5..7 "A" [] [Whitespace(" ")] + 2: (empty) + 3: EQ@7..9 "=" [] [Whitespace(" ")] + 4: TS_IMPORT_TYPE@9..33 + 0: TYPEOF_KW@9..16 "typeof" [] [Whitespace(" ")] + 1: IMPORT_KW@16..22 "import" [] [] + 2: TS_IMPORT_TYPE_ARGUMENTS@22..33 + 0: L_PAREN@22..23 "(" [] [] + 1: TS_STRING_LITERAL_TYPE@23..31 + 0: JS_STRING_LITERAL@23..31 "\"a.json\"" [] [] + 2: COMMA@31..32 "," [] [] + 3: TS_IMPORT_TYPE_ASSERTION_BLOCK@32..33 + 0: L_CURLY@32..33 "{" [] [] + 1: (empty) + 2: (empty) + 4: (empty) + 3: (empty) + 4: (empty) + 5: (empty) + 4: EOF@33..33 "" [] [] + +``` + +## Diagnostics + +``` +import_type_error2.ts:1:34 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `}` but instead the file ends + + > 1 │ type A = typeof import("a.json",{ + │ + + i the file ends here + + > 1 │ type A = typeof import("a.json",{ + │ + +``` diff --git a/xtask/codegen/js.ungram b/xtask/codegen/js.ungram index d8b71d449af2..3f77e4fefb94 100644 --- a/xtask/codegen/js.ungram +++ b/xtask/codegen/js.ungram @@ -2144,13 +2144,10 @@ TsImportTypeAssertionBlock = // a: typeof import("mod", { with: { "resolution-mode": "import" } }) // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TsImportTypeArguments = - '(' - argument: AnyTsType - ( - ',' - TsImportTypeAssertionBlock - )? - ')' + '(' + argument: AnyTsType + (',' TsImportTypeAssertionBlock )? + ')' // a: import("./test").T // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^