From 495ca92160123d65bbb48a3dde407619e62ce80b Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Thu, 9 Jan 2025 15:27:36 -0800 Subject: [PATCH] Restrict to single-statement blocks --- src/compiler/checker.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6d862ae4e6e49..30a7b2c113b2d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -43942,7 +43942,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } function checkBlock(node: Block) { - // Grammar checking for SyntaxKind.Block + if (node.statements.length === 1 && node.statements[0].kind === SyntaxKind.ExpressionStatement) { + if (isSideEffectFree((node.statements[0] as ExpressionStatement).expression)) { + error(node, Diagnostics.Left_side_of_comma_operator_is_unused_and_has_no_side_effects); + } + } if (node.kind === SyntaxKind.Block) { checkGrammarStatementInAmbientContext(node); } @@ -44491,10 +44495,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { // Grammar checking checkGrammarStatementInAmbientContext(node); - if (isSideEffectFree(node.expression)) { - error(node, Diagnostics.Left_side_of_comma_operator_is_unused_and_has_no_side_effects); - } - checkExpression(node.expression); }