Throw a syntax error for a parameter properties in not constructor (#12061)

This commit is contained in:
Sosuke Suzuki
2020-09-15 06:28:06 +09:00
committed by GitHub
parent c8f0b6dc1e
commit bbe0cf09fc
6 changed files with 391 additions and 2 deletions

View File

@@ -90,6 +90,8 @@ const TSErrors = Object.freeze({
"Template literal types cannot have any substitution",
TypeAnnotationAfterAssign:
"Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`",
UnexpectedParameterModifier:
"A parameter property is only allowed in a constructor implementation.",
UnexpectedReadonly:
"'readonly' type modifier is only permitted on array and tuple literal types.",
UnexpectedTypeAnnotation: "Did not expect a type annotation here.",
@@ -1709,9 +1711,12 @@ export default (superClass: Class<Parser>): Class<Parser> =>
let accessibility: ?N.Accessibility;
let readonly = false;
if (allowModifiers) {
if (allowModifiers !== undefined) {
accessibility = this.parseAccessModifier();
readonly = !!this.tsParseModifier(["readonly"]);
if (allowModifiers === false && (accessibility || readonly)) {
this.raise(startPos, TSErrors.UnexpectedParameterModifier);
}
}
const left = this.parseMaybeDefault();