feat: support import specifier guard by hai-x · Pull Request #20320 · webpack/webpack
Summary
Fixes #14814 and closes #15497.
What kind of change does this PR introduce?
Support import specifier guard detection.
For example:
import * as ns from "react"
if(ns.foo){ // create guard for `ns` => ns: ["", "foo"].
ns.foo; // ns->"foo" is in guard.
ns; // ns->"" is in guard.
}
We will firstly walk expression in IfStatement.test (the same as for ConditionalExpression) to collect import specifier guards which will be tagged to the harmonySpecifierTag variable. Then, while walk both IfStatement.test and the IfStatement.consequent(the same as for ConditionalExpression), we visit these guards to determine whether the export is present at runtime.
Did you add tests for your changes?
Yes
Does this PR introduce a breaking change?
No
If relevant, what needs to be documented once your changes are merged or what have you already documented?
No