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 (#4680)
Browse files Browse the repository at this point in the history
* fix(rome_js_parser): Crash at empty default export #4670

* fix(rome_js_parser): Crash at empty default export #4670
  • Loading branch information
denbezrukov committed Jul 11, 2023
1 parent 2716986 commit ac69cfa
Show file tree
Hide file tree
Showing 4 changed files with 214 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#### Other changes

- Fix [#4670](https://github.com/rome/tools/issues/4670), don't crash at empty default export.
- Fix [#4556](https://github.com/rome/tools/issues/4556), which correctly handles new lines in the
`.gitignore` file across OS.
- Add a new option to ignore unknown files `--files-ignore-unknown`:
Expand Down
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 [],
[email protected] "export" [] [Whitespace(" ")],
[email protected] "default" [] [Whitespace(" ")],
],
},
JsEmptyStatement {
semicolon_token: [email protected] ";" [] [],
},
JsBogusStatement {
items: [
JsDecoratorList [],
[email protected] "export" [Newline("\n")] [Whitespace(" ")],
[email protected] "default" [] [Whitespace(" ")],
JsBogusStatement {
items: [
JsDecorator {
at_token: [email protected] "@" [] [],
expression: JsIdentifierExpression {
name: JsReferenceIdentifier {
value_token: [email protected] "decorator" [] [],
},
},
},
],
},
],
},
JsBogusStatement {
items: [
JsDecoratorList [],
[email protected] "export" [Newline("\n")] [Whitespace(" ")],
[email protected] "default" [] [],
],
},
JsBogusStatement {
items: [
JsDecoratorList [],
[email protected] "export" [Newline("\n")] [Whitespace(" ")],
[email protected] "default" [] [Whitespace(" ")],
JsBogusStatement {
items: [
JsDecorator {
at_token: [email protected] "@" [] [],
expression: JsIdentifierExpression {
name: JsReferenceIdentifier {
value_token: [email protected] "decorator" [] [],
},
},
},
],
},
],
},
],
eof_token: [email protected] "" [Newline("\n")] [],
}

0: [email protected]
0: (empty)
1: [email protected]
2: [email protected]
0: [email protected]
0: [email protected]
1: [email protected] "export" [] [Whitespace(" ")]
2: [email protected] "default" [] [Whitespace(" ")]
1: [email protected]
0: [email protected] ";" [] []
2: [email protected]
0: [email protected]
1: [email protected] "export" [Newline("\n")] [Whitespace(" ")]
2: [email protected] "default" [] [Whitespace(" ")]
3: [email protected]
0: [email protected]
0: [email protected] "@" [] []
1: [email protected]
0: [email protected]
0: [email protected] "decorator" [] []
3: [email protected]
0: [email protected]
1: [email protected] "export" [Newline("\n")] [Whitespace(" ")]
2: [email protected] "default" [] []
4: [email protected]
0: [email protected]
1: [email protected] "export" [Newline("\n")] [Whitespace(" ")]
2: [email protected] "default" [] [Whitespace(" ")]
3: [email protected]
0: [email protected]
0: [email protected] "@" [] []
1: [email protected]
0: [email protected]
0: [email protected] "decorator" [] []
3: [email protected] "" [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 ac69cfa

Please sign in to comment.