Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
77261e1ee0 | ||
|
|
903a5df9a5 | ||
|
|
c810ecd081 | ||
|
|
dce9dfce0e | ||
|
|
3d72663689 | ||
|
|
a2b16e89a4 | ||
|
|
b35f4c5a83 | ||
|
|
41eb4f1725 | ||
|
|
94bc221669 | ||
|
|
822d298a55 | ||
|
|
273c6020ba | ||
|
|
1b07f64057 | ||
|
|
80d9c44b22 | ||
|
|
dc0cd088cf | ||
|
|
c69c026728 | ||
|
|
b5f4e1187f | ||
|
|
827bcec186 |
18
.github/workflows/ci.yml
vendored
18
.github/workflows/ci.yml
vendored
@@ -4,7 +4,7 @@ jobs:
|
|||||||
test:
|
test:
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
node: [ "0.10", "0.12", 4, 6, 8, 10, latest ]
|
node: [ "0.10", "0.12", "4", "6", "8", "10", latest ]
|
||||||
os: [ ubuntu-latest, windows-latest ]
|
os: [ ubuntu-latest, windows-latest ]
|
||||||
script: [ compress, mocha, release/benchmark, release/jetstream ]
|
script: [ compress, mocha, release/benchmark, release/jetstream ]
|
||||||
name: ${{ matrix.node }} ${{ matrix.os }} ${{ matrix.script }}
|
name: ${{ matrix.node }} ${{ matrix.os }} ${{ matrix.script }}
|
||||||
@@ -21,11 +21,19 @@ 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 update-notifier false
|
||||||
|
npm --version
|
||||||
|
while !(npm install); do echo "'npm install' failed - retrying..."; done
|
||||||
node test/$TYPE
|
node test/$TYPE
|
||||||
|
|||||||
16
.github/workflows/ufuzz.yml
vendored
16
.github/workflows/ufuzz.yml
vendored
@@ -15,11 +15,19 @@ 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 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
|
||||||
|
|||||||
126
lib/compress.js
126
lib/compress.js
@@ -318,7 +318,7 @@ merge(Compressor.prototype, {
|
|||||||
if (value instanceof AST_RegExp) return native_fns.RegExp[name] && !value.value.global;
|
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
|
||||||
@@ -3243,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 == "-")) {
|
||||||
@@ -5812,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) {
|
||||||
&& can_inject_symbols()) {
|
var def = node.definition();
|
||||||
fn._squeezed = true;
|
if (fn.variables.get(node.name) !== def) {
|
||||||
if (exp !== fn) fn.parent_scope = exp.scope;
|
if (exp !== fn) def.references.push(node);
|
||||||
return make_sequence(self, flatten_fn()).optimize(compressor);
|
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()) {
|
||||||
|
fn._squeezed = true;
|
||||||
|
if (exp !== fn) fn.parent_scope = exp.scope;
|
||||||
|
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)
|
||||||
@@ -5886,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;
|
||||||
@@ -5902,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];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
15
lib/scope.js
15
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;
|
||||||
|
|||||||
170
lib/sourcemap.js
170
lib/sourcemap.js
@@ -43,62 +43,144 @@
|
|||||||
|
|
||||||
"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 = "";
|
||||||
var maps = options.orig && Object.create(null);
|
if (options.orig) Object.keys(options.orig).forEach(function(name) {
|
||||||
if (maps) for (var source in options.orig) {
|
var map = options.orig[name];
|
||||||
var map = new MOZ_SourceMap.SourceMapConsumer(options.orig[source]);
|
var indices = [ 0, 0, 1, 0, 0 ];
|
||||||
if (Array.isArray(options.orig[source].sources)) {
|
map.mappings = map.mappings.split(/;/).map(function(line) {
|
||||||
map._sources.toArray().forEach(function(source) {
|
indices[0] = 0;
|
||||||
var sourceContent = map.sourceContentFor(source, true);
|
return line.split(/,/).map(function(segment) {
|
||||||
if (sourceContent) generator.setSourceContent(source, sourceContent);
|
return indices.slice(0, vlq_decode(indices, segment));
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
if (!sources_content || !map.sourcesContent) return;
|
||||||
|
for (var i = 0; i < map.sources.length; i++) {
|
||||||
|
var content = map.sourcesContent[i];
|
||||||
|
if (content) sources_content[map.sources[i]] = content;
|
||||||
}
|
}
|
||||||
maps[source] = map;
|
});
|
||||||
}
|
var generated_line = 1;
|
||||||
|
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({
|
|
||||||
name: name,
|
|
||||||
source: source,
|
|
||||||
generated: {
|
|
||||||
line: gen_line + options.dest_line_diff,
|
|
||||||
column: gen_col
|
|
||||||
},
|
|
||||||
original: {
|
|
||||||
line: orig_line + options.orig_line_diff,
|
|
||||||
column: orig_col
|
|
||||||
}
|
}
|
||||||
});
|
if (!indices || indices.length < 4) return;
|
||||||
},
|
source = map.sources[indices[1]];
|
||||||
get: function() {
|
orig_line = indices[2];
|
||||||
return generator;
|
orig_col = indices[3];
|
||||||
},
|
if (indices.length > 4) name = map.names[indices[4]];
|
||||||
|
}
|
||||||
|
add(source, gen_line, gen_col, orig_line, orig_col, name);
|
||||||
|
} : add,
|
||||||
|
setSourceContent: sources_content ? function(source, content) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.1",
|
"version": "3.9.0",
|
||||||
"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",
|
||||||
|
|||||||
@@ -2174,3 +2174,19 @@ issue_3738: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "Infinity"
|
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"
|
||||||
|
}
|
||||||
|
|||||||
@@ -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"
|
||||||
|
}
|
||||||
@@ -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,20 +53,23 @@ 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: {
|
||||||
"use strict";
|
function f() {
|
||||||
var c = a; c();
|
"use strict";
|
||||||
var d = a.b; d();
|
var c = a; c();
|
||||||
var e = eval; e();
|
var d = a.b; d();
|
||||||
|
var e = eval; e();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
"use strict";
|
function f() {
|
||||||
a();
|
"use strict";
|
||||||
(0, a.b)();
|
a();
|
||||||
(0, eval)();
|
(0, a.b)();
|
||||||
|
(0, eval)();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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"
|
||||||
|
}
|
||||||
|
|||||||
@@ -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,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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -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,7 +86,7 @@ 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() {
|
it("Should produce same source map with DOS or UNIX line endings", function() {
|
||||||
var code = [
|
var code = [
|
||||||
@@ -108,9 +107,9 @@ describe("sourcemaps", function() {
|
|||||||
|
|
||||||
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
|
||||||
}
|
}
|
||||||
@@ -122,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",
|
||||||
@@ -131,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"
|
||||||
@@ -146,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",
|
||||||
@@ -163,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: {
|
||||||
@@ -186,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",
|
||||||
@@ -195,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: {
|
||||||
@@ -230,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,
|
||||||
},
|
},
|
||||||
@@ -242,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 = [
|
||||||
@@ -281,29 +280,33 @@ describe("sourcemaps", function() {
|
|||||||
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];
|
||||||
map.allGeneratedPositionsFor({
|
lines.forEach(function(segments) {
|
||||||
source: "index.js",
|
indices[0] = 0;
|
||||||
line: 1,
|
segments.split(/,/).forEach(function(segment) {
|
||||||
column: 1
|
UglifyJS.vlq_decode(indices, segment);
|
||||||
}).forEach(function(pos) {
|
assert.ok(indices[2] <= 2, msg);
|
||||||
assert.ok(pos.line <= 2, msg);
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -772,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) + ")";
|
||||||
|
|||||||
@@ -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