Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(es/minifier): Don't drop used variables from sequential inliner #6520

Merged
merged 10 commits into from Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -4,4 +4,4 @@ var a, x = {}, y = {
};
x = a, y = a, a = x, a = y;
var s = "fooo";
a = 123, a = !0, n = a = s, b = a, s = a, a = 123, a = !0, a = "string";
a = 123, a = !0, s = a = s, a = 123, a = !0, a = "string";
Expand Up @@ -2222,7 +2222,8 @@ where
if let Some(usage) = self.data.vars.get(&left_id.to_id()) {
// We are eliminating one usage, so we use 1 instead of
// 0
if !$force_drop && usage.usage_count == 1 {
if !$force_drop && usage.usage_count == 1 && usage.assign_count == 0
{
report_change!("sequences: Dropping inlined variable");
a.name.take();
}
Expand Down
26 changes: 26 additions & 0 deletions crates/swc_ecma_minifier/tests/fixture/next/joda/input.js
@@ -0,0 +1,26 @@
"use strict";
(self["webpackChunk_N_E"] = self["webpackChunk_N_E"] || []).push([[715], {

/***/ 3266:
/***/ (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {

/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "h": function () { return /* binding */ LocalDate; }
/* harmony export */
});

var isInit = false;

function init() {
if (isInit) {
return;
}

isInit = true;
}

init();

})

}]);
15 changes: 15 additions & 0 deletions crates/swc_ecma_minifier/tests/fixture/next/joda/output.js
@@ -0,0 +1,15 @@
"use strict";
(self.webpackChunk_N_E = self.webpackChunk_N_E || []).push([
[
715
],
{
3266: function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
__webpack_require__.d(__webpack_exports__, {
h: function() {
return LocalDate;
}
});
}
}
]);
26 changes: 26 additions & 0 deletions crates/swc_ecma_minifier/tests/pass-1/joda/1/input.js
@@ -0,0 +1,26 @@
"use strict";
(self["webpackChunk_N_E"] = self["webpackChunk_N_E"] || []).push([[715], {

/***/ 3266:
/***/ (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {

/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "h": function () { return /* binding */ LocalDate; }
/* harmony export */
});

var isInit = false;

function init() {
if (isInit) {
return;
}

isInit = true;
}

init();

})

}]);
19 changes: 19 additions & 0 deletions crates/swc_ecma_minifier/tests/pass-1/joda/1/output.js
@@ -0,0 +1,19 @@
"use strict";
(self.webpackChunk_N_E = self.webpackChunk_N_E || []).push([
[
715
],
{
3266: function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
__webpack_require__.d(__webpack_exports__, {
h: function() {
return LocalDate;
}
});
var isInit = !1;
!function() {
if (!isInit) isInit = !0;
}();
}
}
]);
19 changes: 19 additions & 0 deletions crates/swc_ecma_minifier/tests/pass-1/joda/2/input.js
@@ -0,0 +1,19 @@
"use strict";
(self.webpackChunk_N_E = self.webpackChunk_N_E || []).push([
[
715
],
{
3266: function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
__webpack_require__.d(__webpack_exports__, {
h: function () {
return LocalDate;
}
});
var isInit = !1;
!function () {
if (!isInit) isInit = !0;
}();
}
}
]);
17 changes: 17 additions & 0 deletions crates/swc_ecma_minifier/tests/pass-1/joda/2/output.js
@@ -0,0 +1,17 @@
"use strict";
(self.webpackChunk_N_E = self.webpackChunk_N_E || []).push([
[
715
],
{
3266: function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
__webpack_require__.d(__webpack_exports__, {
h: function() {
return LocalDate;
}
});
var isInit = !1;
isInit = !0;
}
}
]);