From 05e7d34ed480429cc26c8eedd675263cd0d94a3e Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Tue, 26 Dec 2017 18:29:28 +0800 Subject: improve `unused` over duplicate variable names (#2656) --- lib/compress.js | 17 +++++++---------- test/compress/drop-unused.js | 21 +++++++++++++++++++++ 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/lib/compress.js b/lib/compress.js index 8cfb56be..8df6bbd5 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -2645,14 +2645,14 @@ merge(Compressor.prototype, { var tw = new TreeWalker(function(node, descend){ if (node === self) return; if (node instanceof AST_Defun) { + var node_def = node.name.definition(); if (!drop_funcs && scope === self) { - var node_def = node.name.definition(); if (!(node_def.id in in_use_ids)) { in_use_ids[node_def.id] = true; in_use.push(node_def); } } - initializations.add(node.name.name, node); + initializations.add(node_def.id, node); return true; // don't go in nested scopes } if (node instanceof AST_SymbolFunarg && scope === self) { @@ -2671,7 +2671,7 @@ merge(Compressor.prototype, { } } if (def.value) { - initializations.add(def.name.name, def.value); + initializations.add(node_def.id, def.value); if (def.value.has_side_effects(compressor)) { def.value.walk(tw); } @@ -2686,13 +2686,10 @@ merge(Compressor.prototype, { // initialization code to figure out if it uses other // symbols (that may not be in_use). tw = new TreeWalker(scan_ref_scoped); - for (var i = 0; i < in_use.length; ++i) { - in_use[i].orig.forEach(function(decl){ - // undeclared globals will be instanceof AST_SymbolRef - var init = initializations.get(decl.name); - if (init) init.forEach(function(init){ - init.walk(tw); - }); + for (var i = 0; i < in_use.length; i++) { + var init = initializations.get(in_use[i].id); + if (init) init.forEach(function(init) { + init.walk(tw); }); } // pass 3: we should drop declarations not in_use diff --git a/test/compress/drop-unused.js b/test/compress/drop-unused.js index 275e0f76..90206ec6 100644 --- a/test/compress/drop-unused.js +++ b/test/compress/drop-unused.js @@ -1413,3 +1413,24 @@ issue_2516_2: { Baz(2); } } + +defun_lambda_same_name: { + options = { + toplevel: true, + unused: true, + } + input: { + function f(n) { + return n ? n * f(n - 1) : 1; + } + console.log(function f(n) { + return n ? n * f(n - 1) : 1; + }(5)); + } + expect: { + console.log(function f(n) { + return n ? n * f(n - 1) : 1; + }(5)); + } + expect_stdout: "120" +} -- cgit v1.2.3 t/gnu/bootloader.scm?id=52d780ea2b0714d035a84e350b516ca2e2c19af1'>gnu: bootloader: Extend `<menu-entry>' for chain-loader....* gnu/bootloader.scm (<menu-entry>)[chain-loader]: New field. (menu-entry->sexp, sexp->menu-entry): Support chain-loader. * doc/guix.texi (Bootloader Configuration): Document it. Co-Authored-By: Julien Lepiller <julien@lepiller.eu> Signed-off-by: Julien Lepiller <julien@lepiller.eu> tiantian 2022-08-30bootloader: Wrap lines....* gnu/bootloader (<bootloader-configuration>): Wrap lines, no functional change. Mathieu Othacehe 2022-08-30bootloader: Add device-tree-support? option....In some specific cases where the device tree file is already loaded in RAM, it can be preferable that the bootloader does not try to use a device tree from the Linux kernel tree. * gnu/bootloader.scm (<bootloader-configuration>)[device-tree-support?]: New field. * gnu/bootloader/extlinux.scm (extlinux-configuration-file): Add FDTDIR line based on <device-tree-support?> field of <bootloader-configuration>. * doc/guix.texi (Bootloader Configuration)[device-tree-support?]: Add documentation for the new field. Reza Alizadeh Majd 2022-08-28bootloader: Convert device in menu-entry to proper sexp....Previously, menu-entry->sexp didn't try to convert `device` to a proper sexp, which was inserted directly into the boot parameters G-exp, leading to a G-exp input error. Now convert both uuid and file-system-label possibilities to sexps, and add parsing code to sexp->menu-entry. This fixes #57307. * gnu/bootloader.scm (menu-entry->sexp, sexp->menu-entry): Take non-string devices into account. Signed-off-by: Marius Bakke <marius@gnu.org> Josselin Poiret 2022-08-21bootloader: Remove expired export....This follows up on commit 8a0e1bb12b3c22a8c9a2be17492058ca63ec7c5d. * gnu/bootloader.scm: Don't export bootloader-configuration-additional-configuration, which no longer exists. Reported by muradm in #guix. Tobias Geerinckx-Rice 2021-11-17gnu: system: Improve location of some configuration warnings....* gnu/bootloader.scm (%warn-target-field-deprecation): Remove it. * gnu/bootloader.scm (warn-target-field-deprecation): Use define-with-syntax-properties. * gnu/system.scm (ensure-setuid-program-list): Ditto. Also rename the 'location' variable to 'properties'. Signed-off-by: Ludovic Courtès <ludo@gnu.org> Josselin Poiret 2021-08-30bootloader: Report location of the deprecated 'target' field....This is a followup to 2ca982ff41270288913ad6b7d5d9e1cad87b06d9. * gnu/bootloader.scm (warn-target-field-deprecation): New macro. (<bootloader-configuration>)[target]: Add 'sanitize' property. (%warn-target-field-deprecation): New procedure. (bootloader-configuration-target): Define using 'define-deprecated'. (bootloader-configuration-targets): Use '%bootloader-configuration-target' rather than the deprecated one. Ludovic Courtès 2021-08-29gnu: bootloader: Support multiple targets....Fixes <https://issues.guix.gnu.org/40997>. * gnu/bootloader.scm (<bootloader-configuration>): New 'targets' field. (%bootloader-configuration-target): New procedure. (bootloader-configuration-target): Add deprecation warning. (bootloader-configuration-targets): New procedure. * guix/scripts/system.scm (install): Access targets via bootloader-configuration-targets. (perform-action)[bootloader-target]: Remove unused argument and update doc. Access targets via bootloader-configuration-targets and fix indentation. (process-action): Access targets via bootloader-configuration-targets. Do not provide the unused BOOTLOADER-TARGET argument when applying `perform-action'. * guix/scripts/system/reconfigure.scm (install-bootloader-program): Rename DEVICE argument to DEVICES. Adjust doc and comment. Apply `installer' and `disk-installer' for every DEVICES. (install-bootloader): Access targets via bootloader-configuration-targets and rename variable from DEVICE to DEVICES. * gnu/tests/install.scm: Adjust accordingly. * tests/guix-system.sh: Likewise. * gnu/tests/reconfigure.scm (run-install-bootloader-test): Adjust the DEVICES argument so that it is a list. * doc/guix.texi: Update doc. Maxim Cournoyer