Skip to content

Commit 86e2bb0

Browse files
authored
fix(es/minifier): Increment ref_count while invoking IIFE (#8904)
**Related issue:** - Closes #8880
1 parent 579a1de commit 86e2bb0

File tree

6 files changed

+336
-2
lines changed

6 files changed

+336
-2
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{
2+
"jsc": {
3+
"externalHelpers": true,
4+
"parser": {
5+
"syntax": "typescript",
6+
"tsx": false
7+
},
8+
"transform": {
9+
"legacyDecorator": true,
10+
},
11+
"target": "es2017",
12+
"loose": false,
13+
"minify": {
14+
"compress": {
15+
"arguments": false,
16+
"arrows": true,
17+
"booleans": false,
18+
"booleans_as_integers": false,
19+
"collapse_vars": true,
20+
"comparisons": true,
21+
"computed_props": true,
22+
"conditionals": true,
23+
"dead_code": true,
24+
"directives": true,
25+
"drop_console": false,
26+
"drop_debugger": true,
27+
"evaluate": true,
28+
"expression": false,
29+
"hoist_funs": false,
30+
"hoist_props": true,
31+
"hoist_vars": false,
32+
"if_return": true,
33+
"join_vars": false,
34+
"keep_classnames": false,
35+
"keep_fargs": true,
36+
"keep_fnames": false,
37+
"keep_infinity": false,
38+
"loops": false,
39+
"negate_iife": false,
40+
"properties": false,
41+
"reduce_funcs": false,
42+
"reduce_vars": false,
43+
"side_effects": true,
44+
"switches": false,
45+
"typeofs": false,
46+
"unsafe": false,
47+
"unsafe_arrows": false,
48+
"unsafe_comps": false,
49+
"unsafe_Function": false,
50+
"unsafe_math": false,
51+
"unsafe_symbols": false,
52+
"unsafe_methods": false,
53+
"unsafe_proto": false,
54+
"unsafe_regexp": false,
55+
"unsafe_undefined": false,
56+
"unused": false,
57+
"const_to_let": false,
58+
"pristine_globals": true,
59+
"sequences": false,
60+
"passes": 2,
61+
},
62+
"mangle": false
63+
}
64+
},
65+
"module": {
66+
"type": "es6"
67+
},
68+
"minify": false,
69+
"isModule": true
70+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
function a(module, exports, farmRequire, farmDynamicRequire) {
2+
"use strict";
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
const _interop_require_default = farmRequire("@swc/helpers/_/_interop_require_default");
7+
const _typeof = _interop_require_default._(farmRequire("8178b9bd"));
8+
const _dep734fea04 = farmRequire("92648bed");
9+
const _dayjs = _interop_require_default._(farmRequire("d0dc4dad"));
10+
farmRequire("15d5169f");
11+
var zhCn = (0, _dep734fea04.c)(function (module, exports) {
12+
!function (e__1, _) {
13+
"object" == 'object' && "undefined" != 'object' ? module.exports = _(_dayjs.default) : "function" == typeof undefined && undefined.amd ? undefined([
14+
"dayjs"
15+
], _) : (e__1 = "undefined" != typeof globalThis ? globalThis : e__1 || self).dayjs_locale_zh_cn = _(e__1.dayjs);
16+
}(_dep734fea04.a, function (e__2) {
17+
"use strict";
18+
function _(e__3) {
19+
return e__3 && "object" == (0, _typeof.default)(e__3) && "default" in e__3 ? e__3 : {
20+
"default": e__3
21+
};
22+
}
23+
var t = _(e__2), d = {
24+
name: "zh-cn",
25+
weekdays: "星期日_星期一_星期二_星期三_星期四_星期五_星期六".split("_"),
26+
weekdaysShort: "周日_周一_周二_周三_周四_周五_周六".split("_"),
27+
weekdaysMin: "日_一_二_三_四_五_六".split("_"),
28+
months: "一月_二月_三月_四月_五月_六月_七月_八月_九月_十月_十一月_十二月".split("_"),
29+
monthsShort: "1月_2月_3月_4月_5月_6月_7月_8月_9月_10月_11月_12月".split("_"),
30+
ordinal: function ordinal(e, _) {
31+
return "W" === _ ? e + "周" : e + "日";
32+
},
33+
weekStart: 1,
34+
yearStart: 4,
35+
formats: {
36+
LT: "HH:mm",
37+
LTS: "HH:mm:ss",
38+
L: "YYYY/MM/DD",
39+
LL: "YYYY年M月D日",
40+
LLL: "YYYY年M月D日Ah点mm分",
41+
LLLL: "YYYY年M月D日ddddAh点mm分",
42+
l: "YYYY/M/D",
43+
ll: "YYYY年M月D日",
44+
lll: "YYYY年M月D日 HH:mm",
45+
llll: "YYYY年M月D日dddd HH:mm"
46+
},
47+
relativeTime: {
48+
future: "%s内",
49+
past: "%s前",
50+
s: "几秒",
51+
m: "1 分钟",
52+
mm: "%d 分钟",
53+
h: "1 小时",
54+
hh: "%d 小时",
55+
d: "1 天",
56+
dd: "%d 天",
57+
M: "1 个月",
58+
MM: "%d 个月",
59+
y: "1 年",
60+
yy: "%d 年"
61+
},
62+
meridiem: function meridiem(e, _) {
63+
var t = 100 * e + _;
64+
return t < 600 ? "凌晨" : t < 900 ? "早上" : t < 1100 ? "上午" : t < 1300 ? "中午" : t < 1800 ? "下午" : "晚上";
65+
}
66+
};
67+
return t["default"].locale(d, null, !0), d;
68+
});
69+
});
70+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
function a(module, exports, farmRequire, farmDynamicRequire) {
2+
Object.defineProperty(exports, "__esModule", {
3+
value: true
4+
});
5+
const _interop_require_default = farmRequire("@swc/helpers/_/_interop_require_default");
6+
const _typeof = _interop_require_default._(farmRequire("8178b9bd"));
7+
const _dep734fea04 = farmRequire("92648bed");
8+
const _dayjs = _interop_require_default._(farmRequire("d0dc4dad"));
9+
farmRequire("15d5169f");
10+
(0, _dep734fea04.c)(function(module, exports) {
11+
var e__1, _;
12+
e__1 = _dep734fea04.a, _ = function(e__2) {
13+
var e__3;
14+
var t = e__2 && "object" == (0, _typeof.default)(e__2) && "default" in e__2 ? e__2 : {
15+
default: e__2
16+
}, d = {
17+
name: "zh-cn",
18+
weekdays: "星期日_星期一_星期二_星期三_星期四_星期五_星期六".split("_"),
19+
weekdaysShort: "周日_周一_周二_周三_周四_周五_周六".split("_"),
20+
weekdaysMin: "日_一_二_三_四_五_六".split("_"),
21+
months: "一月_二月_三月_四月_五月_六月_七月_八月_九月_十月_十一月_十二月".split("_"),
22+
monthsShort: "1月_2月_3月_4月_5月_6月_7月_8月_9月_10月_11月_12月".split("_"),
23+
ordinal: function ordinal(e, _) {
24+
return "W" === _ ? e + "周" : e + "日";
25+
},
26+
weekStart: 1,
27+
yearStart: 4,
28+
formats: {
29+
LT: "HH:mm",
30+
LTS: "HH:mm:ss",
31+
L: "YYYY/MM/DD",
32+
LL: "YYYY年M月D日",
33+
LLL: "YYYY年M月D日Ah点mm分",
34+
LLLL: "YYYY年M月D日ddddAh点mm分",
35+
l: "YYYY/M/D",
36+
ll: "YYYY年M月D日",
37+
lll: "YYYY年M月D日 HH:mm",
38+
llll: "YYYY年M月D日dddd HH:mm"
39+
},
40+
relativeTime: {
41+
future: "%s内",
42+
past: "%s前",
43+
s: "几秒",
44+
m: "1 分钟",
45+
mm: "%d 分钟",
46+
h: "1 小时",
47+
hh: "%d 小时",
48+
d: "1 天",
49+
dd: "%d 天",
50+
M: "1 个月",
51+
MM: "%d 个月",
52+
y: "1 年",
53+
yy: "%d 年"
54+
},
55+
meridiem: function meridiem(e, _) {
56+
var t = 100 * e + _;
57+
return t < 600 ? "凌晨" : t < 900 ? "早上" : t < 1100 ? "上午" : t < 1300 ? "中午" : t < 1800 ? "下午" : "晚上";
58+
}
59+
};
60+
return t["default"].locale(d, null, !0), d;
61+
}, module.exports = _(_dayjs.default);
62+
});
63+
}

crates/swc_ecma_minifier/src/compress/optimize/iife.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ impl Optimizer<'_> {
655655
let new = self.inline_fn_like(&param_ids, body, &mut call.args);
656656
if let Some(new) = new {
657657
self.changed = true;
658-
report_change!("inline: Inlining a function call");
658+
report_change!("inline: Inlining a function call (params = {param_ids:?})");
659659

660660
dump_change_detail!("{}", dump(&new, false));
661661

@@ -849,7 +849,7 @@ impl Optimizer<'_> {
849849
let no_arg = arg.is_none();
850850

851851
if let Some(arg) = arg {
852-
if let Some(usage) = self.data.vars.get(&params[idx].to_id()) {
852+
if let Some(usage) = self.data.vars.get_mut(&params[idx].to_id()) {
853853
if usage.ref_count == 1
854854
&& !usage.reassigned
855855
&& usage.property_mutation_count == 0
@@ -864,6 +864,8 @@ impl Optimizer<'_> {
864864
self.vars.vars_for_inlining.insert(param.to_id(), arg);
865865
continue;
866866
}
867+
868+
usage.ref_count += 1;
867869
}
868870

869871
exprs.push(
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
export function a(module, exports, farmRequire, farmDynamicRequire) {
2+
"use strict";
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
const _interop_require_default = farmRequire("@swc/helpers/_/_interop_require_default");
7+
const _typeof = _interop_require_default._(farmRequire("8178b9bd"));
8+
const _dep734fea04 = farmRequire("92648bed");
9+
const _dayjs = _interop_require_default._(farmRequire("d0dc4dad"));
10+
farmRequire("15d5169f");
11+
var zhCn = (0, _dep734fea04.c)(function (module, exports) {
12+
!function (e, _) {
13+
module.exports = _(_dayjs.default);
14+
}(_dep734fea04.a, function (e) {
15+
"use strict";
16+
function _(e) {
17+
return e && "object" == (0, _typeof.default)(e) && "default" in e ? e : {
18+
default: e
19+
};
20+
}
21+
var t = _(e), d = {
22+
name: "zh-cn",
23+
weekdays: "星期日_星期一_星期二_星期三_星期四_星期五_星期六".split("_"),
24+
weekdaysShort: "周日_周一_周二_周三_周四_周五_周六".split("_"),
25+
weekdaysMin: "日_一_二_三_四_五_六".split("_"),
26+
months: "一月_二月_三月_四月_五月_六月_七月_八月_九月_十月_十一月_十二月".split("_"),
27+
monthsShort: "1月_2月_3月_4月_5月_6月_7月_8月_9月_10月_11月_12月".split("_"),
28+
ordinal: function ordinal(e, _) {
29+
return "W" === _ ? e + "周" : e + "日";
30+
},
31+
weekStart: 1,
32+
yearStart: 4,
33+
formats: {
34+
LT: "HH:mm",
35+
LTS: "HH:mm:ss",
36+
L: "YYYY/MM/DD",
37+
LL: "YYYY年M月D日",
38+
LLL: "YYYY年M月D日Ah点mm分",
39+
LLLL: "YYYY年M月D日ddddAh点mm分",
40+
l: "YYYY/M/D",
41+
ll: "YYYY年M月D日",
42+
lll: "YYYY年M月D日 HH:mm",
43+
llll: "YYYY年M月D日dddd HH:mm"
44+
},
45+
relativeTime: {
46+
future: "%s内",
47+
past: "%s前",
48+
s: "几秒",
49+
m: "1 分钟",
50+
mm: "%d 分钟",
51+
h: "1 小时",
52+
hh: "%d 小时",
53+
d: "1 天",
54+
dd: "%d 天",
55+
M: "1 个月",
56+
MM: "%d 个月",
57+
y: "1 年",
58+
yy: "%d 年"
59+
},
60+
meridiem: function meridiem(e, _) {
61+
var t = 100 * e + _;
62+
return t < 600 ? "凌晨" : t < 900 ? "早上" : t < 1100 ? "上午" : t < 1300 ? "中午" : t < 1800 ? "下午" : "晚上";
63+
}
64+
};
65+
return t.default.locale(d, null, !0), d;
66+
});
67+
});
68+
69+
return zhCn
70+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
export function a(module, exports, farmRequire, farmDynamicRequire) {
2+
"use strict";
3+
Object.defineProperty(exports, "__esModule", {
4+
value: !0
5+
});
6+
const _interop_require_default = farmRequire("@swc/helpers/_/_interop_require_default"), _typeof = _interop_require_default._(farmRequire("8178b9bd")), _dep734fea04 = farmRequire("92648bed"), _dayjs = _interop_require_default._(farmRequire("d0dc4dad"));
7+
return farmRequire("15d5169f"), (0, _dep734fea04.c)(function(module, exports) {
8+
var _;
9+
_dep734fea04.a, _ = function(e) {
10+
var t = e && "object" == (0, _typeof.default)(e) && "default" in e ? e : {
11+
default: e
12+
}, d = {
13+
name: "zh-cn",
14+
weekdays: "星期日_星期一_星期二_星期三_星期四_星期五_星期六".split("_"),
15+
weekdaysShort: "周日_周一_周二_周三_周四_周五_周六".split("_"),
16+
weekdaysMin: "日_一_二_三_四_五_六".split("_"),
17+
months: "一月_二月_三月_四月_五月_六月_七月_八月_九月_十月_十一月_十二月".split("_"),
18+
monthsShort: "1月_2月_3月_4月_5月_6月_7月_8月_9月_10月_11月_12月".split("_"),
19+
ordinal: function(e, _) {
20+
return "W" === _ ? e + "周" : e + "日";
21+
},
22+
weekStart: 1,
23+
yearStart: 4,
24+
formats: {
25+
LT: "HH:mm",
26+
LTS: "HH:mm:ss",
27+
L: "YYYY/MM/DD",
28+
LL: "YYYY年M月D日",
29+
LLL: "YYYY年M月D日Ah点mm分",
30+
LLLL: "YYYY年M月D日ddddAh点mm分",
31+
l: "YYYY/M/D",
32+
ll: "YYYY年M月D日",
33+
lll: "YYYY年M月D日 HH:mm",
34+
llll: "YYYY年M月D日dddd HH:mm"
35+
},
36+
relativeTime: {
37+
future: "%s内",
38+
past: "%s前",
39+
s: "几秒",
40+
m: "1 分钟",
41+
mm: "%d 分钟",
42+
h: "1 小时",
43+
hh: "%d 小时",
44+
d: "1 天",
45+
dd: "%d 天",
46+
M: "1 个月",
47+
MM: "%d 个月",
48+
y: "1 年",
49+
yy: "%d 年"
50+
},
51+
meridiem: function(e, _) {
52+
var t = 100 * e + _;
53+
return t < 600 ? "凌晨" : t < 900 ? "早上" : t < 1100 ? "上午" : t < 1300 ? "中午" : t < 1800 ? "下午" : "晚上";
54+
}
55+
};
56+
return t.default.locale(d, null, !0), d;
57+
}, module.exports = _(_dayjs.default);
58+
});
59+
}

0 commit comments

Comments
 (0)