diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index b8b77193ed0..25849cf6bd3 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -4185,12 +4185,16 @@ namespace ts { */ export function parenthesizeDefaultExpression(e: Expression) { const check = skipPartiallyEmittedExpressions(e); - return (check.kind === SyntaxKind.ClassExpression || - check.kind === SyntaxKind.FunctionExpression || - check.kind === SyntaxKind.CommaListExpression || - isBinaryExpression(check) && check.operatorToken.kind === SyntaxKind.CommaToken) - ? createParen(e) - : e; + let needsParens = check.kind === SyntaxKind.CommaListExpression || + isBinaryExpression(check) && check.operatorToken.kind === SyntaxKind.CommaToken; + if (!needsParens) { + switch (getLeftmostExpression(check, /*stopAtCallExpression*/ false).kind) { + case SyntaxKind.ClassExpression: + case SyntaxKind.FunctionExpression: + needsParens = true; + } + } + return needsParens ? createParen(e) : e; } /**