[Pkg-javascript-commits] [uglifyjs] 159/491: refactor `Compressor.toplevel` (#2149)
Jonas Smedegaard
dr at jones.dk
Wed Feb 14 19:51:31 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 d58b184835d9c2316bfb4411d0907ebb4446aaf0
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date: Fri Jun 23 13:11:40 2017 +0800
refactor `Compressor.toplevel` (#2149)
---
lib/compress.js | 32 ++++++++++++++++----------------
1 file changed, 16 insertions(+), 16 deletions(-)
diff --git a/lib/compress.js b/lib/compress.js
index 8890759..c24510f 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -124,13 +124,13 @@ function Compressor(options, false_by_default) {
};
}
var toplevel = this.options["toplevel"];
- if (typeof toplevel == "string") {
- this.toplevel.funcs = /funcs/.test(toplevel);
- this.toplevel.vars = /vars/.test(toplevel);
- } else {
- this.toplevel = toplevel ? return_true : return_false;
- this.toplevel.funcs = this.toplevel.vars = toplevel;
- }
+ this.toplevel = typeof toplevel == "string" ? {
+ funcs: /funcs/.test(toplevel),
+ vars: /vars/.test(toplevel)
+ } : {
+ funcs: toplevel,
+ vars: toplevel
+ };
var sequences = this.options["sequences"];
this.sequences_limit = sequences == 1 ? 800 : sequences | 0;
this.warnings_produced = {};
@@ -139,11 +139,11 @@ function Compressor(options, false_by_default) {
Compressor.prototype = new TreeTransformer;
merge(Compressor.prototype, {
option: function(key) { return this.options[key] },
- toplevel: function(def) {
- for (var i = 0, len = def.orig.length; i < len; i++)
+ exposed: function(def) {
+ if (def.global) for (var i = 0, len = def.orig.length; i < len; i++)
if (!this.toplevel[def.orig[i] instanceof AST_SymbolDefun ? "funcs" : "vars"])
- return false;
- return true;
+ return true;
+ return false;
},
compress: function(node) {
if (this.option("expression")) {
@@ -345,7 +345,7 @@ merge(Compressor.prototype, {
}
if (node instanceof AST_Defun) {
var d = node.name.definition();
- if (d.global && !compressor.toplevel(d) || safe_to_read(d)) {
+ if (compressor.exposed(d) || safe_to_read(d)) {
d.fixed = false;
} else {
d.fixed = node;
@@ -517,7 +517,7 @@ merge(Compressor.prototype, {
def.escaped = false;
if (def.scope.uses_eval) {
def.fixed = false;
- } else if (!def.global || compressor.toplevel(def)) {
+ } else if (!compressor.exposed(def)) {
def.fixed = undefined;
} else {
def.fixed = false;
@@ -748,7 +748,7 @@ merge(Compressor.prototype, {
}
if (candidate instanceof AST_VarDef) {
var def = candidate.name.definition();
- if (def.references.length == 1 && (!def.global || compressor.toplevel(def))) {
+ if (def.references.length == 1 && !compressor.exposed(def)) {
return maintain_this_binding(parent, node, candidate.value);
}
return make_node(AST_Assign, candidate, {
@@ -810,7 +810,7 @@ merge(Compressor.prototype, {
if (expr instanceof AST_VarDef) {
var def = expr.name.definition();
if (def.orig.length > 1
- || def.references.length == 1 && (!def.global || compressor.toplevel(def))) {
+ || def.references.length == 1 && !compressor.exposed(def)) {
return make_node(AST_SymbolRef, expr.name, expr.name);
}
} else {
@@ -3918,7 +3918,7 @@ merge(Compressor.prototype, {
}
var name_length = d.name.length;
var overhead = 0;
- if (compressor.option("unused") && (!d.global || compressor.toplevel(d))) {
+ if (compressor.option("unused") && !compressor.exposed(d)) {
overhead = (name_length + 2 + value_length) / d.references.length;
}
d.should_replace = value_length <= name_length + overhead ? fn : false;
--
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