Compare commits
34 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
38c3bcf9a0 | ||
|
|
6e9afdc94f | ||
|
|
c4d28e3b2a | ||
|
|
77261e1ee0 | ||
|
|
903a5df9a5 | ||
|
|
c810ecd081 | ||
|
|
dce9dfce0e | ||
|
|
3d72663689 | ||
|
|
a2b16e89a4 | ||
|
|
b35f4c5a83 | ||
|
|
41eb4f1725 | ||
|
|
94bc221669 | ||
|
|
822d298a55 | ||
|
|
273c6020ba | ||
|
|
1b07f64057 | ||
|
|
80d9c44b22 | ||
|
|
dc0cd088cf | ||
|
|
c69c026728 | ||
|
|
b5f4e1187f | ||
|
|
827bcec186 | ||
|
|
d105ab9722 | ||
|
|
b39228892d | ||
|
|
ff72eaa3c3 | ||
|
|
0a1c9b34ce | ||
|
|
03e968be62 | ||
|
|
421bb7083a | ||
|
|
bdc8ef2218 | ||
|
|
bca52fcba2 | ||
|
|
d6d31cbb5a | ||
|
|
a051846d22 | ||
|
|
3485472866 | ||
|
|
c8d60d6983 | ||
|
|
6092bf23de | ||
|
|
7052ce5aef |
24
.github/workflows/ci.yml
vendored
24
.github/workflows/ci.yml
vendored
@@ -4,10 +4,13 @@ jobs:
|
|||||||
test:
|
test:
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
|
node: [ "0.8", "0.10", "0.12", "4", "6", "8", "10", "12", latest ]
|
||||||
os: [ ubuntu-latest, windows-latest ]
|
os: [ ubuntu-latest, windows-latest ]
|
||||||
node: [ "0.10", 0.12, 4, 6, 8, 10, latest ]
|
|
||||||
script: [ compress, mocha, release/benchmark, release/jetstream ]
|
script: [ compress, mocha, release/benchmark, release/jetstream ]
|
||||||
name: ${{ matrix.os }} ${{ matrix.node }} ${{ matrix.script }}
|
exclude:
|
||||||
|
- node: "0.8"
|
||||||
|
script: release/jetstream
|
||||||
|
name: ${{ matrix.node }} ${{ matrix.os }} ${{ matrix.script }}
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
env:
|
env:
|
||||||
NODE: ${{ matrix.node }}
|
NODE: ${{ matrix.node }}
|
||||||
@@ -21,11 +24,20 @@ jobs:
|
|||||||
- name: Perform tests
|
- name: Perform tests
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
git clone --branch v1.5.3 --depth 1 https://github.com/jasongin/nvs.git ~/.nvs
|
git clone --branch v1.5.4 --depth 1 https://github.com/jasongin/nvs.git ~/.nvs
|
||||||
|
while ! timeout 60 bash -c '. ~/.nvs/nvs.sh add $NODE && nvs use $NODE'; do
|
||||||
|
cd ~/.nvs
|
||||||
|
git clean -xdf
|
||||||
|
cd -
|
||||||
|
done
|
||||||
. ~/.nvs/nvs.sh --version
|
. ~/.nvs/nvs.sh --version
|
||||||
nvs add $NODE
|
|
||||||
nvs use $NODE
|
nvs use $NODE
|
||||||
node --version
|
node --version
|
||||||
npm --version --no-update-notifier
|
npm config set audit false
|
||||||
npm install --no-audit --no-optional --no-save --no-update-notifier
|
npm config set optional false
|
||||||
|
npm config set save false
|
||||||
|
npm config set strict-ssl false
|
||||||
|
npm config set update-notifier false
|
||||||
|
npm --version
|
||||||
|
while !(npm install); do echo "'npm install' failed - retrying..."; done
|
||||||
node test/$TYPE
|
node test/$TYPE
|
||||||
|
|||||||
17
.github/workflows/ufuzz.yml
vendored
17
.github/workflows/ufuzz.yml
vendored
@@ -15,11 +15,20 @@ jobs:
|
|||||||
- name: Perform fuzzing
|
- name: Perform fuzzing
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
git clone --branch v1.5.3 --depth 1 https://github.com/jasongin/nvs.git ~/.nvs
|
git clone --branch v1.5.4 --depth 1 https://github.com/jasongin/nvs.git ~/.nvs
|
||||||
|
while ! timeout 60 bash -c '. ~/.nvs/nvs.sh add 10 && nvs use 10'; do
|
||||||
|
cd ~/.nvs
|
||||||
|
git clean -xdf
|
||||||
|
cd -
|
||||||
|
done
|
||||||
. ~/.nvs/nvs.sh --version
|
. ~/.nvs/nvs.sh --version
|
||||||
nvs add 10
|
|
||||||
nvs use 10
|
nvs use 10
|
||||||
node --version
|
node --version
|
||||||
npm --version --no-update-notifier
|
npm config set audit false
|
||||||
npm install --no-audit --no-optional --no-save --no-update-notifier
|
npm config set optional false
|
||||||
|
npm config set save false
|
||||||
|
npm config set strict-ssl false
|
||||||
|
npm config set update-notifier false
|
||||||
|
npm --version
|
||||||
|
while !(npm install); do echo "'npm install' failed - retrying..."; done
|
||||||
node test/ufuzz/job 3600000
|
node test/ufuzz/job 3600000
|
||||||
|
|||||||
@@ -337,7 +337,7 @@ function simple_glob(glob) {
|
|||||||
.replace(/\?/g, "[^/\\\\]") + "$";
|
.replace(/\?/g, "[^/\\\\]") + "$";
|
||||||
var mod = process.platform === "win32" ? "i" : "";
|
var mod = process.platform === "win32" ? "i" : "";
|
||||||
var rx = new RegExp(pattern, mod);
|
var rx = new RegExp(pattern, mod);
|
||||||
var results = entries.filter(function(name) {
|
var results = entries.sort().filter(function(name) {
|
||||||
return rx.test(name);
|
return rx.test(name);
|
||||||
}).map(function(name) {
|
}).map(function(name) {
|
||||||
return path.join(dir, name);
|
return path.join(dir, name);
|
||||||
|
|||||||
156
lib/compress.js
156
lib/compress.js
@@ -315,10 +315,10 @@ merge(Compressor.prototype, {
|
|||||||
if (value instanceof AST_Array) return native_fns.Array[name];
|
if (value instanceof AST_Array) return native_fns.Array[name];
|
||||||
if (value instanceof AST_Function) return native_fns.Function[name];
|
if (value instanceof AST_Function) return native_fns.Function[name];
|
||||||
if (value instanceof AST_Object) return native_fns.Object[name];
|
if (value instanceof AST_Object) return native_fns.Object[name];
|
||||||
if (value instanceof AST_RegExp) return native_fns.RegExp[name];
|
if (value instanceof AST_RegExp) return native_fns.RegExp[name] && !value.value.global;
|
||||||
}
|
}
|
||||||
|
|
||||||
function is_modified(compressor, tw, node, value, level, immutable) {
|
function is_modified(compressor, tw, node, value, level, immutable, recursive) {
|
||||||
var parent = tw.parent(level);
|
var parent = tw.parent(level);
|
||||||
if (compressor.option("unsafe") && parent instanceof AST_Dot && is_read_only_fn(value, parent.property)) {
|
if (compressor.option("unsafe") && parent instanceof AST_Dot && is_read_only_fn(value, parent.property)) {
|
||||||
return;
|
return;
|
||||||
@@ -342,7 +342,7 @@ merge(Compressor.prototype, {
|
|||||||
}
|
}
|
||||||
if (parent instanceof AST_PropAccess && parent.expression === node) {
|
if (parent instanceof AST_PropAccess && parent.expression === node) {
|
||||||
var prop = read_property(value, parent);
|
var prop = read_property(value, parent);
|
||||||
return !immutable && is_modified(compressor, tw, parent, prop, level + 1);
|
return (!immutable || recursive) && is_modified(compressor, tw, parent, prop, level + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -759,7 +759,8 @@ merge(Compressor.prototype, {
|
|||||||
d.fixed = false;
|
d.fixed = false;
|
||||||
} else if (d.fixed) {
|
} else if (d.fixed) {
|
||||||
value = this.fixed_value();
|
value = this.fixed_value();
|
||||||
if (recursive_ref(tw, d)) {
|
var recursive = recursive_ref(tw, d);
|
||||||
|
if (recursive) {
|
||||||
d.recursive_refs++;
|
d.recursive_refs++;
|
||||||
} else if (value && ref_once(tw, compressor, d)) {
|
} else if (value && ref_once(tw, compressor, d)) {
|
||||||
d.single_use = value instanceof AST_Lambda && !value.pinned()
|
d.single_use = value instanceof AST_Lambda && !value.pinned()
|
||||||
@@ -767,7 +768,7 @@ merge(Compressor.prototype, {
|
|||||||
} else {
|
} else {
|
||||||
d.single_use = false;
|
d.single_use = false;
|
||||||
}
|
}
|
||||||
if (is_modified(compressor, tw, this, value, 0, is_immutable(value))) {
|
if (is_modified(compressor, tw, this, value, 0, is_immutable(value), recursive)) {
|
||||||
if (d.single_use) {
|
if (d.single_use) {
|
||||||
d.single_use = "m";
|
d.single_use = "m";
|
||||||
} else {
|
} else {
|
||||||
@@ -995,9 +996,7 @@ merge(Compressor.prototype, {
|
|||||||
|
|
||||||
function needs_unbinding(compressor, val) {
|
function needs_unbinding(compressor, val) {
|
||||||
return val instanceof AST_PropAccess
|
return val instanceof AST_PropAccess
|
||||||
|| compressor.has_directive("use strict")
|
|| is_undeclared_ref(val) && val.name == "eval";
|
||||||
&& is_undeclared_ref(val)
|
|
||||||
&& val.name == "eval";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// we shouldn't compress (1,func)(something) to
|
// we shouldn't compress (1,func)(something) to
|
||||||
@@ -1384,7 +1383,10 @@ merge(Compressor.prototype, {
|
|||||||
function is_last_node(node, parent) {
|
function is_last_node(node, parent) {
|
||||||
if (node instanceof AST_Call) {
|
if (node instanceof AST_Call) {
|
||||||
var fn = node.expression;
|
var fn = node.expression;
|
||||||
if (fn instanceof AST_SymbolRef) fn = fn.fixed_value();
|
if (fn instanceof AST_SymbolRef) {
|
||||||
|
if (fn.definition().recursive_refs > 0) return true;
|
||||||
|
fn = fn.fixed_value();
|
||||||
|
}
|
||||||
if (!(fn instanceof AST_Lambda)) return true;
|
if (!(fn instanceof AST_Lambda)) return true;
|
||||||
if (fn.collapse_scanning) return false;
|
if (fn.collapse_scanning) return false;
|
||||||
fn.collapse_scanning = true;
|
fn.collapse_scanning = true;
|
||||||
@@ -2528,9 +2530,8 @@ merge(Compressor.prototype, {
|
|||||||
return left.is_negative_zero() || right.is_negative_zero();
|
return left.is_negative_zero() || right.is_negative_zero();
|
||||||
case "*":
|
case "*":
|
||||||
case "/":
|
case "/":
|
||||||
return true;
|
|
||||||
case "%":
|
case "%":
|
||||||
return left.is_negative_zero();
|
return true;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -3003,6 +3004,7 @@ merge(Compressor.prototype, {
|
|||||||
].concat(object_fns),
|
].concat(object_fns),
|
||||||
Object: object_fns,
|
Object: object_fns,
|
||||||
RegExp: [
|
RegExp: [
|
||||||
|
"exec",
|
||||||
"test",
|
"test",
|
||||||
].concat(object_fns),
|
].concat(object_fns),
|
||||||
String: [
|
String: [
|
||||||
@@ -3085,6 +3087,7 @@ merge(Compressor.prototype, {
|
|||||||
cached.forEach(function(node) {
|
cached.forEach(function(node) {
|
||||||
delete node._eval;
|
delete node._eval;
|
||||||
});
|
});
|
||||||
|
if (ignore_side_effects) return val;
|
||||||
if (!val || val instanceof RegExp) return val;
|
if (!val || val instanceof RegExp) return val;
|
||||||
if (typeof val == "function" || typeof val == "object") return this;
|
if (typeof val == "function" || typeof val == "object") return this;
|
||||||
return val;
|
return val;
|
||||||
@@ -3239,6 +3242,7 @@ merge(Compressor.prototype, {
|
|||||||
}
|
}
|
||||||
if (isNaN(result)) return compressor.find_parent(AST_With) ? this : result;
|
if (isNaN(result)) return compressor.find_parent(AST_With) ? this : result;
|
||||||
if (compressor.option("unsafe_math")
|
if (compressor.option("unsafe_math")
|
||||||
|
&& !ignore_side_effects
|
||||||
&& result
|
&& result
|
||||||
&& typeof result == "number"
|
&& typeof result == "number"
|
||||||
&& (this.operator == "+" || this.operator == "-")) {
|
&& (this.operator == "+" || this.operator == "-")) {
|
||||||
@@ -3369,15 +3373,18 @@ merge(Compressor.prototype, {
|
|||||||
var args = eval_args(this.args);
|
var args = eval_args(this.args);
|
||||||
if (!args) return this;
|
if (!args) return this;
|
||||||
if (!stat.value) return undefined;
|
if (!stat.value) return undefined;
|
||||||
fn.argnames.forEach(function(sym, i) {
|
if (!all(fn.argnames, function(sym, i) {
|
||||||
var value = args[i];
|
var value = args[i];
|
||||||
sym.definition().references.forEach(function(node) {
|
var def = sym.definition();
|
||||||
|
if (def.orig[def.orig.length - 1] !== sym) return false;
|
||||||
|
def.references.forEach(function(node) {
|
||||||
node._eval = function() {
|
node._eval = function() {
|
||||||
return value;
|
return value;
|
||||||
};
|
};
|
||||||
cached.push(node);
|
cached.push(node);
|
||||||
});
|
});
|
||||||
});
|
return true;
|
||||||
|
})) return this;
|
||||||
fn.evaluating = true;
|
fn.evaluating = true;
|
||||||
var val = stat.value._eval(compressor, ignore_side_effects, cached, depth);
|
var val = stat.value._eval(compressor, ignore_side_effects, cached, depth);
|
||||||
delete fn.evaluating;
|
delete fn.evaluating;
|
||||||
@@ -3400,6 +3407,7 @@ merge(Compressor.prototype, {
|
|||||||
if (val == null || val === e) return this;
|
if (val == null || val === e) return this;
|
||||||
var native_fn = native_fns[val.constructor.name];
|
var native_fn = native_fns[val.constructor.name];
|
||||||
if (!native_fn || !native_fn[key]) return this;
|
if (!native_fn || !native_fn[key]) return this;
|
||||||
|
if (val instanceof RegExp && val.global && !(e instanceof AST_RegExp)) return this;
|
||||||
}
|
}
|
||||||
var args = eval_args(this.args);
|
var args = eval_args(this.args);
|
||||||
if (!args) return this;
|
if (!args) return this;
|
||||||
@@ -3413,6 +3421,8 @@ merge(Compressor.prototype, {
|
|||||||
line: this.start.line,
|
line: this.start.line,
|
||||||
col: this.start.col
|
col: this.start.col
|
||||||
});
|
});
|
||||||
|
} finally {
|
||||||
|
if (val instanceof RegExp) val.lastIndex = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
@@ -3909,14 +3919,18 @@ merge(Compressor.prototype, {
|
|||||||
} else if (node instanceof AST_Unary) {
|
} else if (node instanceof AST_Unary) {
|
||||||
if (node.write_only) sym = node.expression;
|
if (node.write_only) sym = node.expression;
|
||||||
}
|
}
|
||||||
if (!/strict/.test(compressor.option("pure_getters"))) return sym instanceof AST_SymbolRef && sym;
|
if (/strict/.test(compressor.option("pure_getters"))) {
|
||||||
while (sym instanceof AST_PropAccess && !sym.expression.may_throw_on_access(compressor)) {
|
while (sym instanceof AST_PropAccess && !sym.expression.may_throw_on_access(compressor)) {
|
||||||
if (sym instanceof AST_Sub) props.unshift(sym.property);
|
if (sym instanceof AST_Sub) props.unshift(sym.property);
|
||||||
sym = sym.expression;
|
sym = sym.expression;
|
||||||
}
|
}
|
||||||
return sym instanceof AST_SymbolRef && all(sym.definition().orig, function(sym) {
|
}
|
||||||
|
if (!(sym instanceof AST_SymbolRef)) return;
|
||||||
|
if (compressor.exposed(sym.definition())) return;
|
||||||
|
if (!all(sym.definition().orig, function(sym) {
|
||||||
return !(sym instanceof AST_SymbolLambda);
|
return !(sym instanceof AST_SymbolLambda);
|
||||||
}) && sym;
|
})) return;
|
||||||
|
return sym;
|
||||||
};
|
};
|
||||||
var in_use = [];
|
var in_use = [];
|
||||||
var in_use_ids = Object.create(null); // avoid expensive linear scans of in_use
|
var in_use_ids = Object.create(null); // avoid expensive linear scans of in_use
|
||||||
@@ -5798,31 +5812,54 @@ merge(Compressor.prototype, {
|
|||||||
var is_func = fn instanceof AST_Lambda;
|
var is_func = fn instanceof AST_Lambda;
|
||||||
var stat = is_func && fn.first_statement();
|
var stat = is_func && fn.first_statement();
|
||||||
var can_inline = compressor.option("inline") && !self.is_expr_pure(compressor);
|
var can_inline = compressor.option("inline") && !self.is_expr_pure(compressor);
|
||||||
if (exp === fn && can_inline && stat instanceof AST_Return) {
|
if (can_inline && stat instanceof AST_Return) {
|
||||||
var value = stat.value;
|
var value = stat.value;
|
||||||
if (!value || value.is_constant_expression()) {
|
if (exp === fn && (!value || value.is_constant_expression())) {
|
||||||
var args = self.args.concat(value || make_node(AST_Undefined, self));
|
var args = self.args.concat(value || make_node(AST_Undefined, self));
|
||||||
return make_sequence(self, args).optimize(compressor);
|
return make_sequence(self, args).optimize(compressor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (is_func) {
|
if (is_func) {
|
||||||
var def, value, scope, in_loop, level = -1;
|
var def, value, var_assigned = false;
|
||||||
if (can_inline
|
if (can_inline
|
||||||
&& !fn.uses_arguments
|
&& !fn.uses_arguments
|
||||||
&& !fn.pinned()
|
&& !fn.pinned()
|
||||||
&& !(fn.name && fn instanceof AST_Function)
|
&& !(fn.name && fn instanceof AST_Function)
|
||||||
&& (value = can_flatten_body(stat))
|
&& (value = can_flatten_body(stat))
|
||||||
&& (exp === fn
|
&& (exp === fn
|
||||||
|| compressor.option("unused")
|
|| !recursive_ref(compressor, def = exp.definition()) && fn.is_constant_expression(exp.scope))
|
||||||
&& (def = exp.definition()).references.length == 1
|
&& !fn.contains_this()) {
|
||||||
&& !recursive_ref(compressor, def)
|
if (can_substitute_directly()) {
|
||||||
&& fn.is_constant_expression(exp.scope))
|
var args = self.args.slice();
|
||||||
&& !self.pure
|
args.push(value.clone(true).transform(new TreeTransformer(function(node) {
|
||||||
&& !fn.contains_this()
|
if (node instanceof AST_SymbolRef) {
|
||||||
|
var def = node.definition();
|
||||||
|
if (fn.variables.get(node.name) !== def) {
|
||||||
|
if (exp !== fn) def.references.push(node);
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
var index = resolve_index(def);
|
||||||
|
var arg = args[index];
|
||||||
|
if (!arg) return make_node(AST_Undefined, self);
|
||||||
|
args[index] = null;
|
||||||
|
var parent = this.parent();
|
||||||
|
return parent ? maintain_this_binding(compressor, parent, node, arg) : arg;
|
||||||
|
}
|
||||||
|
})));
|
||||||
|
var node = make_sequence(self, args.filter(function(arg) {
|
||||||
|
return arg;
|
||||||
|
})).optimize(compressor);
|
||||||
|
node = maintain_this_binding(compressor, compressor.parent(), compressor.self(), node);
|
||||||
|
if (best_of(compressor, self, node) === node) return node;
|
||||||
|
}
|
||||||
|
var scope, in_loop, level = -1;
|
||||||
|
if ((exp === fn || compressor.option("unused") && exp.definition().references.length == 1)
|
||||||
&& can_inject_symbols()) {
|
&& can_inject_symbols()) {
|
||||||
fn._squeezed = true;
|
fn._squeezed = true;
|
||||||
if (exp !== fn) fn.parent_scope = exp.scope;
|
if (exp !== fn) fn.parent_scope = exp.scope;
|
||||||
return make_sequence(self, flatten_fn()).optimize(compressor);
|
var node = make_sequence(self, flatten_fn()).optimize(compressor);
|
||||||
|
return maintain_this_binding(compressor, compressor.parent(), compressor.self(), node);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (compressor.option("side_effects")
|
if (compressor.option("side_effects")
|
||||||
&& all(fn.body, is_empty)
|
&& all(fn.body, is_empty)
|
||||||
@@ -5872,10 +5909,12 @@ merge(Compressor.prototype, {
|
|||||||
for (var i = 0; i < len; i++) {
|
for (var i = 0; i < len; i++) {
|
||||||
var line = fn.body[i];
|
var line = fn.body[i];
|
||||||
if (line instanceof AST_Var) {
|
if (line instanceof AST_Var) {
|
||||||
if (stat && !all(line.definitions, function(var_def) {
|
var assigned = var_assigned || !all(line.definitions, function(var_def) {
|
||||||
return !var_def.value;
|
return !var_def.value;
|
||||||
})) {
|
});
|
||||||
return false;
|
if (assigned) {
|
||||||
|
var_assigned = true;
|
||||||
|
if (stat) return false;
|
||||||
}
|
}
|
||||||
} else if (line instanceof AST_Defun || line instanceof AST_EmptyStatement) {
|
} else if (line instanceof AST_Defun || line instanceof AST_EmptyStatement) {
|
||||||
continue;
|
continue;
|
||||||
@@ -5888,6 +5927,61 @@ merge(Compressor.prototype, {
|
|||||||
return return_value(stat);
|
return return_value(stat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function resolve_index(def) {
|
||||||
|
for (var i = fn.argnames.length; --i >= 0;) {
|
||||||
|
if (fn.argnames[i].definition() === def) return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function can_substitute_directly() {
|
||||||
|
if (var_assigned) return;
|
||||||
|
if (compressor.option("inline") <= 1 && fn.argnames.length) return;
|
||||||
|
if (!fn.variables.all(function(def) {
|
||||||
|
return def.references.length < 2 && def.orig[0] instanceof AST_SymbolFunarg;
|
||||||
|
})) return;
|
||||||
|
var abort = false;
|
||||||
|
var begin;
|
||||||
|
var in_order = [];
|
||||||
|
var side_effects = false;
|
||||||
|
value.walk(new TreeWalker(function(node) {
|
||||||
|
if (abort) return true;
|
||||||
|
if (node instanceof AST_Binary && lazy_op[node.operator]
|
||||||
|
|| node instanceof AST_Conditional) {
|
||||||
|
in_order = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (node instanceof AST_Scope) return abort = true;
|
||||||
|
var def;
|
||||||
|
if (node instanceof AST_SymbolRef && fn.variables.get(node.name) === (def = node.definition())) {
|
||||||
|
if (def.init instanceof AST_Defun) return abort = true;
|
||||||
|
if (is_lhs(node, this.parent())) return abort = true;
|
||||||
|
var index = resolve_index(def);
|
||||||
|
if (!(begin < index)) begin = index;
|
||||||
|
if (!in_order) return;
|
||||||
|
if (side_effects) {
|
||||||
|
in_order = null;
|
||||||
|
} else {
|
||||||
|
in_order.push(fn.argnames[index]);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (node.has_side_effects(compressor)) side_effects = true;
|
||||||
|
}));
|
||||||
|
if (abort) return;
|
||||||
|
var end = self.args.length;
|
||||||
|
if (in_order && fn.argnames.length >= end) {
|
||||||
|
end = fn.argnames.length;
|
||||||
|
while (end-- > begin && fn.argnames[end] === in_order.pop());
|
||||||
|
end++;
|
||||||
|
}
|
||||||
|
var scope = side_effects && compressor.find_parent(AST_Scope);
|
||||||
|
return end <= begin || all(self.args.slice(begin, end), side_effects ? function(funarg) {
|
||||||
|
return funarg.is_constant_expression(scope);
|
||||||
|
} : function(funarg) {
|
||||||
|
return !funarg.has_side_effects(compressor);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function var_exists(defined, name) {
|
function var_exists(defined, name) {
|
||||||
return defined[name] || identifier_atom[name] || scope.var_names()[name];
|
return defined[name] || identifier_atom[name] || scope.var_names()[name];
|
||||||
}
|
}
|
||||||
@@ -6863,7 +6957,7 @@ merge(Compressor.prototype, {
|
|||||||
if (node.truthy) return true;
|
if (node.truthy) return true;
|
||||||
if (node.falsy) return false;
|
if (node.falsy) return false;
|
||||||
if (node.is_truthy()) return true;
|
if (node.is_truthy()) return true;
|
||||||
return node.evaluate(compressor);
|
return node.evaluate(compressor, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function is_indexFn(node) {
|
function is_indexFn(node) {
|
||||||
|
|||||||
@@ -203,6 +203,7 @@ function minify(files, options) {
|
|||||||
if (!HOP(options.output, "code") || options.output.code) {
|
if (!HOP(options.output, "code") || options.output.code) {
|
||||||
if (options.sourceMap) {
|
if (options.sourceMap) {
|
||||||
options.output.source_map = SourceMap({
|
options.output.source_map = SourceMap({
|
||||||
|
content: options.sourceMap.includeSources,
|
||||||
file: options.sourceMap.filename,
|
file: options.sourceMap.filename,
|
||||||
orig: source_maps,
|
orig: source_maps,
|
||||||
root: options.sourceMap.root
|
root: options.sourceMap.root
|
||||||
@@ -211,10 +212,8 @@ function minify(files, options) {
|
|||||||
if (files instanceof AST_Toplevel) {
|
if (files instanceof AST_Toplevel) {
|
||||||
throw new Error("original source content unavailable");
|
throw new Error("original source content unavailable");
|
||||||
} else for (var name in files) if (HOP(files, name)) {
|
} else for (var name in files) if (HOP(files, name)) {
|
||||||
options.output.source_map.get().setSourceContent(name, files[name]);
|
options.output.source_map.setSourceContent(name, files[name]);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
options.output.source_map.get()._sourcesContents = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete options.output.ast;
|
delete options.output.ast;
|
||||||
|
|||||||
12
lib/parse.js
12
lib/parse.js
@@ -241,16 +241,16 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
|||||||
if (signal_eof && !ch)
|
if (signal_eof && !ch)
|
||||||
throw EX_EOF;
|
throw EX_EOF;
|
||||||
if (NEWLINE_CHARS[ch]) {
|
if (NEWLINE_CHARS[ch]) {
|
||||||
S.newline_before = S.newline_before || !in_string;
|
|
||||||
++S.line;
|
|
||||||
S.col = 0;
|
S.col = 0;
|
||||||
if (!in_string && ch == "\r" && peek() == "\n") {
|
S.line++;
|
||||||
// treat a \r\n sequence as a single \n
|
if (!in_string) S.newline_before = true;
|
||||||
++S.pos;
|
if (ch == "\r" && peek() == "\n") {
|
||||||
|
// treat `\r\n` as `\n`
|
||||||
|
S.pos++;
|
||||||
ch = "\n";
|
ch = "\n";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
++S.col;
|
S.col++;
|
||||||
}
|
}
|
||||||
return ch;
|
return ch;
|
||||||
}
|
}
|
||||||
|
|||||||
22
lib/scope.js
22
lib/scope.js
@@ -162,17 +162,22 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
|
|||||||
}
|
}
|
||||||
if (node instanceof AST_SymbolRef) {
|
if (node instanceof AST_SymbolRef) {
|
||||||
var name = node.name;
|
var name = node.name;
|
||||||
if (name == "eval" && tw.parent() instanceof AST_Call) {
|
|
||||||
for (var s = node.scope; s && !s.uses_eval; s = s.parent_scope) {
|
|
||||||
s.uses_eval = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var sym = node.scope.find_variable(name);
|
var sym = node.scope.find_variable(name);
|
||||||
if (!sym) {
|
if (!sym) {
|
||||||
sym = self.def_global(node);
|
sym = self.def_global(node);
|
||||||
} else if (sym.scope instanceof AST_Lambda && name == "arguments") {
|
} else if (sym.scope instanceof AST_Lambda && name == "arguments") {
|
||||||
sym.scope.uses_arguments = true;
|
sym.scope.uses_arguments = true;
|
||||||
}
|
}
|
||||||
|
if (name == "eval") {
|
||||||
|
var parent = tw.parent();
|
||||||
|
if (parent.TYPE == "Call" && parent.expression === node) {
|
||||||
|
for (var s = node.scope; s && !s.uses_eval; s = s.parent_scope) {
|
||||||
|
s.uses_eval = true;
|
||||||
|
}
|
||||||
|
} else if (sym.undeclared) {
|
||||||
|
self.uses_eval = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
node.thedef = sym;
|
node.thedef = sym;
|
||||||
node.reference(options);
|
node.reference(options);
|
||||||
return true;
|
return true;
|
||||||
@@ -219,7 +224,12 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
|
|||||||
var redef;
|
var redef;
|
||||||
while (redef = new_def.redefined()) new_def = redef;
|
while (redef = new_def.redefined()) new_def = redef;
|
||||||
} else {
|
} else {
|
||||||
new_def = self.globals.get(name) || scope.def_variable(node);
|
new_def = self.globals.get(name);
|
||||||
|
}
|
||||||
|
if (new_def) {
|
||||||
|
new_def.orig.push(node);
|
||||||
|
} else {
|
||||||
|
new_def = scope.def_variable(node);
|
||||||
}
|
}
|
||||||
old_def.orig.concat(old_def.references).forEach(function(node) {
|
old_def.orig.concat(old_def.references).forEach(function(node) {
|
||||||
node.thedef = new_def;
|
node.thedef = new_def;
|
||||||
|
|||||||
172
lib/sourcemap.js
172
lib/sourcemap.js
@@ -43,62 +43,148 @@
|
|||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
// a small wrapper around fitzgen's source-map library
|
var vlq_char = characters("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");
|
||||||
|
var vlq_bits = vlq_char.reduce(function(map, ch, bits) {
|
||||||
|
map[ch] = bits;
|
||||||
|
return map;
|
||||||
|
}, Object.create(null));
|
||||||
|
|
||||||
|
function vlq_decode(indices, str) {
|
||||||
|
var value = 0;
|
||||||
|
var shift = 0;
|
||||||
|
for (var i = 0, j = 0; i < str.length; i++) {
|
||||||
|
var bits = vlq_bits[str[i]];
|
||||||
|
value += (bits & 31) << shift;
|
||||||
|
if (bits & 32) {
|
||||||
|
shift += 5;
|
||||||
|
} else {
|
||||||
|
indices[j++] += value & 1 ? 0x80000000 | -(value >> 1) : value >> 1;
|
||||||
|
value = shift = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return j;
|
||||||
|
}
|
||||||
|
|
||||||
|
function vlq_encode(num) {
|
||||||
|
var result = "";
|
||||||
|
num = Math.abs(num) << 1 | num >>> 31;
|
||||||
|
do {
|
||||||
|
var bits = num & 31;
|
||||||
|
if (num >>>= 5) bits |= 32;
|
||||||
|
result += vlq_char[bits];
|
||||||
|
} while (num);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function create_array_map() {
|
||||||
|
var map = Object.create(null);
|
||||||
|
var array = [];
|
||||||
|
array.index = function(name) {
|
||||||
|
if (!HOP(map, name)) {
|
||||||
|
map[name] = array.length;
|
||||||
|
array.push(name);
|
||||||
|
}
|
||||||
|
return map[name];
|
||||||
|
};
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
|
||||||
function SourceMap(options) {
|
function SourceMap(options) {
|
||||||
options = defaults(options, {
|
options = defaults(options, {
|
||||||
|
content: false,
|
||||||
file: null,
|
file: null,
|
||||||
root: null,
|
root: null,
|
||||||
orig: null,
|
orig: null,
|
||||||
orig_line_diff: 0,
|
|
||||||
dest_line_diff: 0,
|
|
||||||
}, true);
|
}, true);
|
||||||
var generator = new MOZ_SourceMap.SourceMapGenerator({
|
var sources = create_array_map();
|
||||||
file: options.file,
|
var sources_content = options.content && Object.create(null);
|
||||||
sourceRoot: options.root
|
var names = create_array_map();
|
||||||
|
var mappings = "";
|
||||||
|
if (options.orig) Object.keys(options.orig).forEach(function(name) {
|
||||||
|
var map = options.orig[name];
|
||||||
|
var indices = [ 0, 0, 1, 0, 0 ];
|
||||||
|
options.orig[name] = {
|
||||||
|
names: map.names,
|
||||||
|
mappings: map.mappings.split(/;/).map(function(line) {
|
||||||
|
indices[0] = 0;
|
||||||
|
return line.split(/,/).map(function(segment) {
|
||||||
|
return indices.slice(0, vlq_decode(indices, segment));
|
||||||
});
|
});
|
||||||
var maps = options.orig && Object.create(null);
|
}),
|
||||||
if (maps) for (var source in options.orig) {
|
sources: map.sources,
|
||||||
var map = new MOZ_SourceMap.SourceMapConsumer(options.orig[source]);
|
};
|
||||||
if (Array.isArray(options.orig[source].sources)) {
|
if (!sources_content || !map.sourcesContent) return;
|
||||||
map._sources.toArray().forEach(function(source) {
|
for (var i = 0; i < map.sources.length; i++) {
|
||||||
var sourceContent = map.sourceContentFor(source, true);
|
var content = map.sourcesContent[i];
|
||||||
if (sourceContent) generator.setSourceContent(source, sourceContent);
|
if (content) sources_content[map.sources[i]] = content;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
var generated_line = 1;
|
||||||
maps[source] = map;
|
var generated_column = 0;
|
||||||
}
|
var source_index = 0;
|
||||||
|
var original_line = 1;
|
||||||
|
var original_column = 0;
|
||||||
|
var name_index = 0;
|
||||||
return {
|
return {
|
||||||
add: function(source, gen_line, gen_col, orig_line, orig_col, name) {
|
add: options.orig ? function(source, gen_line, gen_col, orig_line, orig_col, name) {
|
||||||
var map = maps && maps[source];
|
var map = options.orig[source];
|
||||||
if (map) {
|
if (map) {
|
||||||
var info = map.originalPositionFor({
|
var segments = map.mappings[orig_line - 1];
|
||||||
line: orig_line,
|
if (!segments) return;
|
||||||
column: orig_col
|
var indices;
|
||||||
});
|
for (var i = 0; i < segments.length; i++) {
|
||||||
if (info.source === null) return;
|
var col = segments[i][0];
|
||||||
source = info.source;
|
if (orig_col >= col) indices = segments[i];
|
||||||
orig_line = info.line;
|
if (orig_col <= col) break;
|
||||||
orig_col = info.column;
|
|
||||||
name = info.name || name;
|
|
||||||
}
|
}
|
||||||
generator.addMapping({
|
if (!indices || indices.length < 4) return;
|
||||||
name: name,
|
source = map.sources[indices[1]];
|
||||||
source: source,
|
orig_line = indices[2];
|
||||||
generated: {
|
orig_col = indices[3];
|
||||||
line: gen_line + options.dest_line_diff,
|
if (indices.length > 4) name = map.names[indices[4]];
|
||||||
column: gen_col
|
|
||||||
},
|
|
||||||
original: {
|
|
||||||
line: orig_line + options.orig_line_diff,
|
|
||||||
column: orig_col
|
|
||||||
}
|
}
|
||||||
});
|
add(source, gen_line, gen_col, orig_line, orig_col, name);
|
||||||
},
|
} : add,
|
||||||
get: function() {
|
setSourceContent: sources_content ? function(source, content) {
|
||||||
return generator;
|
sources_content[source] = content;
|
||||||
},
|
} : noop,
|
||||||
toString: function() {
|
toString: function() {
|
||||||
return JSON.stringify(generator.toJSON());
|
return JSON.stringify({
|
||||||
|
version: 3,
|
||||||
|
file: options.file || undefined,
|
||||||
|
sourceRoot: options.root || undefined,
|
||||||
|
sources: sources,
|
||||||
|
sourcesContent: sources_content ? sources.map(function(source) {
|
||||||
|
return sources_content[source] || null;
|
||||||
|
}) : undefined,
|
||||||
|
names: names,
|
||||||
|
mappings: mappings,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function add(source, gen_line, gen_col, orig_line, orig_col, name) {
|
||||||
|
if (generated_line < gen_line) {
|
||||||
|
generated_column = 0;
|
||||||
|
do {
|
||||||
|
mappings += ";";
|
||||||
|
} while (++generated_line < gen_line);
|
||||||
|
} else if (mappings) {
|
||||||
|
mappings += ",";
|
||||||
|
}
|
||||||
|
mappings += vlq_encode(gen_col - generated_column);
|
||||||
|
generated_column = gen_col;
|
||||||
|
var src_idx = sources.index(source);
|
||||||
|
mappings += vlq_encode(src_idx - source_index);
|
||||||
|
source_index = src_idx;
|
||||||
|
mappings += vlq_encode(orig_line - original_line);
|
||||||
|
original_line = orig_line;
|
||||||
|
mappings += vlq_encode(orig_col - original_column);
|
||||||
|
original_column = orig_col;
|
||||||
|
if (name != null) {
|
||||||
|
var name_idx = names.index(name);
|
||||||
|
mappings += vlq_encode(name_idx - name_index);
|
||||||
|
name_index = name_idx;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -185,7 +185,7 @@ function makePredicate(words) {
|
|||||||
|
|
||||||
function all(array, predicate) {
|
function all(array, predicate) {
|
||||||
for (var i = array.length; --i >= 0;)
|
for (var i = array.length; --i >= 0;)
|
||||||
if (!predicate(array[i]))
|
if (!predicate(array[i], i))
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -217,6 +217,12 @@ Dictionary.prototype = {
|
|||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
has: function(key) { return ("$" + key) in this._values },
|
has: function(key) { return ("$" + key) in this._values },
|
||||||
|
all: function(predicate) {
|
||||||
|
for (var i in this._values)
|
||||||
|
if (!predicate(this._values[i], i.substr(1)))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
},
|
||||||
each: function(f) {
|
each: function(f) {
|
||||||
for (var i in this._values)
|
for (var i in this._values)
|
||||||
f(this._values[i], i.substr(1));
|
f(this._values[i], i.substr(1));
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
"description": "JavaScript parser, mangler/compressor and beautifier toolkit",
|
"description": "JavaScript parser, mangler/compressor and beautifier toolkit",
|
||||||
"author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)",
|
"author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)",
|
||||||
"license": "BSD-2-Clause",
|
"license": "BSD-2-Clause",
|
||||||
"version": "3.8.0",
|
"version": "3.9.1",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=0.8.0"
|
"node": ">=0.8.0"
|
||||||
},
|
},
|
||||||
@@ -23,8 +23,7 @@
|
|||||||
"LICENSE"
|
"LICENSE"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"commander": "~2.20.3",
|
"commander": "~2.20.3"
|
||||||
"source-map": "~0.6.1"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"acorn": "~7.1.0",
|
"acorn": "~7.1.0",
|
||||||
|
|||||||
@@ -5,12 +5,11 @@
|
|||||||
|
|
||||||
var createHash = require("crypto").createHash;
|
var createHash = require("crypto").createHash;
|
||||||
var fetch = require("./fetch");
|
var fetch = require("./fetch");
|
||||||
var fork = require("child_process").fork;
|
var spawn = require("child_process").spawn;
|
||||||
var zlib = require("zlib");
|
var zlib = require("zlib");
|
||||||
var args = process.argv.slice(2);
|
var args = process.argv.slice(2);
|
||||||
if (!args.length) {
|
args.unshift("bin/uglifyjs");
|
||||||
args.push("-mc");
|
if (!args.length) args.push("-mc");
|
||||||
}
|
|
||||||
args.push("--timings");
|
args.push("--timings");
|
||||||
var urls = [
|
var urls = [
|
||||||
"https://code.jquery.com/jquery-3.4.1.js",
|
"https://code.jquery.com/jquery-3.4.1.js",
|
||||||
@@ -70,18 +69,20 @@ urls.forEach(function(url) {
|
|||||||
};
|
};
|
||||||
fetch(url, function(err, res) {
|
fetch(url, function(err, res) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
var uglifyjs = fork("bin/uglifyjs", args, { silent: true });
|
var uglifyjs = spawn(process.argv[0], args, { silent: true });
|
||||||
res.on("data", function(data) {
|
res.on("data", function(data) {
|
||||||
results[url].input += data.length;
|
results[url].input += data.length;
|
||||||
}).pipe(uglifyjs.stdin);
|
}).pipe(uglifyjs.stdin);
|
||||||
|
var sha1 = createHash("sha1");
|
||||||
uglifyjs.stdout.on("data", function(data) {
|
uglifyjs.stdout.on("data", function(data) {
|
||||||
results[url].output += data.length;
|
results[url].output += data.length;
|
||||||
}).pipe(zlib.createGzip({
|
}).pipe(zlib.createGzip({
|
||||||
level: zlib.Z_BEST_COMPRESSION
|
level: zlib.Z_BEST_COMPRESSION
|
||||||
})).on("data", function(data) {
|
})).on("data", function(data) {
|
||||||
results[url].gzip += data.length;
|
results[url].gzip += data.length;
|
||||||
}).pipe(createHash("sha1")).on("data", function(data) {
|
sha1.update(data);
|
||||||
results[url].sha1 = data.toString("hex");
|
}).on("end", function() {
|
||||||
|
results[url].sha1 = sha1.digest("hex");
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
uglifyjs.stderr.setEncoding("utf8");
|
uglifyjs.stderr.setEncoding("utf8");
|
||||||
|
|||||||
@@ -207,8 +207,9 @@ function reminify(orig_options, input_code, input_formatted, stdout) {
|
|||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
var expected = stdout[options.toplevel ? 1 : 0];
|
var toplevel = sandbox.has_toplevel(options);
|
||||||
var actual = run_code(result.code, options.toplevel);
|
var expected = stdout[toplevel ? 1 : 0];
|
||||||
|
var actual = run_code(result.code, toplevel);
|
||||||
if (typeof expected != "string" && typeof actual != "string" && expected.name == actual.name) {
|
if (typeof expected != "string" && typeof actual != "string" && expected.name == actual.name) {
|
||||||
actual = expected;
|
actual = expected;
|
||||||
}
|
}
|
||||||
@@ -378,7 +379,10 @@ function test_case(test) {
|
|||||||
}
|
}
|
||||||
if (test.expect_stdout && (!test.node_version || semver.satisfies(process.version, test.node_version))) {
|
if (test.expect_stdout && (!test.node_version || semver.satisfies(process.version, test.node_version))) {
|
||||||
var stdout = [ run_code(input_code), run_code(input_code, true) ];
|
var stdout = [ run_code(input_code), run_code(input_code, true) ];
|
||||||
var toplevel = test.options.toplevel;
|
var toplevel = sandbox.has_toplevel({
|
||||||
|
compress: test.options,
|
||||||
|
mangle: test.mangle
|
||||||
|
});
|
||||||
var actual = stdout[toplevel ? 1 : 0];
|
var actual = stdout[toplevel ? 1 : 0];
|
||||||
if (test.expect_stdout === true) {
|
if (test.expect_stdout === true) {
|
||||||
test.expect_stdout = actual;
|
test.expect_stdout = actual;
|
||||||
|
|||||||
@@ -7765,3 +7765,44 @@ issue_3700: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_3744: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
inline: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function f(a) {
|
||||||
|
({
|
||||||
|
get p() {
|
||||||
|
switch (1) {
|
||||||
|
case 0:
|
||||||
|
f((a = 2, 3));
|
||||||
|
case 1:
|
||||||
|
console.log(function g(b) {
|
||||||
|
return b || "PASS";
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).p;
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function f(a) {
|
||||||
|
({
|
||||||
|
get p() {
|
||||||
|
switch (1) {
|
||||||
|
case 0:
|
||||||
|
f();
|
||||||
|
case 1:
|
||||||
|
console.log(b || "PASS");
|
||||||
|
}
|
||||||
|
var b;
|
||||||
|
}
|
||||||
|
}).p;
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|||||||
@@ -1240,11 +1240,11 @@ issue_2535_1: {
|
|||||||
expect: {
|
expect: {
|
||||||
y();
|
y();
|
||||||
x() && y();
|
x() && y();
|
||||||
(x(), 1) && y();
|
x(), y();
|
||||||
x() && y();
|
x() && y();
|
||||||
x() && y();
|
x() && y();
|
||||||
x() && y();
|
x() && y();
|
||||||
(x(), 0) && y();
|
x();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2413,3 +2413,34 @@ issue_3673: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_3746: {
|
||||||
|
options = {
|
||||||
|
keep_fargs: "strict",
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
try {
|
||||||
|
A;
|
||||||
|
} catch (e) {
|
||||||
|
var e;
|
||||||
|
}
|
||||||
|
(function f(a) {
|
||||||
|
e = a;
|
||||||
|
})();
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
try {
|
||||||
|
A;
|
||||||
|
} catch (e) {
|
||||||
|
var e;
|
||||||
|
}
|
||||||
|
(function(a) {
|
||||||
|
e = a;
|
||||||
|
})();
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|||||||
@@ -2161,3 +2161,32 @@ collapse_vars_regexp: {
|
|||||||
"abbb",
|
"abbb",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_3738: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(1 / (0 + ([] - 1) % 1));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(1 / (0 + ([] - 1) % 1));
|
||||||
|
}
|
||||||
|
expect_stdout: "Infinity"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3755: {
|
||||||
|
options = {
|
||||||
|
booleans: true,
|
||||||
|
evaluate: true,
|
||||||
|
unsafe: true,
|
||||||
|
unsafe_math: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log((/4/.exec(1 + (!0 - 5 / "23")) || 0).p);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log((/4/.exec(!0 - 5 / "23" + 1), 0).p);
|
||||||
|
}
|
||||||
|
expect_stdout: "undefined"
|
||||||
|
}
|
||||||
|
|||||||
@@ -342,11 +342,7 @@ inner_ref: {
|
|||||||
}(2));
|
}(2));
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
console.log(function(a) {
|
console.log(1, void 0);
|
||||||
return a;
|
|
||||||
}(1), function(a) {
|
|
||||||
return a;
|
|
||||||
}());
|
|
||||||
}
|
}
|
||||||
expect_stdout: "1 undefined"
|
expect_stdout: "1 undefined"
|
||||||
}
|
}
|
||||||
@@ -1024,9 +1020,7 @@ issue_2616: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var c = "FAIL";
|
var c = "FAIL";
|
||||||
!function(NaN) {
|
(true << []) - NaN || (c = "PASS");
|
||||||
(true << NaN) - 0/0 || (c = "PASS");
|
|
||||||
}([]);
|
|
||||||
console.log(c);
|
console.log(c);
|
||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
@@ -1577,7 +1571,23 @@ issue_2663_3: {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
duplicate_argnames: {
|
duplicate_argnames_1: {
|
||||||
|
options = {
|
||||||
|
inline: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function(a, a, a) {
|
||||||
|
return a;
|
||||||
|
}("FAIL", 42, "PASS"));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
duplicate_argnames_2: {
|
||||||
options = {
|
options = {
|
||||||
inline: true,
|
inline: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
@@ -1595,7 +1605,31 @@ duplicate_argnames: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var a = "PASS";
|
var a = "PASS";
|
||||||
console, b && (a = "FAIL");
|
console, void 0 && (a = "FAIL");
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
duplicate_argnames_3: {
|
||||||
|
options = {
|
||||||
|
inline: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "FAIL";
|
||||||
|
function f(b, b, b) {
|
||||||
|
b && (a = "PASS");
|
||||||
|
}
|
||||||
|
f(null, 0, console, "42".toString());
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = "FAIL";
|
||||||
|
b = console, "42".toString(), b && (a = "PASS");
|
||||||
var b;
|
var b;
|
||||||
console.log(a);
|
console.log(a);
|
||||||
}
|
}
|
||||||
@@ -1754,8 +1788,7 @@ inline_2: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
console.log(1);
|
console.log(1);
|
||||||
a = 2, console.log(a);
|
console.log(2);
|
||||||
var a;
|
|
||||||
(function(b) {
|
(function(b) {
|
||||||
var c = b;
|
var c = b;
|
||||||
console.log(c);
|
console.log(c);
|
||||||
@@ -1788,8 +1821,7 @@ inline_3: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
console.log(1);
|
console.log(1);
|
||||||
a = 2, console.log(a);
|
console.log(2);
|
||||||
var a;
|
|
||||||
b = 3, c = b, console.log(c);
|
b = 3, c = b, console.log(c);
|
||||||
var b, c;
|
var b, c;
|
||||||
}
|
}
|
||||||
@@ -1820,8 +1852,7 @@ inline_true: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
console.log(1);
|
console.log(1);
|
||||||
a = 2, console.log(a);
|
console.log(2);
|
||||||
var a;
|
|
||||||
b = 3, c = b, console.log(c);
|
b = 3, c = b, console.log(c);
|
||||||
var b, c;
|
var b, c;
|
||||||
}
|
}
|
||||||
@@ -1857,10 +1888,9 @@ use_before_init_in_loop: {
|
|||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
|
|
||||||
duplicate_arg_var: {
|
duplicate_arg_var_1: {
|
||||||
options = {
|
options = {
|
||||||
inline: true,
|
inline: true,
|
||||||
toplevel: true,
|
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
console.log(function(b) {
|
console.log(function(b) {
|
||||||
@@ -1869,7 +1899,41 @@ duplicate_arg_var: {
|
|||||||
}("PASS"));
|
}("PASS"));
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
console.log((b = "PASS", b));
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
duplicate_arg_var_2: {
|
||||||
|
options = {
|
||||||
|
inline: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function(b) {
|
||||||
|
return b + "SS";
|
||||||
|
var b;
|
||||||
|
}("PA"));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log("PA" + "SS");
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
duplicate_arg_var_3: {
|
||||||
|
options = {
|
||||||
|
inline: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function(b) {
|
||||||
|
return b + "SS";
|
||||||
|
var b;
|
||||||
|
}("PA", "42".toString()));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log((b = "PA", "42".toString(), b + "SS"));
|
||||||
var b;
|
var b;
|
||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
@@ -2017,10 +2081,8 @@ issue_3016_1: {
|
|||||||
expect: {
|
expect: {
|
||||||
var b = 1;
|
var b = 1;
|
||||||
do {
|
do {
|
||||||
a = 3,
|
3[b];
|
||||||
a[b];
|
|
||||||
} while(0);
|
} while(0);
|
||||||
var a;
|
|
||||||
console.log(b);
|
console.log(b);
|
||||||
}
|
}
|
||||||
expect_stdout: "1"
|
expect_stdout: "1"
|
||||||
@@ -2528,10 +2590,9 @@ cross_references_2: {
|
|||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
hoist_props: true,
|
|
||||||
inline: true,
|
inline: true,
|
||||||
passes: 4,
|
passes: 6,
|
||||||
pure_getters: true,
|
properties: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
@@ -3657,9 +3718,7 @@ pr_3595_3: {
|
|||||||
var g = [ "PASS" ];
|
var g = [ "PASS" ];
|
||||||
console.log(function(problem) {
|
console.log(function(problem) {
|
||||||
return g[problem];
|
return g[problem];
|
||||||
}(function(arg) {
|
}(g.indexOf("PASS")));
|
||||||
return g.indexOf(arg);
|
|
||||||
}("PASS")));
|
|
||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
@@ -3785,3 +3844,221 @@ issue_3679_3: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
preceding_side_effects: {
|
||||||
|
options = {
|
||||||
|
inline: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function(a, b, c) {
|
||||||
|
return b;
|
||||||
|
}(console, "PASS", 42));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log((console, 42, "PASS"));
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
trailing_side_effects: {
|
||||||
|
options = {
|
||||||
|
inline: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function(a, b, c) {
|
||||||
|
return b;
|
||||||
|
}(42, "PASS", console));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function(a, b, c) {
|
||||||
|
return b;
|
||||||
|
}(42, "PASS", console));
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
preserve_binding_1: {
|
||||||
|
options = {
|
||||||
|
inline: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var o = {
|
||||||
|
f: function() {
|
||||||
|
return this === o ? "FAIL" : "PASS";
|
||||||
|
},
|
||||||
|
};
|
||||||
|
console.log(function(a) {
|
||||||
|
return a;
|
||||||
|
}(o.f)());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var o = {
|
||||||
|
f: function() {
|
||||||
|
return this === o ? "FAIL" : "PASS";
|
||||||
|
},
|
||||||
|
};
|
||||||
|
console.log((0, o.f)());
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
preserve_binding_2: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
inline: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var o = {
|
||||||
|
f: function() {
|
||||||
|
return this === o ? "FAIL" : "PASS";
|
||||||
|
},
|
||||||
|
};
|
||||||
|
console.log(function(a) {
|
||||||
|
return a;
|
||||||
|
}(o.f)());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var o = {
|
||||||
|
f: function() {
|
||||||
|
return this === o ? "FAIL" : "PASS";
|
||||||
|
},
|
||||||
|
};
|
||||||
|
console.log((0, o.f)());
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3770: {
|
||||||
|
options = {
|
||||||
|
inline: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function() {
|
||||||
|
function f(a, a) {
|
||||||
|
var b = function() {
|
||||||
|
return a || "PASS";
|
||||||
|
}();
|
||||||
|
console.log(b);
|
||||||
|
}
|
||||||
|
f("FAIL");
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function() {
|
||||||
|
b = a || "PASS",
|
||||||
|
console.log(b);
|
||||||
|
var a, b;
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3771: {
|
||||||
|
options = {
|
||||||
|
inline: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
try {
|
||||||
|
function f(a) {
|
||||||
|
var a = f(1234);
|
||||||
|
}
|
||||||
|
f();
|
||||||
|
} catch (e) {
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
try {
|
||||||
|
(function f(a) {
|
||||||
|
f();
|
||||||
|
})();
|
||||||
|
} catch (e) {
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3772: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
dead_code: true,
|
||||||
|
inline: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "PASS";
|
||||||
|
function f() {
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
var b = f();
|
||||||
|
function g() {
|
||||||
|
console.log(f());
|
||||||
|
}
|
||||||
|
g();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = "PASS";
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3777_1: {
|
||||||
|
options = {
|
||||||
|
inline: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function() {
|
||||||
|
ff && ff(NaN);
|
||||||
|
function ff(a) {
|
||||||
|
var a = console.log("PASS");
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function() {
|
||||||
|
ff && ff(NaN);
|
||||||
|
function ff(a) {
|
||||||
|
var a = console.log("PASS");
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3777_2: {
|
||||||
|
options = {
|
||||||
|
inline: true,
|
||||||
|
pure_getters: "strict",
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
ff(ff.p);
|
||||||
|
function ff(a) {
|
||||||
|
var a = console.log("PASS");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
ff(ff.p);
|
||||||
|
function ff(a) {
|
||||||
|
var a = console.log("PASS");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|||||||
@@ -2398,3 +2398,25 @@ issue_3703: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_3750: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
ie8: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function(a) {
|
||||||
|
return function a() {
|
||||||
|
return a && console.log("PASS");
|
||||||
|
}();
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function(a) {
|
||||||
|
return function a() {
|
||||||
|
return a && console.log("PASS");
|
||||||
|
}();
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ warn: {
|
|||||||
}().length);
|
}().length);
|
||||||
}
|
}
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
"WARN: Function.prototype.caller not supported [test/compress/issue-2719.js:5,19]",
|
|
||||||
"WARN: Function.prototype.arguments not supported [test/compress/issue-2719.js:5,19]",
|
"WARN: Function.prototype.arguments not supported [test/compress/issue-2719.js:5,19]",
|
||||||
|
"WARN: Function.prototype.caller not supported [test/compress/issue-2719.js:5,19]",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
128
test/compress/issue-3768.js
Normal file
128
test/compress/issue-3768.js
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
mangle: {
|
||||||
|
mangle = {
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var e = eval, x = 42;
|
||||||
|
(function() {
|
||||||
|
console.log(e("typeof x"));
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var e = eval, x = 42;
|
||||||
|
(function() {
|
||||||
|
console.log(e("typeof x"));
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
compress: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
inline: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function() {
|
||||||
|
var a = 42;
|
||||||
|
return eval("typeof a");
|
||||||
|
}(), function(e) {
|
||||||
|
var a = null;
|
||||||
|
return e("typeof a");
|
||||||
|
}(eval), function(eval) {
|
||||||
|
var a = false;
|
||||||
|
return eval("typeof a");
|
||||||
|
}(eval), function(f) {
|
||||||
|
var a = "STRING";
|
||||||
|
var eval = f;
|
||||||
|
return eval("typeof a");
|
||||||
|
}(eval), function(g) {
|
||||||
|
var a = eval;
|
||||||
|
function eval() {
|
||||||
|
return g;
|
||||||
|
}
|
||||||
|
return eval()("typeof a");
|
||||||
|
}(eval));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function() {
|
||||||
|
var a = 42;
|
||||||
|
return eval("typeof a");
|
||||||
|
}(), (0, eval)("typeof a"), function(eval) {
|
||||||
|
var a = false;
|
||||||
|
return eval("typeof a");
|
||||||
|
}(eval), function(f) {
|
||||||
|
var a = "STRING";
|
||||||
|
var eval = f;
|
||||||
|
return eval("typeof a");
|
||||||
|
}(eval), function(g) {
|
||||||
|
var a = eval;
|
||||||
|
function eval() {
|
||||||
|
return g;
|
||||||
|
}
|
||||||
|
return eval()("typeof a");
|
||||||
|
}(eval));
|
||||||
|
}
|
||||||
|
expect_stdout: "number undefined boolean string undefined"
|
||||||
|
}
|
||||||
|
|
||||||
|
call_arg_1: {
|
||||||
|
mangle = {
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var z = "foo";
|
||||||
|
(function() {
|
||||||
|
var z = false;
|
||||||
|
(function(e) {
|
||||||
|
var z = 42;
|
||||||
|
e("console.log(typeof z)");
|
||||||
|
})(eval);
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var z = "foo";
|
||||||
|
(function() {
|
||||||
|
var o = false;
|
||||||
|
(function(o) {
|
||||||
|
var a = 42;
|
||||||
|
o("console.log(typeof z)");
|
||||||
|
})(eval);
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
call_arg_2: {
|
||||||
|
mangle = {
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function eval() {
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
var z = "foo";
|
||||||
|
(function() {
|
||||||
|
var z = false;
|
||||||
|
(function(e) {
|
||||||
|
var z = 42;
|
||||||
|
e("console.log(typeof z)");
|
||||||
|
})(eval);
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function n() {
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
var o = "foo";
|
||||||
|
(function() {
|
||||||
|
var o = false;
|
||||||
|
(function(o) {
|
||||||
|
var n = 42;
|
||||||
|
o("console.log(typeof z)");
|
||||||
|
})(n);
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
@@ -16,7 +16,6 @@ wrongly_optimized: {
|
|||||||
function func() {
|
function func() {
|
||||||
foo();
|
foo();
|
||||||
}
|
}
|
||||||
// TODO: optimize to `func(), bar()`
|
func(), 1, bar();
|
||||||
(func(), 1) && bar();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,6 +84,7 @@ wrongly_optimized: {
|
|||||||
options = {
|
options = {
|
||||||
booleans: true,
|
booleans: true,
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
|
dead_code: true,
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
expression: true,
|
expression: true,
|
||||||
}
|
}
|
||||||
@@ -99,8 +100,8 @@ wrongly_optimized: {
|
|||||||
function func() {
|
function func() {
|
||||||
foo();
|
foo();
|
||||||
}
|
}
|
||||||
// TODO: optimize to `func(), bar()`
|
func(), 1;
|
||||||
if (func(), 1) bar();
|
bar();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ remove_sequence: {
|
|||||||
(0, 1, _decorators.logThis)();
|
(0, 1, _decorators.logThis)();
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
eval();
|
(0, eval)();
|
||||||
logThis();
|
logThis();
|
||||||
(0, _decorators.logThis)();
|
(0, _decorators.logThis)();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,21 +53,24 @@ this_binding_conditionals: {
|
|||||||
this_binding_collapse_vars: {
|
this_binding_collapse_vars: {
|
||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
|
function f() {
|
||||||
"use strict";
|
"use strict";
|
||||||
var c = a; c();
|
var c = a; c();
|
||||||
var d = a.b; d();
|
var d = a.b; d();
|
||||||
var e = eval; e();
|
var e = eval; e();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
expect: {
|
expect: {
|
||||||
|
function f() {
|
||||||
"use strict";
|
"use strict";
|
||||||
a();
|
a();
|
||||||
(0, a.b)();
|
(0, a.b)();
|
||||||
(0, eval)();
|
(0, eval)();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this_binding_side_effects: {
|
this_binding_side_effects: {
|
||||||
@@ -97,7 +100,7 @@ this_binding_side_effects: {
|
|||||||
(function(foo) {
|
(function(foo) {
|
||||||
foo();
|
foo();
|
||||||
(0, foo.bar)();
|
(0, foo.bar)();
|
||||||
eval("console.log(foo);");
|
(0, eval)("console.log(foo);");
|
||||||
}());
|
}());
|
||||||
(function(foo) {
|
(function(foo) {
|
||||||
"use strict";
|
"use strict";
|
||||||
@@ -144,7 +147,7 @@ this_binding_sequences: {
|
|||||||
return eval("this");
|
return eval("this");
|
||||||
}()),
|
}()),
|
||||||
console.log(typeof function() {
|
console.log(typeof function() {
|
||||||
return eval("this");
|
return (0, eval)("this");
|
||||||
}()),
|
}()),
|
||||||
console.log(typeof function() {
|
console.log(typeof function() {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|||||||
@@ -2289,11 +2289,10 @@ redefine_farg_2: {
|
|||||||
console.log(f([]), g([]), h([]));
|
console.log(f([]), g([]), h([]));
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
console.log((a = [], typeof a), "number",function(a, b) {
|
console.log(typeof [], "number",function(a, b) {
|
||||||
a = b;
|
a = b;
|
||||||
return typeof a;
|
return typeof a;
|
||||||
}([]));
|
}([]));
|
||||||
var a;
|
|
||||||
}
|
}
|
||||||
expect_stdout: "object number undefined"
|
expect_stdout: "object number undefined"
|
||||||
}
|
}
|
||||||
@@ -6511,17 +6510,17 @@ issue_3240_3: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
(function() {
|
(function() {
|
||||||
(function f(b) {
|
f();
|
||||||
|
function f(b) {
|
||||||
if (!f.a) f.a = 0;
|
if (!f.a) f.a = 0;
|
||||||
console.log(f.a.toString());
|
console.log(f.a.toString());
|
||||||
var g = function() {
|
(function() {
|
||||||
(b ? function() {} : function() {
|
(b ? function() {} : function() {
|
||||||
f.a++;
|
f.a++;
|
||||||
f(1);
|
f(1);
|
||||||
})();
|
})();
|
||||||
};
|
|
||||||
g();
|
|
||||||
})();
|
})();
|
||||||
|
}
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
expect_stdout: [
|
expect_stdout: [
|
||||||
@@ -6555,7 +6554,8 @@ issue_3240_4: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
(function() {
|
(function() {
|
||||||
(function f(b) {
|
f();
|
||||||
|
function f(b) {
|
||||||
if (!f.a) f.a = 0;
|
if (!f.a) f.a = 0;
|
||||||
console.log(f.a.toString());
|
console.log(f.a.toString());
|
||||||
(function() {
|
(function() {
|
||||||
@@ -6564,7 +6564,7 @@ issue_3240_4: {
|
|||||||
f(1);
|
f(1);
|
||||||
})();
|
})();
|
||||||
})();
|
})();
|
||||||
})();
|
}
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
expect_stdout: [
|
expect_stdout: [
|
||||||
@@ -6873,3 +6873,42 @@ issue_3666: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "PASS PASS"
|
expect_stdout: "PASS PASS"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_3774: {
|
||||||
|
options = {
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var f = function() {
|
||||||
|
function g() {
|
||||||
|
if (!g.p) {
|
||||||
|
g.p = 1;
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return function() {
|
||||||
|
g();
|
||||||
|
};
|
||||||
|
}();
|
||||||
|
f();
|
||||||
|
f();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var f = function() {
|
||||||
|
function g() {
|
||||||
|
if (!g.p) {
|
||||||
|
g.p = 1;
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return function() {
|
||||||
|
g();
|
||||||
|
};
|
||||||
|
}();
|
||||||
|
f();
|
||||||
|
f();
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|||||||
@@ -255,3 +255,221 @@ issue_3434_4: {
|
|||||||
"false true",
|
"false true",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exec: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
loops: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
while (/a/.exec("AAA"))
|
||||||
|
console.log("FAIL");
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
for (;null;)
|
||||||
|
console.log("FAIL");
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
exec_global: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
loops: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
while (/a/g.exec("AAA"))
|
||||||
|
console.log("FAIL");
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
for (;null;)
|
||||||
|
console.log("FAIL");
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
test: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
while (/a/.test("AAA"))
|
||||||
|
console.log("FAIL");
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
while (false)
|
||||||
|
console.log("FAIL");
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
test_global: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
while (/a/g.test("AAA"))
|
||||||
|
console.log("FAIL");
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
while (false)
|
||||||
|
console.log("FAIL");
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
var_exec: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
loops: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var r = /a/;
|
||||||
|
while (r.exec("AAA"))
|
||||||
|
console.log("FAIL");
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var r = /a/;
|
||||||
|
for (;null;)
|
||||||
|
console.log("FAIL");
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
var_exec_global: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
loops: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var r = /a/g;
|
||||||
|
while (r.exec("aaa"))
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var r = /a/g;
|
||||||
|
for (;r.exec("aaa");)
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"PASS",
|
||||||
|
"PASS",
|
||||||
|
"PASS",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
var_test: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var r = /a/;
|
||||||
|
while (r.test("AAA"))
|
||||||
|
console.log("FAIL");
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var r = /a/;
|
||||||
|
while (false)
|
||||||
|
console.log("FAIL");
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
var_test_global: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var r = /a/g;
|
||||||
|
while (r.test("aaa"))
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var r = /a/g;
|
||||||
|
while (r.test("aaa"))
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"PASS",
|
||||||
|
"PASS",
|
||||||
|
"PASS",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
lazy_boolean: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
passes: 2,
|
||||||
|
side_effects: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
/b/.exec({}) && console.log("PASS");
|
||||||
|
/b/.test({}) && console.log("PASS");
|
||||||
|
/b/g.exec({}) && console.log("PASS");
|
||||||
|
/b/g.test({}) && console.log("PASS");
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log("PASS");
|
||||||
|
console.log("PASS");
|
||||||
|
console.log("PASS");
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"PASS",
|
||||||
|
"PASS",
|
||||||
|
"PASS",
|
||||||
|
"PASS",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
reset_state_between_evaluate: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
passes: 2,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function() {
|
||||||
|
for (var a in /[abc4]/g.exec("a"))
|
||||||
|
return "PASS";
|
||||||
|
return "FAIL";
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function() {
|
||||||
|
for (var a in /[abc4]/g.exec("a"))
|
||||||
|
return "PASS";
|
||||||
|
return "FAIL";
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|||||||
@@ -13,3 +13,4 @@ exports["to_ascii"] = to_ascii;
|
|||||||
exports["tokenizer"] = tokenizer;
|
exports["tokenizer"] = tokenizer;
|
||||||
exports["TreeTransformer"] = TreeTransformer;
|
exports["TreeTransformer"] = TreeTransformer;
|
||||||
exports["TreeWalker"] = TreeWalker;
|
exports["TreeWalker"] = TreeWalker;
|
||||||
|
exports["vlq_decode"] = vlq_decode;
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
function _toConsumableArray(arr){if(Array.isArray(arr)){for(var i=0,arr2=Array(arr.length);i<arr.length;i++){arr2[i]=arr[i]}return arr2}else{return Array.from(arr)}}var _require=require("bar"),foo=_require.foo;var _require2=require("world"),hello=_require2.hello;foo.x.apply(foo,_toConsumableArray(foo.y(hello.z)));
|
function _toConsumableArray(arr){if(Array.isArray(arr)){for(var i=0,arr2=Array(arr.length);i<arr.length;i++){arr2[i]=arr[i]}return arr2}else{return Array.from(arr)}}var _require=require("bar"),foo=_require.foo;var _require2=require("world"),hello=_require2.hello;foo.x.apply(foo,_toConsumableArray(foo.y(hello.z)));
|
||||||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImlucHV0Mi5qcyJdLCJuYW1lcyI6WyJyZXF1aXJlIiwiYXJyIl0sIm1hcHBpbmdzIjoiMEpBQWNBLEtBQVFDIiwic291cmNlc0NvbnRlbnQiOlsiY29uc3Qge2Zvb30gPSByZXF1aXJlKFwiYmFyXCIpO1xuY29uc3Qge2hlbGxvfSA9IHJlcXVpcmUoXCJ3b3JsZFwiKTtcblxuZm9vLngoLi4uZm9vLnkoaGVsbG8ueikpO1xuIl19
|
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImlucHV0Mi5qcyJdLCJzb3VyY2VzQ29udGVudCI6WyJjb25zdCB7Zm9vfSA9IHJlcXVpcmUoXCJiYXJcIik7XG5jb25zdCB7aGVsbG99ID0gcmVxdWlyZShcIndvcmxkXCIpO1xuXG5mb28ueCguLi5mb28ueShoZWxsby56KSk7XG4iXSwibmFtZXMiOlsicmVxdWlyZSIsImFyciJdLCJtYXBwaW5ncyI6IjBKQUFjQSxLQUFRQyJ9
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
new function(){console.log(3)};
|
new function(){console.log(3)};
|
||||||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInN0ZGluIl0sIm5hbWVzIjpbImNvbnNvbGUiLCJsb2ciXSwibWFwcGluZ3MiOiJBQUErQyxJQUFyQyxXQUFnQkEsUUFBUUMsSUFBSSIsInNvdXJjZXNDb250ZW50IjpbImNsYXNzIEZvbyB7IGNvbnN0cnVjdG9yKCl7Y29uc29sZS5sb2coMSsyKTt9IH0gbmV3IEZvbygpO1xuIl19
|
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInN0ZGluIl0sInNvdXJjZXNDb250ZW50IjpbImNsYXNzIEZvbyB7IGNvbnN0cnVjdG9yKCl7Y29uc29sZS5sb2coMSsyKTt9IH0gbmV3IEZvbygpO1xuIl0sIm5hbWVzIjpbImNvbnNvbGUiLCJsb2ciXSwibWFwcGluZ3MiOiJBQUErQyxJQUFyQyxXQUFnQkEsUUFBUUMsSUFBSSJ9
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
new function(){console.log(3)};
|
new function(){console.log(3)};
|
||||||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInN0ZGluIl0sIm5hbWVzIjpbImNvbnNvbGUiLCJsb2ciXSwibWFwcGluZ3MiOiJBQUErQyxJQUFyQyxXQUFnQkEsUUFBUUMsSUFBSSIsInNvdXJjZXNDb250ZW50IjpbImNsYXNzIEZvbyB7IGNvbnN0cnVjdG9yKCl7Y29uc29sZS5sb2coMSsyKTt9IH0gbmV3IEZvbygpO1xuIl19
|
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInN0ZGluIl0sInNvdXJjZXNDb250ZW50IjpbImNsYXNzIEZvbyB7IGNvbnN0cnVjdG9yKCl7Y29uc29sZS5sb2coMSsyKTt9IH0gbmV3IEZvbygpO1xuIl0sIm5hbWVzIjpbImNvbnNvbGUiLCJsb2ciXSwibWFwcGluZ3MiOiJBQUErQyxJQUFyQyxXQUFnQkEsUUFBUUMsSUFBSSJ9
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
|
// (beautified)
|
||||||
var o = this;
|
var o = this;
|
||||||
|
|
||||||
for (var k in o) {
|
for (var k in o) {}
|
||||||
0;
|
|
||||||
}
|
|
||||||
|
|
||||||
var a;
|
var a;
|
||||||
|
|
||||||
|
|||||||
8
test/input/reduce/setter.js
Normal file
8
test/input/reduce/setter.js
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
console.log(function f(a) {
|
||||||
|
({
|
||||||
|
set p(v) {
|
||||||
|
f++;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return f.length;
|
||||||
|
}());
|
||||||
20
test/input/reduce/setter.reduced.js
Normal file
20
test/input/reduce/setter.reduced.js
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
// (beautified)
|
||||||
|
console.log(function f(a) {
|
||||||
|
({
|
||||||
|
set p(v) {
|
||||||
|
f++;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return f.length;
|
||||||
|
}());
|
||||||
|
// output: 1
|
||||||
|
//
|
||||||
|
// minify: 0
|
||||||
|
//
|
||||||
|
// options: {
|
||||||
|
// "compress": {
|
||||||
|
// "keep_fargs": false,
|
||||||
|
// "unsafe": true
|
||||||
|
// },
|
||||||
|
// "mangle": false
|
||||||
|
// }
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// (beautified)
|
||||||
var b = 0;
|
var b = 0;
|
||||||
|
|
||||||
var expr2 = (0 - 1 - .1 - .1).toString();
|
var expr2 = (0 - 1 - .1 - .1).toString();
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
function f(x) {
|
function f(x) {
|
||||||
return g(x);
|
return g(x);
|
||||||
function g(x) {
|
function g(x) {
|
||||||
return x;
|
return x + x;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,15 +8,14 @@ if (typeof phantom == "undefined") {
|
|||||||
require("../tools/exit");
|
require("../tools/exit");
|
||||||
var args = process.argv.slice(2);
|
var args = process.argv.slice(2);
|
||||||
var debug = args.indexOf("--debug");
|
var debug = args.indexOf("--debug");
|
||||||
if (debug >= 0) {
|
if (debug < 0) {
|
||||||
|
debug = false;
|
||||||
|
} else {
|
||||||
args.splice(debug, 1);
|
args.splice(debug, 1);
|
||||||
debug = true;
|
debug = true;
|
||||||
} else {
|
|
||||||
debug = false;
|
|
||||||
}
|
|
||||||
if (!args.length) {
|
|
||||||
args.push("-mcb", "beautify=false,webkit");
|
|
||||||
}
|
}
|
||||||
|
args.unshift("bin/uglifyjs");
|
||||||
|
if (!args.length) args.push("-mcb", "beautify=false,webkit");
|
||||||
args.push("--timings");
|
args.push("--timings");
|
||||||
var child_process = require("child_process");
|
var child_process = require("child_process");
|
||||||
var fetch = require("./fetch");
|
var fetch = require("./fetch");
|
||||||
@@ -39,7 +38,7 @@ if (typeof phantom == "undefined") {
|
|||||||
});
|
});
|
||||||
if (/\.js$/.test(url)) {
|
if (/\.js$/.test(url)) {
|
||||||
var stderr = "";
|
var stderr = "";
|
||||||
var uglifyjs = child_process.fork("bin/uglifyjs", args, {
|
var uglifyjs = child_process.spawn(process.argv[0], args, {
|
||||||
silent: true
|
silent: true
|
||||||
}).on("exit", function(code) {
|
}).on("exit", function(code) {
|
||||||
console.log("uglifyjs", url.slice(site.length + 1), args.join(" "));
|
console.log("uglifyjs", url.slice(site.length + 1), args.join(" "));
|
||||||
|
|||||||
@@ -245,7 +245,7 @@ describe("bin/uglifyjs", function() {
|
|||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(stdout, [
|
assert.strictEqual(stdout, [
|
||||||
"var Foo=function Foo(){console.log(1+2)};new Foo;var bar=function(){function foo(bar){return bar}return foo}();",
|
"var Foo=function Foo(){console.log(1+2)};new Foo;var bar=function(){function foo(bar){return bar}return foo}();",
|
||||||
"//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInN0ZGluIiwidGVzdC9pbnB1dC9pc3N1ZS0xMzIzL3NhbXBsZS5qcyJdLCJuYW1lcyI6WyJGb28iLCJjb25zb2xlIiwibG9nIiwiYmFyIiwiZm9vIl0sIm1hcHBpbmdzIjoiQUFBQSxJQUFNQSxJQUFJLFNBQUFBLE1BQWdCQyxRQUFRQyxJQUFJLEVBQUUsSUFBTyxJQUFJRixJQ0FuRCxJQUFJRyxJQUFNLFdBQ04sU0FBU0MsSUFBS0QsS0FDVixPQUFPQSxJQUdYLE9BQU9DLElBTEQifQ==",
|
"//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInN0ZGluIiwidGVzdC9pbnB1dC9pc3N1ZS0xMzIzL3NhbXBsZS5qcyJdLCJuYW1lcyI6WyJGb28iLCJjb25zb2xlIiwibG9nIiwiYmFyIiwiZm9vIl0sIm1hcHBpbmdzIjoiQUFBQSxJQUFNQSxJQUFJLFNBQUVBLE1BQWNDLFFBQVFDLElBQUksRUFBRSxJQUFPLElBQUlGLElDQW5ELElBQUlHLElBQU0sV0FDTixTQUFTQyxJQUFLRCxLQUNWLE9BQU9BLElBR1gsT0FBT0MsSUFMRCJ9",
|
||||||
"",
|
"",
|
||||||
].join("\n"));
|
].join("\n"));
|
||||||
var stderrLines = stderr.split("\n");
|
var stderrLines = stderr.split("\n");
|
||||||
@@ -587,7 +587,7 @@ describe("bin/uglifyjs", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function read_map() {
|
function read_map() {
|
||||||
var map = JSON.parse(read("./test/input/issue-1236/simple.js.map"));
|
var map = JSON.parse(read("test/input/issue-1236/simple.js.map"));
|
||||||
delete map.sourcesContent;
|
delete map.sourcesContent;
|
||||||
return JSON.stringify(map).replace(/"/g, '\\"');
|
return JSON.stringify(map).replace(/"/g, '\\"');
|
||||||
}
|
}
|
||||||
@@ -674,7 +674,7 @@ describe("bin/uglifyjs", function() {
|
|||||||
var command = uglifyjscmd + " test/input/rename/input.js --rename";
|
var command = uglifyjscmd + " test/input/rename/input.js --rename";
|
||||||
exec(command, function(err, stdout, stderr) {
|
exec(command, function(err, stdout, stderr) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(stdout, "function f(a){return b(a);function b(c){return c}}\n");
|
assert.strictEqual(stdout, "function f(a){return b(a);function b(c){return c+c}}\n");
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -682,7 +682,7 @@ describe("bin/uglifyjs", function() {
|
|||||||
var command = uglifyjscmd + " test/input/rename/input.js -mc passes=2 --no-rename";
|
var command = uglifyjscmd + " test/input/rename/input.js -mc passes=2 --no-rename";
|
||||||
exec(command, function(err, stdout, stderr) {
|
exec(command, function(err, stdout, stderr) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(stdout, "function f(n){return function(n){return n}(n)}\n");
|
assert.strictEqual(stdout, "function f(n){return function(n){return n+n}(n)}\n");
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -690,7 +690,7 @@ describe("bin/uglifyjs", function() {
|
|||||||
var command = uglifyjscmd + " test/input/rename/input.js -mc passes=2";
|
var command = uglifyjscmd + " test/input/rename/input.js -mc passes=2";
|
||||||
exec(command, function(err, stdout, stderr) {
|
exec(command, function(err, stdout, stderr) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(stdout, "function f(n){return n}\n");
|
assert.strictEqual(stdout, "function f(n){return n+n}\n");
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -698,7 +698,7 @@ describe("bin/uglifyjs", function() {
|
|||||||
var command = uglifyjscmd + " test/input/rename/input.js -c passes=2";
|
var command = uglifyjscmd + " test/input/rename/input.js -c passes=2";
|
||||||
exec(command, function(err, stdout, stderr) {
|
exec(command, function(err, stdout, stderr) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(stdout, "function f(x){return function(x){return x}(x)}\n");
|
assert.strictEqual(stdout, "function f(x){return function(x){return x+x}(x)}\n");
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ describe("minify", function() {
|
|||||||
"var a=n(3),b=r(12);",
|
"var a=n(3),b=r(12);",
|
||||||
'c("qux",a,b),o(11);',
|
'c("qux",a,b),o(11);',
|
||||||
].join(""));
|
].join(""));
|
||||||
assert.strictEqual(run_code(compressed), run_code(original));
|
assert.strictEqual(run_code(compressed, true), run_code(original, true));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should work with nameCache", function() {
|
it("Should work with nameCache", function() {
|
||||||
@@ -84,7 +84,7 @@ describe("minify", function() {
|
|||||||
"var a=n(3),b=r(12);",
|
"var a=n(3),b=r(12);",
|
||||||
'c("qux",a,b),o(11);',
|
'c("qux",a,b),o(11);',
|
||||||
].join(""));
|
].join(""));
|
||||||
assert.strictEqual(run_code(compressed), run_code(original));
|
assert.strictEqual(run_code(compressed, true), run_code(original, true));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should avoid cached names when mangling top-level variables", function() {
|
it("Should avoid cached names when mangling top-level variables", function() {
|
||||||
@@ -113,7 +113,7 @@ describe("minify", function() {
|
|||||||
'"xxyyy";var y={y:2,a:3},a=4;',
|
'"xxyyy";var y={y:2,a:3},a=4;',
|
||||||
'console.log(x.x,y.y,y.a,a);',
|
'console.log(x.x,y.y,y.a,a);',
|
||||||
].join(""));
|
].join(""));
|
||||||
assert.strictEqual(run_code(compressed), run_code(original));
|
assert.strictEqual(run_code(compressed, true), run_code(original, true));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should avoid cached names when mangling inner-scoped variables", function() {
|
it("Should avoid cached names when mangling inner-scoped variables", function() {
|
||||||
@@ -137,7 +137,7 @@ describe("minify", function() {
|
|||||||
'var o=function(o,n){console.log("extend");o();n()};function n(){console.log("A")}',
|
'var o=function(o,n){console.log("extend");o();n()};function n(){console.log("A")}',
|
||||||
'var e=function(n){function e(){console.log("B")}o(e,n);return e}(n);',
|
'var e=function(n){function e(){console.log("B")}o(e,n);return e}(n);',
|
||||||
].join(""));
|
].join(""));
|
||||||
assert.strictEqual(run_code(compressed), run_code(original));
|
assert.strictEqual(run_code(compressed, true), run_code(original, true));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should not parse invalid use of reserved words", function() {
|
it("Should not parse invalid use of reserved words", function() {
|
||||||
|
|||||||
@@ -31,6 +31,19 @@ describe("test/reduce.js", function() {
|
|||||||
if (result.error) throw result.error;
|
if (result.error) throw result.error;
|
||||||
assert.strictEqual(result.code, read("test/input/reduce/label.reduced.js"));
|
assert.strictEqual(result.code, read("test/input/reduce/label.reduced.js"));
|
||||||
});
|
});
|
||||||
|
it("Should retain setter arguments", function() {
|
||||||
|
var result = reduce_test(read("test/input/reduce/setter.js"), {
|
||||||
|
compress: {
|
||||||
|
keep_fargs: false,
|
||||||
|
unsafe: true,
|
||||||
|
},
|
||||||
|
mangle: false,
|
||||||
|
}, {
|
||||||
|
verbose: false,
|
||||||
|
});
|
||||||
|
if (result.error) throw result.error;
|
||||||
|
assert.strictEqual(result.code, read("test/input/reduce/setter.reduced.js"));
|
||||||
|
});
|
||||||
it("Should handle test cases with --toplevel", function() {
|
it("Should handle test cases with --toplevel", function() {
|
||||||
var result = reduce_test([
|
var result = reduce_test([
|
||||||
"var Infinity = 42;",
|
"var Infinity = 42;",
|
||||||
@@ -40,21 +53,56 @@ describe("test/reduce.js", function() {
|
|||||||
});
|
});
|
||||||
if (result.error) throw result.error;
|
if (result.error) throw result.error;
|
||||||
assert.strictEqual(result.code, [
|
assert.strictEqual(result.code, [
|
||||||
"// Can't reproduce test failure with minify options provided:",
|
"// Can't reproduce test failure",
|
||||||
"// {",
|
"// minify options: {",
|
||||||
'// "toplevel": true',
|
'// "toplevel": true',
|
||||||
"// }",
|
"// }",
|
||||||
].join("\n"));
|
].join("\n"));
|
||||||
});
|
});
|
||||||
|
it("Should handle test cases with --compress toplevel", function() {
|
||||||
|
var result = reduce_test([
|
||||||
|
"var NaN = 42;",
|
||||||
|
"console.log(NaN);",
|
||||||
|
].join("\n"), {
|
||||||
|
compress: {
|
||||||
|
toplevel: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (result.error) throw result.error;
|
||||||
|
assert.strictEqual(result.code, [
|
||||||
|
"// Can't reproduce test failure",
|
||||||
|
"// minify options: {",
|
||||||
|
'// "compress": {',
|
||||||
|
'// "toplevel": true',
|
||||||
|
"// }",
|
||||||
|
"// }",
|
||||||
|
].join("\n"));
|
||||||
|
});
|
||||||
|
it("Should handle test cases with --mangle toplevel", function() {
|
||||||
|
var result = reduce_test([
|
||||||
|
"var undefined = 42;",
|
||||||
|
"console.log(undefined);",
|
||||||
|
].join("\n"), {
|
||||||
|
mangle: {
|
||||||
|
toplevel: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (result.error) throw result.error;
|
||||||
|
assert.strictEqual(result.code, [
|
||||||
|
"// Can't reproduce test failure",
|
||||||
|
"// minify options: {",
|
||||||
|
'// "mangle": {',
|
||||||
|
'// "toplevel": true',
|
||||||
|
"// }",
|
||||||
|
"// }",
|
||||||
|
].join("\n"));
|
||||||
|
});
|
||||||
it("Should handle test result of NaN", function() {
|
it("Should handle test result of NaN", function() {
|
||||||
var result = reduce_test("throw 0 / 0;");
|
var result = reduce_test("throw 0 / 0;");
|
||||||
if (result.error) throw result.error;
|
if (result.error) throw result.error;
|
||||||
assert.strictEqual(result.code, [
|
assert.strictEqual(result.code, [
|
||||||
"// Can't reproduce test failure with minify options provided:",
|
"// Can't reproduce test failure",
|
||||||
"// {",
|
"// minify options: {}",
|
||||||
'// "compress": {},',
|
|
||||||
'// "mangle": false',
|
|
||||||
"// }",
|
|
||||||
].join("\n"));
|
].join("\n"));
|
||||||
});
|
});
|
||||||
it("Should print correct output for irreducible test case", function() {
|
it("Should print correct output for irreducible test case", function() {
|
||||||
@@ -70,6 +118,7 @@ describe("test/reduce.js", function() {
|
|||||||
});
|
});
|
||||||
if (result.error) throw result.error;
|
if (result.error) throw result.error;
|
||||||
assert.strictEqual(result.code, [
|
assert.strictEqual(result.code, [
|
||||||
|
"// (beautified)",
|
||||||
"console.log(function f(a) {",
|
"console.log(function f(a) {",
|
||||||
" return f.length;",
|
" return f.length;",
|
||||||
"}());",
|
"}());",
|
||||||
@@ -118,6 +167,7 @@ describe("test/reduce.js", function() {
|
|||||||
});
|
});
|
||||||
if (result.error) throw result.error;
|
if (result.error) throw result.error;
|
||||||
assert.strictEqual(result.code, [
|
assert.strictEqual(result.code, [
|
||||||
|
"// (beautified)",
|
||||||
code,
|
code,
|
||||||
"// output: 0.8",
|
"// output: 0.8",
|
||||||
"// 1.6",
|
"// 1.6",
|
||||||
@@ -136,13 +186,43 @@ describe("test/reduce.js", function() {
|
|||||||
].join("\n"));
|
].join("\n"));
|
||||||
});
|
});
|
||||||
it("Should reduce infinite loops with reasonable performance", function() {
|
it("Should reduce infinite loops with reasonable performance", function() {
|
||||||
if (semver.satisfies(process.version, "0.10")) return;
|
if (semver.satisfies(process.version, "<=0.10")) return;
|
||||||
this.timeout(120000);
|
this.timeout(120000);
|
||||||
|
var result = reduce_test("while (/9/.test(1 - .8));", {
|
||||||
|
compress: {
|
||||||
|
unsafe_math: true,
|
||||||
|
},
|
||||||
|
mangle: false,
|
||||||
|
});
|
||||||
|
if (result.error) throw result.error;
|
||||||
|
assert.strictEqual(result.code.replace(/ timed out after [0-9]+ms/, " timed out."), [
|
||||||
|
"// (beautified)",
|
||||||
|
"while (/9/.test(1 - .8)) {}",
|
||||||
|
"// output: Error: Script execution timed out.",
|
||||||
|
"// minify: ",
|
||||||
|
"// options: {",
|
||||||
|
'// "compress": {',
|
||||||
|
'// "unsafe_math": true',
|
||||||
|
"// },",
|
||||||
|
'// "mangle": false',
|
||||||
|
"// }",
|
||||||
|
].join("\n"));
|
||||||
|
});
|
||||||
|
it("Should ignore difference in Error.message", function() {
|
||||||
|
var result = reduce_test("null[function() {\n}];");
|
||||||
|
if (result.error) throw result.error;
|
||||||
|
assert.strictEqual(result.code, (semver.satisfies(process.version, "<=0.10") ? [
|
||||||
|
"// Can't reproduce test failure",
|
||||||
|
"// minify options: {}",
|
||||||
|
] : [
|
||||||
|
"// No differences except in error message",
|
||||||
|
"// minify options: {}",
|
||||||
|
]).join("\n"));
|
||||||
|
});
|
||||||
|
it("Should report trailing whitespace difference in stringified format", function() {
|
||||||
var code = [
|
var code = [
|
||||||
"var a = 9007199254740992, b = 1;",
|
"for (var a in (1 - .8).toString()) {",
|
||||||
"",
|
" console.log();",
|
||||||
"while (a++ + (1 - b) < a) {",
|
|
||||||
" 0;",
|
|
||||||
"}",
|
"}",
|
||||||
].join("\n");
|
].join("\n");
|
||||||
var result = reduce_test(code, {
|
var result = reduce_test(code, {
|
||||||
@@ -152,14 +232,16 @@ describe("test/reduce.js", function() {
|
|||||||
mangle: false,
|
mangle: false,
|
||||||
});
|
});
|
||||||
if (result.error) throw result.error;
|
if (result.error) throw result.error;
|
||||||
assert.strictEqual(result.code.replace(/ timed out after [0-9]+ms/, " timed out."), [
|
assert.strictEqual(result.code, [
|
||||||
|
"// (beautified)",
|
||||||
code,
|
code,
|
||||||
"// output: ",
|
"// (stringified)",
|
||||||
"// minify: Error: Script execution timed out.",
|
'// output: "\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n"',
|
||||||
|
'// minify: "\\n\\n\\n"',
|
||||||
"// options: {",
|
"// options: {",
|
||||||
'// "compress": {',
|
'// "compress": {',
|
||||||
'// "unsafe_math": true',
|
'// "unsafe_math": true',
|
||||||
"// },",
|
'// },',
|
||||||
'// "mangle": false',
|
'// "mangle": false',
|
||||||
"// }",
|
"// }",
|
||||||
].join("\n"));
|
].join("\n"));
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
var assert = require("assert");
|
var assert = require("assert");
|
||||||
var readFileSync = require("fs").readFileSync;
|
var fs = require("fs");
|
||||||
var SourceMapConsumer = require("source-map").SourceMapConsumer;
|
|
||||||
var UglifyJS = require("../node");
|
var UglifyJS = require("../node");
|
||||||
|
|
||||||
function read(path) {
|
function read(path) {
|
||||||
return readFileSync(path, "utf8");
|
return fs.readFileSync(path, "utf8");
|
||||||
}
|
}
|
||||||
|
|
||||||
function source_map(code) {
|
function source_map(code) {
|
||||||
@@ -44,7 +43,7 @@ function prepare_map(sourceMap) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (result.error) throw result.error;
|
if (result.error) throw result.error;
|
||||||
return new SourceMapConsumer(result.map);
|
return JSON.parse(result.map);
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("sourcemaps", function() {
|
describe("sourcemaps", function() {
|
||||||
@@ -87,14 +86,30 @@ describe("sourcemaps", function() {
|
|||||||
});
|
});
|
||||||
if (result.error) throw result.error;
|
if (result.error) throw result.error;
|
||||||
assert.strictEqual(result.code, code);
|
assert.strictEqual(result.code, code);
|
||||||
assert.strictEqual(result.map, '{"version":3,"sources":["0"],"names":["console","log"],"mappings":"AAAAA,QAAQC,IAAI","sourceRoot":"//foo.bar/"}');
|
assert.strictEqual(result.map, '{"version":3,"sourceRoot":"//foo.bar/","sources":["0"],"names":["console","log"],"mappings":"AAAAA,QAAQC,IAAI"}');
|
||||||
|
});
|
||||||
|
it("Should produce same source map with DOS or UNIX line endings", function() {
|
||||||
|
var code = [
|
||||||
|
'console.log("\\',
|
||||||
|
'hello",',
|
||||||
|
'"world");',
|
||||||
|
];
|
||||||
|
var dos = UglifyJS.minify(code.join("\r\n"), {
|
||||||
|
sourceMap: true,
|
||||||
|
});
|
||||||
|
if (dos.error) throw dos.error;
|
||||||
|
var unix = UglifyJS.minify(code.join("\n"), {
|
||||||
|
sourceMap: true,
|
||||||
|
});
|
||||||
|
if (unix.error) throw unix.error;
|
||||||
|
assert.strictEqual(dos.map, unix.map);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("inSourceMap", function() {
|
describe("inSourceMap", function() {
|
||||||
it("Should read the given string filename correctly when sourceMapIncludeSources is enabled", function() {
|
it("Should read the given string filename correctly when sourceMapIncludeSources is enabled", function() {
|
||||||
var result = UglifyJS.minify(read("./test/input/issue-1236/simple.js"), {
|
var result = UglifyJS.minify(read("test/input/issue-1236/simple.js"), {
|
||||||
sourceMap: {
|
sourceMap: {
|
||||||
content: read("./test/input/issue-1236/simple.js.map"),
|
content: read("test/input/issue-1236/simple.js.map"),
|
||||||
filename: "simple.min.js",
|
filename: "simple.min.js",
|
||||||
includeSources: true
|
includeSources: true
|
||||||
}
|
}
|
||||||
@@ -106,7 +121,7 @@ describe("sourcemaps", function() {
|
|||||||
assert.equal(map.sourcesContent[0], 'let foo = x => "foo " + x;\nconsole.log(foo("bar"));');
|
assert.equal(map.sourcesContent[0], 'let foo = x => "foo " + x;\nconsole.log(foo("bar"));');
|
||||||
});
|
});
|
||||||
it("Should process inline source map", function() {
|
it("Should process inline source map", function() {
|
||||||
var result = UglifyJS.minify(read("./test/input/issue-520/input.js"), {
|
var result = UglifyJS.minify(read("test/input/issue-520/input.js"), {
|
||||||
compress: { toplevel: true },
|
compress: { toplevel: true },
|
||||||
sourceMap: {
|
sourceMap: {
|
||||||
content: "inline",
|
content: "inline",
|
||||||
@@ -115,10 +130,10 @@ describe("sourcemaps", function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (result.error) throw result.error;
|
if (result.error) throw result.error;
|
||||||
assert.strictEqual(result.code + "\n", readFileSync("test/input/issue-520/output.js", "utf8"));
|
assert.strictEqual(result.code + "\n", read("test/input/issue-520/output.js"));
|
||||||
});
|
});
|
||||||
it("Should warn for missing inline source map", function() {
|
it("Should warn for missing inline source map", function() {
|
||||||
var result = UglifyJS.minify(read("./test/input/issue-1323/sample.js"), {
|
var result = UglifyJS.minify(read("test/input/issue-1323/sample.js"), {
|
||||||
mangle: false,
|
mangle: false,
|
||||||
sourceMap: {
|
sourceMap: {
|
||||||
content: "inline"
|
content: "inline"
|
||||||
@@ -130,8 +145,8 @@ describe("sourcemaps", function() {
|
|||||||
});
|
});
|
||||||
it("Should handle multiple input and inline source map", function() {
|
it("Should handle multiple input and inline source map", function() {
|
||||||
var result = UglifyJS.minify([
|
var result = UglifyJS.minify([
|
||||||
read("./test/input/issue-520/input.js"),
|
read("test/input/issue-520/input.js"),
|
||||||
read("./test/input/issue-1323/sample.js"),
|
read("test/input/issue-1323/sample.js"),
|
||||||
], {
|
], {
|
||||||
sourceMap: {
|
sourceMap: {
|
||||||
content: "inline",
|
content: "inline",
|
||||||
@@ -147,7 +162,7 @@ describe("sourcemaps", function() {
|
|||||||
assert.deepEqual(result.warnings, [ "WARN: inline source map not found: 1" ]);
|
assert.deepEqual(result.warnings, [ "WARN: inline source map not found: 1" ]);
|
||||||
});
|
});
|
||||||
it("Should drop source contents for includeSources=false", function() {
|
it("Should drop source contents for includeSources=false", function() {
|
||||||
var result = UglifyJS.minify(read("./test/input/issue-520/input.js"), {
|
var result = UglifyJS.minify(read("test/input/issue-520/input.js"), {
|
||||||
compress: false,
|
compress: false,
|
||||||
mangle: false,
|
mangle: false,
|
||||||
sourceMap: {
|
sourceMap: {
|
||||||
@@ -170,7 +185,7 @@ describe("sourcemaps", function() {
|
|||||||
assert.ok(!("sourcesContent" in map));
|
assert.ok(!("sourcesContent" in map));
|
||||||
});
|
});
|
||||||
it("Should parse the correct sourceMappingURL", function() {
|
it("Should parse the correct sourceMappingURL", function() {
|
||||||
var result = UglifyJS.minify(read("./test/input/issue-3294/input.js"), {
|
var result = UglifyJS.minify(read("test/input/issue-3294/input.js"), {
|
||||||
compress: { toplevel: true },
|
compress: { toplevel: true },
|
||||||
sourceMap: {
|
sourceMap: {
|
||||||
content: "inline",
|
content: "inline",
|
||||||
@@ -179,10 +194,10 @@ describe("sourcemaps", function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (result.error) throw result.error;
|
if (result.error) throw result.error;
|
||||||
assert.strictEqual(result.code + "\n", readFileSync("test/input/issue-3294/output.js", "utf8"));
|
assert.strictEqual(result.code + "\n", read("test/input/issue-3294/output.js"));
|
||||||
});
|
});
|
||||||
it("Should work in presence of unrecognised annotations", function() {
|
it("Should work in presence of unrecognised annotations", function() {
|
||||||
var result = UglifyJS.minify(read("./test/input/issue-3441/input.js"), {
|
var result = UglifyJS.minify(read("test/input/issue-3441/input.js"), {
|
||||||
compress: false,
|
compress: false,
|
||||||
mangle: false,
|
mangle: false,
|
||||||
sourceMap: {
|
sourceMap: {
|
||||||
@@ -214,7 +229,7 @@ describe("sourcemaps", function() {
|
|||||||
assert.strictEqual(code, "var a=function(n){return n};");
|
assert.strictEqual(code, "var a=function(n){return n};");
|
||||||
});
|
});
|
||||||
it("Should work with max_line_len", function() {
|
it("Should work with max_line_len", function() {
|
||||||
var result = UglifyJS.minify(read("./test/input/issue-505/input.js"), {
|
var result = UglifyJS.minify(read("test/input/issue-505/input.js"), {
|
||||||
compress: {
|
compress: {
|
||||||
directives: false,
|
directives: false,
|
||||||
},
|
},
|
||||||
@@ -226,7 +241,7 @@ describe("sourcemaps", function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (result.error) throw result.error;
|
if (result.error) throw result.error;
|
||||||
assert.strictEqual(result.code, read("./test/input/issue-505/output.js"));
|
assert.strictEqual(result.code, read("test/input/issue-505/output.js"));
|
||||||
});
|
});
|
||||||
it("Should work with unicode characters", function() {
|
it("Should work with unicode characters", function() {
|
||||||
var code = [
|
var code = [
|
||||||
@@ -262,32 +277,42 @@ describe("sourcemaps", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("input sourcemaps", function() {
|
describe("input sourcemaps", function() {
|
||||||
|
it("Should not modify input source map", function() {
|
||||||
|
var orig = get_map();
|
||||||
|
var original = JSON.stringify(orig);
|
||||||
|
var map = prepare_map(orig);
|
||||||
|
assert.strictEqual(JSON.stringify(orig), original);
|
||||||
|
});
|
||||||
it("Should copy over original sourcesContent", function() {
|
it("Should copy over original sourcesContent", function() {
|
||||||
var orig = get_map();
|
var orig = get_map();
|
||||||
var map = prepare_map(orig);
|
var map = prepare_map(orig);
|
||||||
assert.equal(map.sourceContentFor("index.js"), orig.sourcesContent[0]);
|
assert.strictEqual(map.sources.length, 1);
|
||||||
|
assert.strictEqual(map.sources[0], "index.js");
|
||||||
|
assert.strictEqual(map.sourcesContent.length, 1);
|
||||||
|
assert.equal(map.sourcesContent[0], orig.sourcesContent[0]);
|
||||||
});
|
});
|
||||||
it("Should copy sourcesContent if sources are relative", function() {
|
it("Should copy sourcesContent if sources are relative", function() {
|
||||||
var relativeMap = get_map();
|
var relativeMap = get_map();
|
||||||
relativeMap.sources = ['./index.js'];
|
relativeMap.sources = ['./index.js'];
|
||||||
var map = prepare_map(relativeMap);
|
var map = prepare_map(relativeMap);
|
||||||
assert.notEqual(map.sourcesContent, null);
|
assert.strictEqual(map.sources.length, 1);
|
||||||
assert.equal(map.sourcesContent.length, 1);
|
assert.strictEqual(map.sources[0], "./index.js");
|
||||||
assert.equal(map.sourceContentFor("index.js"), relativeMap.sourcesContent[0]);
|
assert.strictEqual(map.sourcesContent.length, 1);
|
||||||
|
assert.equal(map.sourcesContent[0], relativeMap.sourcesContent[0]);
|
||||||
});
|
});
|
||||||
it("Should not have invalid mappings from inputSourceMap", function() {
|
it("Should not have invalid mappings from inputSourceMap", function() {
|
||||||
var map = prepare_map(get_map());
|
var map = prepare_map(get_map());
|
||||||
// The original source has only 2 lines, check that mappings don't have more lines
|
// The original source has only 2 lines, check that mappings don't have more lines
|
||||||
var msg = "Mapping should not have higher line number than the original file had";
|
var msg = "Mapping should not have higher line number than the original file had";
|
||||||
map.eachMapping(function(mapping) {
|
var lines = map.mappings.split(/;/);
|
||||||
assert.ok(mapping.originalLine <= 2, msg);
|
assert.ok(lines.length <= 2, msg);
|
||||||
|
var indices = [ 0, 0, 1, 0, 0];
|
||||||
|
lines.forEach(function(segments) {
|
||||||
|
indices[0] = 0;
|
||||||
|
segments.split(/,/).forEach(function(segment) {
|
||||||
|
UglifyJS.vlq_decode(indices, segment);
|
||||||
|
assert.ok(indices[2] <= 2, msg);
|
||||||
});
|
});
|
||||||
map.allGeneratedPositionsFor({
|
|
||||||
source: "index.js",
|
|
||||||
line: 1,
|
|
||||||
column: 1
|
|
||||||
}).forEach(function(pos) {
|
|
||||||
assert.ok(pos.line <= 2, msg);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -44,30 +44,37 @@ function test(original, estree, description) {
|
|||||||
try_beautify(transformed.code);
|
try_beautify(transformed.code);
|
||||||
}
|
}
|
||||||
console.log("!!!!!! Failed... round", round);
|
console.log("!!!!!! Failed... round", round);
|
||||||
process.exit(1);
|
return false;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var num_iterations = ufuzz.num_iterations;
|
var num_iterations = ufuzz.num_iterations;
|
||||||
|
var minify_options = require("./ufuzz/options.json").map(JSON.stringify);
|
||||||
|
minify_options.unshift(null);
|
||||||
for (var round = 1; round <= num_iterations; round++) {
|
for (var round = 1; round <= num_iterations; round++) {
|
||||||
process.stdout.write(round + " of " + num_iterations + "\r");
|
process.stdout.write(round + " of " + num_iterations + "\r");
|
||||||
var code = ufuzz.createTopLevelCode();
|
var code = ufuzz.createTopLevelCode();
|
||||||
var uglified = UglifyJS.minify(code, {
|
minify_options.forEach(function(options) {
|
||||||
|
var input = options ? UglifyJS.minify(code, JSON.parse(options)).code : code;
|
||||||
|
var uglified = UglifyJS.minify(input, {
|
||||||
compress: false,
|
compress: false,
|
||||||
mangle: false,
|
mangle: false,
|
||||||
output: {
|
output: {
|
||||||
ast: true
|
ast: true
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
test(uglified.code, uglified.ast.to_mozilla_ast(), "AST_Node.to_mozilla_ast()");
|
var ok = test(uglified.code, uglified.ast.to_mozilla_ast(), "AST_Node.to_mozilla_ast()");
|
||||||
try {
|
try {
|
||||||
test(uglified.code, acorn.parse(code), "acorn.parse()");
|
ok = test(uglified.code, acorn.parse(input), "acorn.parse()") && ok;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log("//=============================================================");
|
console.log("//=============================================================");
|
||||||
console.log("// acorn parser failed... round", round);
|
console.log("// acorn parser failed... round", round);
|
||||||
console.log(e);
|
console.log(e);
|
||||||
console.log("// original code");
|
console.log("// original code");
|
||||||
console.log(code);
|
console.log(input);
|
||||||
}
|
}
|
||||||
|
if (!ok) process.exit(1);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
console.log();
|
console.log();
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
|
|
||||||
new Function("MOZ_SourceMap", "exports", require("../tools/node").FILES.map(function(file) {
|
new Function("exports", require("../tools/node").FILES.map(function(file) {
|
||||||
if (/exports\.js$/.test(file)) file = require.resolve("./exports");
|
if (/exports\.js$/.test(file)) file = require.resolve("./exports");
|
||||||
return fs.readFileSync(file, "utf8");
|
return fs.readFileSync(file, "utf8");
|
||||||
}).join("\n\n"))(require("source-map"), exports);
|
}).join("\n\n"))(exports);
|
||||||
|
|||||||
116
test/reduce.js
116
test/reduce.js
@@ -20,7 +20,7 @@ var sandbox = require("./sandbox");
|
|||||||
|
|
||||||
module.exports = function reduce_test(testcase, minify_options, reduce_options) {
|
module.exports = function reduce_test(testcase, minify_options, reduce_options) {
|
||||||
if (testcase instanceof U.AST_Node) testcase = testcase.print_to_string();
|
if (testcase instanceof U.AST_Node) testcase = testcase.print_to_string();
|
||||||
minify_options = minify_options || { compress: {}, mangle: false };
|
minify_options = minify_options || {};
|
||||||
reduce_options = reduce_options || {};
|
reduce_options = reduce_options || {};
|
||||||
var max_iterations = reduce_options.max_iterations || 1000;
|
var max_iterations = reduce_options.max_iterations || 1000;
|
||||||
var max_timeout = reduce_options.max_timeout || 10000;
|
var max_timeout = reduce_options.max_timeout || 10000;
|
||||||
@@ -36,16 +36,29 @@ module.exports = function reduce_test(testcase, minify_options, reduce_options)
|
|||||||
if (!differs) {
|
if (!differs) {
|
||||||
// same stdout result produced when minified
|
// same stdout result produced when minified
|
||||||
return {
|
return {
|
||||||
code: "// Can't reproduce test failure with minify options provided:"
|
code: [
|
||||||
+ "\n// " + to_comment(minify_options_json)
|
"// Can't reproduce test failure",
|
||||||
|
"// minify options: " + to_comment(minify_options_json)
|
||||||
|
].join("\n")
|
||||||
};
|
};
|
||||||
} else if (differs.timed_out) {
|
} else if (differs.timed_out) {
|
||||||
return {
|
return {
|
||||||
code: "// Can't reproduce test failure within " + max_timeout + "ms:"
|
code: [
|
||||||
+ "\n// " + to_comment(minify_options_json)
|
"// Can't reproduce test failure within " + max_timeout + "ms",
|
||||||
|
"// minify options: " + to_comment(minify_options_json)
|
||||||
|
].join("\n")
|
||||||
};
|
};
|
||||||
} else if (differs.error) {
|
} else if (differs.error) {
|
||||||
return differs;
|
return differs;
|
||||||
|
} else if (is_error(differs.unminified_result)
|
||||||
|
&& is_error(differs.minified_result)
|
||||||
|
&& differs.unminified_result.name == differs.minified_result.name) {
|
||||||
|
return {
|
||||||
|
code: [
|
||||||
|
"// No differences except in error message",
|
||||||
|
"// minify options: " + to_comment(minify_options_json)
|
||||||
|
].join("\n")
|
||||||
|
};
|
||||||
} else {
|
} else {
|
||||||
max_timeout = Math.min(100 * differs.elapsed, max_timeout);
|
max_timeout = Math.min(100 * differs.elapsed, max_timeout);
|
||||||
// Replace expressions with constants that will be parsed into
|
// Replace expressions with constants that will be parsed into
|
||||||
@@ -71,12 +84,13 @@ module.exports = function reduce_test(testcase, minify_options, reduce_options)
|
|||||||
// quick ignores
|
// quick ignores
|
||||||
if (node instanceof U.AST_Accessor) return;
|
if (node instanceof U.AST_Accessor) return;
|
||||||
if (node instanceof U.AST_Directive) return;
|
if (node instanceof U.AST_Directive) return;
|
||||||
|
if (!in_list && node instanceof U.AST_EmptyStatement) return;
|
||||||
if (node instanceof U.AST_Label) return;
|
if (node instanceof U.AST_Label) return;
|
||||||
if (node instanceof U.AST_LabelRef) return;
|
if (node instanceof U.AST_LabelRef) return;
|
||||||
if (!in_list && node instanceof U.AST_SymbolDeclaration) return;
|
if (!in_list && node instanceof U.AST_SymbolDeclaration) return;
|
||||||
if (node instanceof U.AST_Toplevel) return;
|
if (node instanceof U.AST_Toplevel) return;
|
||||||
|
|
||||||
var parent = tt.parent();
|
var parent = tt.parent();
|
||||||
|
if (node instanceof U.AST_SymbolFunarg && parent instanceof U.AST_Accessor) return;
|
||||||
|
|
||||||
// ensure that the _permute prop is a number.
|
// ensure that the _permute prop is a number.
|
||||||
// can not use `node.start._permute |= 0;` as it will erase fractional part.
|
// can not use `node.start._permute |= 0;` as it will erase fractional part.
|
||||||
@@ -112,10 +126,25 @@ module.exports = function reduce_test(testcase, minify_options, reduce_options)
|
|||||||
}
|
}
|
||||||
else if (node instanceof U.AST_Binary) {
|
else if (node instanceof U.AST_Binary) {
|
||||||
CHANGED = true;
|
CHANGED = true;
|
||||||
return [
|
var permute = ((node.start._permute += step) * steps | 0) % 4;
|
||||||
|
var expr = [
|
||||||
node.left,
|
node.left,
|
||||||
node.right,
|
node.right,
|
||||||
][ ((node.start._permute += step) * steps | 0) % 2 ];
|
][ permute & 1 ];
|
||||||
|
if (permute < 2) return expr;
|
||||||
|
// wrap with console.log()
|
||||||
|
return new U.AST_Call({
|
||||||
|
expression: new U.AST_Dot({
|
||||||
|
expression: new U.AST_SymbolRef({
|
||||||
|
name: "console",
|
||||||
|
start: {},
|
||||||
|
}),
|
||||||
|
property: "log",
|
||||||
|
start: {},
|
||||||
|
}),
|
||||||
|
args: [ expr ],
|
||||||
|
start: {},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else if (node instanceof U.AST_Catch || node instanceof U.AST_Finally) {
|
else if (node instanceof U.AST_Catch || node instanceof U.AST_Finally) {
|
||||||
// drop catch or finally block
|
// drop catch or finally block
|
||||||
@@ -357,15 +386,11 @@ module.exports = function reduce_test(testcase, minify_options, reduce_options)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// replace this node
|
// replace this node
|
||||||
var newNode = U.parse(REPLACEMENTS[node.start._permute % REPLACEMENTS.length | 0], {
|
var newNode = is_statement(node) ? new U.AST_EmptyStatement({
|
||||||
|
start: {},
|
||||||
|
}) : U.parse(REPLACEMENTS[node.start._permute % REPLACEMENTS.length | 0], {
|
||||||
expression: true,
|
expression: true,
|
||||||
});
|
});
|
||||||
if (is_statement(node)) {
|
|
||||||
newNode = new U.AST_SimpleStatement({
|
|
||||||
body: newNode,
|
|
||||||
start: {},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
newNode.start._permute = ++node.start._permute;
|
newNode.start._permute = ++node.start._permute;
|
||||||
CHANGED = true;
|
CHANGED = true;
|
||||||
return newNode;
|
return newNode;
|
||||||
@@ -445,7 +470,42 @@ module.exports = function reduce_test(testcase, minify_options, reduce_options)
|
|||||||
console.error("// reduce test pass " + pass + ": " + testcase.length + " bytes");
|
console.error("// reduce test pass " + pass + ": " + testcase.length + " bytes");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
testcase = U.minify(testcase, {
|
testcase = try_beautify(result_cache, testcase, minify_options, differs.unminified_result, max_timeout);
|
||||||
|
var lines = [ "" ];
|
||||||
|
var unminified_result = strip_color_codes(differs.unminified_result);
|
||||||
|
var minified_result = strip_color_codes(differs.minified_result);
|
||||||
|
if (trim_trailing_whitespace(unminified_result) == trim_trailing_whitespace(minified_result)) {
|
||||||
|
lines.push(
|
||||||
|
"// (stringified)",
|
||||||
|
"// output: " + JSON.stringify(unminified_result),
|
||||||
|
"// minify: " + JSON.stringify(minified_result)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
lines.push(
|
||||||
|
"// output: " + to_comment(unminified_result),
|
||||||
|
"// minify: " + to_comment(minified_result)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
lines.push("// options: " + to_comment(minify_options_json));
|
||||||
|
testcase.code += lines.join("\n");
|
||||||
|
return testcase;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
function strip_color_codes(value) {
|
||||||
|
return ("" + value).replace(/\u001b\[\d+m/g, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
function to_comment(value) {
|
||||||
|
return ("" + value).replace(/\n/g, "\n// ");
|
||||||
|
}
|
||||||
|
|
||||||
|
function trim_trailing_whitespace(value) {
|
||||||
|
return ("" + value).replace(/\s+$/, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
function try_beautify(result_cache, testcase, minify_options, expected, timeout) {
|
||||||
|
var result = U.minify(testcase, {
|
||||||
compress: false,
|
compress: false,
|
||||||
mangle: false,
|
mangle: false,
|
||||||
output: {
|
output: {
|
||||||
@@ -454,18 +514,16 @@ module.exports = function reduce_test(testcase, minify_options, reduce_options)
|
|||||||
comments: true,
|
comments: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
testcase.code += [
|
if (result.error) return {
|
||||||
"",
|
code: testcase,
|
||||||
"// output: " + to_comment(differs.unminified_result),
|
};
|
||||||
"// minify: " + to_comment(differs.minified_result),
|
var toplevel = sandbox.has_toplevel(minify_options);
|
||||||
"// options: " + to_comment(minify_options_json),
|
var actual = run_code(result_cache, result.code, toplevel, timeout);
|
||||||
].join("\n").replace(/\u001b\[\d+m/g, "");
|
if (!sandbox.same_stdout(expected, actual)) return {
|
||||||
return testcase;
|
code: testcase,
|
||||||
}
|
};
|
||||||
};
|
result.code = "// (beautified)\n" + result.code;
|
||||||
|
return result;
|
||||||
function to_comment(value) {
|
|
||||||
return ("" + value).replace(/\n/g, "\n// ");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function has_exit(fn) {
|
function has_exit(fn) {
|
||||||
@@ -543,7 +601,7 @@ function producesDifferentResultWhenMinified(result_cache, code, minify_options,
|
|||||||
var minified = U.minify(code, minify_options);
|
var minified = U.minify(code, minify_options);
|
||||||
if (minified.error) return minified;
|
if (minified.error) return minified;
|
||||||
|
|
||||||
var toplevel = minify_options.toplevel;
|
var toplevel = sandbox.has_toplevel(minify_options);
|
||||||
var elapsed = Date.now();
|
var elapsed = Date.now();
|
||||||
var unminified_result = run_code(result_cache, code, toplevel, max_timeout);
|
var unminified_result = run_code(result_cache, code, toplevel, max_timeout);
|
||||||
elapsed = Date.now() - elapsed;
|
elapsed = Date.now() - elapsed;
|
||||||
|
|||||||
@@ -1,6 +1,3 @@
|
|||||||
setInterval(function() {
|
|
||||||
process.stderr.write("\0");
|
|
||||||
}, 8 * 60 * 1000).unref();
|
|
||||||
require("./run")([
|
require("./run")([
|
||||||
"-b",
|
"-b",
|
||||||
"-b braces",
|
"-b braces",
|
||||||
|
|||||||
@@ -87,3 +87,8 @@ exports.same_stdout = semver.satisfies(process.version, "0.12") ? function(expec
|
|||||||
} : function(expected, actual) {
|
} : function(expected, actual) {
|
||||||
return typeof expected == typeof actual && strip_func_ids(expected) == strip_func_ids(actual);
|
return typeof expected == typeof actual && strip_func_ids(expected) == strip_func_ids(actual);
|
||||||
};
|
};
|
||||||
|
exports.has_toplevel = function(options) {
|
||||||
|
return options.toplevel
|
||||||
|
|| options.mangle && options.mangle.toplevel
|
||||||
|
|| options.compress && options.compress.toplevel;
|
||||||
|
};
|
||||||
|
|||||||
@@ -742,6 +742,8 @@ function _createExpression(recurmax, noComma, stmtDepth, canThrow) {
|
|||||||
return " ((" + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + ") || a || 3).toString() ";
|
return " ((" + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + ") || a || 3).toString() ";
|
||||||
case p++:
|
case p++:
|
||||||
return " /[abc4]/.test(((" + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + ") || b || 5).toString()) ";
|
return " /[abc4]/.test(((" + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + ") || b || 5).toString()) ";
|
||||||
|
case p++:
|
||||||
|
return " /[abc4]/g.exec(((" + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + ") || b || 5).toString()) ";
|
||||||
case p++:
|
case p++:
|
||||||
return " ((" + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) +
|
return " ((" + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) +
|
||||||
") || " + rng(10) + ").toString()[" +
|
") || " + rng(10) + ").toString()[" +
|
||||||
@@ -770,6 +772,12 @@ function _createExpression(recurmax, noComma, stmtDepth, canThrow) {
|
|||||||
case p++:
|
case p++:
|
||||||
case p++:
|
case p++:
|
||||||
case p++:
|
case p++:
|
||||||
|
if (rng(16) == 0) {
|
||||||
|
var name = getVarName();
|
||||||
|
var fn = name + "." + getDotKey();
|
||||||
|
called[name] = true;
|
||||||
|
return name + " && " + "typeof " + fn + ' == "function" && --_calls_ >= 0 && ' + fn + "(" + createArgs(recurmax, stmtDepth, canThrow) + ")";
|
||||||
|
}
|
||||||
var name = rng(3) == 0 ? getVarName() : "f" + rng(funcs + 2);
|
var name = rng(3) == 0 ? getVarName() : "f" + rng(funcs + 2);
|
||||||
called[name] = true;
|
called[name] = true;
|
||||||
return "typeof " + name + ' == "function" && --_calls_ >= 0 && ' + name + "(" + createArgs(recurmax, stmtDepth, canThrow) + ")";
|
return "typeof " + name + ' == "function" && --_calls_ >= 0 && ' + name + "(" + createArgs(recurmax, stmtDepth, canThrow) + ")";
|
||||||
@@ -1010,7 +1018,7 @@ function log_suspects(minify_options, component) {
|
|||||||
var defs = default_options[component];
|
var defs = default_options[component];
|
||||||
var suspects = Object.keys(defs).filter(function(name) {
|
var suspects = Object.keys(defs).filter(function(name) {
|
||||||
var flip = name == "keep_fargs";
|
var flip = name == "keep_fargs";
|
||||||
if (flip ? name in options : (name in options ? options : defs)[name]) {
|
if (flip === !(name in options ? options : defs)[name]) {
|
||||||
var m = JSON.parse(JSON.stringify(minify_options));
|
var m = JSON.parse(JSON.stringify(minify_options));
|
||||||
var o = JSON.parse(JSON.stringify(options));
|
var o = JSON.parse(JSON.stringify(options));
|
||||||
o[name] = flip;
|
o[name] = flip;
|
||||||
@@ -1020,7 +1028,7 @@ function log_suspects(minify_options, component) {
|
|||||||
errorln("Error testing options." + component + "." + name);
|
errorln("Error testing options." + component + "." + name);
|
||||||
errorln(result.error);
|
errorln(result.error);
|
||||||
} else {
|
} else {
|
||||||
var r = sandbox.run_code(result.code, m.toplevel);
|
var r = sandbox.run_code(result.code, sandbox.has_toplevel(m));
|
||||||
return sandbox.same_stdout(original_result, r);
|
return sandbox.same_stdout(original_result, r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1034,37 +1042,45 @@ function log_suspects(minify_options, component) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function log_rename(options) {
|
function log_suspects_global(options) {
|
||||||
var m = JSON.parse(JSON.stringify(options));
|
var o = {};
|
||||||
m.rename = false;
|
UglifyJS.minify("", o);
|
||||||
|
var suspects = Object.keys(o).filter(function(component) {
|
||||||
|
return typeof o[component] != "object";
|
||||||
|
}).filter(function(component) {
|
||||||
|
var m = JSON.parse(options);
|
||||||
|
m[component] = false;
|
||||||
var result = UglifyJS.minify(original_code, m);
|
var result = UglifyJS.minify(original_code, m);
|
||||||
if (result.error) {
|
if (result.error) {
|
||||||
errorln("Error testing options.rename");
|
errorln("Error testing options." + component);
|
||||||
errorln(result.error);
|
errorln(result.error);
|
||||||
} else {
|
} else {
|
||||||
var r = sandbox.run_code(result.code, m.toplevel);
|
var r = sandbox.run_code(result.code, sandbox.has_toplevel(m));
|
||||||
if (sandbox.same_stdout(original_result, r)) {
|
return sandbox.same_stdout(original_result, r);
|
||||||
errorln("Suspicious options:");
|
|
||||||
errorln(" rename");
|
|
||||||
errorln();
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
if (suspects.length > 0) {
|
||||||
|
errorln("Suspicious options:");
|
||||||
|
suspects.forEach(function(name) {
|
||||||
|
errorln(" " + name);
|
||||||
|
});
|
||||||
|
errorln();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function log(options) {
|
function log(options) {
|
||||||
var options_copy = JSON.parse(options);
|
var toplevel = sandbox.has_toplevel(JSON.parse(options));
|
||||||
options = JSON.parse(options);
|
|
||||||
if (!ok) errorln("\n\n\n\n\n\n!!!!!!!!!!\n\n\n");
|
if (!ok) errorln("\n\n\n\n\n\n!!!!!!!!!!\n\n\n");
|
||||||
errorln("//=============================================================");
|
errorln("//=============================================================");
|
||||||
if (!ok) errorln("// !!!!!! Failed... round " + round);
|
if (!ok) errorln("// !!!!!! Failed... round " + round);
|
||||||
errorln("// original code");
|
errorln("// original code");
|
||||||
try_beautify(original_code, options.toplevel, original_result, errorln);
|
try_beautify(original_code, toplevel, original_result, errorln);
|
||||||
errorln();
|
errorln();
|
||||||
errorln();
|
errorln();
|
||||||
errorln("//-------------------------------------------------------------");
|
errorln("//-------------------------------------------------------------");
|
||||||
if (typeof uglify_code == "string") {
|
if (typeof uglify_code == "string") {
|
||||||
errorln("// uglified code");
|
errorln("// uglified code");
|
||||||
try_beautify(uglify_code, options.toplevel, uglify_result, errorln);
|
try_beautify(uglify_code, toplevel, uglify_result, errorln);
|
||||||
errorln();
|
errorln();
|
||||||
errorln();
|
errorln();
|
||||||
errorln("original result:");
|
errorln("original result:");
|
||||||
@@ -1072,7 +1088,7 @@ function log(options) {
|
|||||||
errorln("uglified result:");
|
errorln("uglified result:");
|
||||||
errorln(uglify_result);
|
errorln(uglify_result);
|
||||||
errorln("//-------------------------------------------------------------");
|
errorln("//-------------------------------------------------------------");
|
||||||
var reduced = reduce_test(original_code, options_copy, {
|
var reduced = reduce_test(original_code, JSON.parse(options), {
|
||||||
verbose: false,
|
verbose: false,
|
||||||
}).code;
|
}).code;
|
||||||
if (reduced) {
|
if (reduced) {
|
||||||
@@ -1094,11 +1110,11 @@ function log(options) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
errorln("minify(options):");
|
errorln("minify(options):");
|
||||||
errorln(JSON.stringify(options, null, 2));
|
errorln(JSON.stringify(JSON.parse(options), null, 2));
|
||||||
errorln();
|
errorln();
|
||||||
if (!ok && typeof uglify_code == "string") {
|
if (!ok && typeof uglify_code == "string") {
|
||||||
Object.keys(default_options).forEach(log_suspects.bind(null, options));
|
Object.keys(default_options).forEach(log_suspects.bind(null, JSON.parse(options)));
|
||||||
log_rename(options);
|
log_suspects_global(options);
|
||||||
errorln("!!!!!! Failed... round " + round);
|
errorln("!!!!!! Failed... round " + round);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1133,16 +1149,17 @@ for (var round = 1; round <= num_iterations; round++) {
|
|||||||
if (!errored) orig_result.push(sandbox.run_code(original_code, true));
|
if (!errored) orig_result.push(sandbox.run_code(original_code, true));
|
||||||
(errored ? fallback_options : minify_options).forEach(function(options) {
|
(errored ? fallback_options : minify_options).forEach(function(options) {
|
||||||
var o = JSON.parse(options);
|
var o = JSON.parse(options);
|
||||||
|
var toplevel = sandbox.has_toplevel(o);
|
||||||
uglify_code = UglifyJS.minify(original_code, o);
|
uglify_code = UglifyJS.minify(original_code, o);
|
||||||
original_result = orig_result[o.toplevel ? 1 : 0];
|
original_result = orig_result[toplevel ? 1 : 0];
|
||||||
if (!uglify_code.error) {
|
if (!uglify_code.error) {
|
||||||
uglify_code = uglify_code.code;
|
uglify_code = uglify_code.code;
|
||||||
uglify_result = sandbox.run_code(uglify_code, o.toplevel);
|
uglify_result = sandbox.run_code(uglify_code, toplevel);
|
||||||
ok = sandbox.same_stdout(original_result, uglify_result);
|
ok = sandbox.same_stdout(original_result, uglify_result);
|
||||||
if (!ok && typeof uglify_result == "string" && o.compress.unsafe_math) {
|
if (!ok && typeof uglify_result == "string" && o.compress.unsafe_math) {
|
||||||
ok = fuzzy_match(original_result, uglify_result);
|
ok = fuzzy_match(original_result, uglify_result);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
var fuzzy_result = sandbox.run_code(original_code.replace(/( - 0\.1){3}/g, " - 0.3"));
|
var fuzzy_result = sandbox.run_code(original_code.replace(/( - 0\.1){3}/g, " - 0.3"), toplevel);
|
||||||
ok = sandbox.same_stdout(fuzzy_result, uglify_result);
|
ok = sandbox.same_stdout(fuzzy_result, uglify_result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1156,7 +1173,7 @@ for (var round = 1; round <= num_iterations; round++) {
|
|||||||
else if (errored) {
|
else if (errored) {
|
||||||
println("//=============================================================");
|
println("//=============================================================");
|
||||||
println("// original code");
|
println("// original code");
|
||||||
try_beautify(original_code, o.toplevel, original_result, println);
|
try_beautify(original_code, toplevel, original_result, println);
|
||||||
println();
|
println();
|
||||||
println();
|
println();
|
||||||
println("original result:");
|
println("original result:");
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ process.exit = function() {
|
|||||||
process.once("uncaughtException", function() {
|
process.once("uncaughtException", function() {
|
||||||
(function callback() {
|
(function callback() {
|
||||||
if (process.stdout.bufferSize || process.stderr.bufferSize) {
|
if (process.stdout.bufferSize || process.stderr.bufferSize) {
|
||||||
setImmediate(callback);
|
setTimeout(callback, 1);
|
||||||
} else {
|
} else {
|
||||||
exit.apply(process, args);
|
exit.apply(process, args);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,13 +15,13 @@ exports.FILES = [
|
|||||||
require.resolve("./exports.js"),
|
require.resolve("./exports.js"),
|
||||||
];
|
];
|
||||||
|
|
||||||
new Function("MOZ_SourceMap", "exports", function() {
|
new Function("exports", function() {
|
||||||
var code = exports.FILES.map(function(file) {
|
var code = exports.FILES.map(function(file) {
|
||||||
return fs.readFileSync(file, "utf8");
|
return fs.readFileSync(file, "utf8");
|
||||||
});
|
});
|
||||||
code.push("exports.describe_ast = " + describe_ast.toString());
|
code.push("exports.describe_ast = " + describe_ast.toString());
|
||||||
return code.join("\n\n");
|
return code.join("\n\n");
|
||||||
}())(require("source-map"), exports);
|
}())(exports);
|
||||||
|
|
||||||
function describe_ast() {
|
function describe_ast() {
|
||||||
var out = OutputStream({ beautify: true });
|
var out = OutputStream({ beautify: true });
|
||||||
|
|||||||
Reference in New Issue
Block a user