Skip to content

Commit

Permalink
Print necessary parentheses in generator
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Aug 24, 2022
1 parent dbaf378 commit d0ded5b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
7 changes: 3 additions & 4 deletions packages/babel-generator/src/generators/expressions.ts
Expand Up @@ -131,14 +131,13 @@ function isDecoratorMemberExpression(
function shouldParenthesizeDecoratorExpression(
node: t.Expression | t.Super | t.V8IntrinsicIdentifier,
) {
if (node.type === "CallExpression") {
node = node.callee;
}
if (node.type === "ParenthesizedExpression") {
// We didn't check extra?.parenthesized here because we don't track decorators in needsParen
return false;
}
return !isDecoratorMemberExpression(node);
return !isDecoratorMemberExpression(
node.type === "CallExpression" ? node.callee : node,
);
}

export function Decorator(this: Printer, node: t.Decorator) {
Expand Down
Expand Up @@ -9,7 +9,6 @@ class C extends class {} {
@(this.dec)
@(super.dec)
@(new DecFactory)
@(decs[three])()
p;
}

Expand All @@ -20,6 +19,11 @@ class C extends class {} {
p;
}

class ShouldAddParens {
@(decs[three])()
p;
}

class WillPreserveParens {
@(decs)
@(decs.one)
Expand Down
Expand Up @@ -10,7 +10,6 @@ class C extends class {} {
@(this.dec)
@(super.dec)
@(new DecFactory())
@(decs[three])()
p;
}

Expand All @@ -21,6 +20,11 @@ class C extends class {} {
p;
}

class ShouldAddParens {
@((decs[three])())
p;
}

class WillPreserveParens {
@(decs)
@(decs.one)
Expand Down

0 comments on commit d0ded5b

Please sign in to comment.