From 6b1ea96b9404ccfc8e66e22fa2a7b645781255c3 Mon Sep 17 00:00:00 2001 From: Gabriela Araujo Britto Date: Wed, 4 Dec 2024 09:13:13 -0800 Subject: [PATCH] Fix flow node improper reuse (#60662) --- src/compiler/binder.ts | 4 ++++ .../fourslash/unreachableStatementNodeReuse.ts | 13 +++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 tests/cases/fourslash/unreachableStatementNodeReuse.ts diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index b071f72b712c2..41966df6672e9 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -21,6 +21,7 @@ import { BreakOrContinueStatement, CallChain, CallExpression, + canHaveFlowNode, canHaveLocals, canHaveSymbol, CaseBlock, @@ -1104,6 +1105,9 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { // and set it before we descend into nodes that could actually be part of an assignment pattern. inAssignmentPattern = false; if (checkUnreachable(node)) { + if (canHaveFlowNode(node) && node.flowNode) { + node.flowNode = undefined; + } bindEachChild(node); bindJSDoc(node); inAssignmentPattern = saveInAssignmentPattern; diff --git a/tests/cases/fourslash/unreachableStatementNodeReuse.ts b/tests/cases/fourslash/unreachableStatementNodeReuse.ts new file mode 100644 index 0000000000000..9ede6fd059c95 --- /dev/null +++ b/tests/cases/fourslash/unreachableStatementNodeReuse.ts @@ -0,0 +1,13 @@ +/// + +//// function test() { +//// return/*a*/abc(); +//// return; +//// } +//// function abc() { } + +verify.numberOfErrorsInCurrentFile(1); + +goTo.marker("a") +edit.insert(" "); +verify.noErrors(); \ No newline at end of file