Skip to content

Commit 495ca92

Browse files
committed
Restrict to single-statement blocks
1 parent 8b38313 commit 495ca92

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43942,7 +43942,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4394243942
}
4394343943

4394443944
function checkBlock(node: Block) {
43945-
// Grammar checking for SyntaxKind.Block
43945+
if (node.statements.length === 1 && node.statements[0].kind === SyntaxKind.ExpressionStatement) {
43946+
if (isSideEffectFree((node.statements[0] as ExpressionStatement).expression)) {
43947+
error(node, Diagnostics.Left_side_of_comma_operator_is_unused_and_has_no_side_effects);
43948+
}
43949+
}
4394643950
if (node.kind === SyntaxKind.Block) {
4394743951
checkGrammarStatementInAmbientContext(node);
4394843952
}
@@ -44491,10 +44495,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4449144495
// Grammar checking
4449244496
checkGrammarStatementInAmbientContext(node);
4449344497

44494-
if (isSideEffectFree(node.expression)) {
44495-
error(node, Diagnostics.Left_side_of_comma_operator_is_unused_and_has_no_side_effects);
44496-
}
44497-
4449844498
checkExpression(node.expression);
4449944499
}
4450044500

0 commit comments

Comments
 (0)