[ts] Support private methods overloads (#13876)

* [parser] Allow private methods overloads when parsing TS

* Add transform tests

* Fix estree

* Fix flow
This commit is contained in:
Nicolò Ribaudo
2021-10-26 07:29:20 +02:00
committed by GitHub
parent 290d52fdc1
commit fb7ddf4d38
10 changed files with 316 additions and 1 deletions

View File

@@ -2015,7 +2015,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
const bodilessType =
type === "FunctionDeclaration"
? "TSDeclareFunction"
: type === "ClassMethod"
: type === "ClassMethod" || type === "ClassPrivateMethod"
? "TSDeclareMethod"
: undefined;
if (bodilessType && !this.match(tt.braceL) && this.isLineTerminator()) {
@@ -2755,6 +2755,17 @@ export default (superClass: Class<Parser>): Class<Parser> =>
super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
}
declareClassPrivateMethodInScope(
node: N.ClassPrivateMethod | N.EstreeMethodDefinition | N.TSDeclareMethod,
kind: number,
) {
if (node.type === "TSDeclareMethod") return;
// This happens when using the "estree" plugin.
if (node.type === "MethodDefinition" && !node.value.body) return;
super.declareClassPrivateMethodInScope(node, kind);
}
parseClassSuper(node: N.Class): void {
super.parseClassSuper(node);
if (node.superClass && this.isRelational("<")) {