Skip to content

Commit

Permalink
Clean up parsing re: flow typecasts
Browse files Browse the repository at this point in the history
  • Loading branch information
wcjohnson committed Oct 9, 2017
1 parent 322842a commit 0e52088
Show file tree
Hide file tree
Showing 8 changed files with 422 additions and 5 deletions.
16 changes: 14 additions & 2 deletions src/plugins/bangCall.js
Expand Up @@ -18,6 +18,17 @@ export default function(parser) {
);
};

// c/p parseExprListItem
pp.parseBangArg = function () {
let elt;
if (this.match(tt.ellipsis)) {
elt = this.parseSpread();
} else {
elt = this.parseMaybeAssign(false);
}
return elt;
};

// Parse `!` followed by an arg list. Returns truthy if further subscripting
// is legal.
pp.parseBangCall = function(node, nodeType) {
Expand Down Expand Up @@ -57,7 +68,7 @@ export default function(parser) {

// Comma-separated arg and first arg skip ASI/whitespace checks
if (first || this.eat(tt.comma)) {
node.arguments.push(this.parseExprListItem(false));
node.arguments.push(this.parseBangArg());
first = false;
} else {
// ASI: unwind if not at proper indent level
Expand All @@ -70,7 +81,7 @@ export default function(parser) {
}
}

node.arguments.push(this.parseExprListItem(false));
node.arguments.push(this.parseBangArg());
}

if (this.isLineBreak()) {
Expand All @@ -87,6 +98,7 @@ export default function(parser) {
this.state.bangUnwindLevel = oldBangUnwindLevel;
this.state.bangWhiteBlockLevel = oldBangWhiteBlockLevel;

this.toReferencedList(node.arguments);
node = this.finishNode(node, nodeType);

// Subscript only on new line.
Expand Down
1 change: 1 addition & 0 deletions src/plugins/safeCallExistential.js
Expand Up @@ -18,6 +18,7 @@ export default function(parser) {
} else {
this.expect(tt.parenL);
node.arguments = this.parseCallExpressionArguments(tt.parenR, false);
this.toReferencedList(node.arguments);
return [this.finishNode(node, "CallExpression"), true];
}
};
Expand Down
1 change: 1 addition & 0 deletions src/plugins/spreadLoop.js
Expand Up @@ -41,6 +41,7 @@ export default function(parser) {
}

node.elements = elts;
this.toReferencedList(node.elements);
return hasSpreadLoop;
};

Expand Down
154 changes: 154 additions & 0 deletions test/fixtures/bang-call/punctuation/like-typecast/expected.json
@@ -0,0 +1,154 @@
{
"type": "File",
"start": 0,
"end": 12,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 12
}
},
"program": {
"type": "Program",
"start": 0,
"end": 12,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 12
}
},
"sourceType": "script",
"body": [
{
"type": "IfStatement",
"start": 0,
"end": 12,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 12
}
},
"test": {
"type": "CallExpression",
"start": 3,
"end": 9,
"loc": {
"start": {
"line": 1,
"column": 3
},
"end": {
"line": 1,
"column": 9
}
},
"callee": {
"type": "Identifier",
"start": 5,
"end": 6,
"loc": {
"start": {
"line": 1,
"column": 5
},
"end": {
"line": 1,
"column": 6
},
"identifierName": "b"
},
"name": "b"
},
"arguments": [
{
"type": "Identifier",
"start": 3,
"end": 4,
"loc": {
"start": {
"line": 1,
"column": 3
},
"end": {
"line": 1,
"column": 4
},
"identifierName": "a"
},
"name": "a"
},
{
"type": "Identifier",
"start": 8,
"end": 9,
"loc": {
"start": {
"line": 1,
"column": 8
},
"end": {
"line": 1,
"column": 9
},
"identifierName": "c"
},
"name": "c"
}
],
"extra": {
"bang": true
},
"tilde": true
},
"consequent": {
"type": "ExpressionStatement",
"start": 11,
"end": 12,
"loc": {
"start": {
"line": 1,
"column": 11
},
"end": {
"line": 1,
"column": 12
}
},
"expression": {
"type": "Identifier",
"start": 11,
"end": 12,
"loc": {
"start": {
"line": 1,
"column": 11
},
"end": {
"line": 1,
"column": 12
},
"identifierName": "d"
},
"name": "d"
}
},
"alternate": null
}
],
"directives": []
}
}

This file was deleted.

1 change: 1 addition & 0 deletions test/fixtures/flow/typecasts/call-2/actual.js
@@ -0,0 +1 @@
callee((castee: CastTo), (castee2: CastTo2))

0 comments on commit 0e52088

Please sign in to comment.