Skip to content

Commit

Permalink
Print necessary parentheses for functions in postfix expressions (#14532
Browse files Browse the repository at this point in the history
)

fix: isFirstInContext doesn't handle postfix unary operators

Co-authored-by: xiawenqi <xwq167663@alibaba-inc.com>
  • Loading branch information
xiawenqi and xiawenqi committed May 6, 2022
1 parent fbd0652 commit 0984a2a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/babel-generator/src/node/parentheses.ts
Expand Up @@ -5,6 +5,7 @@ import {
isAwaitExpression,
isBinary,
isBinaryExpression,
isUpdateExpression,
isCallExpression,
isClassDeclaration,
isClassExpression,
Expand Down Expand Up @@ -414,6 +415,7 @@ function isFirstInContext(
if (
(hasPostfixPart(node, parent) && !isNewExpression(parent)) ||
(isSequenceExpression(parent) && parent.expressions[0] === node) ||
(isUpdateExpression(parent) && !parent.prefix) ||
isConditional(parent, { test: node }) ||
isBinary(parent, { left: node }) ||
isAssignmentExpression(parent, { left: node })
Expand Down
@@ -0,0 +1 @@
(function () { return {x: 24} }()).x++;
@@ -0,0 +1,5 @@
(function () {
return {
x: 24
};
})().x++;

0 comments on commit 0984a2a

Please sign in to comment.