Fix unstable trailing comment on a parenthesized assignment statement (#19276)
Co-authored-by: fisker <lionkay@gmail.com>
This commit is contained in:
1 parent
73732c4229
commit
eb0155289f
4 files changed
+73
-13
No files matched your search
@@ -1081,6 +1081,14 @@ function handleParenthesizedExpressionTrailingComment({
|
||||
text,
|
||||
}) {
|
||||
if (!followingNode && enclosingNode) {
|
||||
if (
|
||||
enclosingNode.type === "ExpressionStatement" &&
|
||||
enclosingNode.expression === precedingNode
|
||||
) {
|
||||
addTrailingComment(enclosingNode, comment);
|
||||
return true;
|
||||
}
|
||||
|
||||
const isSequence = precedingNode?.type === "SequenceExpression";
|
||||
const isAssignment = precedingNode?.type === "AssignmentExpression";
|
||||
|
||||
@@ -1092,9 +1100,6 @@ function handleParenthesizedExpressionTrailingComment({
|
||||
enclosingNode.init === precedingNode) ||
|
||||
(enclosingNode.type === "ReturnStatement" &&
|
||||
enclosingNode.argument === precedingNode) ||
|
||||
(isSequence &&
|
||||
enclosingNode.type === "ExpressionStatement" &&
|
||||
enclosingNode.expression === precedingNode) ||
|
||||
(isSequence &&
|
||||
enclosingNode.type === "AssignmentExpression" &&
|
||||
enclosingNode.right === precedingNode)) &&
|
||||
|
||||
@@ -136,7 +136,30 @@ const x1 = (a, b, c /* comment */);
|
||||
const x2 = (a = c /* comment */);
|
||||
|
||||
(a, b, c /* comment */);
|
||||
// (a = c /* comment */);
|
||||
(a, b, c /* comment */
|
||||
);
|
||||
(a, b, c
|
||||
/* comment */
|
||||
);
|
||||
(a = c /* comment */);
|
||||
(a = c /* comment */
|
||||
);
|
||||
(a = c
|
||||
/* comment */
|
||||
);
|
||||
({a} = c /* comment */);
|
||||
({a} = c
|
||||
/* comment */
|
||||
);
|
||||
({a} = c /* comment */
|
||||
);
|
||||
|
||||
(foo() /* comment */);
|
||||
(foo()
|
||||
/* comment */
|
||||
);
|
||||
(foo() /* comment */
|
||||
);
|
||||
|
||||
assigned = (a, b, c /* comment */);
|
||||
// assigned = (a = c /* comment */);
|
||||
@@ -150,8 +173,23 @@ function f() {
|
||||
const x1 = (a, b, c /* comment */);
|
||||
const x2 = (a = c /* comment */);
|
||||
|
||||
(a, b, c /* comment */);
|
||||
// (a = c /* comment */);
|
||||
(a, b, c); /* comment */
|
||||
(a, b, c); /* comment */
|
||||
(a, b, c);
|
||||
/* comment */
|
||||
a = c; /* comment */
|
||||
a = c; /* comment */
|
||||
a = c;
|
||||
/* comment */
|
||||
({ a } = c); /* comment */
|
||||
({ a } = c);
|
||||
/* comment */
|
||||
({ a } = c); /* comment */
|
||||
|
||||
foo(); /* comment */
|
||||
foo();
|
||||
/* comment */
|
||||
foo(); /* comment */
|
||||
|
||||
assigned = (a, b, c /* comment */);
|
||||
// assigned = (a = c /* comment */);
|
||||
@@ -171,15 +209,11 @@ parsers: ["babel", "flow", "typescript"]
|
||||
=====================================input======================================
|
||||
// TODO: Enable tests in parenthesized-trailing-comment.js when they are stable
|
||||
|
||||
(a = c /* comment */);
|
||||
|
||||
assigned = (a = c /* comment */);
|
||||
|
||||
=====================================output=====================================
|
||||
// TODO: Enable tests in parenthesized-trailing-comment.js when they are stable
|
||||
|
||||
a = c /* comment */;
|
||||
|
||||
assigned = a = c /* comment */;
|
||||
|
||||
================================================================================
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// TODO: Enable tests in parenthesized-trailing-comment.js when they are stable
|
||||
|
||||
(a = c /* comment */);
|
||||
|
||||
assigned = (a = c /* comment */);
|
||||
@@ -2,7 +2,30 @@ const x1 = (a, b, c /* comment */);
|
||||
const x2 = (a = c /* comment */);
|
||||
|
||||
(a, b, c /* comment */);
|
||||
// (a = c /* comment */);
|
||||
(a, b, c /* comment */
|
||||
);
|
||||
(a, b, c
|
||||
/* comment */
|
||||
);
|
||||
(a = c /* comment */);
|
||||
(a = c /* comment */
|
||||
);
|
||||
(a = c
|
||||
/* comment */
|
||||
);
|
||||
({a} = c /* comment */);
|
||||
({a} = c
|
||||
/* comment */
|
||||
);
|
||||
({a} = c /* comment */
|
||||
);
|
||||
|
||||
(foo() /* comment */);
|
||||
(foo()
|
||||
/* comment */
|
||||
);
|
||||
(foo() /* comment */
|
||||
);
|
||||
|
||||
assigned = (a, b, c /* comment */);
|
||||
// assigned = (a = c /* comment */);
|
||||
|
||||
Reference in new issue
Block a user