feat(ts): raise error for abstract property with initializer (#13523)
* feat: raise error for abstract property with initializer * Improve tests * Address review * JLHwung review * Update packages/babel-parser/src/plugins/typescript/index.js * update test fixtures Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com> Co-authored-by: Huáng Jùnliàng <jlhwung@gmail.com>
This commit is contained in:
@@ -70,6 +70,8 @@ const TSErrors = makeErrorTemplates(
|
||||
{
|
||||
AbstractMethodHasImplementation:
|
||||
"Method '%0' cannot have an implementation because it is marked abstract.",
|
||||
AbstractPropertyHasInitializer:
|
||||
"Property '%0' cannot have an initializer because it is marked abstract.",
|
||||
AccesorCannotDeclareThisParameter:
|
||||
"'get' and 'set' accessors cannot declare 'this' parameters.",
|
||||
AccesorCannotHaveTypeParameters: "An accessor cannot have type parameters.",
|
||||
@@ -2612,6 +2614,16 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
if (this.state.isAmbientContext && this.match(tt.eq)) {
|
||||
this.raise(this.state.start, TSErrors.DeclareClassFieldHasInitializer);
|
||||
}
|
||||
if (node.abstract && this.match(tt.eq)) {
|
||||
const { key } = node;
|
||||
this.raise(
|
||||
this.state.start,
|
||||
TSErrors.AbstractPropertyHasInitializer,
|
||||
key.type === "Identifier" && !node.computed
|
||||
? key.name
|
||||
: `[${this.input.slice(key.start, key.end)}]`,
|
||||
);
|
||||
}
|
||||
|
||||
return super.parseClassProperty(node);
|
||||
}
|
||||
@@ -3201,7 +3213,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
this.raise(
|
||||
method.start,
|
||||
TSErrors.AbstractMethodHasImplementation,
|
||||
key.type === "Identifier"
|
||||
key.type === "Identifier" && !method.computed
|
||||
? key.name
|
||||
: `[${this.input.slice(key.start, key.end)}]`,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user