Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix corner case in functions (#3367)
fixes #3366
  • Loading branch information
alexlamsl committed Apr 18, 2019
1 parent e8a2c0b commit b55a2fd
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/compress.js
Expand Up @@ -3602,7 +3602,7 @@ merge(Compressor.prototype, {
compressor.warn("Declaring {name} as function [{file}:{line},{col}]", template(def.name));
var defun = make_node(AST_Defun, def, def.value);
defun.name = make_node(AST_SymbolDefun, def.name, def.name);
defun.parent_scope.resolve().def_function(defun.name);
def.name.scope.resolve().def_function(defun.name);
body.push(defun);
} else {
if (side_effects.length > 0) {
Expand Down
31 changes: 31 additions & 0 deletions test/compress/functions.js
Expand Up @@ -2981,3 +2981,34 @@ issue_3364: {
}
expect_stdout: "2"
}

issue_3366: {
options = {
functions: true,
inline: true,
reduce_vars: true,
toplevel: true,
unused: true,
}
input: {
function f() {
function g() {
return function() {};
}
var a = g();
(function() {
this && a && console.log("PASS");
})();
}
f();
}
expect: {
(function() {
function a() {}
(function() {
this && a && console.log("PASS");
})();
})();
}
expect_stdout: "PASS"
}
6 changes: 4 additions & 2 deletions test/sandbox.js
Expand Up @@ -73,8 +73,10 @@ exports.run_code = function(code, reuse) {
process.stdout.write = original_write;
if (!reuse || code.indexOf(".prototype") >= 0) {
context = null;
} else for (var key in context) {
delete context[key];
} else {
vm.runInContext(Object.keys(context).map(function(name) {
return "delete " + name;
}).join("\n"), context);
}
}
};
Expand Down

0 comments on commit b55a2fd

Please sign in to comment.