From 004f800eb9e80121e09d5a847bac68510e5fd6b9 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Mon, 18 Nov 2019 09:06:31 +0100 Subject: [PATCH] Do not truncate after switch-statement with removed case --- src/ast/nodes/SwitchStatement.ts | 2 ++ .../switch-statements-removed-default/_config.js | 3 +++ .../samples/switch-statements-removed-default/main.js | 10 ++++++++++ 3 files changed, 15 insertions(+) create mode 100644 test/function/samples/switch-statements-removed-default/_config.js create mode 100644 test/function/samples/switch-statements-removed-default/main.js diff --git a/src/ast/nodes/SwitchStatement.ts b/src/ast/nodes/SwitchStatement.ts index 7939b8ac0b0..2850b18f122 100644 --- a/src/ast/nodes/SwitchStatement.ts +++ b/src/ast/nodes/SwitchStatement.ts @@ -65,6 +65,8 @@ export default class SwitchStatement extends StatementBase { switchCase.include(context, includeChildrenRecursively); minBrokenFlow = minBrokenFlow < context.brokenFlow ? minBrokenFlow : context.brokenFlow; context.brokenFlow = brokenFlow; + } else { + minBrokenFlow = brokenFlow; } } if ( diff --git a/test/function/samples/switch-statements-removed-default/_config.js b/test/function/samples/switch-statements-removed-default/_config.js new file mode 100644 index 00000000000..2c58f54526d --- /dev/null +++ b/test/function/samples/switch-statements-removed-default/_config.js @@ -0,0 +1,3 @@ +module.exports = { + description: 'does not remove code after a switch statement that should be retained' +}; diff --git a/test/function/samples/switch-statements-removed-default/main.js b/test/function/samples/switch-statements-removed-default/main.js new file mode 100644 index 00000000000..034104555ba --- /dev/null +++ b/test/function/samples/switch-statements-removed-default/main.js @@ -0,0 +1,10 @@ +function performSwitch(value) { + switch (value) { + case 'foo': + return false; + default: + } + return true; +} + +assert.ok(performSwitch('baz'));