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

@ -17556,115 +17556,120 @@
}();
},
1951: function(module) {
var __webpack_modules__, __webpack_exports__, __dirname = "/";
__webpack_modules__ = {
965: function(__unused_webpack_module, exports) {
var indexOf = function(e, t) {
if (e.indexOf) return e.indexOf(t);
for(var r = 0; r < e.length; r++)if (e[r] === t) return r;
return -1;
}, Object_keys = function(e) {
if (Object.keys) return Object.keys(e);
var t = [];
for(var r in e)t.push(r);
return t;
}, forEach = function(e, t) {
if (e.forEach) return e.forEach(t);
for(var r = 0; r < e.length; r++)t(e[r], r, e);
}, defineProp = function() {
try {
return Object.defineProperty({}, "_", {}), function(e, t, r) {
Object.defineProperty(e, t, {
writable: !0,
enumerable: !1,
configurable: !0,
value: r
});
};
} catch (e) {
return function(e, t, r) {
e[t] = r;
};
}
}(), globals = [
"Array",
"Boolean",
"Date",
"Error",
"EvalError",
"Function",
"Infinity",
"JSON",
"Math",
"NaN",
"Number",
"Object",
"RangeError",
"ReferenceError",
"RegExp",
"String",
"SyntaxError",
"TypeError",
"URIError",
"decodeURI",
"decodeURIComponent",
"encodeURI",
"encodeURIComponent",
"escape",
"eval",
"isFinite",
"isNaN",
"parseFloat",
"parseInt",
"undefined",
"unescape"
];
function Context() {}
Context.prototype = {};
var Script = exports.Script = function(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));
var __dirname = "/";
!function() {
var __webpack_modules__ = {
965: function(__unused_webpack_module, exports) {
var indexOf = function(e, t) {
if (e.indexOf) return e.indexOf(t);
for(var r = 0; r < e.length; r++)if (e[r] === t) return r;
return -1;
}, Object_keys = function(e) {
if (Object.keys) return Object.keys(e);
var t = [];
for(var r in e)t.push(r);
return t;
}, forEach = function(e, t) {
if (e.forEach) return e.forEach(t);
for(var r = 0; r < e.length; r++)t(e[r], r, e);
}, defineProp = function() {
try {
return Object.defineProperty({}, "_", {}), function(e, t, r) {
Object.defineProperty(e, t, {
writable: !0,
enumerable: !1,
configurable: !0,
value: r
});
};
} catch (e) {
return function(e, t, r) {
e[t] = r;
};
}
}(), globals = [
"Array",
"Boolean",
"Date",
"Error",
"EvalError",
"Function",
"Infinity",
"JSON",
"Math",
"NaN",
"Number",
"Object",
"RangeError",
"ReferenceError",
"RegExp",
"String",
"SyntaxError",
"TypeError",
"URIError",
"decodeURI",
"decodeURIComponent",
"encodeURI",
"encodeURIComponent",
"escape",
"eval",
"isFinite",
"isNaN",
"parseFloat",
"parseInt",
"undefined",
"unescape"
];
function Context() {}
Context.prototype = {};
var Script = exports.Script = function(e) {
if (!(this instanceof Script)) return new Script(e);
this.code = e;
};
}), 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 + "/"), __webpack_exports__ = {}, __webpack_modules__[965](0, __webpack_exports__), module.exports = __webpack_exports__;
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) {
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__) {
let promise;