Refactor bindingProperty parsing (#13929)

* refactor: inline parseMaybePrivateName

* correct test case

* perf: fast exit in checkExpressionErrors

* refactor: add parseBindingProperty

* fix: private property with variance

* Update packages/babel-parser/src/parser/expression.js

Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>

* chore: update testcase

* refactor: remove refExpressionErrors for record/tuple

They are always non-ambiguous.

Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
This commit is contained in:
Huáng Jùnliàng
2021-11-12 10:11:46 -05:00
committed by GitHub
parent 135ab837bc
commit 54c539ecc1
15 changed files with 322 additions and 108 deletions

View File

@@ -2475,15 +2475,10 @@ export default (superClass: Class<Parser>): Class<Parser> =>
}
}
parsePropertyName(
node: N.ObjectOrClassMember | N.ClassMember | N.TsNamedTypeElementBase,
isPrivateNameAllowed: boolean,
): N.Identifier {
const variance = this.flowParseVariance();
const key = super.parsePropertyName(node, isPrivateNameAllowed);
// $FlowIgnore ("variance" not defined on TsNamedTypeElementBase)
node.variance = variance;
return key;
parsePropertyNamePrefixOperator(
node: N.ObjectOrClassMember | N.ClassMember,
): void {
node.variance = this.flowParseVariance();
}
// parse type parameters for object method shorthand

View File

@@ -780,7 +780,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
return idx;
}
this.parsePropertyName(node, /* isPrivateNameAllowed */ false);
this.parsePropertyName(node);
if (
!node.computed &&
node.key.type === "Identifier" &&
@@ -788,7 +788,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
this.tsTokenCanFollowModifier()
) {
node.kind = node.key.name;
this.parsePropertyName(node, /* isPrivateNameAllowed */ false);
this.parsePropertyName(node);
}
return this.tsParsePropertyOrMethodSignature(node, !!node.readonly);
}