Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
fix(rome_js_parser): Crash at empty default export #4670
Browse files Browse the repository at this point in the history
  • Loading branch information
denbezrukov committed Jul 10, 2023
1 parent 2716986 commit f8050a5
Show file tree
Hide file tree
Showing 3 changed files with 213 additions and 0 deletions.
6 changes: 6 additions & 0 deletions crates/rome_js_parser/src/syntax/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default ;
export default @decorator
export default
export default @decorator
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f8050a5

Please sign in to comment.