Skip to content

Commit

Permalink
feat(es/parser): Enforce order of abstract and override (#1668)
Browse files Browse the repository at this point in the history
Co-authored-by: 강동윤 <kdy1997.dev@gmail.com>
  • Loading branch information
g-plane and kdy1 authored May 10, 2021
1 parent 2b918b0 commit 50f8048
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 55 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.56.0"
version = "0.56.1"

[features]
default = []
Expand Down
5 changes: 5 additions & 0 deletions ecmascript/parser/src/parser/class_and_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,11 @@ impl<'a, I: Tokens> Parser<I> {
self.input.prev_span(),
SyntaxError::TS1030(js_word!("abstract")),
);
} else if is_override {
self.emit_err(
self.input.prev_span(),
SyntaxError::TS1029(js_word!("abstract"), js_word!("override")),
);
} else {
is_abstract = true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
abstract class MyClass extends BaseClass {
override abstract show(): void
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
error: 'abstract' modifier must precede 'override' modifier.
--> $DIR/tests/typescript-errors/class/override-with-abstract/input.ts:2:12
|
2 | override abstract show(): void
| ^^^^^^^^

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ class MyClass1 extends BaseClass {
public override show() {}
override size = 5;
override readonly size = 5;
override readonly abstract size = 5;
abstract override readonly size = 5;
private abstract override readonly size = 5;
static override show() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"type": "Script",
"span": {
"start": 0,
"end": 305,
"end": 266,
"ctxt": 0
},
"body": [
Expand All @@ -21,7 +21,7 @@
"declare": false,
"span": {
"start": 0,
"end": 305,
"end": 266,
"ctxt": 0
},
"decorators": [],
Expand Down Expand Up @@ -282,14 +282,14 @@
"type": "ClassProperty",
"span": {
"start": 192,
"end": 228,
"end": 236,
"ctxt": 0
},
"key": {
"type": "Identifier",
"span": {
"start": 219,
"end": 223,
"start": 227,
"end": 231,
"ctxt": 0
},
"value": "size",
Expand All @@ -298,46 +298,8 @@
"value": {
"type": "NumericLiteral",
"span": {
"start": 226,
"end": 227,
"ctxt": 0
},
"value": 5.0
},
"typeAnnotation": null,
"isStatic": false,
"decorators": [],
"computed": false,
"accessibility": null,
"isAbstract": true,
"isOptional": false,
"isOverride": true,
"readonly": true,
"declare": false,
"definite": false
},
{
"type": "ClassProperty",
"span": {
"start": 231,
"end": 275,
"ctxt": 0
},
"key": {
"type": "Identifier",
"span": {
"start": 266,
"end": 270,
"ctxt": 0
},
"value": "size",
"optional": false
},
"value": {
"type": "NumericLiteral",
"span": {
"start": 273,
"end": 274,
"start": 234,
"end": 235,
"ctxt": 0
},
"value": 5.0
Expand All @@ -357,15 +319,15 @@
{
"type": "ClassMethod",
"span": {
"start": 278,
"end": 303,
"start": 239,
"end": 264,
"ctxt": 0
},
"key": {
"type": "Identifier",
"span": {
"start": 294,
"end": 298,
"start": 255,
"end": 259,
"ctxt": 0
},
"value": "show",
Expand All @@ -375,15 +337,15 @@
"params": [],
"decorators": [],
"span": {
"start": 278,
"end": 303,
"start": 239,
"end": 264,
"ctxt": 0
},
"body": {
"type": "BlockStatement",
"span": {
"start": 301,
"end": 303,
"start": 262,
"end": 264,
"ctxt": 0
},
"stmts": []
Expand Down

0 comments on commit 50f8048

Please sign in to comment.