[TS] Allow context type annotation on getters/setters (#9641)

* Allow context type annotation on getters/setters

* Extract getAccessorsExpectedParamCount
This commit is contained in:
Matt Tingen
2019-03-06 16:54:42 -05:00
committed by Nicolò Ribaudo
parent fba5655a44
commit e53be4b387
6 changed files with 441 additions and 2 deletions

View File

@@ -2344,4 +2344,17 @@ export default (superClass: Class<Parser>): Class<Parser> =>
if (typeArguments) node.typeParameters = typeArguments;
return super.jsxParseOpeningElementAfterName(node);
}
getGetterSetterExpectedParamCount(
method: N.ObjectMethod | N.ClassMethod,
): number {
const baseCount = super.getGetterSetterExpectedParamCount(method);
const firstParam = method.params[0];
const hasContextParam =
firstParam &&
firstParam.type === "Identifier" &&
firstParam.name === "this";
return hasContextParam ? baseCount + 1 : baseCount;
}
};