From bfdb1cc3911298500a5d0a5b0e4d25037ae05ff2 Mon Sep 17 00:00:00 2001 From: Klaus Meinhardt Date: Sat, 30 Jun 2018 21:53:34 +0200 Subject: [PATCH] createExportAssignment: parenthesize nested class or function expression Fixes: #25222 --- src/compiler/factory.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) 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; } /**