Refactor parsing object members (#9607)

* Refactor parsing object members

* Ensure decorators on rest don’t swallow decorators silently

* Use hasPrecedingLineBreak

* Add test for async with linebreak

* Update flow whitelist
This commit is contained in:
Daniel Tschinder
2019-02-28 11:42:12 -08:00
committed by GitHub
parent 208195f425
commit 98ab1b6428
51 changed files with 1060 additions and 179 deletions

View File

@@ -126,16 +126,24 @@ export default (superClass: Class<Parser>): Class<Parser> =>
}
checkPropClash(
prop: N.ObjectMember,
prop: N.ObjectMember | N.SpreadElement,
propHash: { [key: string]: boolean },
): void {
if (prop.computed || !isSimpleProperty(prop)) return;
if (
prop.type === "SpreadElement" ||
prop.computed ||
prop.method ||
// $FlowIgnore
prop.shorthand
) {
return;
}
const key = prop.key;
// It is either an Identifier or a String/NumericLiteral
const name = key.type === "Identifier" ? key.name : String(key.value);
if (name === "__proto__") {
if (name === "__proto__" && prop.kind === "init") {
if (propHash.proto) {
this.raise(key.start, "Redefinition of __proto__ property");
}

View File

@@ -570,7 +570,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
const restNode: N.TsRestType = this.startNode();
this.next(); // skips ellipsis
restNode.typeAnnotation = this.tsParseType();
this.checkCommaAfterRest(tt.bracketR, "type");
this.checkCommaAfterRest();
return this.finishNode(restNode, "TSRestType");
}