Skip to content

Commit

Permalink
review
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxingbaoyu committed Nov 16, 2023
1 parent 6223fa1 commit dd62739
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 9 deletions.
27 changes: 20 additions & 7 deletions packages/babel-generator/src/printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -664,20 +664,33 @@ class Printer {
this._insideAux = node.loc == undefined;
this._maybeAddAuxComment(this._insideAux && !oldInAux);

const parenthesized = node.extra?.parenthesized as boolean | undefined;
let shouldPrintParens =
forceParens ||
(format.retainFunctionParens &&
nodeType === "FunctionExpression" &&
node.extra?.parenthesized) ||
(parenthesized &&
format.retainFunctionParens &&
nodeType === "FunctionExpression") ||
needsParens(node, parent, this._printStack);

if (
!shouldPrintParens &&
parent?.type === "MemberExpression" &&
node.extra?.parenthesized &&
node.leadingComments?.length
parenthesized &&
node.leadingComments?.length &&
node.leadingComments[0].type === "CommentBlock"
) {
shouldPrintParens = true;
const parentType = parent?.type;
switch (parentType) {
case "ExpressionStatement":
case "VariableDeclarator":
case "AssignmentExpression":
case "ReturnStatement":
case "CallExpression":
case "OptionalCallExpression":
case "NewExpression":
break;
default:
shouldPrintParens = true;
}
}

if (shouldPrintParens) {
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(/* @__PURE__ */ f()).g();
(/* @__PURE__ */ f())();
(/* @__PURE__ */ f())?.bar;
(/* @__PURE__ */ f())`bar`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
( /* @__PURE__ */f()).g();
/* @__PURE__ */f()();
( /* @__PURE__ */f())?.bar;
( /* @__PURE__ */f())`bar`;

0 comments on commit dd62739

Please sign in to comment.