Skip to content

feat(ts-estree): fix parsing nested sequence expressions #286

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
990 changes: 990 additions & 0 deletions packages/parser/tests/lib/__snapshots__/javascript.ts.snap

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var xx = (xx ? x++ : 4, 10);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var v1 = (1, 2, 3, 4, 5, 6, 7);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var v1 = ((1, 2, 3), 4, 5, (6, 7));
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
function f1() {
var a = 1;
return a, v1, a;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const foo = (((1, 2)));
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const foo = (1);
15 changes: 6 additions & 9 deletions packages/typescript-estree/src/convert.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ tester.addFixturePatternConfig('javascript/classes', {
]
});

tester.addFixturePatternConfig('javascript/commaOperator');

tester.addFixturePatternConfig('javascript/defaultParams');

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