feat(es/parser): Enforce order of abstract and override (#1668)

Co-authored-by: 강동윤 <kdy1997.dev@gmail.com>
This commit is contained in:
Pig Fang 2021-05-10 16:09:51 +08:00 committed by GitHub
parent 2b918b0c3d
commit 50f8048f2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 30 additions and 55 deletions

View File

@ -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 = []

View File

@ -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;
}

View File

@ -0,0 +1,3 @@
abstract class MyClass extends BaseClass {
override abstract show(): void
}

View File

@ -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
| ^^^^^^^^

View File

@ -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() {}

View File

@ -2,7 +2,7 @@
"type": "Script",
"span": {
"start": 0,
"end": 305,
"end": 266,
"ctxt": 0
},
"body": [
@ -21,7 +21,7 @@
"declare": false,
"span": {
"start": 0,
"end": 305,
"end": 266,
"ctxt": 0
},
"decorators": [],
@ -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",
@ -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
@ -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",
@ -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": []