From 789e0db358c824eaf5a643ef128c9b7d503a0c42 Mon Sep 17 00:00:00 2001 From: Gabriela Araujo Britto Date: Mon, 2 Dec 2024 16:29:17 -0800 Subject: [PATCH 1/2] fix flow node improper reuse --- src/compiler/binder.ts | 3 +++ .../fourslash/unreachableStatementNodeReuse.ts | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 tests/cases/fourslash/unreachableStatementNodeReuse.ts diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index b071f72b712c2..8e149d912a436 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -1104,6 +1104,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 ((node as HasFlowNode).flowNode) { + (node as HasFlowNode).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..f2191227c948f --- /dev/null +++ b/tests/cases/fourslash/unreachableStatementNodeReuse.ts @@ -0,0 +1,16 @@ +/// + +//// function test() { +//// return /*a*/abc(); +//// return; +//// } +//// function abc() { } + +verify.noErrors(); + +goTo.marker("a"); +edit.backspace(1); +verify.numberOfErrorsInCurrentFile(1); + +edit.insert(" "); +verify.noErrors(); \ No newline at end of file From 2bdc72d05b73cbd1f490018f187b2fa4d8e9b427 Mon Sep 17 00:00:00 2001 From: Gabriela Araujo Britto Date: Tue, 3 Dec 2024 09:39:26 -0800 Subject: [PATCH 2/2] use canHaveFlowNode and simplify test --- src/compiler/binder.ts | 5 +++-- tests/cases/fourslash/unreachableStatementNodeReuse.ts | 7 ++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 8e149d912a436..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,8 +1105,8 @@ 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 ((node as HasFlowNode).flowNode) { - (node as HasFlowNode).flowNode = undefined; + if (canHaveFlowNode(node) && node.flowNode) { + node.flowNode = undefined; } bindEachChild(node); bindJSDoc(node); diff --git a/tests/cases/fourslash/unreachableStatementNodeReuse.ts b/tests/cases/fourslash/unreachableStatementNodeReuse.ts index f2191227c948f..9ede6fd059c95 100644 --- a/tests/cases/fourslash/unreachableStatementNodeReuse.ts +++ b/tests/cases/fourslash/unreachableStatementNodeReuse.ts @@ -1,16 +1,13 @@ /// //// function test() { -//// return /*a*/abc(); +//// return/*a*/abc(); //// return; //// } //// function abc() { } -verify.noErrors(); - -goTo.marker("a"); -edit.backspace(1); verify.numberOfErrorsInCurrentFile(1); +goTo.marker("a") edit.insert(" "); verify.noErrors(); \ No newline at end of file