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::{ use crate::{
compress::optimize::{util::Remapper, Ctx}, compress::optimize::{util::Remapper, Ctx},
mode::Mode, 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`. /// 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 self.ctx.executed_multiple_time {
if !param_ids.is_empty() { if !param_ids.is_empty() {
let captured = idents_captured_by(body); 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

@ -17556,115 +17556,120 @@
}(); }();
}, },
1951: function(module) { 1951: function(module) {
var __webpack_modules__, __webpack_exports__, __dirname = "/"; var __dirname = "/";
__webpack_modules__ = { !function() {
965: function(__unused_webpack_module, exports) { var __webpack_modules__ = {
var indexOf = function(e, t) { 965: function(__unused_webpack_module, exports) {
if (e.indexOf) return e.indexOf(t); var indexOf = function(e, t) {
for(var r = 0; r < e.length; r++)if (e[r] === t) return r; if (e.indexOf) return e.indexOf(t);
return -1; for(var r = 0; r < e.length; r++)if (e[r] === t) return r;
}, Object_keys = function(e) { return -1;
if (Object.keys) return Object.keys(e); }, Object_keys = function(e) {
var t = []; if (Object.keys) return Object.keys(e);
for(var r in e)t.push(r); var t = [];
return t; for(var r in e)t.push(r);
}, forEach = function(e, t) { return t;
if (e.forEach) return e.forEach(t); }, forEach = function(e, t) {
for(var r = 0; r < e.length; r++)t(e[r], r, e); if (e.forEach) return e.forEach(t);
}, defineProp = function() { for(var r = 0; r < e.length; r++)t(e[r], r, e);
try { }, defineProp = function() {
return Object.defineProperty({}, "_", {}), function(e, t, r) { try {
Object.defineProperty(e, t, { return Object.defineProperty({}, "_", {}), function(e, t, r) {
writable: !0, Object.defineProperty(e, t, {
enumerable: !1, writable: !0,
configurable: !0, enumerable: !1,
value: r configurable: !0,
}); value: r
}; });
} catch (e) { };
return function(e, t, r) { } catch (e) {
e[t] = r; return function(e, t, r) {
}; e[t] = r;
} };
}(), globals = [ }
"Array", }(), globals = [
"Boolean", "Array",
"Date", "Boolean",
"Error", "Date",
"EvalError", "Error",
"Function", "EvalError",
"Infinity", "Function",
"JSON", "Infinity",
"Math", "JSON",
"NaN", "Math",
"Number", "NaN",
"Object", "Number",
"RangeError", "Object",
"ReferenceError", "RangeError",
"RegExp", "ReferenceError",
"String", "RegExp",
"SyntaxError", "String",
"TypeError", "SyntaxError",
"URIError", "TypeError",
"decodeURI", "URIError",
"decodeURIComponent", "decodeURI",
"encodeURI", "decodeURIComponent",
"encodeURIComponent", "encodeURI",
"escape", "encodeURIComponent",
"eval", "escape",
"isFinite", "eval",
"isNaN", "isFinite",
"parseFloat", "isNaN",
"parseInt", "parseFloat",
"undefined", "parseInt",
"unescape" "undefined",
]; "unescape"
function Context() {} ];
Context.prototype = {}; function Context() {}
var Script = exports.Script = function(e) { Context.prototype = {};
if (!(this instanceof Script)) return new Script(e); var Script = exports.Script = function(e) {
this.code = e; if (!(this instanceof Script)) return new Script(e);
}; this.code = e;
Script.prototype.runInContext = function(e) {
if (!(e instanceof Context)) throw TypeError("needs a 'context' argument.");
var t = document.createElement("iframe");
t.style || (t.style = {}), t.style.display = "none", document.body.appendChild(t);
var r = t.contentWindow, n = r.eval, o = r.execScript;
!n && o && (o.call(r, "null"), n = r.eval), forEach(Object_keys(e), function(t) {
r[t] = e[t];
}), forEach(globals, function(t) {
e[t] && (r[t] = e[t]);
});
var c = Object_keys(r), i = n.call(r, this.code);
return forEach(Object_keys(r), function(t) {
(t in e || -1 === indexOf(c, t)) && (e[t] = r[t]);
}), forEach(globals, function(t) {
t in e || defineProp(e, t, r[t]);
}), document.body.removeChild(t), i;
}, Script.prototype.runInThisContext = function() {
return eval(this.code);
}, Script.prototype.runInNewContext = function(e) {
var t = Script.createContext(e), r = this.runInContext(t);
return e && forEach(Object_keys(t), function(r) {
e[r] = t[r];
}), r;
}, forEach(Object_keys(Script.prototype), function(e) {
exports[e] = Script[e] = function(t) {
var r = Script(t);
return r[e].apply(r, [].slice.call(arguments, 1));
}; };
}), exports.isContext = function(e) { Script.prototype.runInContext = function(e) {
return e instanceof Context; if (!(e instanceof Context)) throw TypeError("needs a 'context' argument.");
}, exports.createScript = function(e) { var t = document.createElement("iframe");
return exports.Script(e); t.style || (t.style = {}), t.style.display = "none", document.body.appendChild(t);
}, exports.createContext = Script.createContext = function(e) { var r = t.contentWindow, n = r.eval, o = r.execScript;
var t = new Context; !n && o && (o.call(r, "null"), n = r.eval), forEach(Object_keys(e), function(t) {
return "object" == typeof e && forEach(Object_keys(e), function(r) { r[t] = e[t];
t[r] = e[r]; }), forEach(globals, function(t) {
}), t; e[t] && (r[t] = e[t]);
}; });
} var c = Object_keys(r), i = n.call(r, this.code);
}, "undefined" != typeof __nccwpck_require__ && (__nccwpck_require__.ab = __dirname + "/"), __webpack_exports__ = {}, __webpack_modules__[965](0, __webpack_exports__), module.exports = __webpack_exports__; return forEach(Object_keys(r), function(t) {
(t in e || -1 === indexOf(c, t)) && (e[t] = r[t]);
}), forEach(globals, function(t) {
t in e || defineProp(e, t, r[t]);
}), document.body.removeChild(t), i;
}, Script.prototype.runInThisContext = function() {
return eval(this.code);
}, Script.prototype.runInNewContext = function(e) {
var t = Script.createContext(e), r = this.runInContext(t);
return e && forEach(Object_keys(t), function(r) {
e[r] = t[r];
}), r;
}, forEach(Object_keys(Script.prototype), function(e) {
exports[e] = Script[e] = function(t) {
var r = Script(t);
return r[e].apply(r, [].slice.call(arguments, 1));
};
}), exports.isContext = function(e) {
return e instanceof Context;
}, exports.createScript = function(e) {
return exports.Script(e);
}, exports.createContext = Script.createContext = function(e) {
var t = new Context;
return "object" == typeof e && forEach(Object_keys(e), function(r) {
t[r] = e[r];
}), t;
};
}
};
"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__) { 4375: function(module, __unused_webpack_exports, __webpack_require__) {
let promise; let promise;