Skip to content

Commit ecc9631

Browse files
armano2bradzacher
authored andcommitted
feat(ts-estree): fix parsing nested sequence expressions (typescript-eslint#286)
1 parent 5ada030 commit ecc9631

File tree

11 files changed

+3905
-9
lines changed

11 files changed

+3905
-9
lines changed

Diff for: packages/parser/tests/lib/__snapshots__/javascript.ts.snap

+990
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
var xx = (xx ? x++ : 4, 10);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
var v1 = (1, 2, 3, 4, 5, 6, 7);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
var v1 = ((1, 2, 3), 4, 5, (6, 7));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
function f1() {
2+
var a = 1;
3+
return a, v1, a;
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
const foo = (((1, 2)));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
const foo = (1);

Diff for: packages/typescript-estree/src/convert.ts

+6-9
Original file line numberDiff line numberDiff line change
@@ -1596,20 +1596,17 @@ export class Converter {
15961596
expressions: []
15971597
});
15981598

1599-
const left = this.convertChild(node.left),
1600-
right = this.convertChild(node.right);
1601-
1602-
if (left.type === AST_NODE_TYPES.SequenceExpression) {
1599+
const left = this.convertChild(node.left);
1600+
if (
1601+
left.type === AST_NODE_TYPES.SequenceExpression &&
1602+
node.left.kind !== SyntaxKind.ParenthesizedExpression
1603+
) {
16031604
result.expressions = result.expressions.concat(left.expressions);
16041605
} else {
16051606
result.expressions.push(left);
16061607
}
16071608

1608-
if (right.type === AST_NODE_TYPES.SequenceExpression) {
1609-
result.expressions = result.expressions.concat(right.expressions);
1610-
} else {
1611-
result.expressions.push(right);
1612-
}
1609+
result.expressions.push(this.convertChild(node.right));
16131610
return result;
16141611
} else {
16151612
const type = getBinaryExpressionType(node.operatorToken);

Diff for: packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts

+2
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ tester.addFixturePatternConfig('javascript/classes', {
206206
]
207207
});
208208

209+
tester.addFixturePatternConfig('javascript/commaOperator');
210+
209211
tester.addFixturePatternConfig('javascript/defaultParams');
210212

211213
tester.addFixturePatternConfig('javascript/destructuring');

0 commit comments

Comments
 (0)