[Pkg-javascript-commits] [uglifyjs] 220/491: enhance `reduce_vars` for `AST_Accessor` (#2339)
Jonas Smedegaard
dr at jones.dk
Wed Feb 14 19:51:38 UTC 2018
This is an automated email from the git hooks/post-receive script.
js pushed a commit to annotated tag debian/3.3.10-1
in repository uglifyjs.
commit dd71639264f201902e08d078fcef1946eaad2ef3
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date: Sun Oct 1 03:01:50 2017 +0800
enhance `reduce_vars` for `AST_Accessor` (#2339)
fixes #2336
---
lib/compress.js | 9 ++++++---
test/compress/reduce_vars.js | 29 ++++++++++++++++++++++++++++-
2 files changed, 34 insertions(+), 4 deletions(-)
diff --git a/lib/compress.js b/lib/compress.js
index 9e516a8..d4a72d7 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -285,6 +285,10 @@ merge(Compressor.prototype, {
AST_Node.DEFMETHOD("reset_opt_flags", function(compressor, rescan) {
var reduce_vars = rescan && compressor.option("reduce_vars");
+ // Stack of look-up tables to keep track of whether a `SymbolDef` has been
+ // properly assigned before use:
+ // - `push()` & `pop()` when visiting conditional branches
+ // - backup & restore via `save_ids` when visiting out-of-order sections
var safe_ids = Object.create(null);
var suppressor = new TreeWalker(function(node) {
if (!(node instanceof AST_Symbol)) return;
@@ -391,10 +395,9 @@ merge(Compressor.prototype, {
return true;
}
if (node instanceof AST_Accessor) {
- var save_ids = safe_ids;
- safe_ids = Object.create(null);
+ push();
descend();
- safe_ids = save_ids;
+ pop();
return true;
}
if (node instanceof AST_Binary
diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js
index 556bcad..4e096d9 100644
--- a/test/compress/reduce_vars.js
+++ b/test/compress/reduce_vars.js
@@ -2549,7 +2549,7 @@ issue_1922_2: {
expect_stdout: "1"
}
-accessor: {
+accessor_1: {
options = {
evaluate: true,
reduce_vars: true,
@@ -2578,6 +2578,33 @@ accessor: {
expect_stdout: "1 1"
}
+accessor_2: {
+ options = {
+ collapse_vars: true,
+ evaluate: true,
+ reduce_vars: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ var A = 1;
+ var B = {
+ get c() {
+ console.log(A);
+ }
+ };
+ B.c;
+ }
+ expect: {
+ ({
+ get c() {
+ console.log(1);
+ }
+ }).c;
+ }
+ expect_stdout: "1"
+}
+
for_in_prop: {
options = {
reduce_vars: true,
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/uglifyjs.git
More information about the Pkg-javascript-commits
mailing list