fix AST_Function scope invariance (#2052)
improve function name hack in `run_code()`
This commit is contained in:
@@ -2957,7 +2957,7 @@ merge(Compressor.prototype, {
|
|||||||
&& !(def.scope.uses_arguments
|
&& !(def.scope.uses_arguments
|
||||||
&& def.orig[0] instanceof AST_SymbolFunarg)
|
&& def.orig[0] instanceof AST_SymbolFunarg)
|
||||||
&& !def.scope.uses_eval
|
&& !def.scope.uses_eval
|
||||||
&& compressor.find_parent(AST_Scope) === def.scope) {
|
&& compressor.find_parent(AST_Scope) === exp.parent_scope) {
|
||||||
self.expression = exp;
|
self.expression = exp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -751,12 +751,12 @@ issue_1583: {
|
|||||||
expect: {
|
expect: {
|
||||||
function m(t) {
|
function m(t) {
|
||||||
(function(e) {
|
(function(e) {
|
||||||
t = (function() {
|
t = e();
|
||||||
return (function(a) {
|
})(function() {
|
||||||
return a;
|
return (function(a) {
|
||||||
})(function(a) {});
|
return a;
|
||||||
})();
|
})(function(a) {});
|
||||||
})();
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1311,19 +1311,48 @@ iife_func_side_effects: {
|
|||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
|
function x() {
|
||||||
|
console.log("x");
|
||||||
|
}
|
||||||
|
function y() {
|
||||||
|
console.log("y");
|
||||||
|
}
|
||||||
|
function z() {
|
||||||
|
console.log("z");
|
||||||
|
}
|
||||||
(function(a, b, c) {
|
(function(a, b, c) {
|
||||||
return b();
|
function y() {
|
||||||
|
console.log("FAIL");
|
||||||
|
}
|
||||||
|
return y + b();
|
||||||
})(x(), function() {
|
})(x(), function() {
|
||||||
return y();
|
return y();
|
||||||
}, z());
|
}, z());
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
|
function x() {
|
||||||
|
console.log("x");
|
||||||
|
}
|
||||||
|
function y() {
|
||||||
|
console.log("y");
|
||||||
|
}
|
||||||
|
function z() {
|
||||||
|
console.log("z");
|
||||||
|
}
|
||||||
(function(a, b, c) {
|
(function(a, b, c) {
|
||||||
return function() {
|
function y() {
|
||||||
return y();
|
console.log("FAIL");
|
||||||
}();
|
}
|
||||||
})(x(), 0, z());
|
return y + b();
|
||||||
|
})(x(), function() {
|
||||||
|
return y();
|
||||||
|
}, z());
|
||||||
}
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"x",
|
||||||
|
"z",
|
||||||
|
"y",
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_1595_1: {
|
issue_1595_1: {
|
||||||
|
|||||||
@@ -26,16 +26,18 @@ var FUNC_TOSTRING = [
|
|||||||
" var i = this.name;",
|
" var i = this.name;",
|
||||||
' if (typeof i != "number") {',
|
' if (typeof i != "number") {',
|
||||||
" i = ++id;",
|
" i = ++id;",
|
||||||
|
].concat(Object.getOwnPropertyDescriptor(Function.prototype, "name").configurable ? [
|
||||||
' Object.defineProperty(this, "name", {',
|
' Object.defineProperty(this, "name", {',
|
||||||
" get: function() {",
|
" get: function() {",
|
||||||
" return i;",
|
" return i;",
|
||||||
" }",
|
" }",
|
||||||
" });",
|
" });",
|
||||||
|
] : [], [
|
||||||
" }",
|
" }",
|
||||||
' return "[Function: " + i + "]";',
|
' return "[Function: " + i + "]";',
|
||||||
" }",
|
" }",
|
||||||
"}();",
|
"}();",
|
||||||
].join("\n");
|
]).join("\n");
|
||||||
exports.run_code = function(code) {
|
exports.run_code = function(code) {
|
||||||
var stdout = "";
|
var stdout = "";
|
||||||
var original_write = process.stdout.write;
|
var original_write = process.stdout.write;
|
||||||
|
|||||||
Reference in New Issue
Block a user