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

packages/parser/tests/lib/__snapshots__/javascript.ts.snap

Lines changed: 990 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
var xx = (xx ? x++ : 4, 10);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
var v1 = (1, 2, 3, 4, 5, 6, 7);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
var v1 = ((1, 2, 3), 4, 5, (6, 7));
Lines changed: 4 additions & 0 deletions
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+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
const foo = (((1, 2)));
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
const foo = (1);

packages/typescript-estree/src/convert.ts

Lines changed: 6 additions & 9 deletions
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);

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

Lines changed: 2 additions & 0 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy