fix AST_Function scope invariance (#2052)

improve function name hack in `run_code()`
This commit is contained in:
Alex Lam S.L
2017-06-04 19:27:43 +08:00
committed by GitHub
parent 84634da4b5
commit 540220b91b
4 changed files with 44 additions and 13 deletions

View File

@@ -2957,7 +2957,7 @@ merge(Compressor.prototype, {
&& !(def.scope.uses_arguments
&& def.orig[0] instanceof AST_SymbolFunarg)
&& !def.scope.uses_eval
&& compressor.find_parent(AST_Scope) === def.scope) {
&& compressor.find_parent(AST_Scope) === exp.parent_scope) {
self.expression = exp;
}
}

View File

@@ -751,12 +751,12 @@ issue_1583: {
expect: {
function m(t) {
(function(e) {
t = (function() {
t = e();
})(function() {
return (function(a) {
return a;
})(function(a) {});
})();
})();
});
}
}
}

View File

@@ -1311,19 +1311,48 @@ iife_func_side_effects: {
unused: true,
}
input: {
function x() {
console.log("x");
}
function y() {
console.log("y");
}
function z() {
console.log("z");
}
(function(a, b, c) {
return b();
function y() {
console.log("FAIL");
}
return y + b();
})(x(), function() {
return y();
}, z());
}
expect: {
(function(a, b, c) {
return function() {
return y();
}();
})(x(), 0, z());
function x() {
console.log("x");
}
function y() {
console.log("y");
}
function z() {
console.log("z");
}
(function(a, b, c) {
function y() {
console.log("FAIL");
}
return y + b();
})(x(), function() {
return y();
}, z());
}
expect_stdout: [
"x",
"z",
"y",
]
}
issue_1595_1: {

View File

@@ -26,16 +26,18 @@ var FUNC_TOSTRING = [
" var i = this.name;",
' if (typeof i != "number") {',
" i = ++id;",
].concat(Object.getOwnPropertyDescriptor(Function.prototype, "name").configurable ? [
' Object.defineProperty(this, "name", {',
" get: function() {",
" return i;",
" }",
" });",
] : [], [
" }",
' return "[Function: " + i + "]";',
" }",
"}();",
].join("\n");
]).join("\n");
exports.run_code = function(code) {
var stdout = "";
var original_write = process.stdout.write;