Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
30a75049f5 | ||
|
|
a3cc3a9b87 | ||
|
|
96f8befdd7 | ||
|
|
cd58635dcc | ||
|
|
274331d0ea | ||
|
|
0489d6de64 | ||
|
|
fb092839c2 | ||
|
|
b7c112eefe |
10
README.md
10
README.md
@@ -68,7 +68,8 @@ The available options are:
|
||||
--source-map-inline Write base64-encoded source map to the end of js output.
|
||||
--in-source-map Input source map, useful if you're compressing
|
||||
JS that was generated from some other original
|
||||
code.
|
||||
code. Specify "inline" if the source map is included
|
||||
inline with the sources.
|
||||
--screw-ie8 Use this flag if you don't wish to support
|
||||
Internet Explorer 6/7/8.
|
||||
By default UglifyJS will not try to be IE-proof.
|
||||
@@ -200,9 +201,10 @@ compressed JS by mapping every token in the compiled JS to its original
|
||||
location.
|
||||
|
||||
To use this feature you need to pass `--in-source-map
|
||||
/path/to/input/source.map`. Normally the input source map should also point
|
||||
to the file containing the generated JS, so if that's correct you can omit
|
||||
input files from the command line.
|
||||
/path/to/input/source.map` or `--in-source-map inline` if the source map is
|
||||
included inline with the sources. Normally the input source map should also
|
||||
point to the file containing the generated JS, so if that's correct you can
|
||||
omit input files from the command line.
|
||||
|
||||
## Mangler options
|
||||
|
||||
|
||||
@@ -2656,7 +2656,7 @@ merge(Compressor.prototype, {
|
||||
if (self.args.length != 1) {
|
||||
return make_node(AST_Array, self, {
|
||||
elements: self.args
|
||||
}).transform(compressor);
|
||||
}).optimize(compressor);
|
||||
}
|
||||
break;
|
||||
case "Object":
|
||||
@@ -2674,7 +2674,7 @@ merge(Compressor.prototype, {
|
||||
left: self.args[0],
|
||||
operator: "+",
|
||||
right: make_node(AST_String, self, { value: "" })
|
||||
}).transform(compressor);
|
||||
}).optimize(compressor);
|
||||
break;
|
||||
case "Number":
|
||||
if (self.args.length == 0) return make_node(AST_Number, self, {
|
||||
@@ -2683,7 +2683,7 @@ merge(Compressor.prototype, {
|
||||
if (self.args.length == 1) return make_node(AST_UnaryPrefix, self, {
|
||||
expression: self.args[0],
|
||||
operator: "+"
|
||||
}).transform(compressor);
|
||||
}).optimize(compressor);
|
||||
case "Boolean":
|
||||
if (self.args.length == 0) return make_node(AST_False, self);
|
||||
if (self.args.length == 1) return make_node(AST_UnaryPrefix, self, {
|
||||
@@ -2692,7 +2692,7 @@ merge(Compressor.prototype, {
|
||||
operator: "!"
|
||||
}),
|
||||
operator: "!"
|
||||
}).transform(compressor);
|
||||
}).optimize(compressor);
|
||||
break;
|
||||
case "Function":
|
||||
// new Function() => function(){}
|
||||
@@ -2757,7 +2757,7 @@ merge(Compressor.prototype, {
|
||||
left: make_node(AST_String, self, { value: "" }),
|
||||
operator: "+",
|
||||
right: exp.expression
|
||||
}).transform(compressor);
|
||||
}).optimize(compressor);
|
||||
}
|
||||
else if (exp instanceof AST_Dot && exp.expression instanceof AST_Array && exp.property == "join") EXIT: {
|
||||
var separator;
|
||||
@@ -2811,7 +2811,7 @@ merge(Compressor.prototype, {
|
||||
left : prev,
|
||||
right : el
|
||||
});
|
||||
}, first).transform(compressor);
|
||||
}, first).optimize(compressor);
|
||||
}
|
||||
// need this awkward cloning to not affect original element
|
||||
// best_of will decide which one to get through.
|
||||
@@ -2821,6 +2821,16 @@ merge(Compressor.prototype, {
|
||||
node.expression.expression.elements = elements;
|
||||
return best_of(compressor, self, node);
|
||||
}
|
||||
else if (exp instanceof AST_Dot && exp.expression.is_string(compressor) && exp.property == "charAt") {
|
||||
var arg = self.args[0];
|
||||
var index = arg ? arg.evaluate(compressor) : 0;
|
||||
if (index !== arg) {
|
||||
return make_node(AST_Sub, exp, {
|
||||
expression: exp.expression,
|
||||
property: make_node_from_constant(index | 0, arg || exp)
|
||||
}).optimize(compressor);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (exp instanceof AST_Function) {
|
||||
if (exp.body[0] instanceof AST_Return) {
|
||||
@@ -2989,14 +2999,6 @@ merge(Compressor.prototype, {
|
||||
return self;
|
||||
});
|
||||
|
||||
function has_side_effects_or_prop_access(node, compressor) {
|
||||
var save_pure_getters = compressor.option("pure_getters");
|
||||
compressor.options.pure_getters = false;
|
||||
var ret = node.has_side_effects(compressor);
|
||||
compressor.options.pure_getters = save_pure_getters;
|
||||
return ret;
|
||||
}
|
||||
|
||||
AST_Binary.DEFMETHOD("lift_sequences", function(compressor){
|
||||
if (compressor.option("sequences")) {
|
||||
if (this.left instanceof AST_Seq) {
|
||||
@@ -3004,18 +3006,23 @@ merge(Compressor.prototype, {
|
||||
var x = seq.to_array();
|
||||
this.left = x.pop();
|
||||
x.push(this);
|
||||
seq = AST_Seq.from_array(x).transform(compressor);
|
||||
return seq;
|
||||
return AST_Seq.from_array(x).optimize(compressor);
|
||||
}
|
||||
if (this.right instanceof AST_Seq
|
||||
&& this instanceof AST_Assign
|
||||
&& !has_side_effects_or_prop_access(this.left, compressor)) {
|
||||
var seq = this.right;
|
||||
var x = seq.to_array();
|
||||
this.right = x.pop();
|
||||
x.push(this);
|
||||
seq = AST_Seq.from_array(x).transform(compressor);
|
||||
return seq;
|
||||
if (this.right instanceof AST_Seq && !this.left.has_side_effects(compressor)) {
|
||||
var assign = this.operator == "=" && this.left instanceof AST_SymbolRef;
|
||||
var root = this.right;
|
||||
var cursor, seq = root;
|
||||
while (assign || !seq.car.has_side_effects(compressor)) {
|
||||
cursor = seq;
|
||||
if (seq.cdr instanceof AST_Seq) {
|
||||
seq = seq.cdr;
|
||||
} else break;
|
||||
}
|
||||
if (cursor) {
|
||||
this.right = cursor.cdr;
|
||||
cursor.cdr = this;
|
||||
return root.optimize(compressor);
|
||||
}
|
||||
}
|
||||
}
|
||||
return this;
|
||||
@@ -3050,32 +3057,6 @@ merge(Compressor.prototype, {
|
||||
reverse();
|
||||
}
|
||||
}
|
||||
if (/^[!=]==?$/.test(self.operator)) {
|
||||
if (self.left instanceof AST_SymbolRef && self.right instanceof AST_Conditional) {
|
||||
if (self.right.consequent instanceof AST_SymbolRef
|
||||
&& self.right.consequent.definition() === self.left.definition()) {
|
||||
if (/^==/.test(self.operator)) return self.right.condition;
|
||||
if (/^!=/.test(self.operator)) return self.right.condition.negate(compressor);
|
||||
}
|
||||
if (self.right.alternative instanceof AST_SymbolRef
|
||||
&& self.right.alternative.definition() === self.left.definition()) {
|
||||
if (/^==/.test(self.operator)) return self.right.condition.negate(compressor);
|
||||
if (/^!=/.test(self.operator)) return self.right.condition;
|
||||
}
|
||||
}
|
||||
if (self.right instanceof AST_SymbolRef && self.left instanceof AST_Conditional) {
|
||||
if (self.left.consequent instanceof AST_SymbolRef
|
||||
&& self.left.consequent.definition() === self.right.definition()) {
|
||||
if (/^==/.test(self.operator)) return self.left.condition;
|
||||
if (/^!=/.test(self.operator)) return self.left.condition.negate(compressor);
|
||||
}
|
||||
if (self.left.alternative instanceof AST_SymbolRef
|
||||
&& self.left.alternative.definition() === self.right.definition()) {
|
||||
if (/^==/.test(self.operator)) return self.left.condition.negate(compressor);
|
||||
if (/^!=/.test(self.operator)) return self.left.condition;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
self = self.lift_sequences(compressor);
|
||||
if (compressor.option("comparisons")) switch (self.operator) {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
"homepage": "http://lisperator.net/uglifyjs",
|
||||
"author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)",
|
||||
"license": "BSD-2-Clause",
|
||||
"version": "2.8.13",
|
||||
"version": "2.8.14",
|
||||
"engines": {
|
||||
"node": ">=0.8.0"
|
||||
},
|
||||
|
||||
@@ -43,6 +43,7 @@ collapse_vars_side_effects_1: {
|
||||
z = i += 4;
|
||||
log(x, z, y, i);
|
||||
}
|
||||
f1(), f2(), f3(), f4();
|
||||
}
|
||||
expect: {
|
||||
function f1() {
|
||||
@@ -73,7 +74,9 @@ collapse_vars_side_effects_1: {
|
||||
y = i += 3;
|
||||
log(x, i += 4, y, i);
|
||||
}
|
||||
f1(), f2(), f3(), f4();
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
collapse_vars_side_effects_2: {
|
||||
@@ -823,6 +826,7 @@ collapse_vars_repeated: {
|
||||
console.log(e + "!");
|
||||
})("!");
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
collapse_vars_closures: {
|
||||
@@ -1109,6 +1113,7 @@ collapse_vars_eval_and_with: {
|
||||
return function() { with (o) console.log(a) };
|
||||
})()();
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
collapse_vars_constants: {
|
||||
@@ -1168,6 +1173,7 @@ collapse_vars_arguments: {
|
||||
(function(){console.log(arguments);})(7, 1);
|
||||
})();
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
collapse_vars_short_circuit: {
|
||||
@@ -1317,6 +1323,7 @@ collapse_vars_regexp: {
|
||||
console.log(result[0]);
|
||||
})();
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
issue_1537: {
|
||||
|
||||
@@ -51,6 +51,7 @@ concat_2: {
|
||||
"1" + "2" + "3"
|
||||
);
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
concat_3: {
|
||||
@@ -79,6 +80,7 @@ concat_3: {
|
||||
1 + 2 + "3" + "4" + "5"
|
||||
);
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
concat_4: {
|
||||
@@ -107,6 +109,7 @@ concat_4: {
|
||||
1 + "2" + "3" + "4" + "5"
|
||||
);
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
concat_5: {
|
||||
@@ -135,6 +138,7 @@ concat_5: {
|
||||
"1" + 2 + "3" + "4" + "5"
|
||||
);
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
concat_6: {
|
||||
@@ -163,6 +167,7 @@ concat_6: {
|
||||
"1" + "2" + "3" + "4" + "5"
|
||||
);
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
concat_7: {
|
||||
@@ -188,6 +193,7 @@ concat_7: {
|
||||
x += "foo"
|
||||
);
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
concat_8: {
|
||||
@@ -213,4 +219,5 @@ concat_8: {
|
||||
x += "foo"
|
||||
);
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
@@ -797,3 +797,99 @@ no_evaluate: {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
equality_conditionals_false: {
|
||||
options = {
|
||||
conditionals: false,
|
||||
sequences: true,
|
||||
}
|
||||
input: {
|
||||
function f(a, b, c) {
|
||||
console.log(
|
||||
a == (b ? a : a),
|
||||
a == (b ? a : c),
|
||||
a != (b ? a : a),
|
||||
a != (b ? a : c),
|
||||
a === (b ? a : a),
|
||||
a === (b ? a : c),
|
||||
a !== (b ? a : a),
|
||||
a !== (b ? a : c)
|
||||
);
|
||||
}
|
||||
f(0, 0, 0);
|
||||
f(0, true, 0);
|
||||
f(1, 2, 3);
|
||||
f(1, null, 3);
|
||||
f(NaN);
|
||||
f(NaN, "foo");
|
||||
}
|
||||
expect: {
|
||||
function f(a, b, c) {
|
||||
console.log(
|
||||
a == (b ? a : a),
|
||||
a == (b ? a : c),
|
||||
a != (b ? a : a),
|
||||
a != (b ? a : c),
|
||||
a === (b ? a : a),
|
||||
a === (b ? a : c),
|
||||
a !== (b ? a : a),
|
||||
a !== (b ? a : c)
|
||||
);
|
||||
}
|
||||
f(0, 0, 0),
|
||||
f(0, true, 0),
|
||||
f(1, 2, 3),
|
||||
f(1, null, 3),
|
||||
f(NaN),
|
||||
f(NaN, "foo");
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
equality_conditionals_true: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
sequences: true,
|
||||
}
|
||||
input: {
|
||||
function f(a, b, c) {
|
||||
console.log(
|
||||
a == (b ? a : a),
|
||||
a == (b ? a : c),
|
||||
a != (b ? a : a),
|
||||
a != (b ? a : c),
|
||||
a === (b ? a : a),
|
||||
a === (b ? a : c),
|
||||
a !== (b ? a : a),
|
||||
a !== (b ? a : c)
|
||||
);
|
||||
}
|
||||
f(0, 0, 0);
|
||||
f(0, true, 0);
|
||||
f(1, 2, 3);
|
||||
f(1, null, 3);
|
||||
f(NaN);
|
||||
f(NaN, "foo");
|
||||
}
|
||||
expect: {
|
||||
function f(a, b, c) {
|
||||
console.log(
|
||||
(b, a == a),
|
||||
a == (b ? a : c),
|
||||
(b, a != a),
|
||||
a != (b ? a : c),
|
||||
(b, a === a),
|
||||
a === (b ? a : c),
|
||||
(b, a !== a),
|
||||
a !== (b ? a : c)
|
||||
);
|
||||
}
|
||||
f(0, 0, 0),
|
||||
f(0, true, 0),
|
||||
f(1, 2, 3),
|
||||
f(1, null, 3),
|
||||
f(NaN),
|
||||
f(NaN, "foo");
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
@@ -162,4 +162,5 @@ regexp_literal_not_const: {
|
||||
while (result = REGEXP_LITERAL.exec("acdabcdeabbb")) console.log(result[0]);
|
||||
})();
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
@@ -87,6 +87,7 @@ dead_code_constant_boolean_should_warn_more: {
|
||||
var x = 10, y;
|
||||
var moo;
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
dead_code_const_declaration: {
|
||||
@@ -113,6 +114,7 @@ dead_code_const_declaration: {
|
||||
var moo;
|
||||
function bar() {}
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
dead_code_const_annotation: {
|
||||
@@ -140,6 +142,7 @@ dead_code_const_annotation: {
|
||||
var moo;
|
||||
function bar() {}
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
dead_code_const_annotation_regex: {
|
||||
@@ -163,6 +166,7 @@ dead_code_const_annotation_regex: {
|
||||
var CONST_FOO_ANN = !1;
|
||||
CONST_FOO_ANN && console.log('reachable');
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
dead_code_const_annotation_complex_scope: {
|
||||
@@ -208,4 +212,5 @@ dead_code_const_annotation_complex_scope: {
|
||||
var meat = 'beef';
|
||||
var pork = 'bad';
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
@@ -200,6 +200,7 @@ negative_zero: {
|
||||
1 / (-0)
|
||||
);
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
positive_zero: {
|
||||
@@ -220,6 +221,7 @@ positive_zero: {
|
||||
1 / (0)
|
||||
);
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
unsafe_constant: {
|
||||
@@ -243,6 +245,7 @@ unsafe_constant: {
|
||||
(void 0).a
|
||||
);
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
unsafe_object: {
|
||||
@@ -266,6 +269,7 @@ unsafe_object: {
|
||||
1..b + 1
|
||||
);
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
unsafe_object_nested: {
|
||||
@@ -289,6 +293,7 @@ unsafe_object_nested: {
|
||||
2
|
||||
);
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
unsafe_object_complex: {
|
||||
@@ -312,6 +317,7 @@ unsafe_object_complex: {
|
||||
2
|
||||
);
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
unsafe_object_repeated: {
|
||||
@@ -335,6 +341,7 @@ unsafe_object_repeated: {
|
||||
1..b + 1
|
||||
);
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
unsafe_object_accessor: {
|
||||
@@ -384,6 +391,7 @@ unsafe_function: {
|
||||
({a:{b:1},b:function(){}}).a.b + 1
|
||||
);
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
unsafe_integer_key: {
|
||||
@@ -411,6 +419,7 @@ unsafe_integer_key: {
|
||||
1["1"] + 1
|
||||
);
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
unsafe_integer_key_complex: {
|
||||
@@ -438,6 +447,7 @@ unsafe_integer_key_complex: {
|
||||
2
|
||||
);
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
unsafe_float_key: {
|
||||
@@ -465,6 +475,7 @@ unsafe_float_key: {
|
||||
1["3.14"] + 1
|
||||
);
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
unsafe_float_key_complex: {
|
||||
@@ -492,6 +503,7 @@ unsafe_float_key_complex: {
|
||||
2
|
||||
);
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
unsafe_array: {
|
||||
@@ -527,6 +539,7 @@ unsafe_array: {
|
||||
(void 0)[1] + 1
|
||||
);
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
unsafe_string: {
|
||||
@@ -554,6 +567,7 @@ unsafe_string: {
|
||||
"11"
|
||||
);
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
unsafe_array_bad_index: {
|
||||
@@ -575,6 +589,7 @@ unsafe_array_bad_index: {
|
||||
[1, 2, 3, 4][3.14] + 1
|
||||
);
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
unsafe_string_bad_index: {
|
||||
@@ -596,6 +611,7 @@ unsafe_string_bad_index: {
|
||||
"1234"[3.14] + 1
|
||||
);
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
unsafe_prototype_function: {
|
||||
@@ -642,6 +658,7 @@ call_args: {
|
||||
console.log(1);
|
||||
+(1, 1);
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
call_args_drop_param: {
|
||||
@@ -663,6 +680,7 @@ call_args_drop_param: {
|
||||
console.log(1);
|
||||
+(b, 1);
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
in_boolean_context: {
|
||||
@@ -700,4 +718,74 @@ in_boolean_context: {
|
||||
(foo(), !1)
|
||||
);
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
unsafe_charAt: {
|
||||
options = {
|
||||
evaluate : true,
|
||||
unsafe : true
|
||||
}
|
||||
input: {
|
||||
console.log(
|
||||
"1234" + 1,
|
||||
"1234".charAt(0) + 1,
|
||||
"1234".charAt(6 - 5) + 1,
|
||||
("12" + "34").charAt(0) + 1,
|
||||
("12" + "34").charAt(6 - 5) + 1,
|
||||
[1, 2, 3, 4].join("").charAt(0) + 1
|
||||
);
|
||||
}
|
||||
expect: {
|
||||
console.log(
|
||||
"12341",
|
||||
"11",
|
||||
"21",
|
||||
"11",
|
||||
"21",
|
||||
"11"
|
||||
);
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
unsafe_charAt_bad_index: {
|
||||
options = {
|
||||
evaluate : true,
|
||||
unsafe : true
|
||||
}
|
||||
input: {
|
||||
console.log(
|
||||
"1234".charAt() + 1,
|
||||
"1234".charAt("a") + 1,
|
||||
"1234".charAt(3.14) + 1
|
||||
);
|
||||
}
|
||||
expect: {
|
||||
console.log(
|
||||
"11",
|
||||
"11",
|
||||
"41"
|
||||
);
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
unsafe_charAt_noop: {
|
||||
options = {
|
||||
evaluate : true,
|
||||
unsafe : true
|
||||
}
|
||||
input: {
|
||||
console.log(
|
||||
s.charAt(0),
|
||||
"string".charAt(x)
|
||||
);
|
||||
}
|
||||
expect: {
|
||||
console.log(
|
||||
s.charAt(0),
|
||||
"string".charAt(x)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ iifes_returning_constants_keep_fargs_true: {
|
||||
console.log(6);
|
||||
console.log((a(), b(), 6));
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
iifes_returning_constants_keep_fargs_false: {
|
||||
@@ -73,6 +74,7 @@ iifes_returning_constants_keep_fargs_false: {
|
||||
console.log(6);
|
||||
console.log((a(), b(), 6));
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
issue_485_crashing_1530: {
|
||||
|
||||
@@ -49,4 +49,3 @@ mangle_keep_fnames_true: {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -46,4 +46,5 @@ string_plus_optimization: {
|
||||
}
|
||||
foo();
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ issue_1321_no_debug: {
|
||||
x["a"] = 2 * x.b;
|
||||
console.log(x.b, x["a"]);
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
issue_1321_debug: {
|
||||
@@ -33,6 +34,7 @@ issue_1321_debug: {
|
||||
x["_$foo$_"] = 2 * x.a;
|
||||
console.log(x.a, x["_$foo$_"]);
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
issue_1321_with_quoted: {
|
||||
@@ -51,4 +53,5 @@ issue_1321_with_quoted: {
|
||||
x["b"] = 2 * x.a;
|
||||
console.log(x.a, x["b"]);
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
@@ -42,4 +42,5 @@ conditional_false_stray_else_in_loop: {
|
||||
}
|
||||
}
|
||||
expect_exact: "for(var i=1;i<=4;++i)if(!(i<=2))console.log(i);"
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
@@ -85,3 +85,15 @@ unsafe_undefined: {
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
runtime_error: {
|
||||
input: {
|
||||
const a = 1;
|
||||
console.log(a++);
|
||||
}
|
||||
expect: {
|
||||
const a = 1;
|
||||
console.log(a++);
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
@@ -48,6 +48,7 @@ dead_code_const_annotation_regex: {
|
||||
var CONST_FOO_ANN = !1;
|
||||
if (CONST_FOO_ANN) console.log('reachable');
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
drop_console_2: {
|
||||
@@ -225,6 +226,7 @@ issue_1254_negate_iife_true: {
|
||||
})()();
|
||||
}
|
||||
expect_exact: '(function(){return function(){console.log("test")}})()();'
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
issue_1254_negate_iife_nested: {
|
||||
@@ -240,6 +242,7 @@ issue_1254_negate_iife_nested: {
|
||||
})()()()()();
|
||||
}
|
||||
expect_exact: '(function(){return function(){console.log("test")}})()()()()();'
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
conditional: {
|
||||
|
||||
@@ -29,4 +29,5 @@ dont_mangle_arguments: {
|
||||
})(5,6,7);
|
||||
}
|
||||
expect_exact: "(function(){var arguments=arguments,o=9;console.log(o,arguments)})(5,6,7);"
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ eval_collapse_vars: {
|
||||
eval("console.log(a);");
|
||||
})(eval);
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
eval_unused: {
|
||||
|
||||
@@ -9,6 +9,7 @@ labels_1: {
|
||||
expect: {
|
||||
foo || console.log("bar");
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
labels_2: {
|
||||
@@ -40,6 +41,7 @@ labels_3: {
|
||||
for (var i = 0; i < 5; ++i)
|
||||
i < 3 || console.log(i);
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
labels_4: {
|
||||
@@ -54,6 +56,7 @@ labels_4: {
|
||||
for (var i = 0; i < 5; ++i)
|
||||
i < 3 || console.log(i);
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
labels_5: {
|
||||
|
||||
@@ -166,6 +166,7 @@ keep_collapse_const_in_own_block_scope: {
|
||||
console.log(i);
|
||||
console.log(c);
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
keep_collapse_const_in_own_block_scope_2: {
|
||||
@@ -186,6 +187,7 @@ keep_collapse_const_in_own_block_scope_2: {
|
||||
console.log(i);
|
||||
console.log(c);
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
evaluate: {
|
||||
|
||||
@@ -70,6 +70,7 @@ negate_iife_3_evaluate: {
|
||||
expect: {
|
||||
console.log(true);
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
negate_iife_3_side_effects: {
|
||||
@@ -111,6 +112,7 @@ negate_iife_3_off_evaluate: {
|
||||
expect: {
|
||||
console.log(true);
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
negate_iife_4: {
|
||||
@@ -243,6 +245,7 @@ negate_iife_nested: {
|
||||
}(7);
|
||||
}).f();
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
negate_iife_nested_off: {
|
||||
@@ -275,6 +278,7 @@ negate_iife_nested_off: {
|
||||
})(7);
|
||||
}).f();
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
negate_iife_issue_1073: {
|
||||
@@ -299,6 +303,7 @@ negate_iife_issue_1073: {
|
||||
};
|
||||
}(7))();
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
issue_1254_negate_iife_false: {
|
||||
@@ -313,6 +318,7 @@ issue_1254_negate_iife_false: {
|
||||
})()();
|
||||
}
|
||||
expect_exact: '(function(){return function(){console.log("test")}})()();'
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
issue_1254_negate_iife_true: {
|
||||
@@ -327,6 +333,7 @@ issue_1254_negate_iife_true: {
|
||||
})()();
|
||||
}
|
||||
expect_exact: '!function(){return function(){console.log("test")}}()();'
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
issue_1254_negate_iife_nested: {
|
||||
@@ -341,6 +348,7 @@ issue_1254_negate_iife_nested: {
|
||||
})()()()()();
|
||||
}
|
||||
expect_exact: '!function(){return function(){console.log("test")}}()()()()();'
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
issue_1288: {
|
||||
|
||||
@@ -58,6 +58,7 @@ reduce_vars: {
|
||||
})();
|
||||
console.log(2);
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
modified: {
|
||||
@@ -166,7 +167,7 @@ modified: {
|
||||
console.log(A ? 'yes' : 'no');
|
||||
console.log(B ? 'yes' : 'no');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsafe_evaluate: {
|
||||
@@ -401,6 +402,7 @@ iife: {
|
||||
console.log(0, 1 * b, 5);
|
||||
}(1, 2, 3);
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
iife_new: {
|
||||
@@ -420,6 +422,7 @@ iife_new: {
|
||||
console.log(0, 1 * b, 5);
|
||||
}(1, 2, 3);
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
multi_def: {
|
||||
@@ -707,6 +710,7 @@ toplevel_on: {
|
||||
expect: {
|
||||
console.log(3);
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
toplevel_off: {
|
||||
@@ -724,6 +728,7 @@ toplevel_off: {
|
||||
var x = 3;
|
||||
console.log(x);
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
toplevel_on_loops_1: {
|
||||
@@ -751,6 +756,7 @@ toplevel_on_loops_1: {
|
||||
})();
|
||||
while (x);
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
toplevel_off_loops_1: {
|
||||
@@ -779,6 +785,7 @@ toplevel_off_loops_1: {
|
||||
bar();
|
||||
while (x);
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
toplevel_on_loops_2: {
|
||||
@@ -1121,6 +1128,7 @@ defun_label: {
|
||||
}(2));
|
||||
}();
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
double_reference: {
|
||||
@@ -1164,6 +1172,7 @@ iife_arguments_1: {
|
||||
return f;
|
||||
});
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
iife_arguments_2: {
|
||||
@@ -1186,6 +1195,7 @@ iife_arguments_2: {
|
||||
}() === arguments[0]);
|
||||
})();
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
iife_eval_1: {
|
||||
@@ -1207,6 +1217,7 @@ iife_eval_1: {
|
||||
return f;
|
||||
});
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
iife_eval_2: {
|
||||
@@ -1230,6 +1241,7 @@ iife_eval_2: {
|
||||
console.log(x() === eval("x"));
|
||||
})();
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
iife_func_side_effects: {
|
||||
@@ -1326,6 +1338,7 @@ issue_1595_4: {
|
||||
if (a) iife(a - 1, b, c);
|
||||
})(3, 4, 5);
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
issue_1606: {
|
||||
|
||||
@@ -1,20 +1,29 @@
|
||||
do_screw: {
|
||||
options = { screw_ie8: true };
|
||||
options = {
|
||||
screw_ie8: true,
|
||||
}
|
||||
beautify = {
|
||||
screw_ie8: true,
|
||||
ascii_only: true
|
||||
};
|
||||
|
||||
input: f("\v");
|
||||
expect_exact: 'f("\\v");';
|
||||
ascii_only: true,
|
||||
}
|
||||
input: {
|
||||
f("\v");
|
||||
}
|
||||
expect_exact: 'f("\\v");'
|
||||
}
|
||||
|
||||
dont_screw: {
|
||||
options = { screw_ie8: false };
|
||||
beautify = { screw_ie8: false, ascii_only: true };
|
||||
|
||||
input: f("\v");
|
||||
expect_exact: 'f("\\x0B");';
|
||||
options = {
|
||||
screw_ie8: false,
|
||||
}
|
||||
beautify = {
|
||||
screw_ie8: false,
|
||||
ascii_only: true,
|
||||
}
|
||||
input: {
|
||||
f("\v");
|
||||
}
|
||||
expect_exact: 'f("\\x0B");'
|
||||
}
|
||||
|
||||
do_screw_constants: {
|
||||
@@ -119,6 +128,7 @@ do_screw_try_catch_undefined: {
|
||||
return void 0===o
|
||||
}
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
dont_screw_try_catch_undefined: {
|
||||
@@ -147,6 +157,7 @@ dont_screw_try_catch_undefined: {
|
||||
return n === undefined
|
||||
}
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
reduce_vars: {
|
||||
@@ -199,6 +210,7 @@ issue_1586_1: {
|
||||
}
|
||||
}
|
||||
expect_exact: "function f(){try{}catch(c){console.log(c.message)}}"
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
issue_1586_2: {
|
||||
@@ -217,4 +229,5 @@ issue_1586_2: {
|
||||
}
|
||||
}
|
||||
expect_exact: "function f(){try{}catch(c){console.log(c.message)}}"
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
@@ -86,6 +86,7 @@ make_sequences_4: {
|
||||
switch (x = 5, y) {}
|
||||
with (x = 5, obj);
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
lift_sequences_1: {
|
||||
@@ -103,15 +104,18 @@ lift_sequences_1: {
|
||||
lift_sequences_2: {
|
||||
options = { sequences: true, evaluate: true };
|
||||
input: {
|
||||
var foo, bar;
|
||||
var foo = 1, bar;
|
||||
foo.x = (foo = {}, 10);
|
||||
bar = (bar = {}, 10);
|
||||
console.log(foo, bar);
|
||||
}
|
||||
expect: {
|
||||
var foo, bar;
|
||||
var foo = 1, bar;
|
||||
foo.x = (foo = {}, 10),
|
||||
bar = {}, bar = 10;
|
||||
bar = {}, bar = 10,
|
||||
console.log(foo, bar);
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
lift_sequences_3: {
|
||||
@@ -138,6 +142,23 @@ lift_sequences_4: {
|
||||
}
|
||||
}
|
||||
|
||||
lift_sequences_5: {
|
||||
options = {
|
||||
sequences: true,
|
||||
}
|
||||
input: {
|
||||
var a = 2, b;
|
||||
a *= (b, a = 4, 3);
|
||||
console.log(a);
|
||||
}
|
||||
expect: {
|
||||
var a = 2, b;
|
||||
b, a *= (a = 4, 3),
|
||||
console.log(a);
|
||||
}
|
||||
expect_stdout: "6"
|
||||
}
|
||||
|
||||
for_sequences: {
|
||||
options = { sequences: true };
|
||||
input: {
|
||||
@@ -230,6 +251,7 @@ negate_iife_for: {
|
||||
for (!function() {}(), i = 0; i < 5; i++) console.log(i);
|
||||
for (function() {}(); i < 5; i++) console.log(i);
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
iife: {
|
||||
|
||||
@@ -13,6 +13,7 @@ booleans_evaluate: {
|
||||
console.log(!0, !0);
|
||||
console.log(!1, !1);
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
booleans_global_defs: {
|
||||
@@ -29,6 +30,7 @@ booleans_global_defs: {
|
||||
expect: {
|
||||
console.log(!0);
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
condition_evaluate: {
|
||||
|
||||
@@ -11,6 +11,17 @@ var vm = require("vm");
|
||||
var tests_dir = path.dirname(module.filename);
|
||||
var failures = 0;
|
||||
var failed_files = {};
|
||||
var same_stdout = ~process.version.lastIndexOf("v0.12.", 0) ? function(expected, actual) {
|
||||
if (typeof expected != typeof actual) return false;
|
||||
if (typeof expected != "string") {
|
||||
if (expected.name != actual.name) return false;
|
||||
expected = expected.message.slice(expected.message.lastIndexOf("\n") + 1);
|
||||
actual = actual.message.slice(actual.message.lastIndexOf("\n") + 1);
|
||||
}
|
||||
return expected == actual;
|
||||
} : function(expected, actual) {
|
||||
return typeof expected == typeof actual && expected.toString() == actual.toString();
|
||||
};
|
||||
|
||||
run_compress_tests();
|
||||
if (failures) {
|
||||
@@ -72,10 +83,15 @@ function test_directory(dir) {
|
||||
}
|
||||
|
||||
function as_toplevel(input, mangle_options) {
|
||||
if (input instanceof U.AST_BlockStatement) input = input.body;
|
||||
else if (input instanceof U.AST_Statement) input = [ input ];
|
||||
else throw new Error("Unsupported input syntax");
|
||||
var toplevel = new U.AST_Toplevel({ body: input });
|
||||
if (!(input instanceof U.AST_BlockStatement))
|
||||
throw new Error("Unsupported input syntax");
|
||||
for (var i = 0; i < input.body.length; i++) {
|
||||
var stat = input.body[i];
|
||||
if (stat instanceof U.AST_SimpleStatement && stat.body instanceof U.AST_String)
|
||||
input.body[i] = new U.AST_Directive(stat.body);
|
||||
else break;
|
||||
}
|
||||
var toplevel = new U.AST_Toplevel(input);
|
||||
toplevel.figure_out_scope(mangle_options);
|
||||
return toplevel;
|
||||
}
|
||||
@@ -167,48 +183,33 @@ function run_compress_tests() {
|
||||
}
|
||||
}
|
||||
if (test.expect_stdout) {
|
||||
try {
|
||||
var stdout = run_code(input_code);
|
||||
if (test.expect_stdout === true) {
|
||||
test.expect_stdout = stdout;
|
||||
}
|
||||
if (test.expect_stdout != stdout) {
|
||||
log("!!! Invalid input or expected stdout\n---INPUT---\n{input}\n---EXPECTED STDOUT---\n{expected}\n---ACTUAL STDOUT---\n{actual}\n\n", {
|
||||
var stdout = run_code(make_code(input, output_options));
|
||||
if (test.expect_stdout === true) {
|
||||
test.expect_stdout = stdout;
|
||||
}
|
||||
if (!same_stdout(test.expect_stdout, stdout)) {
|
||||
log("!!! Invalid input or expected stdout\n---INPUT---\n{input}\n---EXPECTED {expected_type}---\n{expected}\n---ACTUAL {actual_type}---\n{actual}\n\n", {
|
||||
input: input_code,
|
||||
expected_type: typeof test.expect_stdout == "string" ? "STDOUT" : "ERROR",
|
||||
expected: test.expect_stdout,
|
||||
actual_type: typeof stdout == "string" ? "STDOUT" : "ERROR",
|
||||
actual: stdout,
|
||||
});
|
||||
failures++;
|
||||
failed_files[file] = 1;
|
||||
} else {
|
||||
stdout = run_code(output);
|
||||
if (!same_stdout(test.expect_stdout, stdout)) {
|
||||
log("!!! failed\n---INPUT---\n{input}\n---EXPECTED {expected_type}---\n{expected}\n---ACTUAL {actual_type}---\n{actual}\n\n", {
|
||||
input: input_code,
|
||||
expected_type: typeof test.expect_stdout == "string" ? "STDOUT" : "ERROR",
|
||||
expected: test.expect_stdout,
|
||||
actual_type: typeof stdout == "string" ? "STDOUT" : "ERROR",
|
||||
actual: stdout,
|
||||
});
|
||||
failures++;
|
||||
failed_files[file] = 1;
|
||||
} else {
|
||||
try {
|
||||
stdout = run_code(output);
|
||||
if (test.expect_stdout != stdout) {
|
||||
log("!!! failed\n---INPUT---\n{input}\n---EXPECTED STDOUT---\n{expected}\n---ACTUAL STDOUT---\n{actual}\n\n", {
|
||||
input: input_code,
|
||||
expected: test.expect_stdout,
|
||||
actual: stdout,
|
||||
});
|
||||
failures++;
|
||||
failed_files[file] = 1;
|
||||
}
|
||||
} catch (ex) {
|
||||
log("!!! Execution of output failed\n---INPUT---\n{input}\n---OUTPUT---\n{output}\n--ERROR--\n{error}\n\n", {
|
||||
input: input_code,
|
||||
output: output,
|
||||
error: ex.toString(),
|
||||
});
|
||||
failures++;
|
||||
failed_files[file] = 1;
|
||||
}
|
||||
}
|
||||
} catch (ex) {
|
||||
log("!!! Execution of input failed\n---INPUT---\n{input}\n--ERROR--\n{error}\n\n", {
|
||||
input: input_code,
|
||||
error: ex.toString(),
|
||||
});
|
||||
failures++;
|
||||
failed_files[file] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -299,10 +300,6 @@ function parse_test(file) {
|
||||
})
|
||||
);
|
||||
var stat = node.body;
|
||||
if (stat instanceof U.AST_BlockStatement) {
|
||||
if (stat.body.length == 1) stat = stat.body[0];
|
||||
else if (stat.body.length == 0) stat = new U.AST_EmptyStatement();
|
||||
}
|
||||
if (label.name == "expect_exact") {
|
||||
test[label.name] = read_string(stat);
|
||||
} else if (label.name == "expect_stdout") {
|
||||
@@ -344,6 +341,8 @@ function run_code(code) {
|
||||
try {
|
||||
new vm.Script(code).runInNewContext({ console: console }, { timeout: 5000 });
|
||||
return stdout;
|
||||
} catch (ex) {
|
||||
return ex;
|
||||
} finally {
|
||||
process.stdout.write = original_write;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user