From 5e36b790bcafdcca9e9b01d80bc966fc2c1a0a85 Mon Sep 17 00:00:00 2001 From: jugglinmike Date: Sun, 26 Apr 2020 16:21:53 -0400 Subject: [PATCH] [[CHORE]] Remove unreachable branch (#3467) The `_checkParams` function included a guard to ensure it was only invoked in appropriate situations. Because its one and only call site was itself guarded by an equivalent condition, the branch in `_checkParams` was unreachable. Although this situation made the internal guard of `_checkParams` safe to remove, doing so would have made the function more dangerous in general since anyone introducing new invocations in the future would have to take care to perform a similar check. To avoid introducing such a dangerous interface, remove the function entirely and inline its body at its only call site. --- src/scope-manager.js | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/src/scope-manager.js b/src/scope-manager.js index e27c71fd50..ee6f8a528e 100644 --- a/src/scope-manager.js +++ b/src/scope-manager.js @@ -137,34 +137,21 @@ var scopeManager = function(state, predefined, exported, declared) { * Check the current scope for unused identifiers */ function _checkForUnused() { - // function parameters are validated by a dedicated function - // assume that parameters are the only thing declared in the param scope - if (_current["(type)"] === "functionparams") { - _checkParams(); - return; - } - var currentBindings = _current["(bindings)"]; - for (var bindingName in currentBindings) { - if (currentBindings[bindingName]["(type)"] !== "exception" && - currentBindings[bindingName]["(unused)"]) { - _warnUnused(bindingName, currentBindings[bindingName]["(token)"], "var"); + if (_current["(type)"] !== "functionparams") { + var currentBindings = _current["(bindings)"]; + for (var bindingName in currentBindings) { + if (currentBindings[bindingName]["(type)"] !== "exception" && + currentBindings[bindingName]["(unused)"]) { + _warnUnused(bindingName, currentBindings[bindingName]["(token)"], "var"); + } } + return; } - } - /** - * Check the current scope for unused parameters and issue warnings as - * necessary. This function may only be invoked when the current scope is a - * "function parameter" scope. - */ - function _checkParams() { + // Check the current scope for unused parameters and issue warnings as + // necessary. var params = _current["(params)"]; - if (!params) { - /* istanbul ignore next */ - return; - } - var param = params.pop(); var unused_opt;