aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2019-04-19 02:55:43 +0800
committerGitHub <noreply@github.com>2019-04-19 02:55:43 +0800
commitb55a2fd53113d70900c7cd96ad8cfdcc235629c2 (patch)
treea251bbf35f87daf3fc0da63e3cf0afdb0c8a15fb
parente8a2c0b5bf18659a3e1285b6038ea755a290220d (diff)
downloadtracifyjs-b55a2fd53113d70900c7cd96ad8cfdcc235629c2.tar.gz
tracifyjs-b55a2fd53113d70900c7cd96ad8cfdcc235629c2.zip
fix corner case in `functions` (#3367)
fixes #3366
-rw-r--r--lib/compress.js2
-rw-r--r--test/compress/functions.js31
-rw-r--r--test/sandbox.js6
3 files changed, 36 insertions, 3 deletions
diff --git a/lib/compress.js b/lib/compress.js
index f5479bef..f72972b1 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -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) {
diff --git a/test/compress/functions.js b/test/compress/functions.js
index c43c17eb..7303b91b 100644
--- a/test/compress/functions.js
+++ b/test/compress/functions.js
@@ -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"
+}
diff --git a/test/sandbox.js b/test/sandbox.js
index 23fb4fc9..396a08f1 100644
--- a/test/sandbox.js
+++ b/test/sandbox.js
@@ -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);
}
}
};