Skip to content

Commit

Permalink
fix(es/parser): Fix parsing of abstract class over multiple lines (#1837
Browse files Browse the repository at this point in the history
)

swc_ecma_parser:
 - Don't allow `abstract` and `class` to be on different lines.
  • Loading branch information
kdy1 authored Jun 20, 2021
1 parent 11f75df commit 6c49279
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 7 deletions.
2 changes: 1 addition & 1 deletion ecmascript/parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ include = ["Cargo.toml", "src/**/*.rs", "examples/**/*.rs"]
license = "Apache-2.0/MIT"
name = "swc_ecma_parser"
repository = "https://github.com/swc-project/swc.git"
version = "0.60.0"
version = "0.60.1"

[features]
default = []
Expand Down
5 changes: 4 additions & 1 deletion ecmascript/parser/src/parser/stmt/module_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,10 @@ impl<'a, I: Tokens> Parser<I> {

if !type_only && export_ns.is_none() && eat!(self, "default") {
if self.input.syntax().typescript() {
if is!(self, "abstract") && peeked_is!(self, "class") {
if is!(self, "abstract")
&& peeked_is!(self, "class")
&& !self.input.has_linebreak_between_cur_and_peeked()
{
let class_start = cur_pos!(self);
assert_and_bump!(self, "abstract");
let _ = cur!(self, true);
Expand Down
2 changes: 1 addition & 1 deletion ecmascript/parser/src/parser/typescript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2304,7 +2304,7 @@ impl<I: Tokens> Parser<I> {
) -> PResult<Option<Decl>> {
match value {
js_word!("abstract") => {
if next || is!(self, "class") {
if next || (is!(self, "class") && !self.input.had_line_break_before_cur()) {
if next {
bump!(self);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,24 @@
"superTypeParams": null,
"implements": []
},
{
"type": "ExpressionStatement",
"span": {
"start": 21,
"end": 29,
"ctxt": 0
},
"expression": {
"type": "Identifier",
"span": {
"start": 21,
"end": 29,
"ctxt": 0
},
"value": "abstract",
"optional": false
}
},
{
"type": "ClassDeclaration",
"identifier": {
Expand All @@ -46,18 +64,36 @@
},
"declare": false,
"span": {
"start": 21,
"start": 30,
"end": 40,
"ctxt": 0
},
"decorators": [],
"body": [],
"superClass": null,
"isAbstract": true,
"isAbstract": false,
"typeParams": null,
"superTypeParams": null,
"implements": []
},
{
"type": "ExpressionStatement",
"span": {
"start": 42,
"end": 50,
"ctxt": 0
},
"expression": {
"type": "Identifier",
"span": {
"start": 42,
"end": 50,
"ctxt": 0
},
"value": "abstract",
"optional": false
}
},
{
"type": "ClassDeclaration",
"identifier": {
Expand All @@ -72,14 +108,14 @@
},
"declare": false,
"span": {
"start": 42,
"start": 52,
"end": 62,
"ctxt": 0
},
"decorators": [],
"body": [],
"superClass": null,
"isAbstract": true,
"isAbstract": false,
"typeParams": null,
"superTypeParams": null,
"implements": []
Expand Down

0 comments on commit 6c49279

Please sign in to comment.