diff --git a/crates/rome_js_parser/src/syntax/module.rs b/crates/rome_js_parser/src/syntax/module.rs index 7711ecdb4ed..de6075383f9 100644 --- a/crates/rome_js_parser/src/syntax/module.rs +++ b/crates/rome_js_parser/src/syntax/module.rs @@ -1425,6 +1425,12 @@ fn parse_export_default_expression_clause( start: TextSize, ) -> ParsedSyntax { if !is_at_expression(p) { + // test_err js export_default_expression_broken + // export default ; + // export default @decorator + // export default + // export default @decorator + m.abandon(p); return Absent; } diff --git a/crates/rome_js_parser/test_data/inline/err/export_default_expression_broken.js b/crates/rome_js_parser/test_data/inline/err/export_default_expression_broken.js new file mode 100644 index 00000000000..8206a58e908 --- /dev/null +++ b/crates/rome_js_parser/test_data/inline/err/export_default_expression_broken.js @@ -0,0 +1,4 @@ +export default ; +export default @decorator +export default +export default @decorator diff --git a/crates/rome_js_parser/test_data/inline/err/export_default_expression_broken.rast b/crates/rome_js_parser/test_data/inline/err/export_default_expression_broken.rast new file mode 100644 index 00000000000..c0a9b112e4a --- /dev/null +++ b/crates/rome_js_parser/test_data/inline/err/export_default_expression_broken.rast @@ -0,0 +1,203 @@ +JsModule { + interpreter_token: missing (optional), + directives: JsDirectiveList [], + items: JsModuleItemList [ + JsBogusStatement { + items: [ + JsDecoratorList [], + EXPORT_KW@0..7 "export" [] [Whitespace(" ")], + DEFAULT_KW@7..15 "default" [] [Whitespace(" ")], + ], + }, + JsEmptyStatement { + semicolon_token: SEMICOLON@15..16 ";" [] [], + }, + JsBogusStatement { + items: [ + JsDecoratorList [], + EXPORT_KW@16..24 "export" [Newline("\n")] [Whitespace(" ")], + DEFAULT_KW@24..32 "default" [] [Whitespace(" ")], + JsBogusStatement { + items: [ + JsDecorator { + at_token: AT@32..33 "@" [] [], + expression: JsIdentifierExpression { + name: JsReferenceIdentifier { + value_token: IDENT@33..42 "decorator" [] [], + }, + }, + }, + ], + }, + ], + }, + JsBogusStatement { + items: [ + JsDecoratorList [], + EXPORT_KW@42..50 "export" [Newline("\n")] [Whitespace(" ")], + DEFAULT_KW@50..57 "default" [] [], + ], + }, + JsBogusStatement { + items: [ + JsDecoratorList [], + EXPORT_KW@57..65 "export" [Newline("\n")] [Whitespace(" ")], + DEFAULT_KW@65..73 "default" [] [Whitespace(" ")], + JsBogusStatement { + items: [ + JsDecorator { + at_token: AT@73..74 "@" [] [], + expression: JsIdentifierExpression { + name: JsReferenceIdentifier { + value_token: IDENT@74..83 "decorator" [] [], + }, + }, + }, + ], + }, + ], + }, + ], + eof_token: EOF@83..84 "" [Newline("\n")] [], +} + +0: JS_MODULE@0..84 + 0: (empty) + 1: JS_DIRECTIVE_LIST@0..0 + 2: JS_MODULE_ITEM_LIST@0..83 + 0: JS_BOGUS_STATEMENT@0..15 + 0: JS_DECORATOR_LIST@0..0 + 1: EXPORT_KW@0..7 "export" [] [Whitespace(" ")] + 2: DEFAULT_KW@7..15 "default" [] [Whitespace(" ")] + 1: JS_EMPTY_STATEMENT@15..16 + 0: SEMICOLON@15..16 ";" [] [] + 2: JS_BOGUS_STATEMENT@16..42 + 0: JS_DECORATOR_LIST@16..16 + 1: EXPORT_KW@16..24 "export" [Newline("\n")] [Whitespace(" ")] + 2: DEFAULT_KW@24..32 "default" [] [Whitespace(" ")] + 3: JS_BOGUS_STATEMENT@32..42 + 0: JS_DECORATOR@32..42 + 0: AT@32..33 "@" [] [] + 1: JS_IDENTIFIER_EXPRESSION@33..42 + 0: JS_REFERENCE_IDENTIFIER@33..42 + 0: IDENT@33..42 "decorator" [] [] + 3: JS_BOGUS_STATEMENT@42..57 + 0: JS_DECORATOR_LIST@42..42 + 1: EXPORT_KW@42..50 "export" [Newline("\n")] [Whitespace(" ")] + 2: DEFAULT_KW@50..57 "default" [] [] + 4: JS_BOGUS_STATEMENT@57..83 + 0: JS_DECORATOR_LIST@57..57 + 1: EXPORT_KW@57..65 "export" [Newline("\n")] [Whitespace(" ")] + 2: DEFAULT_KW@65..73 "default" [] [Whitespace(" ")] + 3: JS_BOGUS_STATEMENT@73..83 + 0: JS_DECORATOR@73..83 + 0: AT@73..74 "@" [] [] + 1: JS_IDENTIFIER_EXPRESSION@74..83 + 0: JS_REFERENCE_IDENTIFIER@74..83 + 0: IDENT@74..83 "decorator" [] [] + 3: EOF@83..84 "" [Newline("\n")] [] +-- +export_default_expression_broken.js:1:16 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected a class, a function, or a variable declaration but instead found ';' + + > 1 │ export default ; + │ ^ + 2 │ export default @decorator + 3 │ export default + + i Expected a class, a function, or a variable declaration here + + > 1 │ export default ; + │ ^ + 2 │ export default @decorator + 3 │ export default + +-- +export_default_expression_broken.js:2:16 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Decorators are not valid here. + + 1 │ export default ; + > 2 │ export default @decorator + │ ^^^^^^^^^^ + 3 │ export default + 4 │ export default @decorator + + i Decorators are only valid on class declarations, class expressions, and class methods. + +-- +export_default_expression_broken.js:3:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected a class, a function, or a variable declaration but instead found 'export' + + 1 │ export default ; + 2 │ export default @decorator + > 3 │ export default + │ ^^^^^^ + 4 │ export default @decorator + 5 │ + + i Expected a class, a function, or a variable declaration here + + 1 │ export default ; + 2 │ export default @decorator + > 3 │ export default + │ ^^^^^^ + 4 │ export default @decorator + 5 │ + +-- +export_default_expression_broken.js:4:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected a class, a function, or a variable declaration but instead found 'export' + + 2 │ export default @decorator + 3 │ export default + > 4 │ export default @decorator + │ ^^^^^^ + 5 │ + + i Expected a class, a function, or a variable declaration here + + 2 │ export default @decorator + 3 │ export default + > 4 │ export default @decorator + │ ^^^^^^ + 5 │ + +-- +export_default_expression_broken.js:4:16 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Decorators are not valid here. + + 2 │ export default @decorator + 3 │ export default + > 4 │ export default @decorator + │ ^^^^^^^^^^ + 5 │ + + i Decorators are only valid on class declarations, class expressions, and class methods. + +-- +export_default_expression_broken.js:5:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected a class, a function, or a variable declaration but instead found the end of the file + + 3 │ export default + 4 │ export default @decorator + > 5 │ + │ + + i Expected a class, a function, or a variable declaration here + + 3 │ export default + 4 │ export default @decorator + > 5 │ + │ + +-- +export default ; +export default @decorator +export default +export default @decorator