Skip to content

Commit

Permalink
[[CHORE]] Remove unreachable branch (#3467)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jugglinmike committed Apr 26, 2020
1 parent 75adb99 commit 5e36b79
Showing 1 changed file with 10 additions and 23 deletions.
33 changes: 10 additions & 23 deletions src/scope-manager.js
Expand Up @@ -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;

Expand Down

0 comments on commit 5e36b79

Please sign in to comment.