diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 6f0f1ac7863..fef23770475 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -912,8 +912,8 @@ namespace ts { preSwitchCaseFlow = currentFlow; bind(node.caseBlock); addAntecedent(postSwitchLabel, currentFlow); - const hasDefault = forEach(node.caseBlock.clauses, c => c.kind === SyntaxKind.DefaultClause); - if (!hasDefault) { + const hasNonEmptyDefault = forEach(node.caseBlock.clauses, c => c.kind === SyntaxKind.DefaultClause && c.statements.length); + if (!hasNonEmptyDefault) { addAntecedent(postSwitchLabel, preSwitchCaseFlow); } currentBreakTarget = saveBreakTarget; diff --git a/tests/baselines/reference/reachabilityCheckWithEmptyDefault.js b/tests/baselines/reference/reachabilityCheckWithEmptyDefault.js new file mode 100644 index 00000000000..0096d2d2f9a --- /dev/null +++ b/tests/baselines/reference/reachabilityCheckWithEmptyDefault.js @@ -0,0 +1,18 @@ +//// [reachabilityCheckWithEmptyDefault.ts] +declare function print(s: string): void; +function foo(x: any) { + switch(x) { + case 1: return; + default: + } + print('1'); +} + +//// [reachabilityCheckWithEmptyDefault.js] +function foo(x) { + switch (x) { + case 1: return; + default: + } + print('1'); +} diff --git a/tests/baselines/reference/reachabilityCheckWithEmptyDefault.symbols b/tests/baselines/reference/reachabilityCheckWithEmptyDefault.symbols new file mode 100644 index 00000000000..d3123c0e8ba --- /dev/null +++ b/tests/baselines/reference/reachabilityCheckWithEmptyDefault.symbols @@ -0,0 +1,18 @@ +=== tests/cases/compiler/reachabilityCheckWithEmptyDefault.ts === +declare function print(s: string): void; +>print : Symbol(print, Decl(reachabilityCheckWithEmptyDefault.ts, 0, 0)) +>s : Symbol(s, Decl(reachabilityCheckWithEmptyDefault.ts, 0, 23)) + +function foo(x: any) { +>foo : Symbol(foo, Decl(reachabilityCheckWithEmptyDefault.ts, 0, 40)) +>x : Symbol(x, Decl(reachabilityCheckWithEmptyDefault.ts, 1, 13)) + + switch(x) { +>x : Symbol(x, Decl(reachabilityCheckWithEmptyDefault.ts, 1, 13)) + + case 1: return; + default: + } + print('1'); +>print : Symbol(print, Decl(reachabilityCheckWithEmptyDefault.ts, 0, 0)) +} diff --git a/tests/baselines/reference/reachabilityCheckWithEmptyDefault.types b/tests/baselines/reference/reachabilityCheckWithEmptyDefault.types new file mode 100644 index 00000000000..3d01b876473 --- /dev/null +++ b/tests/baselines/reference/reachabilityCheckWithEmptyDefault.types @@ -0,0 +1,22 @@ +=== tests/cases/compiler/reachabilityCheckWithEmptyDefault.ts === +declare function print(s: string): void; +>print : (s: string) => void +>s : string + +function foo(x: any) { +>foo : (x: any) => void +>x : any + + switch(x) { +>x : any + + case 1: return; +>1 : number + + default: + } + print('1'); +>print('1') : void +>print : (s: string) => void +>'1' : string +} diff --git a/tests/cases/compiler/reachabilityCheckWithEmptyDefault.ts b/tests/cases/compiler/reachabilityCheckWithEmptyDefault.ts new file mode 100644 index 00000000000..6429528a0da --- /dev/null +++ b/tests/cases/compiler/reachabilityCheckWithEmptyDefault.ts @@ -0,0 +1,8 @@ +declare function print(s: string): void; +function foo(x: any) { + switch(x) { + case 1: return; + default: + } + print('1'); +} \ No newline at end of file