fix: throw for constructors with type parameters (#12065)

* Throw a syntax error for a constructor with type parameters

* Modify to match error location with TypeScript

* Update typescript parser tests

Update allowlist.txt
This commit is contained in:
Sosuke Suzuki
2020-09-18 02:03:33 +09:00
committed by GitHub
parent 69e98fcf4a
commit 7028a14c7f
5 changed files with 101 additions and 1 deletions

View File

@@ -65,6 +65,8 @@ type ParsingContext =
const TSErrors = Object.freeze({
ClassMethodHasDeclare: "Class methods cannot have the 'declare' modifier",
ClassMethodHasReadonly: "Class methods cannot have the 'readonly' modifier",
ConstructorHasTypeParameters:
"Type parameters cannot appear on a constructor declaration.",
DeclareClassFieldHasInitializer:
"'declare' class fields cannot have an initializer",
DuplicateModifier: "Duplicate modifier: '%0'",
@@ -2296,6 +2298,9 @@ export default (superClass: Class<Parser>): Class<Parser> =>
allowsDirectSuper: boolean,
): void {
const typeParameters = this.tsTryParseTypeParameters();
if (typeParameters && isConstructor) {
this.raise(typeParameters.start, TSErrors.ConstructorHasTypeParameters);
}
if (typeParameters) method.typeParameters = typeParameters;
super.pushClassMethod(
classBody,