[ts] raise SyntaxError for declare before getter/setter (#13143)
* fix: raise `SyntaxError` for `declare` before getter/setter * fix: allow `declare` when class property name is `get` or `set`
This commit is contained in:
@@ -67,6 +67,7 @@ const TSErrors = Object.freeze({
|
||||
ClassMethodHasReadonly: "Class methods cannot have the 'readonly' modifier",
|
||||
ConstructorHasTypeParameters:
|
||||
"Type parameters cannot appear on a constructor declaration.",
|
||||
DeclareAccessor: "'declare' is not allowed in %0ters.",
|
||||
DeclareClassFieldHasInitializer:
|
||||
"Initializers are not allowed in ambient contexts.",
|
||||
DeclareFunctionHasImplementation:
|
||||
@@ -2470,6 +2471,11 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
if (typeParameters && isConstructor) {
|
||||
this.raise(typeParameters.start, TSErrors.ConstructorHasTypeParameters);
|
||||
}
|
||||
|
||||
// $FlowIgnore
|
||||
if (method.declare && (method.kind === "get" || method.kind === "set")) {
|
||||
this.raise(method.start, TSErrors.DeclareAccessor, method.kind);
|
||||
}
|
||||
if (typeParameters) method.typeParameters = typeParameters;
|
||||
super.pushClassMethod(
|
||||
classBody,
|
||||
|
||||
Reference in New Issue
Block a user