Skip to content

Commit

Permalink
feat(ts-estree): fix parsing nested sequence expressions (#286)
Browse files Browse the repository at this point in the history
  • Loading branch information
armano2 authored and bradzacher committed Feb 16, 2019
1 parent 5ada030 commit ecc9631
Show file tree
Hide file tree
Showing 11 changed files with 3,905 additions and 9 deletions.
990 changes: 990 additions & 0 deletions packages/parser/tests/lib/__snapshots__/javascript.ts.snap

Large diffs are not rendered by default.

@@ -0,0 +1 @@
var xx = (xx ? x++ : 4, 10);
@@ -0,0 +1 @@
var v1 = (1, 2, 3, 4, 5, 6, 7);
@@ -0,0 +1 @@
var v1 = ((1, 2, 3), 4, 5, (6, 7));
@@ -0,0 +1,4 @@
function f1() {
var a = 1;
return a, v1, a;
}
@@ -0,0 +1 @@
const foo = (((1, 2)));
@@ -0,0 +1 @@
const foo = (1);
15 changes: 6 additions & 9 deletions packages/typescript-estree/src/convert.ts
Expand Up @@ -1596,20 +1596,17 @@ export class Converter {
expressions: []
});

const left = this.convertChild(node.left),
right = this.convertChild(node.right);

if (left.type === AST_NODE_TYPES.SequenceExpression) {
const left = this.convertChild(node.left);
if (
left.type === AST_NODE_TYPES.SequenceExpression &&
node.left.kind !== SyntaxKind.ParenthesizedExpression
) {
result.expressions = result.expressions.concat(left.expressions);
} else {
result.expressions.push(left);
}

if (right.type === AST_NODE_TYPES.SequenceExpression) {
result.expressions = result.expressions.concat(right.expressions);
} else {
result.expressions.push(right);
}
result.expressions.push(this.convertChild(node.right));
return result;
} else {
const type = getBinaryExpressionType(node.operatorToken);
Expand Down
Expand Up @@ -206,6 +206,8 @@ tester.addFixturePatternConfig('javascript/classes', {
]
});

tester.addFixturePatternConfig('javascript/commaOperator');

tester.addFixturePatternConfig('javascript/defaultParams');

tester.addFixturePatternConfig('javascript/destructuring');
Expand Down

0 comments on commit ecc9631

Please sign in to comment.