Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(es/parser): Set class property to abstract or override even in error states #8610

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions crates/swc_ecma_parser/src/parser/class_and_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,9 +622,8 @@ impl<I: Tokens> Parser<I> {
self.input.prev_span(),
SyntaxError::TS1029("abstract".into(), "override".into()),
);
} else {
is_abstract = true;
}
is_abstract = true;
}
"override" => {
if is_override {
Expand All @@ -644,9 +643,8 @@ impl<I: Tokens> Parser<I> {
);
} else if !self.ctx().has_super_class {
self.emit_err(self.input.prev_span(), SyntaxError::TS4112);
} else {
is_override = true;
}
is_override = true;
}
"readonly" => {
let readonly_span = self.input.prev_span();
Expand Down
4 changes: 2 additions & 2 deletions crates/swc_ecma_parser/tests/tsc/override1.json
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@
"accessibility": null,
"isAbstract": false,
"isOptional": false,
"isOverride": false
"isOverride": true
}
],
"superClass": null,
Expand Down Expand Up @@ -1328,7 +1328,7 @@
"accessibility": null,
"isAbstract": false,
"isOptional": false,
"isOverride": false
"isOverride": true
}
],
"superClass": null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"accessibility": null,
"isAbstract": false,
"isOptional": false,
"isOverride": false
"isOverride": true
}
],
"superClass": null,
Expand Down Expand Up @@ -182,7 +182,7 @@
"accessibility": null,
"isAbstract": false,
"isOptional": false,
"isOverride": false
"isOverride": true
}
],
"superClass": null,
Expand Down
12 changes: 12 additions & 0 deletions crates/swc_ecma_parser/tests/typescript/class/abstract/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,15 @@ export abstract class C {}
export default abstract class { }
export default abstract class C { }
// `abstract class` is not valid as an expression.

export abstract class C {
abstract prop: number;
abstract method(): void;
}
export class C {
// should still have as abstract even though parent is not
abstract prop: number;
abstract method(): void;
// should be abstract in spite of override in wrong place
override abstract method(): string;
}
Loading
Loading