This diff adds the ability to skip unreachable require() calls - it's turned on by default, but may be turned off by passing the {unreachables: true} option. This is originally from my unreachable-branch-transform. However, for performance considerations and from a "this-is-how-it-should-work" perspective, it makes sense to have this functionality baked into node-detective.
"Unreachability" is determined by very basic static analysis of if statements, ternaries (?) and logical short-circuit evaluations (||/&&). switchs and whiles are not analyzed. Only the operations that can be statically determined are considered - there is no guessing or heuristics - it's 100% safe. Once a code branch is determined to be unreachable, traversal of its children is aborted, but the rest continues.
Integrating with browserify:
browserify users should ideally have control over this option. browserify already passes options to module-deps, but module-deps does not pass options to detective. If this diff is merged. I'll submit the appropriate downstream PRs to address this.
The additional analysis logic has a negligible performance impact:
This diff adds the ability to skip unreachable
require()
calls - it's turned on by default, but may be turned off by passing the{unreachables: true}
option. This is originally from myunreachable-branch-transform
. However, for performance considerations and from a "this-is-how-it-should-work" perspective, it makes sense to have this functionality baked intonode-detective
."Unreachability" is determined by very basic static analysis of
if
statements, ternaries (?
) and logical short-circuit evaluations (||
/&&
).switch
s andwhile
s are not analyzed. Only the operations that can be statically determined are considered - there is no guessing or heuristics - it's 100% safe. Once a code branch is determined to be unreachable, traversal of its children is aborted, but the rest continues.Integrating with browserify: browserify users should ideally have control over this option. browserify already passes options to module-deps, but module-deps does not pass options to detective. If this diff is merged. I'll submit the appropriate downstream PRs to address this.
The additional analysis logic has a negligible performance impact:
cc: @substack