mirror of
https://github.com/swc-project/swc.git
synced 2024-11-24 02:06:08 +03:00
fix(es/minifier): Report is_fn_local
even if var is hoisted (#7876)
**Related issue:** - Closes #7847
This commit is contained in:
parent
c31f05a675
commit
87a47bfb2c
@ -47,7 +47,6 @@ impl Optimizer<'_> {
|
||||
|
||||
// We only handle identifiers on lhs for now.
|
||||
if let Some(lhs) = assign.left.as_ident() {
|
||||
//
|
||||
if self
|
||||
.data
|
||||
.vars
|
||||
|
@ -315,7 +315,7 @@ impl Storage for ProgramData {
|
||||
}
|
||||
}
|
||||
ScopeKind::Block => {
|
||||
if var_info.used_in_non_child_fn {
|
||||
if e.get().used_in_non_child_fn {
|
||||
e.get_mut().is_fn_local = false;
|
||||
e.get_mut().used_in_non_child_fn = true;
|
||||
}
|
||||
|
17
crates/swc_ecma_minifier/tests/fixture/issues/7847/input.js
Normal file
17
crates/swc_ecma_minifier/tests/fixture/issues/7847/input.js
Normal file
@ -0,0 +1,17 @@
|
||||
function requireState() {
|
||||
if (hasRequiredState) return state;
|
||||
hasRequiredState = 1;
|
||||
return state = {
|
||||
getHighWaterMark: function(o) {
|
||||
return o.objectMode ? 16 : 16384;
|
||||
}
|
||||
};
|
||||
}
|
||||
if (g()) {
|
||||
var state, hasRequiredState;
|
||||
const a = requireState()
|
||||
console.log(a.getHighWaterMark())
|
||||
|
||||
const b = requireState()
|
||||
console.log(b.getHighWaterMark())
|
||||
}
|
14
crates/swc_ecma_minifier/tests/fixture/issues/7847/output.js
Normal file
14
crates/swc_ecma_minifier/tests/fixture/issues/7847/output.js
Normal file
@ -0,0 +1,14 @@
|
||||
function requireState() {
|
||||
return hasRequiredState ? state : (hasRequiredState = 1, state = {
|
||||
getHighWaterMark: function(o) {
|
||||
return o.objectMode ? 16 : 16384;
|
||||
}
|
||||
});
|
||||
}
|
||||
if (g()) {
|
||||
var state, hasRequiredState;
|
||||
const a = requireState();
|
||||
console.log(a.getHighWaterMark());
|
||||
const b = requireState();
|
||||
console.log(b.getHighWaterMark());
|
||||
}
|
Loading…
Reference in New Issue
Block a user