(ts) Raise syntax error for abstract methods with a body (#12687)
Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
This commit is contained in:
@@ -60,6 +60,8 @@ type ParsingContext =
|
||||
| "TypeParametersOrArguments";
|
||||
|
||||
const TSErrors = Object.freeze({
|
||||
AbstractMethodHasImplementation:
|
||||
"Method '%0' cannot have an implementation because it is marked abstract.",
|
||||
ClassMethodHasDeclare: "Class methods cannot have the 'declare' modifier",
|
||||
ClassMethodHasReadonly: "Class methods cannot have the 'readonly' modifier",
|
||||
ConstructorHasTypeParameters:
|
||||
@@ -2933,4 +2935,24 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
this.unexpected(null, tt._class);
|
||||
}
|
||||
}
|
||||
|
||||
parseMethod(...args: any[]) {
|
||||
const method = super.parseMethod(...args);
|
||||
if (method.abstract) {
|
||||
const hasBody = this.hasPlugin("estree")
|
||||
? !!method.value.body
|
||||
: !!method.body;
|
||||
if (hasBody) {
|
||||
const { key } = method;
|
||||
this.raise(
|
||||
method.start,
|
||||
TSErrors.AbstractMethodHasImplementation,
|
||||
key.type === "Identifier"
|
||||
? key.name
|
||||
: `[${this.input.slice(key.start, key.end)}]`,
|
||||
);
|
||||
}
|
||||
}
|
||||
return method;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user