Skip to content
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

fix: perserve parentheses of lhs id with rhs unamed fn #14524

Merged
merged 2 commits into from May 6, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/babel-generator/src/node/parentheses.ts
Expand Up @@ -17,6 +17,7 @@ import {
isForInStatement,
isForOfStatement,
isForStatement,
isFunctionExpression,
isIfStatement,
isIndexedAccessType,
isIntersectionTypeAnnotation,
Expand Down Expand Up @@ -344,6 +345,16 @@ export function Identifier(
parent: t.Node,
printStack: Array<t.Node>,
): boolean {
// 13.15.2 AssignmentExpression RS: Evaluation
// (fn) = function () {};
if (
node.extra?.parenthesized &&
isAssignmentExpression(parent, { left: node }) &&
(isFunctionExpression(parent.right) || isClassExpression(parent.right)) &&
parent.right.id == null
) {
return true;
}
// Non-strict code allows the identifier `let`, but it cannot occur as-is in
// certain contexts to avoid ambiguity with contextual keyword `let`.
if (node.name === "let") {
Expand Down
@@ -0,0 +1,7 @@
var f, g, h;
(f) = function () {};
(f) = class {};
g = function () {};
g = class {};
(h) = function noParen() {};
(h) = class noParen {}
@@ -0,0 +1,13 @@
var f, g, h;

(f) = function () {};

(f) = class {};

g = function () {};

g = class {};

h = function noParen() {};

h = class noParen {};