fix(es/minifier): Abort IIFE invoker on eval (#6478)

**Related issue:**

 - https://github.com/vercel/next.js/issues/43052.
This commit is contained in:
Donny/강동윤 2022-12-13 13:18:57 +09:00 committed by GitHub
parent 581d9ce769
commit 8b2e1d17e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 1473 additions and 1384 deletions

View File

@ -15,7 +15,7 @@ use crate::debug::dump;
use crate::{
compress::optimize::{util::Remapper, Ctx},
mode::Mode,
util::{idents_captured_by, idents_used_by, make_number},
util::{contains_eval, idents_captured_by, idents_used_by, make_number},
};
/// Methods related to the option `negate_iife`.
@ -728,6 +728,13 @@ where
}
}
// Abort on eval.
// See https://github.com/swc-project/swc/pull/6478
if contains_eval(body, false) {
log_abort!("iife: [x] Aborting because of eval");
return false;
}
if self.ctx.executed_multiple_time {
if !param_ids.is_empty() {
let captured = idents_captured_by(body);

View File

@ -0,0 +1,6 @@
{
"defaults": false,
"toplevel": true,
"passes": 2,
"inline": true
}

View File

@ -0,0 +1,37 @@
use((function (__unused_webpack_module, exports, __webpack_require__) {
! function (e, t) {
true ? t(exports, __webpack_require__(7294), __webpack_require__(1321)) : 0
}(this, (function (exports, React) {
"use strict";
var index_production = {
exports: {}
};
(function (module, exports) {
var t;
t = function (exports) {
function inquire(moduleName) {
try {
var mod = eval("quire".replace(/^/, "re"))(moduleName);
if (mod && (mod.length || Object.keys(mod).length)) return mod
} catch (e) { }
return null
}
Object.defineProperty(exports, "__esModule", {
value: !0
})
}, t(exports)
})(index_production, index_production.exports);
exports.chunkBlocks = index_production.exports.chunkBlocks, exports.encodeDirectory = index_production.exports.encodeDirectory, exports.encodeFile = index_production.exports.encodeFile, Object.defineProperty(exports, "__esModule", {
value: !0
})
}));
}));
(function checkMangler() {
const longName = 1;
use(longName)
})

View File

@ -0,0 +1 @@
{}

View File

@ -0,0 +1,31 @@
use(function(__unused_webpack_module, exports, __webpack_require__) {
var e, t;
e = this, t = function(exports, React) {
"use strict";
var index_production = {
exports: {}
};
(function(module, exports) {
var t;
t = function(exports) {
function inquire(moduleName) {
try {
var mod = eval("quire".replace(/^/, "re"))(moduleName);
if (mod && (mod.length || Object.keys(mod).length)) return mod;
} catch (e) {}
return null;
}
Object.defineProperty(exports, "__esModule", {
value: !0
});
}, t(exports);
})(index_production, index_production.exports);
exports.chunkBlocks = index_production.exports.chunkBlocks, exports.encodeDirectory = index_production.exports.encodeDirectory, exports.encodeFile = index_production.exports.encodeFile, Object.defineProperty(exports, "__esModule", {
value: !0
});
}, t(exports, __webpack_require__(7294), __webpack_require__(1321)), true;
});
(function e() {
const e = 1;
use(e);
});

View File

@ -4,7 +4,8 @@
],
{
7029: function(t, e, r) {
r.g, t.exports = (()=>{
r.g, t.exports = function() {
return (()=>{
var t = {
873: (t)=>{
t.exports = function(t) {
@ -1299,6 +1300,7 @@
}(y()));
})(), n;
})();
}();
},
9720: function(t, e, r) {
var o = r(1876).Buffer, n = r(3454);

View File

@ -17556,8 +17556,9 @@
}();
},
1951: function(module) {
var __webpack_modules__, __webpack_exports__, __dirname = "/";
__webpack_modules__ = {
var __dirname = "/";
!function() {
var __webpack_modules__ = {
965: function(__unused_webpack_module, exports) {
var indexOf = function(e, t) {
if (e.indexOf) return e.indexOf(t);
@ -17664,7 +17665,11 @@
}), t;
};
}
}, "undefined" != typeof __nccwpck_require__ && (__nccwpck_require__.ab = __dirname + "/"), __webpack_exports__ = {}, __webpack_modules__[965](0, __webpack_exports__), module.exports = __webpack_exports__;
};
"undefined" != typeof __nccwpck_require__ && (__nccwpck_require__.ab = __dirname + "/");
var __webpack_exports__ = {};
__webpack_modules__[965](0, __webpack_exports__), module.exports = __webpack_exports__;
}();
},
4375: function(module, __unused_webpack_exports, __webpack_require__) {
let promise;