diff --git a/crates/rome_js_factory/src/generated/node_factory.rs b/crates/rome_js_factory/src/generated/node_factory.rs index 922e12a3423..4ddcfbacf3b 100644 --- a/crates/rome_js_factory/src/generated/node_factory.rs +++ b/crates/rome_js_factory/src/generated/node_factory.rs @@ -1939,7 +1939,7 @@ impl JsImportBuilder { } } pub fn js_import_assertion( - assert_token: SyntaxToken, + assertion_token: SyntaxToken, l_curly_token: SyntaxToken, assertions: JsImportAssertionEntryList, r_curly_token: SyntaxToken, @@ -1947,7 +1947,7 @@ pub fn js_import_assertion( JsImportAssertion::unwrap_cast(SyntaxNode::new_detached( JsSyntaxKind::JS_IMPORT_ASSERTION, [ - Some(SyntaxElement::Token(assert_token)), + Some(SyntaxElement::Token(assertion_token)), Some(SyntaxElement::Token(l_curly_token)), Some(SyntaxElement::Node(assertions.into_syntax())), Some(SyntaxElement::Token(r_curly_token)), diff --git a/crates/rome_js_factory/src/generated/syntax_factory.rs b/crates/rome_js_factory/src/generated/syntax_factory.rs index d6c4a4b8f7e..388bd52abee 100644 --- a/crates/rome_js_factory/src/generated/syntax_factory.rs +++ b/crates/rome_js_factory/src/generated/syntax_factory.rs @@ -2809,7 +2809,7 @@ impl SyntaxFactory for JsSyntaxFactory { let mut slots: RawNodeSlots<4usize> = RawNodeSlots::default(); let mut current_element = elements.next(); if let Some(element) = ¤t_element { - if element.kind() == T![assert] { + if matches!(element.kind(), T![assert] | T![with]) { slots.mark_present(); current_element = elements.next(); } diff --git a/crates/rome_js_parser/src/parse.rs b/crates/rome_js_parser/src/parse.rs index 75fb6ba2e9b..73ef88495a5 100644 --- a/crates/rome_js_parser/src/parse.rs +++ b/crates/rome_js_parser/src/parse.rs @@ -262,6 +262,8 @@ pub fn parse_js_with_cache( tracing::debug_span!("parse").in_scope(move || { let (events, errors, tokens) = parse_common(text, source_type); let mut tree_sink = JsLosslessTreeSink::with_cache(text, &tokens, cache); + dbg!(&tree_sink); + dbg!(&events); rome_parser::event::process(&mut tree_sink, events, errors); let (green, parse_errors) = tree_sink.finish(); Parse::new(green, parse_errors) diff --git a/crates/rome_js_parser/src/syntax/module.rs b/crates/rome_js_parser/src/syntax/module.rs index fb4dcfb4b6e..ad960ca39ee 100644 --- a/crates/rome_js_parser/src/syntax/module.rs +++ b/crates/rome_js_parser/src/syntax/module.rs @@ -539,6 +539,15 @@ fn parse_any_named_import_specifier(p: &mut JsParser) -> ParsedSyntax { // import "x" assert // { type: "json" } +// test import_attribute +// import "x" with { type: "json" } +// import "foo" with { "type": "json" }; +// import foo from "foo.json" with { type: "json" }; +// import {test} from "foo.json" with { for: "for" } +// import foo_json from "foo.json" with { type: "json", hasOwnProperty: "true" }; +// import "x" with +// { type: "json" } + // test_err import_assertion_err // import "foo" assert { type, "json" }; // import "bar" \u{61}ssert { type: "json" }; @@ -549,15 +558,40 @@ fn parse_any_named_import_specifier(p: &mut JsParser) -> ParsedSyntax { // import "x" assert; // import ipsum from "ipsum.json" assert { type: "json", lazy: true, startAtLine: 1 }; // import { a } from "a.json" assert + +// test_err import_attribute_err +// import "foo" with { type, "json" }; +// import { foo } with { type: "json" }; +// import "lorem" +// assert { type: "json" } +// import foo2 from "foo.json" with { "type": "json", type: "html", "type": "js" }; +// import "x" with; +// import ipsum from "ipsum.json" with { type: "json", lazy: true, startAtLine: 1 }; +// import { a } from "a.json" with fn parse_import_assertion(p: &mut JsParser) -> ParsedSyntax { - if !p.at(T![assert]) || p.has_preceding_line_break() { + if p.has_preceding_line_break() { + return Absent; + } + if !p.at(T![assert]) && !p.at(T![with]) { return Absent; } let m = p.start(); - p.expect(T![assert]); - p.expect(T!['{']); + match p.cur() { + T![assert] => { + p.expect(T![assert]); + } + T![with] => { + p.expect(T![with]); + } + _ => { + m.abandon(p); + return Absent; + } + }; + // bump assert or with + p.expect(T!['{']); ImportAssertionList::default().parse_list(p); p.expect(T!['}']); diff --git a/crates/rome_js_parser/src/tests.rs b/crates/rome_js_parser/src/tests.rs index 836e34119bd..49e2180596d 100644 --- a/crates/rome_js_parser/src/tests.rs +++ b/crates/rome_js_parser/src/tests.rs @@ -14,9 +14,7 @@ use std::path::{Path, PathBuf}; #[test] fn parser_smoke_test() { let src = r#" -let -// comment -a; +import "x" with { type: "json" } "#; let module = parse(src, JsFileSource::tsx()); diff --git a/crates/rome_js_parser/test_data/inline/err/import_assertion_err.rast b/crates/rome_js_parser/test_data/inline/err/import_assertion_err.rast index 19b10e254f9..3b764ccec40 100644 --- a/crates/rome_js_parser/test_data/inline/err/import_assertion_err.rast +++ b/crates/rome_js_parser/test_data/inline/err/import_assertion_err.rast @@ -9,7 +9,7 @@ JsModule { value_token: JS_STRING_LITERAL@7..13 "\"foo\"" [] [Whitespace(" ")], }, assertion: JsImportAssertion { - assert_token: ASSERT_KW@13..20 "assert" [] [Whitespace(" ")], + assertion: ASSERT_KW@13..20 "assert" [] [Whitespace(" ")], l_curly_token: L_CURLY@20..22 "{" [] [Whitespace(" ")], assertions: JsImportAssertionEntryList [ JsImportAssertionEntry { @@ -76,7 +76,7 @@ JsModule { from_token: missing (required), source: missing (required), assertion: JsImportAssertion { - assert_token: ASSERT_KW@96..103 "assert" [] [Whitespace(" ")], + assertion: ASSERT_KW@96..103 "assert" [] [Whitespace(" ")], l_curly_token: L_CURLY@103..105 "{" [] [Whitespace(" ")], assertions: JsImportAssertionEntryList [ JsImportAssertionEntry { @@ -136,7 +136,7 @@ JsModule { value_token: JS_STRING_LITERAL@177..188 "\"foo.json\"" [] [Whitespace(" ")], }, assertion: JsImportAssertion { - assert_token: ASSERT_KW@188..195 "assert" [] [Whitespace(" ")], + assertion: ASSERT_KW@188..195 "assert" [] [Whitespace(" ")], l_curly_token: L_CURLY@195..197 "{" [] [Whitespace(" ")], assertions: JsImportAssertionEntryList [ JsImportAssertionEntry { @@ -173,7 +173,7 @@ JsModule { value_token: JS_STRING_LITERAL@250..254 "\"x\"" [] [Whitespace(" ")], }, assertion: JsImportAssertion { - assert_token: ASSERT_KW@254..260 "assert" [] [], + assertion: ASSERT_KW@254..260 "assert" [] [], l_curly_token: missing (required), assertions: JsImportAssertionEntryList [], r_curly_token: missing (required), @@ -193,7 +193,7 @@ JsModule { value_token: JS_STRING_LITERAL@280..293 "\"ipsum.json\"" [] [Whitespace(" ")], }, assertion: JsImportAssertion { - assert_token: ASSERT_KW@293..300 "assert" [] [Whitespace(" ")], + assertion: ASSERT_KW@293..300 "assert" [] [Whitespace(" ")], l_curly_token: L_CURLY@300..302 "{" [] [Whitespace(" ")], assertions: JsImportAssertionEntryList [ JsImportAssertionEntry { @@ -253,7 +253,7 @@ JsModule { value_token: JS_STRING_LITERAL@364..373 "\"a.json\"" [] [Whitespace(" ")], }, assertion: JsImportAssertion { - assert_token: ASSERT_KW@373..379 "assert" [] [], + assertion: ASSERT_KW@373..379 "assert" [] [], l_curly_token: missing (required), assertions: JsImportAssertionEntryList [], r_curly_token: missing (required), diff --git a/crates/rome_js_parser/test_data/inline/err/import_attribute_err.js b/crates/rome_js_parser/test_data/inline/err/import_attribute_err.js new file mode 100644 index 00000000000..07ad6c8c1e9 --- /dev/null +++ b/crates/rome_js_parser/test_data/inline/err/import_attribute_err.js @@ -0,0 +1,8 @@ +import "foo" with { type, "json" }; +import { foo } with { type: "json" }; +import "lorem" +assert { type: "json" } +import foo2 from "foo.json" with { "type": "json", type: "html", "type": "js" }; +import "x" with; +import ipsum from "ipsum.json" with { type: "json", lazy: true, startAtLine: 1 }; +import { a } from "a.json" with diff --git a/crates/rome_js_parser/test_data/inline/err/import_attribute_err.rast b/crates/rome_js_parser/test_data/inline/err/import_attribute_err.rast new file mode 100644 index 00000000000..ff831a709c9 --- /dev/null +++ b/crates/rome_js_parser/test_data/inline/err/import_attribute_err.rast @@ -0,0 +1,591 @@ +JsModule { + interpreter_token: missing (optional), + directives: JsDirectiveList [], + items: JsModuleItemList [ + JsImport { + import_token: IMPORT_KW@0..7 "import" [] [Whitespace(" ")], + import_clause: JsImportBareClause { + source: JsModuleSource { + value_token: JS_STRING_LITERAL@7..13 "\"foo\"" [] [Whitespace(" ")], + }, + assertion: JsImportAssertion { + assertion: WITH_KW@13..18 "with" [] [Whitespace(" ")], + l_curly_token: L_CURLY@18..20 "{" [] [Whitespace(" ")], + assertions: JsImportAssertionEntryList [ + JsImportAssertionEntry { + key: IDENT@20..24 "type" [] [], + colon_token: missing (required), + value_token: missing (required), + }, + COMMA@24..26 "," [] [Whitespace(" ")], + JsImportAssertionEntry { + key: JS_STRING_LITERAL@26..33 "\"json\"" [] [Whitespace(" ")], + colon_token: missing (required), + value_token: missing (required), + }, + ], + r_curly_token: R_CURLY@33..34 "}" [] [], + }, + }, + semicolon_token: SEMICOLON@34..35 ";" [] [], + }, + JsImport { + import_token: IMPORT_KW@35..43 "import" [Newline("\n")] [Whitespace(" ")], + import_clause: JsImportNamedClause { + type_token: missing (optional), + default_specifier: missing (optional), + named_import: JsNamedImportSpecifiers { + l_curly_token: L_CURLY@43..45 "{" [] [Whitespace(" ")], + specifiers: JsNamedImportSpecifierList [ + JsShorthandNamedImportSpecifier { + type_token: missing (optional), + local_name: JsIdentifierBinding { + name_token: IDENT@45..49 "foo" [] [Whitespace(" ")], + }, + }, + ], + r_curly_token: R_CURLY@49..51 "}" [] [Whitespace(" ")], + }, + from_token: missing (required), + source: missing (required), + assertion: JsImportAssertion { + assertion: WITH_KW@51..56 "with" [] [Whitespace(" ")], + l_curly_token: L_CURLY@56..58 "{" [] [Whitespace(" ")], + assertions: JsImportAssertionEntryList [ + JsImportAssertionEntry { + key: IDENT@58..62 "type" [] [], + colon_token: COLON@62..64 ":" [] [Whitespace(" ")], + value_token: JS_STRING_LITERAL@64..71 "\"json\"" [] [Whitespace(" ")], + }, + ], + r_curly_token: R_CURLY@71..72 "}" [] [], + }, + }, + semicolon_token: SEMICOLON@72..73 ";" [] [], + }, + JsImport { + import_token: IMPORT_KW@73..81 "import" [Newline("\n")] [Whitespace(" ")], + import_clause: JsImportBareClause { + source: JsModuleSource { + value_token: JS_STRING_LITERAL@81..88 "\"lorem\"" [] [], + }, + assertion: missing (optional), + }, + semicolon_token: missing (optional), + }, + JsExpressionStatement { + expression: JsIdentifierExpression { + name: JsReferenceIdentifier { + value_token: IDENT@88..96 "assert" [Newline("\n")] [Whitespace(" ")], + }, + }, + semicolon_token: missing (optional), + }, + JsBlockStatement { + l_curly_token: L_CURLY@96..98 "{" [] [Whitespace(" ")], + statements: JsStatementList [ + JsLabeledStatement { + label_token: IDENT@98..102 "type" [] [], + colon_token: COLON@102..104 ":" [] [Whitespace(" ")], + body: JsExpressionStatement { + expression: JsStringLiteralExpression { + value_token: JS_STRING_LITERAL@104..111 "\"json\"" [] [Whitespace(" ")], + }, + semicolon_token: missing (optional), + }, + }, + ], + r_curly_token: R_CURLY@111..112 "}" [] [], + }, + JsImport { + import_token: IMPORT_KW@112..120 "import" [Newline("\n")] [Whitespace(" ")], + import_clause: JsImportDefaultClause { + type_token: missing (optional), + local_name: JsIdentifierBinding { + name_token: IDENT@120..125 "foo2" [] [Whitespace(" ")], + }, + from_token: FROM_KW@125..130 "from" [] [Whitespace(" ")], + source: JsModuleSource { + value_token: JS_STRING_LITERAL@130..141 "\"foo.json\"" [] [Whitespace(" ")], + }, + assertion: JsImportAssertion { + assertion: WITH_KW@141..146 "with" [] [Whitespace(" ")], + l_curly_token: L_CURLY@146..148 "{" [] [Whitespace(" ")], + assertions: JsImportAssertionEntryList [ + JsImportAssertionEntry { + key: JS_STRING_LITERAL@148..154 "\"type\"" [] [], + colon_token: COLON@154..156 ":" [] [Whitespace(" ")], + value_token: JS_STRING_LITERAL@156..162 "\"json\"" [] [], + }, + COMMA@162..164 "," [] [Whitespace(" ")], + JsBogusImportAssertionEntry { + items: [ + IDENT@164..168 "type" [] [], + COLON@168..170 ":" [] [Whitespace(" ")], + JS_STRING_LITERAL@170..176 "\"html\"" [] [], + ], + }, + COMMA@176..178 "," [] [Whitespace(" ")], + JsBogusImportAssertionEntry { + items: [ + JS_STRING_LITERAL@178..184 "\"type\"" [] [], + COLON@184..186 ":" [] [Whitespace(" ")], + JS_STRING_LITERAL@186..191 "\"js\"" [] [Whitespace(" ")], + ], + }, + ], + r_curly_token: R_CURLY@191..192 "}" [] [], + }, + }, + semicolon_token: SEMICOLON@192..193 ";" [] [], + }, + JsImport { + import_token: IMPORT_KW@193..201 "import" [Newline("\n")] [Whitespace(" ")], + import_clause: JsImportBareClause { + source: JsModuleSource { + value_token: JS_STRING_LITERAL@201..205 "\"x\"" [] [Whitespace(" ")], + }, + assertion: JsImportAssertion { + assertion: WITH_KW@205..209 "with" [] [], + l_curly_token: missing (required), + assertions: JsImportAssertionEntryList [], + r_curly_token: missing (required), + }, + }, + semicolon_token: SEMICOLON@209..210 ";" [] [], + }, + JsImport { + import_token: IMPORT_KW@210..218 "import" [Newline("\n")] [Whitespace(" ")], + import_clause: JsImportDefaultClause { + type_token: missing (optional), + local_name: JsIdentifierBinding { + name_token: IDENT@218..224 "ipsum" [] [Whitespace(" ")], + }, + from_token: FROM_KW@224..229 "from" [] [Whitespace(" ")], + source: JsModuleSource { + value_token: JS_STRING_LITERAL@229..242 "\"ipsum.json\"" [] [Whitespace(" ")], + }, + assertion: JsImportAssertion { + assertion: WITH_KW@242..247 "with" [] [Whitespace(" ")], + l_curly_token: L_CURLY@247..249 "{" [] [Whitespace(" ")], + assertions: JsImportAssertionEntryList [ + JsImportAssertionEntry { + key: IDENT@249..253 "type" [] [], + colon_token: COLON@253..255 ":" [] [Whitespace(" ")], + value_token: JS_STRING_LITERAL@255..261 "\"json\"" [] [], + }, + COMMA@261..263 "," [] [Whitespace(" ")], + JsImportAssertionEntry { + key: IDENT@263..267 "lazy" [] [], + colon_token: COLON@267..269 ":" [] [Whitespace(" ")], + value_token: missing (required), + }, + missing separator, + JsImportAssertionEntry { + key: IDENT@269..273 "true" [] [], + colon_token: missing (required), + value_token: missing (required), + }, + COMMA@273..275 "," [] [Whitespace(" ")], + JsImportAssertionEntry { + key: IDENT@275..286 "startAtLine" [] [], + colon_token: COLON@286..288 ":" [] [Whitespace(" ")], + value_token: missing (required), + }, + missing separator, + JsBogusImportAssertionEntry { + items: [ + JS_NUMBER_LITERAL@288..290 "1" [] [Whitespace(" ")], + ], + }, + ], + r_curly_token: R_CURLY@290..291 "}" [] [], + }, + }, + semicolon_token: SEMICOLON@291..292 ";" [] [], + }, + JsImport { + import_token: IMPORT_KW@292..300 "import" [Newline("\n")] [Whitespace(" ")], + import_clause: JsImportNamedClause { + type_token: missing (optional), + default_specifier: missing (optional), + named_import: JsNamedImportSpecifiers { + l_curly_token: L_CURLY@300..302 "{" [] [Whitespace(" ")], + specifiers: JsNamedImportSpecifierList [ + JsShorthandNamedImportSpecifier { + type_token: missing (optional), + local_name: JsIdentifierBinding { + name_token: IDENT@302..304 "a" [] [Whitespace(" ")], + }, + }, + ], + r_curly_token: R_CURLY@304..306 "}" [] [Whitespace(" ")], + }, + from_token: FROM_KW@306..311 "from" [] [Whitespace(" ")], + source: JsModuleSource { + value_token: JS_STRING_LITERAL@311..320 "\"a.json\"" [] [Whitespace(" ")], + }, + assertion: JsImportAssertion { + assertion: WITH_KW@320..324 "with" [] [], + l_curly_token: missing (required), + assertions: JsImportAssertionEntryList [], + r_curly_token: missing (required), + }, + }, + semicolon_token: missing (optional), + }, + ], + eof_token: EOF@324..325 "" [Newline("\n")] [], +} + +0: JS_MODULE@0..325 + 0: (empty) + 1: JS_DIRECTIVE_LIST@0..0 + 2: JS_MODULE_ITEM_LIST@0..324 + 0: JS_IMPORT@0..35 + 0: IMPORT_KW@0..7 "import" [] [Whitespace(" ")] + 1: JS_IMPORT_BARE_CLAUSE@7..34 + 0: JS_MODULE_SOURCE@7..13 + 0: JS_STRING_LITERAL@7..13 "\"foo\"" [] [Whitespace(" ")] + 1: JS_IMPORT_ASSERTION@13..34 + 0: WITH_KW@13..18 "with" [] [Whitespace(" ")] + 1: L_CURLY@18..20 "{" [] [Whitespace(" ")] + 2: JS_IMPORT_ASSERTION_ENTRY_LIST@20..33 + 0: JS_IMPORT_ASSERTION_ENTRY@20..24 + 0: IDENT@20..24 "type" [] [] + 1: (empty) + 2: (empty) + 1: COMMA@24..26 "," [] [Whitespace(" ")] + 2: JS_IMPORT_ASSERTION_ENTRY@26..33 + 0: JS_STRING_LITERAL@26..33 "\"json\"" [] [Whitespace(" ")] + 1: (empty) + 2: (empty) + 3: R_CURLY@33..34 "}" [] [] + 2: SEMICOLON@34..35 ";" [] [] + 1: JS_IMPORT@35..73 + 0: IMPORT_KW@35..43 "import" [Newline("\n")] [Whitespace(" ")] + 1: JS_IMPORT_NAMED_CLAUSE@43..72 + 0: (empty) + 1: (empty) + 2: JS_NAMED_IMPORT_SPECIFIERS@43..51 + 0: L_CURLY@43..45 "{" [] [Whitespace(" ")] + 1: JS_NAMED_IMPORT_SPECIFIER_LIST@45..49 + 0: JS_SHORTHAND_NAMED_IMPORT_SPECIFIER@45..49 + 0: (empty) + 1: JS_IDENTIFIER_BINDING@45..49 + 0: IDENT@45..49 "foo" [] [Whitespace(" ")] + 2: R_CURLY@49..51 "}" [] [Whitespace(" ")] + 3: (empty) + 4: (empty) + 5: JS_IMPORT_ASSERTION@51..72 + 0: WITH_KW@51..56 "with" [] [Whitespace(" ")] + 1: L_CURLY@56..58 "{" [] [Whitespace(" ")] + 2: JS_IMPORT_ASSERTION_ENTRY_LIST@58..71 + 0: JS_IMPORT_ASSERTION_ENTRY@58..71 + 0: IDENT@58..62 "type" [] [] + 1: COLON@62..64 ":" [] [Whitespace(" ")] + 2: JS_STRING_LITERAL@64..71 "\"json\"" [] [Whitespace(" ")] + 3: R_CURLY@71..72 "}" [] [] + 2: SEMICOLON@72..73 ";" [] [] + 2: JS_IMPORT@73..88 + 0: IMPORT_KW@73..81 "import" [Newline("\n")] [Whitespace(" ")] + 1: JS_IMPORT_BARE_CLAUSE@81..88 + 0: JS_MODULE_SOURCE@81..88 + 0: JS_STRING_LITERAL@81..88 "\"lorem\"" [] [] + 1: (empty) + 2: (empty) + 3: JS_EXPRESSION_STATEMENT@88..96 + 0: JS_IDENTIFIER_EXPRESSION@88..96 + 0: JS_REFERENCE_IDENTIFIER@88..96 + 0: IDENT@88..96 "assert" [Newline("\n")] [Whitespace(" ")] + 1: (empty) + 4: JS_BLOCK_STATEMENT@96..112 + 0: L_CURLY@96..98 "{" [] [Whitespace(" ")] + 1: JS_STATEMENT_LIST@98..111 + 0: JS_LABELED_STATEMENT@98..111 + 0: IDENT@98..102 "type" [] [] + 1: COLON@102..104 ":" [] [Whitespace(" ")] + 2: JS_EXPRESSION_STATEMENT@104..111 + 0: JS_STRING_LITERAL_EXPRESSION@104..111 + 0: JS_STRING_LITERAL@104..111 "\"json\"" [] [Whitespace(" ")] + 1: (empty) + 2: R_CURLY@111..112 "}" [] [] + 5: JS_IMPORT@112..193 + 0: IMPORT_KW@112..120 "import" [Newline("\n")] [Whitespace(" ")] + 1: JS_IMPORT_DEFAULT_CLAUSE@120..192 + 0: (empty) + 1: JS_IDENTIFIER_BINDING@120..125 + 0: IDENT@120..125 "foo2" [] [Whitespace(" ")] + 2: FROM_KW@125..130 "from" [] [Whitespace(" ")] + 3: JS_MODULE_SOURCE@130..141 + 0: JS_STRING_LITERAL@130..141 "\"foo.json\"" [] [Whitespace(" ")] + 4: JS_IMPORT_ASSERTION@141..192 + 0: WITH_KW@141..146 "with" [] [Whitespace(" ")] + 1: L_CURLY@146..148 "{" [] [Whitespace(" ")] + 2: JS_IMPORT_ASSERTION_ENTRY_LIST@148..191 + 0: JS_IMPORT_ASSERTION_ENTRY@148..162 + 0: JS_STRING_LITERAL@148..154 "\"type\"" [] [] + 1: COLON@154..156 ":" [] [Whitespace(" ")] + 2: JS_STRING_LITERAL@156..162 "\"json\"" [] [] + 1: COMMA@162..164 "," [] [Whitespace(" ")] + 2: JS_BOGUS_IMPORT_ASSERTION_ENTRY@164..176 + 0: IDENT@164..168 "type" [] [] + 1: COLON@168..170 ":" [] [Whitespace(" ")] + 2: JS_STRING_LITERAL@170..176 "\"html\"" [] [] + 3: COMMA@176..178 "," [] [Whitespace(" ")] + 4: JS_BOGUS_IMPORT_ASSERTION_ENTRY@178..191 + 0: JS_STRING_LITERAL@178..184 "\"type\"" [] [] + 1: COLON@184..186 ":" [] [Whitespace(" ")] + 2: JS_STRING_LITERAL@186..191 "\"js\"" [] [Whitespace(" ")] + 3: R_CURLY@191..192 "}" [] [] + 2: SEMICOLON@192..193 ";" [] [] + 6: JS_IMPORT@193..210 + 0: IMPORT_KW@193..201 "import" [Newline("\n")] [Whitespace(" ")] + 1: JS_IMPORT_BARE_CLAUSE@201..209 + 0: JS_MODULE_SOURCE@201..205 + 0: JS_STRING_LITERAL@201..205 "\"x\"" [] [Whitespace(" ")] + 1: JS_IMPORT_ASSERTION@205..209 + 0: WITH_KW@205..209 "with" [] [] + 1: (empty) + 2: JS_IMPORT_ASSERTION_ENTRY_LIST@209..209 + 3: (empty) + 2: SEMICOLON@209..210 ";" [] [] + 7: JS_IMPORT@210..292 + 0: IMPORT_KW@210..218 "import" [Newline("\n")] [Whitespace(" ")] + 1: JS_IMPORT_DEFAULT_CLAUSE@218..291 + 0: (empty) + 1: JS_IDENTIFIER_BINDING@218..224 + 0: IDENT@218..224 "ipsum" [] [Whitespace(" ")] + 2: FROM_KW@224..229 "from" [] [Whitespace(" ")] + 3: JS_MODULE_SOURCE@229..242 + 0: JS_STRING_LITERAL@229..242 "\"ipsum.json\"" [] [Whitespace(" ")] + 4: JS_IMPORT_ASSERTION@242..291 + 0: WITH_KW@242..247 "with" [] [Whitespace(" ")] + 1: L_CURLY@247..249 "{" [] [Whitespace(" ")] + 2: JS_IMPORT_ASSERTION_ENTRY_LIST@249..290 + 0: JS_IMPORT_ASSERTION_ENTRY@249..261 + 0: IDENT@249..253 "type" [] [] + 1: COLON@253..255 ":" [] [Whitespace(" ")] + 2: JS_STRING_LITERAL@255..261 "\"json\"" [] [] + 1: COMMA@261..263 "," [] [Whitespace(" ")] + 2: JS_IMPORT_ASSERTION_ENTRY@263..269 + 0: IDENT@263..267 "lazy" [] [] + 1: COLON@267..269 ":" [] [Whitespace(" ")] + 2: (empty) + 3: (empty) + 4: JS_IMPORT_ASSERTION_ENTRY@269..273 + 0: IDENT@269..273 "true" [] [] + 1: (empty) + 2: (empty) + 5: COMMA@273..275 "," [] [Whitespace(" ")] + 6: JS_IMPORT_ASSERTION_ENTRY@275..288 + 0: IDENT@275..286 "startAtLine" [] [] + 1: COLON@286..288 ":" [] [Whitespace(" ")] + 2: (empty) + 7: (empty) + 8: JS_BOGUS_IMPORT_ASSERTION_ENTRY@288..290 + 0: JS_NUMBER_LITERAL@288..290 "1" [] [Whitespace(" ")] + 3: R_CURLY@290..291 "}" [] [] + 2: SEMICOLON@291..292 ";" [] [] + 8: JS_IMPORT@292..324 + 0: IMPORT_KW@292..300 "import" [Newline("\n")] [Whitespace(" ")] + 1: JS_IMPORT_NAMED_CLAUSE@300..324 + 0: (empty) + 1: (empty) + 2: JS_NAMED_IMPORT_SPECIFIERS@300..306 + 0: L_CURLY@300..302 "{" [] [Whitespace(" ")] + 1: JS_NAMED_IMPORT_SPECIFIER_LIST@302..304 + 0: JS_SHORTHAND_NAMED_IMPORT_SPECIFIER@302..304 + 0: (empty) + 1: JS_IDENTIFIER_BINDING@302..304 + 0: IDENT@302..304 "a" [] [Whitespace(" ")] + 2: R_CURLY@304..306 "}" [] [Whitespace(" ")] + 3: FROM_KW@306..311 "from" [] [Whitespace(" ")] + 4: JS_MODULE_SOURCE@311..320 + 0: JS_STRING_LITERAL@311..320 "\"a.json\"" [] [Whitespace(" ")] + 5: JS_IMPORT_ASSERTION@320..324 + 0: WITH_KW@320..324 "with" [] [] + 1: (empty) + 2: JS_IMPORT_ASSERTION_ENTRY_LIST@324..324 + 3: (empty) + 2: (empty) + 3: EOF@324..325 "" [Newline("\n")] [] +-- +import_attribute_err.js:1:25 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `:` but instead found `,` + + > 1 │ import "foo" with { type, "json" }; + │ ^ + 2 │ import { foo } with { type: "json" }; + 3 │ import "lorem" + + i Remove , + +-- +import_attribute_err.js:1:34 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `:` but instead found `}` + + > 1 │ import "foo" with { type, "json" }; + │ ^ + 2 │ import { foo } with { type: "json" }; + 3 │ import "lorem" + + i Remove } + +-- +import_attribute_err.js:2:16 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `from` but instead found `with` + + 1 │ import "foo" with { type, "json" }; + > 2 │ import { foo } with { type: "json" }; + │ ^^^^ + 3 │ import "lorem" + 4 │ assert { type: "json" } + + i Remove with + +-- +import_attribute_err.js:4:8 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected a semicolon or an implicit semicolon after a statement, but found none + + 2 │ import { foo } with { type: "json" }; + 3 │ import "lorem" + > 4 │ assert { type: "json" } + │ ^ + 5 │ import foo2 from "foo.json" with { "type": "json", type: "html", "type": "js" }; + 6 │ import "x" with; + + i An explicit or implicit semicolon is expected here... + + 2 │ import { foo } with { type: "json" }; + 3 │ import "lorem" + > 4 │ assert { type: "json" } + │ ^ + 5 │ import foo2 from "foo.json" with { "type": "json", type: "html", "type": "js" }; + 6 │ import "x" with; + + i ...Which is required to end this statement + + 2 │ import { foo } with { type: "json" }; + 3 │ import "lorem" + > 4 │ assert { type: "json" } + │ ^^^^^^^^ + 5 │ import foo2 from "foo.json" with { "type": "json", type: "html", "type": "js" }; + 6 │ import "x" with; + +-- +import_attribute_err.js:5:36 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Duplicate assertion keys are not allowed + + 3 │ import "lorem" + 4 │ assert { type: "json" } + > 5 │ import foo2 from "foo.json" with { "type": "json", type: "html", "type": "js" }; + │ ^^^^^^ + 6 │ import "x" with; + 7 │ import ipsum from "ipsum.json" with { type: "json", lazy: true, startAtLine: 1 }; + + i First use of the key `type` + + 3 │ import "lorem" + 4 │ assert { type: "json" } + > 5 │ import foo2 from "foo.json" with { "type": "json", type: "html", "type": "js" }; + │ ^^^^^^ + 6 │ import "x" with; + 7 │ import ipsum from "ipsum.json" with { type: "json", lazy: true, startAtLine: 1 }; + + i second use here + + 3 │ import "lorem" + 4 │ assert { type: "json" } + > 5 │ import foo2 from "foo.json" with { "type": "json", type: "html", "type": "js" }; + │ ^^^^ + 6 │ import "x" with; + 7 │ import ipsum from "ipsum.json" with { type: "json", lazy: true, startAtLine: 1 }; + +-- +import_attribute_err.js:6:16 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `{` but instead found `;` + + 4 │ assert { type: "json" } + 5 │ import foo2 from "foo.json" with { "type": "json", type: "html", "type": "js" }; + > 6 │ import "x" with; + │ ^ + 7 │ import ipsum from "ipsum.json" with { type: "json", lazy: true, startAtLine: 1 }; + 8 │ import { a } from "a.json" with + + i Remove ; + +-- +import_attribute_err.js:7:59 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `string literal` but instead found `true` + + 5 │ import foo2 from "foo.json" with { "type": "json", type: "html", "type": "js" }; + 6 │ import "x" with; + > 7 │ import ipsum from "ipsum.json" with { type: "json", lazy: true, startAtLine: 1 }; + │ ^^^^ + 8 │ import { a } from "a.json" with + 9 │ + + i Remove true + +-- +import_attribute_err.js:7:63 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `:` but instead found `,` + + 5 │ import foo2 from "foo.json" with { "type": "json", type: "html", "type": "js" }; + 6 │ import "x" with; + > 7 │ import ipsum from "ipsum.json" with { type: "json", lazy: true, startAtLine: 1 }; + │ ^ + 8 │ import { a } from "a.json" with + 9 │ + + i Remove , + +-- +import_attribute_err.js:7:78 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `string literal` but instead found `1` + + 5 │ import foo2 from "foo.json" with { "type": "json", type: "html", "type": "js" }; + 6 │ import "x" with; + > 7 │ import ipsum from "ipsum.json" with { type: "json", lazy: true, startAtLine: 1 }; + │ ^ + 8 │ import { a } from "a.json" with + 9 │ + + i Remove 1 + +-- +import_attribute_err.js:9:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `{` but instead the file ends + + 7 │ import ipsum from "ipsum.json" with { type: "json", lazy: true, startAtLine: 1 }; + 8 │ import { a } from "a.json" with + > 9 │ + │ + + i the file ends here + + 7 │ import ipsum from "ipsum.json" with { type: "json", lazy: true, startAtLine: 1 }; + 8 │ import { a } from "a.json" with + > 9 │ + │ + +-- +import "foo" with { type, "json" }; +import { foo } with { type: "json" }; +import "lorem" +assert { type: "json" } +import foo2 from "foo.json" with { "type": "json", type: "html", "type": "js" }; +import "x" with; +import ipsum from "ipsum.json" with { type: "json", lazy: true, startAtLine: 1 }; +import { a } from "a.json" with diff --git a/crates/rome_js_parser/test_data/inline/ok/export_from_clause.rast b/crates/rome_js_parser/test_data/inline/ok/export_from_clause.rast index 969ad8bac72..8b79fcddc2b 100644 --- a/crates/rome_js_parser/test_data/inline/ok/export_from_clause.rast +++ b/crates/rome_js_parser/test_data/inline/ok/export_from_clause.rast @@ -127,7 +127,7 @@ JsModule { value_token: JS_STRING_LITERAL@158..164 "\"mod\"" [] [Whitespace(" ")], }, assertion: JsImportAssertion { - assert_token: ASSERT_KW@164..171 "assert" [] [Whitespace(" ")], + assertion: ASSERT_KW@164..171 "assert" [] [Whitespace(" ")], l_curly_token: L_CURLY@171..173 "{" [] [Whitespace(" ")], assertions: JsImportAssertionEntryList [ JsImportAssertionEntry { diff --git a/crates/rome_js_parser/test_data/inline/ok/export_named_from_clause.rast b/crates/rome_js_parser/test_data/inline/ok/export_named_from_clause.rast index 5142fd0054f..4b85dd15492 100644 --- a/crates/rome_js_parser/test_data/inline/ok/export_named_from_clause.rast +++ b/crates/rome_js_parser/test_data/inline/ok/export_named_from_clause.rast @@ -192,7 +192,7 @@ JsModule { value_token: JS_STRING_LITERAL@201..207 "\"mod\"" [] [Whitespace(" ")], }, assertion: JsImportAssertion { - assert_token: ASSERT_KW@207..214 "assert" [] [Whitespace(" ")], + assertion: ASSERT_KW@207..214 "assert" [] [Whitespace(" ")], l_curly_token: L_CURLY@214..216 "{" [] [Whitespace(" ")], assertions: JsImportAssertionEntryList [ JsImportAssertionEntry { diff --git a/crates/rome_js_parser/test_data/inline/ok/import_assertion.rast b/crates/rome_js_parser/test_data/inline/ok/import_assertion.rast index 1d14678c8e3..334c9759365 100644 --- a/crates/rome_js_parser/test_data/inline/ok/import_assertion.rast +++ b/crates/rome_js_parser/test_data/inline/ok/import_assertion.rast @@ -9,7 +9,7 @@ JsModule { value_token: JS_STRING_LITERAL@7..11 "\"x\"" [] [Whitespace(" ")], }, assertion: JsImportAssertion { - assert_token: ASSERT_KW@11..18 "assert" [] [Whitespace(" ")], + assertion: ASSERT_KW@11..18 "assert" [] [Whitespace(" ")], l_curly_token: L_CURLY@18..20 "{" [] [Whitespace(" ")], assertions: JsImportAssertionEntryList [ JsImportAssertionEntry { @@ -30,7 +30,7 @@ JsModule { value_token: JS_STRING_LITERAL@42..48 "\"foo\"" [] [Whitespace(" ")], }, assertion: JsImportAssertion { - assert_token: ASSERT_KW@48..55 "assert" [] [Whitespace(" ")], + assertion: ASSERT_KW@48..55 "assert" [] [Whitespace(" ")], l_curly_token: L_CURLY@55..57 "{" [] [Whitespace(" ")], assertions: JsImportAssertionEntryList [ JsImportAssertionEntry { @@ -56,7 +56,7 @@ JsModule { value_token: JS_STRING_LITERAL@91..102 "\"foo.json\"" [] [Whitespace(" ")], }, assertion: JsImportAssertion { - assert_token: ASSERT_KW@102..109 "assert" [] [Whitespace(" ")], + assertion: ASSERT_KW@102..109 "assert" [] [Whitespace(" ")], l_curly_token: L_CURLY@109..111 "{" [] [Whitespace(" ")], assertions: JsImportAssertionEntryList [ JsImportAssertionEntry { @@ -92,7 +92,7 @@ JsModule { value_token: JS_STRING_LITERAL@146..157 "\"foo.json\"" [] [Whitespace(" ")], }, assertion: JsImportAssertion { - assert_token: ASSERT_KW@157..164 "assert" [] [Whitespace(" ")], + assertion: ASSERT_KW@157..164 "assert" [] [Whitespace(" ")], l_curly_token: L_CURLY@164..166 "{" [] [Whitespace(" ")], assertions: JsImportAssertionEntryList [ JsImportAssertionEntry { @@ -118,7 +118,7 @@ JsModule { value_token: JS_STRING_LITERAL@200..211 "\"foo.json\"" [] [Whitespace(" ")], }, assertion: JsImportAssertion { - assert_token: ASSERT_KW@211..218 "assert" [] [Whitespace(" ")], + assertion: ASSERT_KW@211..218 "assert" [] [Whitespace(" ")], l_curly_token: L_CURLY@218..220 "{" [] [Whitespace(" ")], assertions: JsImportAssertionEntryList [ JsImportAssertionEntry { @@ -145,7 +145,7 @@ JsModule { value_token: JS_STRING_LITERAL@267..271 "\"x\"" [] [Whitespace(" ")], }, assertion: JsImportAssertion { - assert_token: ASSERT_KW@271..277 "assert" [] [], + assertion: ASSERT_KW@271..277 "assert" [] [], l_curly_token: L_CURLY@277..280 "{" [Newline("\n")] [Whitespace(" ")], assertions: JsImportAssertionEntryList [ JsImportAssertionEntry { diff --git a/crates/rome_js_parser/test_data/inline/ok/import_attribute.js b/crates/rome_js_parser/test_data/inline/ok/import_attribute.js new file mode 100644 index 00000000000..9e396ebdb73 --- /dev/null +++ b/crates/rome_js_parser/test_data/inline/ok/import_attribute.js @@ -0,0 +1,7 @@ +import "x" with { type: "json" } +import "foo" with { "type": "json" }; +import foo from "foo.json" with { type: "json" }; +import {test} from "foo.json" with { for: "for" } +import foo_json from "foo.json" with { type: "json", hasOwnProperty: "true" }; +import "x" with +{ type: "json" } diff --git a/crates/rome_js_parser/test_data/inline/ok/import_attribute.rast b/crates/rome_js_parser/test_data/inline/ok/import_attribute.rast new file mode 100644 index 00000000000..217c83fd7e9 --- /dev/null +++ b/crates/rome_js_parser/test_data/inline/ok/import_attribute.rast @@ -0,0 +1,284 @@ +JsModule { + interpreter_token: missing (optional), + directives: JsDirectiveList [], + items: JsModuleItemList [ + JsImport { + import_token: IMPORT_KW@0..7 "import" [] [Whitespace(" ")], + import_clause: JsImportBareClause { + source: JsModuleSource { + value_token: JS_STRING_LITERAL@7..11 "\"x\"" [] [Whitespace(" ")], + }, + assertion: JsImportAssertion { + assertion: WITH_KW@11..16 "with" [] [Whitespace(" ")], + l_curly_token: L_CURLY@16..18 "{" [] [Whitespace(" ")], + assertions: JsImportAssertionEntryList [ + JsImportAssertionEntry { + key: IDENT@18..22 "type" [] [], + colon_token: COLON@22..24 ":" [] [Whitespace(" ")], + value_token: JS_STRING_LITERAL@24..31 "\"json\"" [] [Whitespace(" ")], + }, + ], + r_curly_token: R_CURLY@31..32 "}" [] [], + }, + }, + semicolon_token: missing (optional), + }, + JsImport { + import_token: IMPORT_KW@32..40 "import" [Newline("\n")] [Whitespace(" ")], + import_clause: JsImportBareClause { + source: JsModuleSource { + value_token: JS_STRING_LITERAL@40..46 "\"foo\"" [] [Whitespace(" ")], + }, + assertion: JsImportAssertion { + assertion: WITH_KW@46..51 "with" [] [Whitespace(" ")], + l_curly_token: L_CURLY@51..53 "{" [] [Whitespace(" ")], + assertions: JsImportAssertionEntryList [ + JsImportAssertionEntry { + key: JS_STRING_LITERAL@53..59 "\"type\"" [] [], + colon_token: COLON@59..61 ":" [] [Whitespace(" ")], + value_token: JS_STRING_LITERAL@61..68 "\"json\"" [] [Whitespace(" ")], + }, + ], + r_curly_token: R_CURLY@68..69 "}" [] [], + }, + }, + semicolon_token: SEMICOLON@69..70 ";" [] [], + }, + JsImport { + import_token: IMPORT_KW@70..78 "import" [Newline("\n")] [Whitespace(" ")], + import_clause: JsImportDefaultClause { + type_token: missing (optional), + local_name: JsIdentifierBinding { + name_token: IDENT@78..82 "foo" [] [Whitespace(" ")], + }, + from_token: FROM_KW@82..87 "from" [] [Whitespace(" ")], + source: JsModuleSource { + value_token: JS_STRING_LITERAL@87..98 "\"foo.json\"" [] [Whitespace(" ")], + }, + assertion: JsImportAssertion { + assertion: WITH_KW@98..103 "with" [] [Whitespace(" ")], + l_curly_token: L_CURLY@103..105 "{" [] [Whitespace(" ")], + assertions: JsImportAssertionEntryList [ + JsImportAssertionEntry { + key: IDENT@105..109 "type" [] [], + colon_token: COLON@109..111 ":" [] [Whitespace(" ")], + value_token: JS_STRING_LITERAL@111..118 "\"json\"" [] [Whitespace(" ")], + }, + ], + r_curly_token: R_CURLY@118..119 "}" [] [], + }, + }, + semicolon_token: SEMICOLON@119..120 ";" [] [], + }, + JsImport { + import_token: IMPORT_KW@120..128 "import" [Newline("\n")] [Whitespace(" ")], + import_clause: JsImportNamedClause { + type_token: missing (optional), + default_specifier: missing (optional), + named_import: JsNamedImportSpecifiers { + l_curly_token: L_CURLY@128..129 "{" [] [], + specifiers: JsNamedImportSpecifierList [ + JsShorthandNamedImportSpecifier { + type_token: missing (optional), + local_name: JsIdentifierBinding { + name_token: IDENT@129..133 "test" [] [], + }, + }, + ], + r_curly_token: R_CURLY@133..135 "}" [] [Whitespace(" ")], + }, + from_token: FROM_KW@135..140 "from" [] [Whitespace(" ")], + source: JsModuleSource { + value_token: JS_STRING_LITERAL@140..151 "\"foo.json\"" [] [Whitespace(" ")], + }, + assertion: JsImportAssertion { + assertion: WITH_KW@151..156 "with" [] [Whitespace(" ")], + l_curly_token: L_CURLY@156..158 "{" [] [Whitespace(" ")], + assertions: JsImportAssertionEntryList [ + JsImportAssertionEntry { + key: IDENT@158..161 "for" [] [], + colon_token: COLON@161..163 ":" [] [Whitespace(" ")], + value_token: JS_STRING_LITERAL@163..169 "\"for\"" [] [Whitespace(" ")], + }, + ], + r_curly_token: R_CURLY@169..170 "}" [] [], + }, + }, + semicolon_token: missing (optional), + }, + JsImport { + import_token: IMPORT_KW@170..178 "import" [Newline("\n")] [Whitespace(" ")], + import_clause: JsImportDefaultClause { + type_token: missing (optional), + local_name: JsIdentifierBinding { + name_token: IDENT@178..187 "foo_json" [] [Whitespace(" ")], + }, + from_token: FROM_KW@187..192 "from" [] [Whitespace(" ")], + source: JsModuleSource { + value_token: JS_STRING_LITERAL@192..203 "\"foo.json\"" [] [Whitespace(" ")], + }, + assertion: JsImportAssertion { + assertion: WITH_KW@203..208 "with" [] [Whitespace(" ")], + l_curly_token: L_CURLY@208..210 "{" [] [Whitespace(" ")], + assertions: JsImportAssertionEntryList [ + JsImportAssertionEntry { + key: IDENT@210..214 "type" [] [], + colon_token: COLON@214..216 ":" [] [Whitespace(" ")], + value_token: JS_STRING_LITERAL@216..222 "\"json\"" [] [], + }, + COMMA@222..224 "," [] [Whitespace(" ")], + JsImportAssertionEntry { + key: IDENT@224..238 "hasOwnProperty" [] [], + colon_token: COLON@238..240 ":" [] [Whitespace(" ")], + value_token: JS_STRING_LITERAL@240..247 "\"true\"" [] [Whitespace(" ")], + }, + ], + r_curly_token: R_CURLY@247..248 "}" [] [], + }, + }, + semicolon_token: SEMICOLON@248..249 ";" [] [], + }, + JsImport { + import_token: IMPORT_KW@249..257 "import" [Newline("\n")] [Whitespace(" ")], + import_clause: JsImportBareClause { + source: JsModuleSource { + value_token: JS_STRING_LITERAL@257..261 "\"x\"" [] [Whitespace(" ")], + }, + assertion: JsImportAssertion { + assertion: WITH_KW@261..265 "with" [] [], + l_curly_token: L_CURLY@265..268 "{" [Newline("\n")] [Whitespace(" ")], + assertions: JsImportAssertionEntryList [ + JsImportAssertionEntry { + key: IDENT@268..272 "type" [] [], + colon_token: COLON@272..274 ":" [] [Whitespace(" ")], + value_token: JS_STRING_LITERAL@274..281 "\"json\"" [] [Whitespace(" ")], + }, + ], + r_curly_token: R_CURLY@281..282 "}" [] [], + }, + }, + semicolon_token: missing (optional), + }, + ], + eof_token: EOF@282..283 "" [Newline("\n")] [], +} + +0: JS_MODULE@0..283 + 0: (empty) + 1: JS_DIRECTIVE_LIST@0..0 + 2: JS_MODULE_ITEM_LIST@0..282 + 0: JS_IMPORT@0..32 + 0: IMPORT_KW@0..7 "import" [] [Whitespace(" ")] + 1: JS_IMPORT_BARE_CLAUSE@7..32 + 0: JS_MODULE_SOURCE@7..11 + 0: JS_STRING_LITERAL@7..11 "\"x\"" [] [Whitespace(" ")] + 1: JS_IMPORT_ASSERTION@11..32 + 0: WITH_KW@11..16 "with" [] [Whitespace(" ")] + 1: L_CURLY@16..18 "{" [] [Whitespace(" ")] + 2: JS_IMPORT_ASSERTION_ENTRY_LIST@18..31 + 0: JS_IMPORT_ASSERTION_ENTRY@18..31 + 0: IDENT@18..22 "type" [] [] + 1: COLON@22..24 ":" [] [Whitespace(" ")] + 2: JS_STRING_LITERAL@24..31 "\"json\"" [] [Whitespace(" ")] + 3: R_CURLY@31..32 "}" [] [] + 2: (empty) + 1: JS_IMPORT@32..70 + 0: IMPORT_KW@32..40 "import" [Newline("\n")] [Whitespace(" ")] + 1: JS_IMPORT_BARE_CLAUSE@40..69 + 0: JS_MODULE_SOURCE@40..46 + 0: JS_STRING_LITERAL@40..46 "\"foo\"" [] [Whitespace(" ")] + 1: JS_IMPORT_ASSERTION@46..69 + 0: WITH_KW@46..51 "with" [] [Whitespace(" ")] + 1: L_CURLY@51..53 "{" [] [Whitespace(" ")] + 2: JS_IMPORT_ASSERTION_ENTRY_LIST@53..68 + 0: JS_IMPORT_ASSERTION_ENTRY@53..68 + 0: JS_STRING_LITERAL@53..59 "\"type\"" [] [] + 1: COLON@59..61 ":" [] [Whitespace(" ")] + 2: JS_STRING_LITERAL@61..68 "\"json\"" [] [Whitespace(" ")] + 3: R_CURLY@68..69 "}" [] [] + 2: SEMICOLON@69..70 ";" [] [] + 2: JS_IMPORT@70..120 + 0: IMPORT_KW@70..78 "import" [Newline("\n")] [Whitespace(" ")] + 1: JS_IMPORT_DEFAULT_CLAUSE@78..119 + 0: (empty) + 1: JS_IDENTIFIER_BINDING@78..82 + 0: IDENT@78..82 "foo" [] [Whitespace(" ")] + 2: FROM_KW@82..87 "from" [] [Whitespace(" ")] + 3: JS_MODULE_SOURCE@87..98 + 0: JS_STRING_LITERAL@87..98 "\"foo.json\"" [] [Whitespace(" ")] + 4: JS_IMPORT_ASSERTION@98..119 + 0: WITH_KW@98..103 "with" [] [Whitespace(" ")] + 1: L_CURLY@103..105 "{" [] [Whitespace(" ")] + 2: JS_IMPORT_ASSERTION_ENTRY_LIST@105..118 + 0: JS_IMPORT_ASSERTION_ENTRY@105..118 + 0: IDENT@105..109 "type" [] [] + 1: COLON@109..111 ":" [] [Whitespace(" ")] + 2: JS_STRING_LITERAL@111..118 "\"json\"" [] [Whitespace(" ")] + 3: R_CURLY@118..119 "}" [] [] + 2: SEMICOLON@119..120 ";" [] [] + 3: JS_IMPORT@120..170 + 0: IMPORT_KW@120..128 "import" [Newline("\n")] [Whitespace(" ")] + 1: JS_IMPORT_NAMED_CLAUSE@128..170 + 0: (empty) + 1: (empty) + 2: JS_NAMED_IMPORT_SPECIFIERS@128..135 + 0: L_CURLY@128..129 "{" [] [] + 1: JS_NAMED_IMPORT_SPECIFIER_LIST@129..133 + 0: JS_SHORTHAND_NAMED_IMPORT_SPECIFIER@129..133 + 0: (empty) + 1: JS_IDENTIFIER_BINDING@129..133 + 0: IDENT@129..133 "test" [] [] + 2: R_CURLY@133..135 "}" [] [Whitespace(" ")] + 3: FROM_KW@135..140 "from" [] [Whitespace(" ")] + 4: JS_MODULE_SOURCE@140..151 + 0: JS_STRING_LITERAL@140..151 "\"foo.json\"" [] [Whitespace(" ")] + 5: JS_IMPORT_ASSERTION@151..170 + 0: WITH_KW@151..156 "with" [] [Whitespace(" ")] + 1: L_CURLY@156..158 "{" [] [Whitespace(" ")] + 2: JS_IMPORT_ASSERTION_ENTRY_LIST@158..169 + 0: JS_IMPORT_ASSERTION_ENTRY@158..169 + 0: IDENT@158..161 "for" [] [] + 1: COLON@161..163 ":" [] [Whitespace(" ")] + 2: JS_STRING_LITERAL@163..169 "\"for\"" [] [Whitespace(" ")] + 3: R_CURLY@169..170 "}" [] [] + 2: (empty) + 4: JS_IMPORT@170..249 + 0: IMPORT_KW@170..178 "import" [Newline("\n")] [Whitespace(" ")] + 1: JS_IMPORT_DEFAULT_CLAUSE@178..248 + 0: (empty) + 1: JS_IDENTIFIER_BINDING@178..187 + 0: IDENT@178..187 "foo_json" [] [Whitespace(" ")] + 2: FROM_KW@187..192 "from" [] [Whitespace(" ")] + 3: JS_MODULE_SOURCE@192..203 + 0: JS_STRING_LITERAL@192..203 "\"foo.json\"" [] [Whitespace(" ")] + 4: JS_IMPORT_ASSERTION@203..248 + 0: WITH_KW@203..208 "with" [] [Whitespace(" ")] + 1: L_CURLY@208..210 "{" [] [Whitespace(" ")] + 2: JS_IMPORT_ASSERTION_ENTRY_LIST@210..247 + 0: JS_IMPORT_ASSERTION_ENTRY@210..222 + 0: IDENT@210..214 "type" [] [] + 1: COLON@214..216 ":" [] [Whitespace(" ")] + 2: JS_STRING_LITERAL@216..222 "\"json\"" [] [] + 1: COMMA@222..224 "," [] [Whitespace(" ")] + 2: JS_IMPORT_ASSERTION_ENTRY@224..247 + 0: IDENT@224..238 "hasOwnProperty" [] [] + 1: COLON@238..240 ":" [] [Whitespace(" ")] + 2: JS_STRING_LITERAL@240..247 "\"true\"" [] [Whitespace(" ")] + 3: R_CURLY@247..248 "}" [] [] + 2: SEMICOLON@248..249 ";" [] [] + 5: JS_IMPORT@249..282 + 0: IMPORT_KW@249..257 "import" [Newline("\n")] [Whitespace(" ")] + 1: JS_IMPORT_BARE_CLAUSE@257..282 + 0: JS_MODULE_SOURCE@257..261 + 0: JS_STRING_LITERAL@257..261 "\"x\"" [] [Whitespace(" ")] + 1: JS_IMPORT_ASSERTION@261..282 + 0: WITH_KW@261..265 "with" [] [] + 1: L_CURLY@265..268 "{" [Newline("\n")] [Whitespace(" ")] + 2: JS_IMPORT_ASSERTION_ENTRY_LIST@268..281 + 0: JS_IMPORT_ASSERTION_ENTRY@268..281 + 0: IDENT@268..272 "type" [] [] + 1: COLON@272..274 ":" [] [Whitespace(" ")] + 2: JS_STRING_LITERAL@274..281 "\"json\"" [] [Whitespace(" ")] + 3: R_CURLY@281..282 "}" [] [] + 2: (empty) + 3: EOF@282..283 "" [Newline("\n")] [] diff --git a/crates/rome_js_syntax/src/generated/nodes.rs b/crates/rome_js_syntax/src/generated/nodes.rs index a38bd653afa..c3b978d38be 100644 --- a/crates/rome_js_syntax/src/generated/nodes.rs +++ b/crates/rome_js_syntax/src/generated/nodes.rs @@ -3294,13 +3294,13 @@ impl JsImportAssertion { pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { Self { syntax } } pub fn as_fields(&self) -> JsImportAssertionFields { JsImportAssertionFields { - assert_token: self.assert_token(), + assertion: self.assertion(), l_curly_token: self.l_curly_token(), assertions: self.assertions(), r_curly_token: self.r_curly_token(), } } - pub fn assert_token(&self) -> SyntaxResult { + pub fn assertion(&self) -> SyntaxResult { support::required_token(&self.syntax, 0usize) } pub fn l_curly_token(&self) -> SyntaxResult { @@ -3322,7 +3322,7 @@ impl Serialize for JsImportAssertion { } #[cfg_attr(feature = "serde", derive(Serialize))] pub struct JsImportAssertionFields { - pub assert_token: SyntaxResult, + pub assertion: SyntaxResult, pub l_curly_token: SyntaxResult, pub assertions: JsImportAssertionEntryList, pub r_curly_token: SyntaxResult, @@ -17933,10 +17933,7 @@ impl AstNode for JsImportAssertion { impl std::fmt::Debug for JsImportAssertion { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("JsImportAssertion") - .field( - "assert_token", - &support::DebugSyntaxResult(self.assert_token()), - ) + .field("assertion", &support::DebugSyntaxResult(self.assertion())) .field( "l_curly_token", &support::DebugSyntaxResult(self.l_curly_token()), diff --git a/crates/rome_js_syntax/src/generated/nodes_mut.rs b/crates/rome_js_syntax/src/generated/nodes_mut.rs index 6f48130db17..6d1bf16b6d6 100644 --- a/crates/rome_js_syntax/src/generated/nodes_mut.rs +++ b/crates/rome_js_syntax/src/generated/nodes_mut.rs @@ -1765,7 +1765,7 @@ impl JsImport { } } impl JsImportAssertion { - pub fn with_assert_token(self, element: SyntaxToken) -> Self { + pub fn with_assertion_token(self, element: SyntaxToken) -> Self { Self::unwrap_cast( self.syntax .splice_slots(0usize..=0usize, once(Some(element.into()))), diff --git a/xtask/codegen/js.ungram b/xtask/codegen/js.ungram index 6decd8e35f4..c9c25a5835b 100644 --- a/xtask/codegen/js.ungram +++ b/xtask/codegen/js.ungram @@ -1318,7 +1318,7 @@ JsShorthandNamedImportSpecifier = // import a from "mod" assert { type: "json" } // ^^^^^^^^^^^^^^^^^^^^^^^ JsImportAssertion = - 'assert' + assertion: ('assert' | 'with') '{' assertions: JsImportAssertionEntryList '}'