Skip to content

Commit

Permalink
fix: Do not allow TypeCastExpressions w/o parens inside of SequenceEx…
Browse files Browse the repository at this point in the history
…pressions
  • Loading branch information
danez committed Oct 31, 2018
1 parent 0d9e77f commit e6a6ed3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
17 changes: 16 additions & 1 deletion packages/babel-parser/src/plugins/flow.js
Expand Up @@ -2494,9 +2494,24 @@ export default (superClass: Class<Parser>): Class<Parser> =>
}

parseParenAndDistinguishExpression(canBeArrow: boolean): N.Expression {
return super.parseParenAndDistinguishExpression(
const list = super.parseParenAndDistinguishExpression(
canBeArrow && this.state.noArrowAt.indexOf(this.state.start) === -1,
);

// Ensure that TypeCastExpressions without parens are not allowed inside SequenceExpressions
// e.g. (A, B: T)
if (list.type === "SequenceExpression") {
const firstTypeCast = list.expressions.find(
({ type, extra }) =>
type === "TypeCastExpression" &&
(!extra || extra.parenthesized !== true),
);
if (firstTypeCast) {
this.unexpected(firstTypeCast.typeAnnotation.start);
}
}

return list;
}

parseSubscripts(
Expand Down
@@ -0,0 +1 @@
(A, B: T)
@@ -0,0 +1,8 @@
{
"sourceType": "module",
"plugins": [
"jsx",
"flow"
],
"throws": "Unexpected token (1:5)"
}

0 comments on commit e6a6ed3

Please sign in to comment.