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