Skip to content

Commit bfdb1cc

Browse files
committed
createExportAssignment: parenthesize nested class or function expression
Fixes: #25222
1 parent a1746d4 commit bfdb1cc

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/compiler/factory.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4185,12 +4185,16 @@ namespace ts {
41854185
*/
41864186
export function parenthesizeDefaultExpression(e: Expression) {
41874187
const check = skipPartiallyEmittedExpressions(e);
4188-
return (check.kind === SyntaxKind.ClassExpression ||
4189-
check.kind === SyntaxKind.FunctionExpression ||
4190-
check.kind === SyntaxKind.CommaListExpression ||
4191-
isBinaryExpression(check) && check.operatorToken.kind === SyntaxKind.CommaToken)
4192-
? createParen(e)
4193-
: e;
4188+
let needsParens = check.kind === SyntaxKind.CommaListExpression ||
4189+
isBinaryExpression(check) && check.operatorToken.kind === SyntaxKind.CommaToken;
4190+
if (!needsParens) {
4191+
switch (getLeftmostExpression(check, /*stopAtCallExpression*/ false).kind) {
4192+
case SyntaxKind.ClassExpression:
4193+
case SyntaxKind.FunctionExpression:
4194+
needsParens = true;
4195+
}
4196+
}
4197+
return needsParens ? createParen(e) : e;
41944198
}
41954199

41964200
/**

0 commit comments

Comments
 (0)