@@ -5758,9 +5758,10 @@ merge(Compressor.prototype, {
|
|||||||
if (fixed instanceof AST_Defun) {
|
if (fixed instanceof AST_Defun) {
|
||||||
fixed._squeezed = true;
|
fixed._squeezed = true;
|
||||||
fixed = make_node(AST_Function, fixed, fixed);
|
fixed = make_node(AST_Function, fixed, fixed);
|
||||||
|
fixed.name = make_node(AST_SymbolLambda, fixed.name, fixed.name);
|
||||||
}
|
}
|
||||||
var value;
|
var value;
|
||||||
if (d.recursive_refs > 0 && fixed.name instanceof AST_SymbolDefun) {
|
if (d.recursive_refs > 0) {
|
||||||
value = fixed.clone(true);
|
value = fixed.clone(true);
|
||||||
var defun_def = value.name.definition();
|
var defun_def = value.name.definition();
|
||||||
var lambda_def = value.variables.get(value.name.name);
|
var lambda_def = value.variables.get(value.name.name);
|
||||||
|
|||||||
@@ -58,3 +58,52 @@ lambda_name_mangle: {
|
|||||||
expect_exact: "console.log(typeof function o(n){});"
|
expect_exact: "console.log(typeof function o(n){});"
|
||||||
expect_stdout: "function"
|
expect_stdout: "function"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lambda_name_mangle_ie8: {
|
||||||
|
mangle = {
|
||||||
|
ie8: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(typeof function foo(bar) {});
|
||||||
|
}
|
||||||
|
expect_exact: "console.log(typeof function n(o){});"
|
||||||
|
expect_stdout: "function"
|
||||||
|
}
|
||||||
|
|
||||||
|
function_name_mangle: {
|
||||||
|
options = {
|
||||||
|
keep_fnames: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
mangle = {}
|
||||||
|
input: {
|
||||||
|
(function() {
|
||||||
|
function foo(bar) {}
|
||||||
|
console.log(typeof foo);
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_exact: "(function(){console.log(typeof function o(n){})})();"
|
||||||
|
expect_stdout: "function"
|
||||||
|
}
|
||||||
|
|
||||||
|
function_name_mangle_ie8: {
|
||||||
|
options = {
|
||||||
|
keep_fnames: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
ie8: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function() {
|
||||||
|
function foo(bar) {}
|
||||||
|
console.log(typeof foo);
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_exact: "(function(){console.log(typeof function n(o){})})();"
|
||||||
|
expect_stdout: "function"
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,21 +1,6 @@
|
|||||||
var semver = require("semver");
|
var semver = require("semver");
|
||||||
var vm = require("vm");
|
var vm = require("vm");
|
||||||
|
|
||||||
function createContext() {
|
|
||||||
return vm.createContext(Object.defineProperty({}, "console", {
|
|
||||||
value: {
|
|
||||||
log: function(msg) {
|
|
||||||
if (arguments.length == 1 && typeof msg == "string") {
|
|
||||||
return console.log("%s", msg);
|
|
||||||
}
|
|
||||||
return console.log.apply(console, [].map.call(arguments, function(arg) {
|
|
||||||
return safe_log(arg, 3);
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
function safe_log(arg, level) {
|
function safe_log(arg, level) {
|
||||||
if (arg) switch (typeof arg) {
|
if (arg) switch (typeof arg) {
|
||||||
case "function":
|
case "function":
|
||||||
@@ -25,20 +10,20 @@ function safe_log(arg, level) {
|
|||||||
arg.constructor.toString();
|
arg.constructor.toString();
|
||||||
if (level--) for (var key in arg) {
|
if (level--) for (var key in arg) {
|
||||||
var desc = Object.getOwnPropertyDescriptor(arg, key);
|
var desc = Object.getOwnPropertyDescriptor(arg, key);
|
||||||
if (!desc || !desc.get) {
|
if (!desc || !desc.get) arg[key] = safe_log(arg[key], level);
|
||||||
arg[key] = safe_log(arg[key], level);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return arg;
|
return arg;
|
||||||
}
|
}
|
||||||
|
|
||||||
function strip_func_ids(text) {
|
function log(msg) {
|
||||||
return ("" + text).replace(/F[0-9]{6}N/g, "<F<>N>");
|
if (arguments.length == 1 && typeof msg == "string") return console.log("%s", msg);
|
||||||
|
return console.log.apply(console, [].map.call(arguments, function(arg) {
|
||||||
|
return safe_log(arg, 3);
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
var context;
|
var func_toString = new vm.Script([
|
||||||
var FUNC_TOSTRING = [
|
|
||||||
"[ Array, Boolean, Error, Function, Number, Object, RegExp, String ].forEach(function(f) {",
|
"[ Array, Boolean, Error, Function, Number, Object, RegExp, String ].forEach(function(f) {",
|
||||||
" f.toString = Function.prototype.toString;",
|
" f.toString = Function.prototype.toString;",
|
||||||
"});",
|
"});",
|
||||||
@@ -59,7 +44,15 @@ var FUNC_TOSTRING = [
|
|||||||
' return "function(){}";',
|
' return "function(){}";',
|
||||||
" };",
|
" };",
|
||||||
"}();",
|
"}();",
|
||||||
]).join("\n");
|
]).join("\n"));
|
||||||
|
|
||||||
|
function createContext() {
|
||||||
|
var ctx = vm.createContext(Object.defineProperty({}, "console", { value: { log: log } }));
|
||||||
|
func_toString.runInContext(ctx);
|
||||||
|
return ctx;
|
||||||
|
}
|
||||||
|
|
||||||
|
var context;
|
||||||
exports.run_code = function(code, reuse) {
|
exports.run_code = function(code, reuse) {
|
||||||
var stdout = "";
|
var stdout = "";
|
||||||
var original_write = process.stdout.write;
|
var original_write = process.stdout.write;
|
||||||
@@ -69,7 +62,6 @@ exports.run_code = function(code, reuse) {
|
|||||||
try {
|
try {
|
||||||
if (!reuse || !context) context = createContext();
|
if (!reuse || !context) context = createContext();
|
||||||
vm.runInContext([
|
vm.runInContext([
|
||||||
FUNC_TOSTRING,
|
|
||||||
"!function() {",
|
"!function() {",
|
||||||
code,
|
code,
|
||||||
"}();",
|
"}();",
|
||||||
@@ -86,6 +78,11 @@ exports.run_code = function(code, reuse) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function strip_func_ids(text) {
|
||||||
|
return ("" + text).replace(/F[0-9]{6}N/g, "<F<>N>");
|
||||||
|
}
|
||||||
|
|
||||||
exports.same_stdout = semver.satisfies(process.version, "0.12") ? function(expected, actual) {
|
exports.same_stdout = semver.satisfies(process.version, "0.12") ? function(expected, actual) {
|
||||||
if (typeof expected != typeof actual) return false;
|
if (typeof expected != typeof actual) return false;
|
||||||
if (typeof expected != "string") {
|
if (typeof expected != "string") {
|
||||||
|
|||||||
Reference in New Issue
Block a user