aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-12-26 08:52:16 +0000
committerGitHub <noreply@github.com>2020-12-26 16:52:16 +0800
commit94f3819dc6267f6e2efefdffc4b02e92a8e8a5d9 (patch)
tree578a45db1cbe311cc17db52c07eae185f65baa27
parentbe1f5199f422080a42e962670758bd68f34b5bb6 (diff)
downloadtracifyjs-94f3819dc6267f6e2efefdffc4b02e92a8e8a5d9.tar.gz
tracifyjs-94f3819dc6267f6e2efefdffc4b02e92a8e8a5d9.zip
fix corner case in `reduce_vars` & `unused` (#4465)
fixes #4464
-rw-r--r--lib/compress.js17
-rw-r--r--test/compress/drop-unused.js71
-rw-r--r--test/reduce.js5
3 files changed, 87 insertions, 6 deletions
diff --git a/lib/compress.js b/lib/compress.js
index ae66d140..97b6149b 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -363,6 +363,10 @@ merge(Compressor.prototype, {
return orig.length == 1 && orig[0] instanceof AST_SymbolFunarg;
}
+ function is_funarg(def) {
+ return def.orig[0] instanceof AST_SymbolFunarg || def.orig[1] instanceof AST_SymbolFunarg;
+ }
+
function cross_scope(def, sym) {
do {
if (def === sym) return false;
@@ -371,9 +375,9 @@ merge(Compressor.prototype, {
}
function can_drop_symbol(ref, keep_lambda) {
- var orig = ref.definition().orig;
- if (ref.in_arg && (orig[0] instanceof AST_SymbolFunarg || orig[1] instanceof AST_SymbolFunarg)) return false;
- return all(orig, function(sym) {
+ var def = ref.definition();
+ if (ref.in_arg && is_funarg(def)) return false;
+ return all(def.orig, function(sym) {
return !(sym instanceof AST_SymbolConst || sym instanceof AST_SymbolLet
|| keep_lambda && sym instanceof AST_SymbolLambda);
});
@@ -541,7 +545,8 @@ merge(Compressor.prototype, {
return compressor.option("unused")
&& !def.scope.pinned()
&& def.single_use !== false
- && def.references.length - def.recursive_refs == 1;
+ && def.references.length - def.recursive_refs == 1
+ && !(is_funarg(def) && def.scope.uses_arguments);
}
function is_immutable(value) {
@@ -9331,7 +9336,7 @@ merge(Compressor.prototype, {
single_use = false;
} else if (fixed.name && fixed.name.definition() !== def) {
single_use = false;
- } else if (fixed.parent_scope !== self.scope.resolve() || def.orig[0] instanceof AST_SymbolFunarg) {
+ } else if (fixed.parent_scope !== self.scope.resolve() || is_funarg(def)) {
single_use = fixed.is_constant_expression(self.scope);
if (single_use == "f") {
var scope = self.scope;
@@ -9414,7 +9419,7 @@ merge(Compressor.prototype, {
if (fixed && (local || def.should_replace !== false)) {
var init;
if (fixed instanceof AST_This) {
- if (!(def.orig[0] instanceof AST_SymbolFunarg) && same_scope(def)) {
+ if (!is_funarg(def) && same_scope(def)) {
init = fixed;
}
} else {
diff --git a/test/compress/drop-unused.js b/test/compress/drop-unused.js
index 3feb0183..ae1a6e5b 100644
--- a/test/compress/drop-unused.js
+++ b/test/compress/drop-unused.js
@@ -3125,3 +3125,74 @@ issue_4413: {
}
expect_stdout: "0"
}
+
+issue_4464_1: {
+ options = {
+ reduce_vars: true,
+ unused: true,
+ }
+ input: {
+ function f(a) {
+ var a = function() {};
+ return [ arguments, a ];
+ }
+ console.log(typeof f()[1]);
+ }
+ expect: {
+ function f(a) {
+ a = function() {};
+ return [ arguments, a ];
+ }
+ console.log(typeof f()[1]);
+ }
+ expect_stdout: "function"
+}
+
+issue_4464_2: {
+ options = {
+ reduce_vars: true,
+ unused: true,
+ }
+ input: {
+ function f(a) {
+ var a = function() {};
+ return [ arguments, a ];
+ }
+ console.log(typeof f(42)[0][0]);
+ }
+ expect: {
+ function f(a) {
+ a = function() {};
+ return [ arguments, a ];
+ }
+ console.log(typeof f(42)[0][0]);
+ }
+ expect_stdout: "function"
+}
+
+issue_4464_3: {
+ options = {
+ reduce_vars: true,
+ unused: true,
+ }
+ input: {
+ (function a(a) {
+ var a = function() {};
+ return [ arguments[0], a ];
+ })(42).forEach(function(b) {
+ console.log(typeof b);
+ });
+ }
+ expect: {
+ (function(a) {
+ a = function() {};
+ return [ arguments[0], a ];
+ })(42).forEach(function(b) {
+ console.log(typeof b);
+ });
+ }
+ expect_stdout: [
+ "function",
+ "function",
+ ]
+}
diff --git a/test/reduce.js b/test/reduce.js
index f6b54141..48030b0f 100644
--- a/test/reduce.js
+++ b/test/reduce.js
@@ -352,6 +352,11 @@ module.exports = function reduce_test(testcase, minify_options, reduce_options)
}
}
}
+ else if (node instanceof U.AST_Spread) {
+ node.start._permute++;
+ CHANGED = true;
+ return node.expression;
+ }
else if (node instanceof U.AST_Switch) {
var expr = [
node.expression, // switch expression
articularly in Nix/Guix builds: https://github.com/fpco/streaming-commons/issues/49. * gnu/packages/haskell.scm (ghc-streaming-commons): Update to 0.2.1.1. Signed-off-by: Ludovic Courtès <ludo@gnu.org> 2019-06-06gnu: gash: Install modules in the standard locations.Ludovic Courtès * gnu/packages/shells.scm (gash)[source](modules, snippet): New fields. 2019-06-06gnu: ocaml-cmdliner: Fix non determinism.Julien Lepiller * gnu/packages/ocaml.scm (ocaml-cmdliner)[arguments]: Patch build.ml to fix a file ordering issue. 2019-06-06gnu: ocaml-num: Make stublibs a directory.Julien Lepiller * gnu/packages/ocaml.scm (ocaml-num)[arguments]: Fix 'fix-stublibs phase. 2019-06-06gnu: Add gnurobots.Jesse Gibbons * gnu/packages/games.scm (gnurobots): New variable. Signed-off-by: Ricardo Wurmus <rekado@elephly.net> Co-authored-by: Ricardo Wurmus <rekado@elephly.net> 2019-06-06gnu: emacs-dashboard: Update to 1.5.0.Oleg Pykhalov * gnu/packages/emacs-xyz.scm (emacs-dashboard): Update to 1.5.0. 2019-06-06gnu: shaderc: Update to 2019.0.Rutger Helling * gnu/packages/vulkan.scm (shaderc): Update to 2019.0. 2019-06-06gnu: mame: Update to 0.210.Nicolas Goaziou * gnu/packages/emulators.scm (mame): Update to 0.210. [inputs]: Add libxi. 2019-06-06gnu: tiled: Use HTTPS home page.Tobias Geerinckx-Rice * gnu/packages/game-development.scm (tiled)[home-page]: Use HTTPS. 2019-06-06gnu: qjackctl: Update to 0.5.8.Tobias Geerinckx-Rice * gnu/packages/audio.scm (qjackctl): Update to 0.5.8. 2019-06-06gnu: pencil2d: Update to 0.6.4.Tobias Geerinckx-Rice * gnu/packages/animation.scm (pencil2d): Update to 0.6.4. 2019-06-06gnu: toybox: Update to 0.8.1.Tobias Geerinckx-Rice * gnu/packages/busybox.scm (toybox): Update to 0.8.1. 2019-06-06gnu: tiled: Update to 1.2.4.Tobias Geerinckx-Rice * gnu/packages/game-development.scm (tiled): Update to 1.2.4. 2019-06-06gnu: fio: Update to 3.14.Tobias Geerinckx-Rice * gnu/packages/benchmark.scm (fio): Update to 3.14. 2019-06-06gnu: ansible: Update to 2.8.0.Tobias Geerinckx-Rice * gnu/packages/admin.scm (ansible): Update to 2.8.0. 2019-06-06gnu: thefuck: Update to 3.29.Tobias Geerinckx-Rice * gnu/packages/admin.scm (thefuck): Update to 3.29. 2019-06-06gnu: inxi, inxi-minimal: Update to 3.0.34-1.Tobias Geerinckx-Rice * gnu/packages/admin.scm (inxi-minimal): Update to 3.0.34-1. 2019-06-06gnu: dstat: Update to 0.7.4.Tobias Geerinckx-Rice * gnu/packages/admin.scm (dstat): Update to 0.7.4. 2019-06-06gnu: aide: Update to 0.16.2.Tobias Geerinckx-Rice * gnu/packages/admin.scm (aide): Update to 0.16.2. 2019-06-06gnu: wireless-regdb: Update to 2019.06.03.Tobias Geerinckx-Rice * gnu/packages/linux.scm (wireless-regdb): Update to 2019.06.03. [arguments]: Add ‘omit-signature’ phase. Add FIRMWARE_PATH & REGDB_PUBCERT #:make-flags, removing unused LSB_ID, DISTRO_PUBKEY & DISTRO_PRIVKEY. Exdent. 2019-06-06gnu: liburcu: Update to 0.11.1.Tobias Geerinckx-Rice * gnu/packages/datastructures.scm (liburcu): Update to 0.11.1. 2019-06-05gnu: Add qview.Nicolas Goaziou * gnu/packages/image-viewers.scm (qview): New variable. 2019-06-05gnu: minizip: Do not install crypt.h.Ludovic Courtès * gnu/packages/compression.scm (minizip)[arguments]: Add 'remove-crypt-h' phase.