terser 3.16.1 → 3.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of terser might be problematic. Click here for more details.
- package/CHANGELOG.md +10 -1
- package/README.md +39 -11
- package/bin/uglifyjs +26 -16
- package/bin/uglifyjsnobundle +3 -2
- package/dist/bundle.js +314 -304
- package/dist/bundle.js.map +1 -1
- package/dist/bundle.min.js +1 -1
- package/dist/bundle.min.js.map +1 -1
- package/package.json +16 -15
- package/tools/domprops.js +4 -0
package/dist/bundle.js
CHANGED
@@ -54,7 +54,7 @@
|
|
54
54
|
}
|
55
55
|
|
56
56
|
function member(name, array) {
|
57
|
-
return array.
|
57
|
+
return array.includes(name);
|
58
58
|
}
|
59
59
|
|
60
60
|
function find_if(func, array) {
|
@@ -174,7 +174,7 @@
|
|
174
174
|
})();
|
175
175
|
|
176
176
|
function push_uniq(array, el) {
|
177
|
-
if (array.
|
177
|
+
if (!array.includes(el))
|
178
178
|
array.push(el);
|
179
179
|
}
|
180
180
|
|
@@ -552,10 +552,7 @@
|
|
552
552
|
}
|
553
553
|
|
554
554
|
function is_identifier(name) {
|
555
|
-
|
556
|
-
return false;
|
557
|
-
|
558
|
-
return true;
|
555
|
+
return typeof name === "string" && !RESERVED_WORDS(name);
|
559
556
|
}
|
560
557
|
|
561
558
|
function is_identifier_start(ch) {
|
@@ -924,7 +921,7 @@
|
|
924
921
|
// update stream position
|
925
922
|
forward(get_full_char_length(text) /* text length doesn't count \r\n as 2 char while S.pos - i does */ + 2);
|
926
923
|
S.comments_before.push(token("comment2", text, true));
|
927
|
-
S.newline_before = S.newline_before || text.
|
924
|
+
S.newline_before = S.newline_before || text.includes("\n");
|
928
925
|
S.regex_allowed = regex_allowed;
|
929
926
|
return next_token;
|
930
927
|
});
|
@@ -1353,7 +1350,7 @@
|
|
1353
1350
|
case "string":
|
1354
1351
|
if (S.in_directives) {
|
1355
1352
|
var token = peek();
|
1356
|
-
if (S.token.raw.
|
1353
|
+
if (!S.token.raw.includes("\\")
|
1357
1354
|
&& (is_token(token, "punc", ";")
|
1358
1355
|
|| is_token(token, "punc", "}")
|
1359
1356
|
|| has_newline_before(token)
|
@@ -1946,7 +1943,7 @@
|
|
1946
1943
|
used_parameters.mark_spread(S.token);
|
1947
1944
|
next();
|
1948
1945
|
}
|
1949
|
-
if (is("name") && (is_token(peek(), "punc") || is_token(peek(), "operator")) && [",", "}", "="].
|
1946
|
+
if (is("name") && (is_token(peek(), "punc") || is_token(peek(), "operator")) && [",", "}", "="].includes(peek().value)) {
|
1950
1947
|
used_parameters.add_parameter(S.token);
|
1951
1948
|
var start = prev();
|
1952
1949
|
var value = as_symbol(symbol_type);
|
@@ -2972,7 +2969,7 @@
|
|
2972
2969
|
next();
|
2973
2970
|
return null;
|
2974
2971
|
}
|
2975
|
-
if (["delete", "in", "instanceof", "new", "typeof", "void"].
|
2972
|
+
if (!["delete", "in", "instanceof", "new", "typeof", "void"].includes(tmp.value)) {
|
2976
2973
|
unexpected(tmp);
|
2977
2974
|
}
|
2978
2975
|
case "name":
|
@@ -5262,10 +5259,9 @@
|
|
5262
5259
|
function print(str) {
|
5263
5260
|
str = String(str);
|
5264
5261
|
var ch = get_full_char(str, 0);
|
5265
|
-
var prev = get_full_char(last, last.length - 1);
|
5266
5262
|
if (need_newline_indented && ch) {
|
5267
5263
|
need_newline_indented = false;
|
5268
|
-
if (ch
|
5264
|
+
if (ch !== "\n") {
|
5269
5265
|
print("\n");
|
5270
5266
|
indent();
|
5271
5267
|
}
|
@@ -5281,7 +5277,7 @@
|
|
5281
5277
|
if (might_need_semicolon) {
|
5282
5278
|
might_need_semicolon = false;
|
5283
5279
|
|
5284
|
-
if (prev
|
5280
|
+
if (prev === ":" && ch === "}" || (!ch || !";}".includes(ch)) && prev !== ";") {
|
5285
5281
|
if (options.semicolons || requireSemicolonChars(ch)) {
|
5286
5282
|
OUTPUT += ";";
|
5287
5283
|
current_col++;
|
@@ -5586,7 +5582,7 @@
|
|
5586
5582
|
print_name : function(name) { print(make_name(name)); },
|
5587
5583
|
print_string : function(str, quote, escape_directive) {
|
5588
5584
|
var encoded = encode_string(str, quote);
|
5589
|
-
if (escape_directive === true && encoded.
|
5585
|
+
if (escape_directive === true && !encoded.includes("\\")) {
|
5590
5586
|
// Insert semicolons to break directive prologue
|
5591
5587
|
if (!EXPECT_DIRECTIVE.test(OUTPUT)) {
|
5592
5588
|
force_semicolon();
|
@@ -6842,19 +6838,14 @@
|
|
6842
6838
|
function make_num(num) {
|
6843
6839
|
var str = num.toString(10), a = [ str.replace(/^0\./, ".").replace("e+", "e") ], m;
|
6844
6840
|
if (Math.floor(num) === num) {
|
6845
|
-
|
6846
|
-
|
6847
|
-
|
6848
|
-
|
6849
|
-
a.push("-0x" + (-num).toString(16).toLowerCase(), // probably pointless
|
6850
|
-
"-0" + (-num).toString(8)); // same.
|
6851
|
-
}
|
6852
|
-
if ((m = /^(.*?)(0+)$/.exec(num))) {
|
6841
|
+
a.push(
|
6842
|
+
(num >= 0 ? "0x" : "-0x") + num.toString(16).toLowerCase() // probably pointless
|
6843
|
+
);
|
6844
|
+
if ((m = /^(.*?)(0{3,})$/.exec(num))) {
|
6853
6845
|
a.push(m[1] + "e" + m[2].length);
|
6854
6846
|
}
|
6855
6847
|
} else if ((m = /^0?\.(0+)(.*)$/.exec(num))) {
|
6856
|
-
a.push(m[2] + "e-" + (m[1].length + m[2].length)
|
6857
|
-
str.substr(str.indexOf(".")));
|
6848
|
+
a.push(m[2] + "e-" + (m[1].length + m[2].length));
|
6858
6849
|
}
|
6859
6850
|
return best_of(a);
|
6860
6851
|
}
|
@@ -7392,7 +7383,7 @@
|
|
7392
7383
|
var name;
|
7393
7384
|
do {
|
7394
7385
|
name = next_mangled(this, options);
|
7395
|
-
} while (
|
7386
|
+
} while (this.mangled_names.has(name));
|
7396
7387
|
return name;
|
7397
7388
|
});
|
7398
7389
|
|
@@ -7462,12 +7453,12 @@
|
|
7462
7453
|
var lname = -1;
|
7463
7454
|
var to_mangle = [];
|
7464
7455
|
|
7465
|
-
var mangled_names = this.mangled_names =
|
7456
|
+
var mangled_names = this.mangled_names = new Set();
|
7466
7457
|
if (options.cache) {
|
7467
7458
|
this.globals.each(collect);
|
7468
7459
|
if (options.cache.props) {
|
7469
7460
|
options.cache.props.each(function(mangled_name) {
|
7470
|
-
|
7461
|
+
mangled_names.add(mangled_name);
|
7471
7462
|
});
|
7472
7463
|
}
|
7473
7464
|
}
|
@@ -7765,7 +7756,7 @@
|
|
7765
7756
|
this.pure_funcs = pure_funcs;
|
7766
7757
|
} else {
|
7767
7758
|
this.pure_funcs = pure_funcs ? function(node) {
|
7768
|
-
return pure_funcs.
|
7759
|
+
return !pure_funcs.includes(node.expression.print_to_string());
|
7769
7760
|
} : return_true;
|
7770
7761
|
}
|
7771
7762
|
var top_retain = this.options["top_retain"];
|
@@ -7780,7 +7771,7 @@
|
|
7780
7771
|
top_retain = top_retain.split(/,/);
|
7781
7772
|
}
|
7782
7773
|
this.top_retain = function(def) {
|
7783
|
-
return top_retain.
|
7774
|
+
return top_retain.includes(def.name);
|
7784
7775
|
};
|
7785
7776
|
}
|
7786
7777
|
if (this.options["module"]) {
|
@@ -7898,7 +7889,7 @@
|
|
7898
7889
|
}
|
7899
7890
|
// Before https://github.com/mishoo/UglifyJS2/pull/1602 AST_Node.optimize()
|
7900
7891
|
// would call AST_Node.transform() if a different instance of AST_Node is
|
7901
|
-
// produced after
|
7892
|
+
// produced after def_optimize().
|
7902
7893
|
// This corrupts TreeWalker.stack, which cause AST look-ups to malfunction.
|
7903
7894
|
// Migrate and defer all children's AST_Node.transform() to below, which
|
7904
7895
|
// will now happen after this parent AST_Node has been properly substituted
|
@@ -7920,7 +7911,7 @@
|
|
7920
7911
|
|
7921
7912
|
(function() {
|
7922
7913
|
|
7923
|
-
function
|
7914
|
+
function def_optimize(node, optimizer) {
|
7924
7915
|
node.DEFMETHOD("optimize", function(compressor) {
|
7925
7916
|
var self = this;
|
7926
7917
|
if (self._optimized) return self;
|
@@ -7931,7 +7922,7 @@
|
|
7931
7922
|
});
|
7932
7923
|
}
|
7933
7924
|
|
7934
|
-
|
7925
|
+
def_optimize(AST_Node, function(self, compressor) {
|
7935
7926
|
return self;
|
7936
7927
|
});
|
7937
7928
|
|
@@ -8048,8 +8039,8 @@
|
|
8048
8039
|
}
|
8049
8040
|
}
|
8050
8041
|
|
8051
|
-
(function(
|
8052
|
-
|
8042
|
+
(function(def_reduce_vars) {
|
8043
|
+
def_reduce_vars(AST_Node, noop);
|
8053
8044
|
|
8054
8045
|
function reset_def(compressor, def) {
|
8055
8046
|
def.assignments = 0;
|
@@ -8187,15 +8178,15 @@
|
|
8187
8178
|
if (node instanceof AST_SymbolRef) d.references.push(node);
|
8188
8179
|
d.fixed = false;
|
8189
8180
|
});
|
8190
|
-
|
8181
|
+
def_reduce_vars(AST_Accessor, function(tw, descend, compressor) {
|
8191
8182
|
push(tw);
|
8192
8183
|
reset_variables(tw, compressor, this);
|
8193
8184
|
descend();
|
8194
8185
|
pop(tw);
|
8195
8186
|
return true;
|
8196
8187
|
});
|
8197
|
-
|
8198
|
-
|
8188
|
+
def_reduce_vars(AST_Arrow, mark_func_expr);
|
8189
|
+
def_reduce_vars(AST_Assign, function(tw, descend, compressor) {
|
8199
8190
|
var node = this;
|
8200
8191
|
if (node.left instanceof AST_Destructuring) {
|
8201
8192
|
node.left.walk(suppressor);
|
@@ -8229,7 +8220,7 @@
|
|
8229
8220
|
mark_escaped(tw, d, sym.scope, node, value, 0, 1);
|
8230
8221
|
return true;
|
8231
8222
|
});
|
8232
|
-
|
8223
|
+
def_reduce_vars(AST_Binary, function(tw) {
|
8233
8224
|
if (!lazy_op(this.operator)) return;
|
8234
8225
|
this.left.walk(tw);
|
8235
8226
|
push(tw);
|
@@ -8237,10 +8228,10 @@
|
|
8237
8228
|
pop(tw);
|
8238
8229
|
return true;
|
8239
8230
|
});
|
8240
|
-
|
8231
|
+
def_reduce_vars(AST_Block, function(tw, descend, compressor) {
|
8241
8232
|
reset_block_variables(compressor, this);
|
8242
8233
|
});
|
8243
|
-
|
8234
|
+
def_reduce_vars(AST_Case, function(tw) {
|
8244
8235
|
push(tw);
|
8245
8236
|
this.expression.walk(tw);
|
8246
8237
|
pop(tw);
|
@@ -8249,14 +8240,14 @@
|
|
8249
8240
|
pop(tw);
|
8250
8241
|
return true;
|
8251
8242
|
});
|
8252
|
-
|
8243
|
+
def_reduce_vars(AST_ClassExpression, function(tw, descend) {
|
8253
8244
|
this.inlined = false;
|
8254
8245
|
push(tw);
|
8255
8246
|
descend();
|
8256
8247
|
pop(tw);
|
8257
8248
|
return true;
|
8258
8249
|
});
|
8259
|
-
|
8250
|
+
def_reduce_vars(AST_Conditional, function(tw) {
|
8260
8251
|
this.condition.walk(tw);
|
8261
8252
|
push(tw);
|
8262
8253
|
this.consequent.walk(tw);
|
@@ -8266,7 +8257,7 @@
|
|
8266
8257
|
pop(tw);
|
8267
8258
|
return true;
|
8268
8259
|
});
|
8269
|
-
|
8260
|
+
def_reduce_vars(AST_Default, function(tw, descend) {
|
8270
8261
|
push(tw);
|
8271
8262
|
descend();
|
8272
8263
|
pop(tw);
|
@@ -8283,9 +8274,9 @@
|
|
8283
8274
|
return true;
|
8284
8275
|
}
|
8285
8276
|
|
8286
|
-
|
8287
|
-
|
8288
|
-
|
8277
|
+
def_reduce_vars(AST_DefClass, mark_def_node);
|
8278
|
+
def_reduce_vars(AST_Defun, mark_def_node);
|
8279
|
+
def_reduce_vars(AST_Do, function(tw, descend, compressor) {
|
8289
8280
|
reset_block_variables(compressor, this);
|
8290
8281
|
var saved_loop = tw.in_loop;
|
8291
8282
|
tw.in_loop = this;
|
@@ -8300,7 +8291,7 @@
|
|
8300
8291
|
tw.in_loop = saved_loop;
|
8301
8292
|
return true;
|
8302
8293
|
});
|
8303
|
-
|
8294
|
+
def_reduce_vars(AST_For, function(tw, descend, compressor) {
|
8304
8295
|
reset_block_variables(compressor, this);
|
8305
8296
|
if (this.init) this.init.walk(tw);
|
8306
8297
|
var saved_loop = tw.in_loop;
|
@@ -8319,7 +8310,7 @@
|
|
8319
8310
|
tw.in_loop = saved_loop;
|
8320
8311
|
return true;
|
8321
8312
|
});
|
8322
|
-
|
8313
|
+
def_reduce_vars(AST_ForIn, function(tw, descend, compressor) {
|
8323
8314
|
reset_block_variables(compressor, this);
|
8324
8315
|
this.init.walk(suppressor);
|
8325
8316
|
this.object.walk(tw);
|
@@ -8363,8 +8354,8 @@
|
|
8363
8354
|
return true;
|
8364
8355
|
}
|
8365
8356
|
|
8366
|
-
|
8367
|
-
|
8357
|
+
def_reduce_vars(AST_Function, mark_func_expr);
|
8358
|
+
def_reduce_vars(AST_If, function(tw) {
|
8368
8359
|
this.condition.walk(tw);
|
8369
8360
|
push(tw);
|
8370
8361
|
this.body.walk(tw);
|
@@ -8376,16 +8367,16 @@
|
|
8376
8367
|
}
|
8377
8368
|
return true;
|
8378
8369
|
});
|
8379
|
-
|
8370
|
+
def_reduce_vars(AST_LabeledStatement, function(tw) {
|
8380
8371
|
push(tw);
|
8381
8372
|
this.body.walk(tw);
|
8382
8373
|
pop(tw);
|
8383
8374
|
return true;
|
8384
8375
|
});
|
8385
|
-
|
8376
|
+
def_reduce_vars(AST_SymbolCatch, function() {
|
8386
8377
|
this.definition().fixed = false;
|
8387
8378
|
});
|
8388
|
-
|
8379
|
+
def_reduce_vars(AST_SymbolRef, function(tw, descend, compressor) {
|
8389
8380
|
var d = this.definition();
|
8390
8381
|
d.references.push(this);
|
8391
8382
|
if (d.references.length == 1
|
@@ -8417,13 +8408,13 @@
|
|
8417
8408
|
}
|
8418
8409
|
mark_escaped(tw, d, this.scope, this, value, 0, 1);
|
8419
8410
|
});
|
8420
|
-
|
8411
|
+
def_reduce_vars(AST_Toplevel, function(tw, descend, compressor) {
|
8421
8412
|
this.globals.each(function(def) {
|
8422
8413
|
reset_def(compressor, def);
|
8423
8414
|
});
|
8424
8415
|
reset_variables(tw, compressor, this);
|
8425
8416
|
});
|
8426
|
-
|
8417
|
+
def_reduce_vars(AST_Try, function(tw, descend, compressor) {
|
8427
8418
|
reset_block_variables(compressor, this);
|
8428
8419
|
push(tw);
|
8429
8420
|
walk_body(this, tw);
|
@@ -8436,7 +8427,7 @@
|
|
8436
8427
|
if (this.bfinally) this.bfinally.walk(tw);
|
8437
8428
|
return true;
|
8438
8429
|
});
|
8439
|
-
|
8430
|
+
def_reduce_vars(AST_Unary, function(tw, descend) {
|
8440
8431
|
var node = this;
|
8441
8432
|
if (node.operator != "++" && node.operator != "--") return;
|
8442
8433
|
var exp = node.expression;
|
@@ -8464,7 +8455,7 @@
|
|
8464
8455
|
mark(tw, d, true);
|
8465
8456
|
return true;
|
8466
8457
|
});
|
8467
|
-
|
8458
|
+
def_reduce_vars(AST_VarDef, function(tw, descend) {
|
8468
8459
|
var node = this;
|
8469
8460
|
if (node.name instanceof AST_Destructuring) {
|
8470
8461
|
node.name.walk(suppressor);
|
@@ -8486,7 +8477,7 @@
|
|
8486
8477
|
}
|
8487
8478
|
}
|
8488
8479
|
});
|
8489
|
-
|
8480
|
+
def_reduce_vars(AST_While, function(tw, descend, compressor) {
|
8490
8481
|
reset_block_variables(compressor, this);
|
8491
8482
|
var saved_loop = tw.in_loop;
|
8492
8483
|
tw.in_loop = this;
|
@@ -9705,9 +9696,9 @@
|
|
9705
9696
|
prop = "" + prop;
|
9706
9697
|
var diff = compressor.option("ecma") < 6
|
9707
9698
|
&& compressor.has_directive("use strict") ? function(node) {
|
9708
|
-
return node.key != prop && node.key.name != prop;
|
9699
|
+
return node.key != prop && (node.key && node.key.name != prop);
|
9709
9700
|
} : function(node) {
|
9710
|
-
return node.key.name != prop;
|
9701
|
+
return node.key && node.key.name != prop;
|
9711
9702
|
};
|
9712
9703
|
if (!all(def.value.properties, diff)) break;
|
9713
9704
|
var p = def.value.properties.filter(function (p) { return p.key === prop; })[0];
|
@@ -9858,7 +9849,7 @@
|
|
9858
9849
|
|
9859
9850
|
// may_throw_on_access()
|
9860
9851
|
// returns true if this node may be null, undefined or contain `AST_Accessor`
|
9861
|
-
(function(
|
9852
|
+
(function(def_dot_throw) {
|
9862
9853
|
AST_Node.DEFMETHOD("may_throw_on_access", function(compressor) {
|
9863
9854
|
return !compressor.option("pure_getters")
|
9864
9855
|
|| this._dot_throw(compressor);
|
@@ -9868,49 +9859,49 @@
|
|
9868
9859
|
return /strict/.test(compressor.option("pure_getters"));
|
9869
9860
|
}
|
9870
9861
|
|
9871
|
-
|
9872
|
-
|
9873
|
-
|
9874
|
-
|
9875
|
-
|
9876
|
-
|
9862
|
+
def_dot_throw(AST_Node, is_strict);
|
9863
|
+
def_dot_throw(AST_Null, return_true);
|
9864
|
+
def_dot_throw(AST_Undefined, return_true);
|
9865
|
+
def_dot_throw(AST_Constant, return_false);
|
9866
|
+
def_dot_throw(AST_Array, return_false);
|
9867
|
+
def_dot_throw(AST_Object, function(compressor) {
|
9877
9868
|
if (!is_strict(compressor)) return false;
|
9878
9869
|
for (var i = this.properties.length; --i >=0;)
|
9879
9870
|
if (this.properties[i]._dot_throw(compressor)) return true;
|
9880
9871
|
return false;
|
9881
9872
|
});
|
9882
|
-
|
9883
|
-
|
9884
|
-
|
9873
|
+
def_dot_throw(AST_ObjectProperty, return_false);
|
9874
|
+
def_dot_throw(AST_ObjectGetter, return_true);
|
9875
|
+
def_dot_throw(AST_Expansion, function(compressor) {
|
9885
9876
|
return this.expression._dot_throw(compressor);
|
9886
9877
|
});
|
9887
|
-
|
9888
|
-
|
9889
|
-
|
9890
|
-
|
9878
|
+
def_dot_throw(AST_Function, return_false);
|
9879
|
+
def_dot_throw(AST_Arrow, return_false);
|
9880
|
+
def_dot_throw(AST_UnaryPostfix, return_false);
|
9881
|
+
def_dot_throw(AST_UnaryPrefix, function() {
|
9891
9882
|
return this.operator == "void";
|
9892
9883
|
});
|
9893
|
-
|
9884
|
+
def_dot_throw(AST_Binary, function(compressor) {
|
9894
9885
|
return (this.operator == "&&" || this.operator == "||")
|
9895
9886
|
&& (this.left._dot_throw(compressor) || this.right._dot_throw(compressor));
|
9896
9887
|
});
|
9897
|
-
|
9888
|
+
def_dot_throw(AST_Assign, function(compressor) {
|
9898
9889
|
return this.operator == "="
|
9899
9890
|
&& this.right._dot_throw(compressor);
|
9900
9891
|
});
|
9901
|
-
|
9892
|
+
def_dot_throw(AST_Conditional, function(compressor) {
|
9902
9893
|
return this.consequent._dot_throw(compressor)
|
9903
9894
|
|| this.alternative._dot_throw(compressor);
|
9904
9895
|
});
|
9905
|
-
|
9896
|
+
def_dot_throw(AST_Dot, function(compressor) {
|
9906
9897
|
if (!is_strict(compressor)) return false;
|
9907
9898
|
if (this.expression instanceof AST_Function && this.property == "prototype") return false;
|
9908
9899
|
return true;
|
9909
9900
|
});
|
9910
|
-
|
9901
|
+
def_dot_throw(AST_Sequence, function(compressor) {
|
9911
9902
|
return this.tail_node()._dot_throw(compressor);
|
9912
9903
|
});
|
9913
|
-
|
9904
|
+
def_dot_throw(AST_SymbolRef, function(compressor) {
|
9914
9905
|
if (this.is_undefined) return true;
|
9915
9906
|
if (!is_strict(compressor)) return false;
|
9916
9907
|
if (is_undeclared_ref(this) && this.is_declared(compressor)) return false;
|
@@ -9925,56 +9916,56 @@
|
|
9925
9916
|
/* -----[ boolean/negation helpers ]----- */
|
9926
9917
|
|
9927
9918
|
// methods to determine whether an expression has a boolean result type
|
9928
|
-
(function(
|
9919
|
+
(function(def_is_boolean) {
|
9929
9920
|
var unary_bool = [ "!", "delete" ];
|
9930
9921
|
var binary_bool = [ "in", "instanceof", "==", "!=", "===", "!==", "<", "<=", ">=", ">" ];
|
9931
|
-
|
9932
|
-
|
9922
|
+
def_is_boolean(AST_Node, return_false);
|
9923
|
+
def_is_boolean(AST_UnaryPrefix, function() {
|
9933
9924
|
return member(this.operator, unary_bool);
|
9934
9925
|
});
|
9935
|
-
|
9926
|
+
def_is_boolean(AST_Binary, function() {
|
9936
9927
|
return member(this.operator, binary_bool)
|
9937
9928
|
|| lazy_op(this.operator)
|
9938
9929
|
&& this.left.is_boolean()
|
9939
9930
|
&& this.right.is_boolean();
|
9940
9931
|
});
|
9941
|
-
|
9932
|
+
def_is_boolean(AST_Conditional, function() {
|
9942
9933
|
return this.consequent.is_boolean() && this.alternative.is_boolean();
|
9943
9934
|
});
|
9944
|
-
|
9935
|
+
def_is_boolean(AST_Assign, function() {
|
9945
9936
|
return this.operator == "=" && this.right.is_boolean();
|
9946
9937
|
});
|
9947
|
-
|
9938
|
+
def_is_boolean(AST_Sequence, function() {
|
9948
9939
|
return this.tail_node().is_boolean();
|
9949
9940
|
});
|
9950
|
-
|
9951
|
-
|
9941
|
+
def_is_boolean(AST_True, return_true);
|
9942
|
+
def_is_boolean(AST_False, return_true);
|
9952
9943
|
})(function(node, func) {
|
9953
9944
|
node.DEFMETHOD("is_boolean", func);
|
9954
9945
|
});
|
9955
9946
|
|
9956
9947
|
// methods to determine if an expression has a numeric result type
|
9957
|
-
(function(
|
9958
|
-
|
9959
|
-
|
9948
|
+
(function(def_is_number) {
|
9949
|
+
def_is_number(AST_Node, return_false);
|
9950
|
+
def_is_number(AST_Number, return_true);
|
9960
9951
|
var unary = makePredicate("+ - ~ ++ --");
|
9961
|
-
|
9952
|
+
def_is_number(AST_Unary, function() {
|
9962
9953
|
return unary(this.operator);
|
9963
9954
|
});
|
9964
9955
|
var binary = makePredicate("- * / % & | ^ << >> >>>");
|
9965
|
-
|
9956
|
+
def_is_number(AST_Binary, function(compressor) {
|
9966
9957
|
return binary(this.operator) || this.operator == "+"
|
9967
9958
|
&& this.left.is_number(compressor)
|
9968
9959
|
&& this.right.is_number(compressor);
|
9969
9960
|
});
|
9970
|
-
|
9961
|
+
def_is_number(AST_Assign, function(compressor) {
|
9971
9962
|
return binary(this.operator.slice(0, -1))
|
9972
9963
|
|| this.operator == "=" && this.right.is_number(compressor);
|
9973
9964
|
});
|
9974
|
-
|
9965
|
+
def_is_number(AST_Sequence, function(compressor) {
|
9975
9966
|
return this.tail_node().is_number(compressor);
|
9976
9967
|
});
|
9977
|
-
|
9968
|
+
def_is_number(AST_Conditional, function(compressor) {
|
9978
9969
|
return this.consequent.is_number(compressor) && this.alternative.is_number(compressor);
|
9979
9970
|
});
|
9980
9971
|
})(function(node, func) {
|
@@ -9982,26 +9973,26 @@
|
|
9982
9973
|
});
|
9983
9974
|
|
9984
9975
|
// methods to determine if an expression has a string result type
|
9985
|
-
(function(
|
9986
|
-
|
9987
|
-
|
9988
|
-
|
9976
|
+
(function(def_is_string) {
|
9977
|
+
def_is_string(AST_Node, return_false);
|
9978
|
+
def_is_string(AST_String, return_true);
|
9979
|
+
def_is_string(AST_TemplateString, function() {
|
9989
9980
|
return this.segments.length === 1;
|
9990
9981
|
});
|
9991
|
-
|
9982
|
+
def_is_string(AST_UnaryPrefix, function() {
|
9992
9983
|
return this.operator == "typeof";
|
9993
9984
|
});
|
9994
|
-
|
9985
|
+
def_is_string(AST_Binary, function(compressor) {
|
9995
9986
|
return this.operator == "+" &&
|
9996
9987
|
(this.left.is_string(compressor) || this.right.is_string(compressor));
|
9997
9988
|
});
|
9998
|
-
|
9989
|
+
def_is_string(AST_Assign, function(compressor) {
|
9999
9990
|
return (this.operator == "=" || this.operator == "+=") && this.right.is_string(compressor);
|
10000
9991
|
});
|
10001
|
-
|
9992
|
+
def_is_string(AST_Sequence, function(compressor) {
|
10002
9993
|
return this.tail_node().is_string(compressor);
|
10003
9994
|
});
|
10004
|
-
|
9995
|
+
def_is_string(AST_Conditional, function(compressor) {
|
10005
9996
|
return this.consequent.is_string(compressor) && this.alternative.is_string(compressor);
|
10006
9997
|
});
|
10007
9998
|
})(function(node, func) {
|
@@ -10016,7 +10007,7 @@
|
|
10016
10007
|
if (parent instanceof AST_Assign && parent.left === node) return node;
|
10017
10008
|
}
|
10018
10009
|
|
10019
|
-
(function(
|
10010
|
+
(function(def_find_defs) {
|
10020
10011
|
function to_node(value, orig) {
|
10021
10012
|
if (value instanceof AST_Node) return make_node(value.CTOR, orig, value);
|
10022
10013
|
if (Array.isArray(value)) return make_node(AST_Array, orig, {
|
@@ -10062,15 +10053,15 @@
|
|
10062
10053
|
return def;
|
10063
10054
|
}));
|
10064
10055
|
});
|
10065
|
-
|
10066
|
-
|
10056
|
+
def_find_defs(AST_Node, noop);
|
10057
|
+
def_find_defs(AST_Dot, function(compressor, suffix) {
|
10067
10058
|
return this.expression._find_defs(compressor, "." + this.property + suffix);
|
10068
10059
|
});
|
10069
|
-
|
10060
|
+
def_find_defs(AST_SymbolDeclaration, function(compressor) {
|
10070
10061
|
if (!this.global()) return;
|
10071
10062
|
if (HOP(compressor.option("global_defs"), this.name)) warn(compressor, this);
|
10072
10063
|
});
|
10073
|
-
|
10064
|
+
def_find_defs(AST_SymbolRef, function(compressor, suffix) {
|
10074
10065
|
if (!this.global()) return;
|
10075
10066
|
var defines = compressor.option("global_defs");
|
10076
10067
|
var name = this.name + suffix;
|
@@ -10191,7 +10182,7 @@
|
|
10191
10182
|
convert_to_predicate(static_fns);
|
10192
10183
|
|
10193
10184
|
// methods to evaluate a constant expression
|
10194
|
-
(function(
|
10185
|
+
(function(def_eval) {
|
10195
10186
|
// If the node has been successfully reduced to a constant,
|
10196
10187
|
// then its value is returned; otherwise the element itself
|
10197
10188
|
// is returned.
|
@@ -10216,20 +10207,20 @@
|
|
10216
10207
|
&& unaryPrefix(this.operator);
|
10217
10208
|
}
|
10218
10209
|
});
|
10219
|
-
|
10210
|
+
def_eval(AST_Statement, function() {
|
10220
10211
|
throw new Error(string_template("Cannot evaluate a statement [{file}:{line},{col}]", this.start));
|
10221
10212
|
});
|
10222
|
-
|
10223
|
-
|
10224
|
-
|
10225
|
-
|
10213
|
+
def_eval(AST_Lambda, return_this);
|
10214
|
+
def_eval(AST_Class, return_this);
|
10215
|
+
def_eval(AST_Node, return_this);
|
10216
|
+
def_eval(AST_Constant, function() {
|
10226
10217
|
return this.getValue();
|
10227
10218
|
});
|
10228
|
-
|
10219
|
+
def_eval(AST_TemplateString, function() {
|
10229
10220
|
if (this.segments.length !== 1) return this;
|
10230
10221
|
return this.segments[0].value;
|
10231
10222
|
});
|
10232
|
-
|
10223
|
+
def_eval(AST_Function, function(compressor) {
|
10233
10224
|
if (compressor.option("unsafe")) {
|
10234
10225
|
var fn = function() {};
|
10235
10226
|
fn.node = this;
|
@@ -10240,7 +10231,7 @@
|
|
10240
10231
|
}
|
10241
10232
|
return this;
|
10242
10233
|
});
|
10243
|
-
|
10234
|
+
def_eval(AST_Array, function(compressor, depth) {
|
10244
10235
|
if (compressor.option("unsafe")) {
|
10245
10236
|
var elements = [];
|
10246
10237
|
for (var i = 0, len = this.elements.length; i < len; i++) {
|
@@ -10253,7 +10244,7 @@
|
|
10253
10244
|
}
|
10254
10245
|
return this;
|
10255
10246
|
});
|
10256
|
-
|
10247
|
+
def_eval(AST_Object, function(compressor, depth) {
|
10257
10248
|
if (compressor.option("unsafe")) {
|
10258
10249
|
var val = {};
|
10259
10250
|
for (var i = 0, len = this.properties.length; i < len; i++) {
|
@@ -10278,7 +10269,7 @@
|
|
10278
10269
|
return this;
|
10279
10270
|
});
|
10280
10271
|
var non_converting_unary = makePredicate("! typeof void");
|
10281
|
-
|
10272
|
+
def_eval(AST_UnaryPrefix, function(compressor, depth) {
|
10282
10273
|
var e = this.expression;
|
10283
10274
|
// Function would be evaluated to an array and so typeof would
|
10284
10275
|
// incorrectly return 'object'. Hence making is a special case.
|
@@ -10307,7 +10298,7 @@
|
|
10307
10298
|
return this;
|
10308
10299
|
});
|
10309
10300
|
var non_converting_binary = makePredicate("&& || === !==");
|
10310
|
-
|
10301
|
+
def_eval(AST_Binary, function(compressor, depth) {
|
10311
10302
|
if (!non_converting_binary(this.operator)) depth++;
|
10312
10303
|
var left = this.left._eval(compressor, depth);
|
10313
10304
|
if (left === this.left) return this;
|
@@ -10346,14 +10337,14 @@
|
|
10346
10337
|
}
|
10347
10338
|
return result;
|
10348
10339
|
});
|
10349
|
-
|
10340
|
+
def_eval(AST_Conditional, function(compressor, depth) {
|
10350
10341
|
var condition = this.condition._eval(compressor, depth);
|
10351
10342
|
if (condition === this.condition) return this;
|
10352
10343
|
var node = condition ? this.consequent : this.alternative;
|
10353
10344
|
var value = node._eval(compressor, depth);
|
10354
10345
|
return value === node ? this : value;
|
10355
10346
|
});
|
10356
|
-
|
10347
|
+
def_eval(AST_SymbolRef, function(compressor, depth) {
|
10357
10348
|
var fixed = this.fixed_value();
|
10358
10349
|
if (!fixed) return this;
|
10359
10350
|
var value;
|
@@ -10401,7 +10392,7 @@
|
|
10401
10392
|
],
|
10402
10393
|
};
|
10403
10394
|
convert_to_predicate(static_values);
|
10404
|
-
|
10395
|
+
def_eval(AST_PropAccess, function(compressor, depth) {
|
10405
10396
|
if (compressor.option("unsafe")) {
|
10406
10397
|
var key = this.property;
|
10407
10398
|
if (key instanceof AST_Node) {
|
@@ -10418,6 +10409,9 @@
|
|
10418
10409
|
&& (aa = compressor.parent() && compressor.parent().args)
|
10419
10410
|
&& (aa && aa[0]
|
10420
10411
|
&& aa[0].evaluate(compressor));
|
10412
|
+
|
10413
|
+
first_arg = first_arg instanceof AST_Dot ? first_arg.expression : first_arg;
|
10414
|
+
|
10421
10415
|
if (first_arg == null || first_arg.thedef && first_arg.thedef.undeclared) {
|
10422
10416
|
return this.clone();
|
10423
10417
|
}
|
@@ -10439,7 +10433,7 @@
|
|
10439
10433
|
}
|
10440
10434
|
return this;
|
10441
10435
|
});
|
10442
|
-
|
10436
|
+
def_eval(AST_Call, function(compressor, depth) {
|
10443
10437
|
var exp = this.expression;
|
10444
10438
|
if (compressor.option("unsafe") && exp instanceof AST_PropAccess) {
|
10445
10439
|
var key = exp.property;
|
@@ -10454,6 +10448,9 @@
|
|
10454
10448
|
e.name === "hasOwnProperty" &&
|
10455
10449
|
key === "call" &&
|
10456
10450
|
(this.args[0] && this.args[0].evaluate(compressor));
|
10451
|
+
|
10452
|
+
first_arg = first_arg instanceof AST_Dot ? first_arg.expression : first_arg;
|
10453
|
+
|
10457
10454
|
if ((first_arg == null || first_arg.thedef && first_arg.thedef.undeclared)) {
|
10458
10455
|
return this.clone();
|
10459
10456
|
}
|
@@ -10483,13 +10480,13 @@
|
|
10483
10480
|
}
|
10484
10481
|
return this;
|
10485
10482
|
});
|
10486
|
-
|
10483
|
+
def_eval(AST_New, return_this);
|
10487
10484
|
})(function(node, func) {
|
10488
10485
|
node.DEFMETHOD("_eval", func);
|
10489
10486
|
});
|
10490
10487
|
|
10491
10488
|
// method to negate an expression
|
10492
|
-
(function(
|
10489
|
+
(function(def_negate) {
|
10493
10490
|
function basic_negation(exp) {
|
10494
10491
|
return make_node(AST_UnaryPrefix, exp, {
|
10495
10492
|
operator: "!",
|
@@ -10506,35 +10503,35 @@
|
|
10506
10503
|
}
|
10507
10504
|
return best_of_expression(negated, alt);
|
10508
10505
|
}
|
10509
|
-
|
10506
|
+
def_negate(AST_Node, function() {
|
10510
10507
|
return basic_negation(this);
|
10511
10508
|
});
|
10512
|
-
|
10509
|
+
def_negate(AST_Statement, function() {
|
10513
10510
|
throw new Error("Cannot negate a statement");
|
10514
10511
|
});
|
10515
|
-
|
10512
|
+
def_negate(AST_Function, function() {
|
10516
10513
|
return basic_negation(this);
|
10517
10514
|
});
|
10518
|
-
|
10515
|
+
def_negate(AST_Arrow, function() {
|
10519
10516
|
return basic_negation(this);
|
10520
10517
|
});
|
10521
|
-
|
10518
|
+
def_negate(AST_UnaryPrefix, function() {
|
10522
10519
|
if (this.operator == "!")
|
10523
10520
|
return this.expression;
|
10524
10521
|
return basic_negation(this);
|
10525
10522
|
});
|
10526
|
-
|
10523
|
+
def_negate(AST_Sequence, function(compressor) {
|
10527
10524
|
var expressions = this.expressions.slice();
|
10528
10525
|
expressions.push(expressions.pop().negate(compressor));
|
10529
10526
|
return make_sequence(this, expressions);
|
10530
10527
|
});
|
10531
|
-
|
10528
|
+
def_negate(AST_Conditional, function(compressor, first_in_statement$$1) {
|
10532
10529
|
var self = this.clone();
|
10533
10530
|
self.consequent = self.consequent.negate(compressor);
|
10534
10531
|
self.alternative = self.alternative.negate(compressor);
|
10535
10532
|
return best(this, self, first_in_statement$$1);
|
10536
10533
|
});
|
10537
|
-
|
10534
|
+
def_negate(AST_Binary, function(compressor, first_in_statement$$1) {
|
10538
10535
|
var self = this.clone(), op = this.operator;
|
10539
10536
|
if (compressor.option("unsafe_comps")) {
|
10540
10537
|
switch (op) {
|
@@ -10582,7 +10579,7 @@
|
|
10582
10579
|
if (is_undeclared_ref(expr) && global_pure_fns(expr.name)) return true;
|
10583
10580
|
if (expr instanceof AST_Dot
|
10584
10581
|
&& is_undeclared_ref(expr.expression)
|
10585
|
-
&& (static_fns[expr.expression.name] || return_false)(expr.property)) {
|
10582
|
+
&& (static_fns.hasOwnProperty(expr.expression.name) && static_fns[expr.expression.name] || return_false)(expr.property)) {
|
10586
10583
|
return true;
|
10587
10584
|
}
|
10588
10585
|
}
|
@@ -10610,12 +10607,12 @@
|
|
10610
10607
|
});
|
10611
10608
|
|
10612
10609
|
// determine if expression has side effects
|
10613
|
-
(function(
|
10614
|
-
|
10610
|
+
(function(def_has_side_effects) {
|
10611
|
+
def_has_side_effects(AST_Node, return_true);
|
10615
10612
|
|
10616
|
-
|
10617
|
-
|
10618
|
-
|
10613
|
+
def_has_side_effects(AST_EmptyStatement, return_false);
|
10614
|
+
def_has_side_effects(AST_Constant, return_false);
|
10615
|
+
def_has_side_effects(AST_This, return_false);
|
10619
10616
|
|
10620
10617
|
function any(list, compressor) {
|
10621
10618
|
for (var i = list.length; --i >= 0;)
|
@@ -10624,10 +10621,10 @@
|
|
10624
10621
|
return false;
|
10625
10622
|
}
|
10626
10623
|
|
10627
|
-
|
10624
|
+
def_has_side_effects(AST_Block, function(compressor) {
|
10628
10625
|
return any(this.body, compressor);
|
10629
10626
|
});
|
10630
|
-
|
10627
|
+
def_has_side_effects(AST_Call, function(compressor) {
|
10631
10628
|
if (!this.is_expr_pure(compressor)
|
10632
10629
|
&& (!this.expression.is_call_pure(compressor)
|
10633
10630
|
|| this.expression.has_side_effects(compressor))) {
|
@@ -10635,83 +10632,83 @@
|
|
10635
10632
|
}
|
10636
10633
|
return any(this.args, compressor);
|
10637
10634
|
});
|
10638
|
-
|
10635
|
+
def_has_side_effects(AST_Switch, function(compressor) {
|
10639
10636
|
return this.expression.has_side_effects(compressor)
|
10640
10637
|
|| any(this.body, compressor);
|
10641
10638
|
});
|
10642
|
-
|
10639
|
+
def_has_side_effects(AST_Case, function(compressor) {
|
10643
10640
|
return this.expression.has_side_effects(compressor)
|
10644
10641
|
|| any(this.body, compressor);
|
10645
10642
|
});
|
10646
|
-
|
10643
|
+
def_has_side_effects(AST_Try, function(compressor) {
|
10647
10644
|
return any(this.body, compressor)
|
10648
10645
|
|| this.bcatch && this.bcatch.has_side_effects(compressor)
|
10649
10646
|
|| this.bfinally && this.bfinally.has_side_effects(compressor);
|
10650
10647
|
});
|
10651
|
-
|
10648
|
+
def_has_side_effects(AST_If, function(compressor) {
|
10652
10649
|
return this.condition.has_side_effects(compressor)
|
10653
10650
|
|| this.body && this.body.has_side_effects(compressor)
|
10654
10651
|
|| this.alternative && this.alternative.has_side_effects(compressor);
|
10655
10652
|
});
|
10656
|
-
|
10653
|
+
def_has_side_effects(AST_LabeledStatement, function(compressor) {
|
10657
10654
|
return this.body.has_side_effects(compressor);
|
10658
10655
|
});
|
10659
|
-
|
10656
|
+
def_has_side_effects(AST_SimpleStatement, function(compressor) {
|
10660
10657
|
return this.body.has_side_effects(compressor);
|
10661
10658
|
});
|
10662
|
-
|
10663
|
-
|
10664
|
-
|
10665
|
-
|
10659
|
+
def_has_side_effects(AST_Lambda, return_false);
|
10660
|
+
def_has_side_effects(AST_Class, return_false);
|
10661
|
+
def_has_side_effects(AST_DefClass, return_true);
|
10662
|
+
def_has_side_effects(AST_Binary, function(compressor) {
|
10666
10663
|
return this.left.has_side_effects(compressor)
|
10667
10664
|
|| this.right.has_side_effects(compressor);
|
10668
10665
|
});
|
10669
|
-
|
10670
|
-
|
10666
|
+
def_has_side_effects(AST_Assign, return_true);
|
10667
|
+
def_has_side_effects(AST_Conditional, function(compressor) {
|
10671
10668
|
return this.condition.has_side_effects(compressor)
|
10672
10669
|
|| this.consequent.has_side_effects(compressor)
|
10673
10670
|
|| this.alternative.has_side_effects(compressor);
|
10674
10671
|
});
|
10675
|
-
|
10672
|
+
def_has_side_effects(AST_Unary, function(compressor) {
|
10676
10673
|
return unary_side_effects(this.operator)
|
10677
10674
|
|| this.expression.has_side_effects(compressor);
|
10678
10675
|
});
|
10679
|
-
|
10676
|
+
def_has_side_effects(AST_SymbolRef, function(compressor) {
|
10680
10677
|
return !this.is_declared(compressor);
|
10681
10678
|
});
|
10682
|
-
|
10683
|
-
|
10679
|
+
def_has_side_effects(AST_SymbolDeclaration, return_false);
|
10680
|
+
def_has_side_effects(AST_Object, function(compressor) {
|
10684
10681
|
return any(this.properties, compressor);
|
10685
10682
|
});
|
10686
|
-
|
10683
|
+
def_has_side_effects(AST_ObjectProperty, function(compressor) {
|
10687
10684
|
if (this.key instanceof AST_ObjectKeyVal &&
|
10688
10685
|
this.key.has_side_effects(compressor))
|
10689
10686
|
return true;
|
10690
10687
|
return this.value.has_side_effects(compressor);
|
10691
10688
|
});
|
10692
|
-
|
10689
|
+
def_has_side_effects(AST_Array, function(compressor) {
|
10693
10690
|
return any(this.elements, compressor);
|
10694
10691
|
});
|
10695
|
-
|
10692
|
+
def_has_side_effects(AST_Dot, function(compressor) {
|
10696
10693
|
return this.expression.may_throw_on_access(compressor)
|
10697
10694
|
|| this.expression.has_side_effects(compressor);
|
10698
10695
|
});
|
10699
|
-
|
10696
|
+
def_has_side_effects(AST_Sub, function(compressor) {
|
10700
10697
|
return this.expression.may_throw_on_access(compressor)
|
10701
10698
|
|| this.expression.has_side_effects(compressor)
|
10702
10699
|
|| this.property.has_side_effects(compressor);
|
10703
10700
|
});
|
10704
|
-
|
10701
|
+
def_has_side_effects(AST_Sequence, function(compressor) {
|
10705
10702
|
return any(this.expressions, compressor);
|
10706
10703
|
});
|
10707
|
-
|
10704
|
+
def_has_side_effects(AST_Definitions, function(compressor) {
|
10708
10705
|
return any(this.definitions, compressor);
|
10709
10706
|
});
|
10710
|
-
|
10707
|
+
def_has_side_effects(AST_VarDef, function(compressor) {
|
10711
10708
|
return this.value;
|
10712
10709
|
});
|
10713
|
-
|
10714
|
-
|
10710
|
+
def_has_side_effects(AST_TemplateSegment, return_false);
|
10711
|
+
def_has_side_effects(AST_TemplateString, function(compressor) {
|
10715
10712
|
return any(this.segments, compressor);
|
10716
10713
|
});
|
10717
10714
|
})(function(node, func) {
|
@@ -10719,15 +10716,15 @@
|
|
10719
10716
|
});
|
10720
10717
|
|
10721
10718
|
// determine if expression may throw
|
10722
|
-
(function(
|
10723
|
-
|
10719
|
+
(function(def_may_throw) {
|
10720
|
+
def_may_throw(AST_Node, return_true);
|
10724
10721
|
|
10725
|
-
|
10726
|
-
|
10727
|
-
|
10728
|
-
|
10729
|
-
|
10730
|
-
|
10722
|
+
def_may_throw(AST_Class, return_false);
|
10723
|
+
def_may_throw(AST_Constant, return_false);
|
10724
|
+
def_may_throw(AST_EmptyStatement, return_false);
|
10725
|
+
def_may_throw(AST_Lambda, return_false);
|
10726
|
+
def_may_throw(AST_SymbolDeclaration, return_false);
|
10727
|
+
def_may_throw(AST_This, return_false);
|
10731
10728
|
|
10732
10729
|
function any(list, compressor) {
|
10733
10730
|
for (var i = list.length; --i >= 0;)
|
@@ -10736,10 +10733,10 @@
|
|
10736
10733
|
return false;
|
10737
10734
|
}
|
10738
10735
|
|
10739
|
-
|
10736
|
+
def_may_throw(AST_Array, function(compressor) {
|
10740
10737
|
return any(this.elements, compressor);
|
10741
10738
|
});
|
10742
|
-
|
10739
|
+
def_may_throw(AST_Assign, function(compressor) {
|
10743
10740
|
if (this.right.may_throw(compressor)) return true;
|
10744
10741
|
if (!compressor.has_directive("use strict")
|
10745
10742
|
&& this.operator == "="
|
@@ -10748,81 +10745,81 @@
|
|
10748
10745
|
}
|
10749
10746
|
return this.left.may_throw(compressor);
|
10750
10747
|
});
|
10751
|
-
|
10748
|
+
def_may_throw(AST_Binary, function(compressor) {
|
10752
10749
|
return this.left.may_throw(compressor)
|
10753
10750
|
|| this.right.may_throw(compressor);
|
10754
10751
|
});
|
10755
|
-
|
10752
|
+
def_may_throw(AST_Block, function(compressor) {
|
10756
10753
|
return any(this.body, compressor);
|
10757
10754
|
});
|
10758
|
-
|
10755
|
+
def_may_throw(AST_Call, function(compressor) {
|
10759
10756
|
if (any(this.args, compressor)) return true;
|
10760
10757
|
if (this.is_expr_pure(compressor)) return false;
|
10761
10758
|
if (this.expression.may_throw(compressor)) return true;
|
10762
10759
|
return !(this.expression instanceof AST_Lambda)
|
10763
10760
|
|| any(this.expression.body, compressor);
|
10764
10761
|
});
|
10765
|
-
|
10762
|
+
def_may_throw(AST_Case, function(compressor) {
|
10766
10763
|
return this.expression.may_throw(compressor)
|
10767
10764
|
|| any(this.body, compressor);
|
10768
10765
|
});
|
10769
|
-
|
10766
|
+
def_may_throw(AST_Conditional, function(compressor) {
|
10770
10767
|
return this.condition.may_throw(compressor)
|
10771
10768
|
|| this.consequent.may_throw(compressor)
|
10772
10769
|
|| this.alternative.may_throw(compressor);
|
10773
10770
|
});
|
10774
|
-
|
10771
|
+
def_may_throw(AST_Definitions, function(compressor) {
|
10775
10772
|
return any(this.definitions, compressor);
|
10776
10773
|
});
|
10777
|
-
|
10774
|
+
def_may_throw(AST_Dot, function(compressor) {
|
10778
10775
|
return this.expression.may_throw_on_access(compressor)
|
10779
10776
|
|| this.expression.may_throw(compressor);
|
10780
10777
|
});
|
10781
|
-
|
10778
|
+
def_may_throw(AST_If, function(compressor) {
|
10782
10779
|
return this.condition.may_throw(compressor)
|
10783
10780
|
|| this.body && this.body.may_throw(compressor)
|
10784
10781
|
|| this.alternative && this.alternative.may_throw(compressor);
|
10785
10782
|
});
|
10786
|
-
|
10783
|
+
def_may_throw(AST_LabeledStatement, function(compressor) {
|
10787
10784
|
return this.body.may_throw(compressor);
|
10788
10785
|
});
|
10789
|
-
|
10786
|
+
def_may_throw(AST_Object, function(compressor) {
|
10790
10787
|
return any(this.properties, compressor);
|
10791
10788
|
});
|
10792
|
-
|
10789
|
+
def_may_throw(AST_ObjectProperty, function(compressor) {
|
10793
10790
|
return this.value.may_throw(compressor);
|
10794
10791
|
});
|
10795
|
-
|
10792
|
+
def_may_throw(AST_Return, function(compressor) {
|
10796
10793
|
return this.value && this.value.may_throw(compressor);
|
10797
10794
|
});
|
10798
|
-
|
10795
|
+
def_may_throw(AST_Sequence, function(compressor) {
|
10799
10796
|
return any(this.expressions, compressor);
|
10800
10797
|
});
|
10801
|
-
|
10798
|
+
def_may_throw(AST_SimpleStatement, function(compressor) {
|
10802
10799
|
return this.body.may_throw(compressor);
|
10803
10800
|
});
|
10804
|
-
|
10801
|
+
def_may_throw(AST_Sub, function(compressor) {
|
10805
10802
|
return this.expression.may_throw_on_access(compressor)
|
10806
10803
|
|| this.expression.may_throw(compressor)
|
10807
10804
|
|| this.property.may_throw(compressor);
|
10808
10805
|
});
|
10809
|
-
|
10806
|
+
def_may_throw(AST_Switch, function(compressor) {
|
10810
10807
|
return this.expression.may_throw(compressor)
|
10811
10808
|
|| any(this.body, compressor);
|
10812
10809
|
});
|
10813
|
-
|
10810
|
+
def_may_throw(AST_SymbolRef, function(compressor) {
|
10814
10811
|
return !this.is_declared(compressor);
|
10815
10812
|
});
|
10816
|
-
|
10813
|
+
def_may_throw(AST_Try, function(compressor) {
|
10817
10814
|
return this.bcatch ? this.bcatch.may_throw(compressor) : any(this.body, compressor)
|
10818
10815
|
|| this.bfinally && this.bfinally.may_throw(compressor);
|
10819
10816
|
});
|
10820
|
-
|
10817
|
+
def_may_throw(AST_Unary, function(compressor) {
|
10821
10818
|
if (this.operator == "typeof" && this.expression instanceof AST_SymbolRef)
|
10822
10819
|
return false;
|
10823
10820
|
return this.expression.may_throw(compressor);
|
10824
10821
|
});
|
10825
|
-
|
10822
|
+
def_may_throw(AST_VarDef, function(compressor) {
|
10826
10823
|
if (!this.value) return false;
|
10827
10824
|
return this.value.may_throw(compressor);
|
10828
10825
|
});
|
@@ -10831,7 +10828,7 @@
|
|
10831
10828
|
});
|
10832
10829
|
|
10833
10830
|
// determine if expression is constant
|
10834
|
-
(function(
|
10831
|
+
(function(def_is_constant_expression) {
|
10835
10832
|
function all$$1(list) {
|
10836
10833
|
for (var i = list.length; --i >= 0;)
|
10837
10834
|
if (!list[i].is_constant_expression())
|
@@ -10871,29 +10868,29 @@
|
|
10871
10868
|
return result;
|
10872
10869
|
}
|
10873
10870
|
|
10874
|
-
|
10875
|
-
|
10876
|
-
|
10871
|
+
def_is_constant_expression(AST_Node, return_false);
|
10872
|
+
def_is_constant_expression(AST_Constant, return_true);
|
10873
|
+
def_is_constant_expression(AST_Class, function(scope) {
|
10877
10874
|
var self = this;
|
10878
10875
|
if (self.extends && !self.extends.is_constant_expression(scope)) {
|
10879
10876
|
return false;
|
10880
10877
|
}
|
10881
10878
|
return all_refs_local.call(self, scope);
|
10882
10879
|
});
|
10883
|
-
|
10884
|
-
|
10880
|
+
def_is_constant_expression(AST_Lambda, all_refs_local);
|
10881
|
+
def_is_constant_expression(AST_Unary, function() {
|
10885
10882
|
return this.expression.is_constant_expression();
|
10886
10883
|
});
|
10887
|
-
|
10884
|
+
def_is_constant_expression(AST_Binary, function() {
|
10888
10885
|
return this.left.is_constant_expression() && this.right.is_constant_expression();
|
10889
10886
|
});
|
10890
|
-
|
10887
|
+
def_is_constant_expression(AST_Array, function() {
|
10891
10888
|
return all$$1(this.elements);
|
10892
10889
|
});
|
10893
|
-
|
10890
|
+
def_is_constant_expression(AST_Object, function() {
|
10894
10891
|
return all$$1(this.properties);
|
10895
10892
|
});
|
10896
|
-
|
10893
|
+
def_is_constant_expression(AST_ObjectProperty, function() {
|
10897
10894
|
return !(this.key instanceof AST_Node) && this.value.is_constant_expression();
|
10898
10895
|
});
|
10899
10896
|
})(function(node, func) {
|
@@ -10928,7 +10925,7 @@
|
|
10928
10925
|
/* -----[ optimizers ]----- */
|
10929
10926
|
|
10930
10927
|
var directives = ["use asm", "use strict"];
|
10931
|
-
|
10928
|
+
def_optimize(AST_Directive, function(self, compressor) {
|
10932
10929
|
if (compressor.option("directives")
|
10933
10930
|
&& (!member(self.value, directives) || compressor.has_directive(self.value) !== self)) {
|
10934
10931
|
return make_node(AST_EmptyStatement, self);
|
@@ -10936,13 +10933,13 @@
|
|
10936
10933
|
return self;
|
10937
10934
|
});
|
10938
10935
|
|
10939
|
-
|
10936
|
+
def_optimize(AST_Debugger, function(self, compressor) {
|
10940
10937
|
if (compressor.option("drop_debugger"))
|
10941
10938
|
return make_node(AST_EmptyStatement, self);
|
10942
10939
|
return self;
|
10943
10940
|
});
|
10944
10941
|
|
10945
|
-
|
10942
|
+
def_optimize(AST_LabeledStatement, function(self, compressor) {
|
10946
10943
|
if (self.body instanceof AST_Break
|
10947
10944
|
&& compressor.loopcontrol_target(self.body) === self.body) {
|
10948
10945
|
return make_node(AST_EmptyStatement, self);
|
@@ -10950,7 +10947,7 @@
|
|
10950
10947
|
return self.label.references.length == 0 ? self.body : self;
|
10951
10948
|
});
|
10952
10949
|
|
10953
|
-
|
10950
|
+
def_optimize(AST_Block, function(self, compressor) {
|
10954
10951
|
tighten_body(self.body, compressor);
|
10955
10952
|
return self;
|
10956
10953
|
});
|
@@ -10963,7 +10960,7 @@
|
|
10963
10960
|
);
|
10964
10961
|
}
|
10965
10962
|
|
10966
|
-
|
10963
|
+
def_optimize(AST_BlockStatement, function(self, compressor) {
|
10967
10964
|
tighten_body(self.body, compressor);
|
10968
10965
|
switch (self.body.length) {
|
10969
10966
|
case 1:
|
@@ -10988,7 +10985,7 @@
|
|
10988
10985
|
}
|
10989
10986
|
return self;
|
10990
10987
|
}
|
10991
|
-
|
10988
|
+
def_optimize(AST_Lambda, opt_AST_Lambda);
|
10992
10989
|
|
10993
10990
|
AST_Scope.DEFMETHOD("drop_unused", function(compressor) {
|
10994
10991
|
if (!compressor.option("unused")) return;
|
@@ -11492,10 +11489,11 @@
|
|
11492
11489
|
return self;
|
11493
11490
|
});
|
11494
11491
|
|
11495
|
-
AST_Scope.DEFMETHOD("var_names", function() {
|
11492
|
+
AST_Scope.DEFMETHOD("var_names", function varNames() {
|
11496
11493
|
var var_names = this._var_names;
|
11497
11494
|
if (!var_names) {
|
11498
|
-
this.
|
11495
|
+
const isParentScopeAvailable = this.parent_scope && !this.parent_scope instanceof AST_Toplevel;
|
11496
|
+
this._var_names = var_names = isParentScopeAvailable ? varNames.call(this.parent_scope) : Object.create(null);
|
11499
11497
|
this.enclosed.forEach(function(def) {
|
11500
11498
|
var_names[def.name] = true;
|
11501
11499
|
});
|
@@ -11576,7 +11574,7 @@
|
|
11576
11574
|
|
11577
11575
|
// drop_side_effect_free()
|
11578
11576
|
// remove side-effect-free parts which only affects return value
|
11579
|
-
(function(
|
11577
|
+
(function(def_drop_side_effect_free) {
|
11580
11578
|
// Drop side-effect-free elements from an array of expressions.
|
11581
11579
|
// Returns an array of expressions with side-effects or null
|
11582
11580
|
// if all elements were dropped. Note: original array may be
|
@@ -11596,10 +11594,10 @@
|
|
11596
11594
|
return changed ? ret.length ? ret : null : nodes;
|
11597
11595
|
}
|
11598
11596
|
|
11599
|
-
|
11600
|
-
|
11601
|
-
|
11602
|
-
|
11597
|
+
def_drop_side_effect_free(AST_Node, return_this);
|
11598
|
+
def_drop_side_effect_free(AST_Constant, return_null);
|
11599
|
+
def_drop_side_effect_free(AST_This, return_null);
|
11600
|
+
def_drop_side_effect_free(AST_Call, function(compressor, first_in_statement$$1) {
|
11603
11601
|
if (!this.is_expr_pure(compressor)) {
|
11604
11602
|
if (this.expression.is_call_pure(compressor)) {
|
11605
11603
|
var exprs = this.args.slice();
|
@@ -11621,11 +11619,11 @@
|
|
11621
11619
|
var args = trim(this.args, compressor, first_in_statement$$1);
|
11622
11620
|
return args && make_sequence(this, args);
|
11623
11621
|
});
|
11624
|
-
|
11625
|
-
|
11626
|
-
|
11627
|
-
|
11628
|
-
|
11622
|
+
def_drop_side_effect_free(AST_Accessor, return_null);
|
11623
|
+
def_drop_side_effect_free(AST_Function, return_null);
|
11624
|
+
def_drop_side_effect_free(AST_Arrow, return_null);
|
11625
|
+
def_drop_side_effect_free(AST_ClassExpression, return_null);
|
11626
|
+
def_drop_side_effect_free(AST_Binary, function(compressor, first_in_statement$$1) {
|
11629
11627
|
var right = this.right.drop_side_effect_free(compressor);
|
11630
11628
|
if (!right) return this.left.drop_side_effect_free(compressor, first_in_statement$$1);
|
11631
11629
|
if (lazy_op(this.operator)) {
|
@@ -11639,7 +11637,7 @@
|
|
11639
11637
|
return make_sequence(this, [ left, right ]);
|
11640
11638
|
}
|
11641
11639
|
});
|
11642
|
-
|
11640
|
+
def_drop_side_effect_free(AST_Assign, function(compressor) {
|
11643
11641
|
var left = this.left;
|
11644
11642
|
if (left.has_side_effects(compressor)
|
11645
11643
|
|| compressor.has_directive("use strict")
|
@@ -11656,7 +11654,7 @@
|
|
11656
11654
|
}
|
11657
11655
|
return this;
|
11658
11656
|
});
|
11659
|
-
|
11657
|
+
def_drop_side_effect_free(AST_Conditional, function(compressor) {
|
11660
11658
|
var consequent = this.consequent.drop_side_effect_free(compressor);
|
11661
11659
|
var alternative = this.alternative.drop_side_effect_free(compressor);
|
11662
11660
|
if (consequent === this.consequent && alternative === this.alternative) return this;
|
@@ -11675,7 +11673,7 @@
|
|
11675
11673
|
node.alternative = alternative;
|
11676
11674
|
return node;
|
11677
11675
|
});
|
11678
|
-
|
11676
|
+
def_drop_side_effect_free(AST_Unary, function(compressor, first_in_statement$$1) {
|
11679
11677
|
if (unary_side_effects(this.operator)) {
|
11680
11678
|
this.write_only = !this.expression.has_side_effects(compressor);
|
11681
11679
|
return this;
|
@@ -11688,25 +11686,25 @@
|
|
11688
11686
|
}
|
11689
11687
|
return expression;
|
11690
11688
|
});
|
11691
|
-
|
11689
|
+
def_drop_side_effect_free(AST_SymbolRef, function(compressor) {
|
11692
11690
|
return this.is_declared(compressor) ? null : this;
|
11693
11691
|
});
|
11694
|
-
|
11692
|
+
def_drop_side_effect_free(AST_Object, function(compressor, first_in_statement$$1) {
|
11695
11693
|
var values = trim(this.properties, compressor, first_in_statement$$1);
|
11696
11694
|
return values && make_sequence(this, values);
|
11697
11695
|
});
|
11698
|
-
|
11696
|
+
def_drop_side_effect_free(AST_ObjectProperty, function(compressor, first_in_statement$$1) {
|
11699
11697
|
return this.value.drop_side_effect_free(compressor, first_in_statement$$1);
|
11700
11698
|
});
|
11701
|
-
|
11699
|
+
def_drop_side_effect_free(AST_Array, function(compressor, first_in_statement$$1) {
|
11702
11700
|
var values = trim(this.elements, compressor, first_in_statement$$1);
|
11703
11701
|
return values && make_sequence(this, values);
|
11704
11702
|
});
|
11705
|
-
|
11703
|
+
def_drop_side_effect_free(AST_Dot, function(compressor, first_in_statement$$1) {
|
11706
11704
|
if (this.expression.may_throw_on_access(compressor)) return this;
|
11707
11705
|
return this.expression.drop_side_effect_free(compressor, first_in_statement$$1);
|
11708
11706
|
});
|
11709
|
-
|
11707
|
+
def_drop_side_effect_free(AST_Sub, function(compressor, first_in_statement$$1) {
|
11710
11708
|
if (this.expression.may_throw_on_access(compressor)) return this;
|
11711
11709
|
var expression = this.expression.drop_side_effect_free(compressor, first_in_statement$$1);
|
11712
11710
|
if (!expression) return this.property.drop_side_effect_free(compressor, first_in_statement$$1);
|
@@ -11714,7 +11712,7 @@
|
|
11714
11712
|
if (!property) return expression;
|
11715
11713
|
return make_sequence(this, [ expression, property ]);
|
11716
11714
|
});
|
11717
|
-
|
11715
|
+
def_drop_side_effect_free(AST_Sequence, function(compressor) {
|
11718
11716
|
var last = this.tail_node();
|
11719
11717
|
var expr = last.drop_side_effect_free(compressor);
|
11720
11718
|
if (expr === last) return this;
|
@@ -11722,11 +11720,11 @@
|
|
11722
11720
|
if (expr) expressions.push(expr);
|
11723
11721
|
return make_sequence(this, expressions);
|
11724
11722
|
});
|
11725
|
-
|
11723
|
+
def_drop_side_effect_free(AST_Expansion, function(compressor, first_in_statement$$1) {
|
11726
11724
|
return this.expression.drop_side_effect_free(compressor, first_in_statement$$1);
|
11727
11725
|
});
|
11728
|
-
|
11729
|
-
|
11726
|
+
def_drop_side_effect_free(AST_TemplateSegment, return_null);
|
11727
|
+
def_drop_side_effect_free(AST_TemplateString, function(compressor) {
|
11730
11728
|
var values = trim(this.segments, compressor, first_in_statement);
|
11731
11729
|
return values && make_sequence(this, values);
|
11732
11730
|
});
|
@@ -11746,7 +11744,7 @@
|
|
11746
11744
|
"document",
|
11747
11745
|
"location"
|
11748
11746
|
];
|
11749
|
-
|
11747
|
+
def_optimize(AST_SimpleStatement, function(self, compressor) {
|
11750
11748
|
if (self.body instanceof AST_SymbolRef && pure_prop_access_globals.indexOf(self.body.name) !== -1) {
|
11751
11749
|
return make_node(AST_EmptyStatement, self);
|
11752
11750
|
}
|
@@ -11764,7 +11762,7 @@
|
|
11764
11762
|
return self;
|
11765
11763
|
});
|
11766
11764
|
|
11767
|
-
|
11765
|
+
def_optimize(AST_While, function(self, compressor) {
|
11768
11766
|
return compressor.option("loops") ? make_node(AST_For, self, self).optimize(compressor) : self;
|
11769
11767
|
});
|
11770
11768
|
|
@@ -11782,7 +11780,7 @@
|
|
11782
11780
|
return found;
|
11783
11781
|
}
|
11784
11782
|
|
11785
|
-
|
11783
|
+
def_optimize(AST_Do, function(self, compressor) {
|
11786
11784
|
if (!compressor.option("loops")) return self;
|
11787
11785
|
var cond = self.condition.tail_node().evaluate(compressor);
|
11788
11786
|
if (!(cond instanceof AST_Node)) {
|
@@ -11878,7 +11876,7 @@
|
|
11878
11876
|
}
|
11879
11877
|
}
|
11880
11878
|
|
11881
|
-
|
11879
|
+
def_optimize(AST_For, function(self, compressor) {
|
11882
11880
|
if (!compressor.option("loops")) return self;
|
11883
11881
|
if (compressor.option("side_effects") && self.init) {
|
11884
11882
|
self.init = self.init.drop_side_effect_free(compressor);
|
@@ -11915,7 +11913,7 @@
|
|
11915
11913
|
return if_break_in_loop(self, compressor);
|
11916
11914
|
});
|
11917
11915
|
|
11918
|
-
|
11916
|
+
def_optimize(AST_If, function(self, compressor) {
|
11919
11917
|
if (is_empty(self.alternative)) self.alternative = null;
|
11920
11918
|
|
11921
11919
|
if (!compressor.option("conditionals")) return self;
|
@@ -12059,7 +12057,7 @@
|
|
12059
12057
|
return self;
|
12060
12058
|
});
|
12061
12059
|
|
12062
|
-
|
12060
|
+
def_optimize(AST_Switch, function(self, compressor) {
|
12063
12061
|
if (!compressor.option("switches")) return self;
|
12064
12062
|
var branch;
|
12065
12063
|
var value = self.expression.evaluate(compressor);
|
@@ -12165,7 +12163,7 @@
|
|
12165
12163
|
}
|
12166
12164
|
});
|
12167
12165
|
|
12168
|
-
|
12166
|
+
def_optimize(AST_Try, function(self, compressor) {
|
12169
12167
|
tighten_body(self.body, compressor);
|
12170
12168
|
if (self.bcatch && self.bfinally && all(self.bfinally.body, is_empty)) self.bfinally = null;
|
12171
12169
|
if (compressor.option("dead_code") && all(self.body, is_empty)) {
|
@@ -12239,13 +12237,13 @@
|
|
12239
12237
|
return make_sequence(this, assignments);
|
12240
12238
|
});
|
12241
12239
|
|
12242
|
-
|
12240
|
+
def_optimize(AST_Definitions, function(self, compressor) {
|
12243
12241
|
if (self.definitions.length == 0)
|
12244
12242
|
return make_node(AST_EmptyStatement, self);
|
12245
12243
|
return self;
|
12246
12244
|
});
|
12247
12245
|
|
12248
|
-
|
12246
|
+
def_optimize(AST_Import, function(self, compressor) {
|
12249
12247
|
return self;
|
12250
12248
|
});
|
12251
12249
|
|
@@ -12257,7 +12255,7 @@
|
|
12257
12255
|
&& compressor.top_retain(fn.name);
|
12258
12256
|
}
|
12259
12257
|
|
12260
|
-
|
12258
|
+
def_optimize(AST_Call, function(self, compressor) {
|
12261
12259
|
var exp = self.expression;
|
12262
12260
|
var fn = exp;
|
12263
12261
|
inline_array_like_spread(self, compressor, self.args);
|
@@ -12814,24 +12812,31 @@
|
|
12814
12812
|
}
|
12815
12813
|
});
|
12816
12814
|
|
12817
|
-
|
12818
|
-
|
12819
|
-
|
12820
|
-
|
12821
|
-
|
12822
|
-
|
12823
|
-
|
12824
|
-
|
12825
|
-
|
12826
|
-
|
12815
|
+
def_optimize(AST_New, function(self, compressor) {
|
12816
|
+
const {args, expression: exp} = self;
|
12817
|
+
|
12818
|
+
if (compressor.option("unsafe") && is_undeclared_ref(exp)) {
|
12819
|
+
if (["Object", "RegExp", "Function", "Error"].includes(exp.name))
|
12820
|
+
return make_node(AST_Call, self, self).transform(compressor);
|
12821
|
+
|
12822
|
+
if (exp.name === "Array" && args.length < 2) {
|
12823
|
+
if (args.length === 0 || args[0].value === 0) return new AST_Array;
|
12824
|
+
|
12825
|
+
if (args[0].value > 11) {
|
12827
12826
|
return make_node(AST_Call, self, self).transform(compressor);
|
12828
12827
|
}
|
12828
|
+
|
12829
|
+
const elements = [];
|
12830
|
+
for (let i = 0; i < self.args[0].value; i++) elements.push(new AST_Hole);
|
12831
|
+
|
12832
|
+
return new AST_Array({elements});
|
12829
12833
|
}
|
12830
12834
|
}
|
12835
|
+
|
12831
12836
|
return self;
|
12832
12837
|
});
|
12833
12838
|
|
12834
|
-
|
12839
|
+
def_optimize(AST_Sequence, function(self, compressor) {
|
12835
12840
|
if (!compressor.option("side_effects")) return self;
|
12836
12841
|
var expressions = [];
|
12837
12842
|
filter_for_side_effects();
|
@@ -12882,11 +12887,11 @@
|
|
12882
12887
|
return this;
|
12883
12888
|
});
|
12884
12889
|
|
12885
|
-
|
12890
|
+
def_optimize(AST_UnaryPostfix, function(self, compressor) {
|
12886
12891
|
return self.lift_sequences(compressor);
|
12887
12892
|
});
|
12888
12893
|
|
12889
|
-
|
12894
|
+
def_optimize(AST_UnaryPrefix, function(self, compressor) {
|
12890
12895
|
var e = self.expression;
|
12891
12896
|
if (self.operator == "delete"
|
12892
12897
|
&& !(e instanceof AST_SymbolRef
|
@@ -13002,7 +13007,7 @@
|
|
13002
13007
|
|| node instanceof AST_Class;
|
13003
13008
|
}
|
13004
13009
|
|
13005
|
-
|
13010
|
+
def_optimize(AST_Binary, function(self, compressor) {
|
13006
13011
|
function reversible() {
|
13007
13012
|
return self.left.is_constant()
|
13008
13013
|
|| self.right.is_constant()
|
@@ -13430,7 +13435,7 @@
|
|
13430
13435
|
return self;
|
13431
13436
|
});
|
13432
13437
|
|
13433
|
-
|
13438
|
+
def_optimize(AST_SymbolExport, function(self, compressor) {
|
13434
13439
|
return self;
|
13435
13440
|
});
|
13436
13441
|
|
@@ -13458,7 +13463,7 @@
|
|
13458
13463
|
return false;
|
13459
13464
|
}
|
13460
13465
|
|
13461
|
-
|
13466
|
+
def_optimize(AST_SymbolRef, function(self, compressor) {
|
13462
13467
|
if (!compressor.option("ie8")
|
13463
13468
|
&& is_undeclared_ref(self)
|
13464
13469
|
&& (!self.scope.uses_with || !compressor.find_parent(AST_With))) {
|
@@ -13598,7 +13603,7 @@
|
|
13598
13603
|
return lhs instanceof AST_SymbolRef || lhs.TYPE === self.TYPE;
|
13599
13604
|
}
|
13600
13605
|
|
13601
|
-
|
13606
|
+
def_optimize(AST_Undefined, function(self, compressor) {
|
13602
13607
|
if (compressor.option("unsafe_undefined")) {
|
13603
13608
|
var undef = find_variable(compressor, "undefined");
|
13604
13609
|
if (undef) {
|
@@ -13621,7 +13626,7 @@
|
|
13621
13626
|
});
|
13622
13627
|
});
|
13623
13628
|
|
13624
|
-
|
13629
|
+
def_optimize(AST_Infinity, function(self, compressor) {
|
13625
13630
|
var lhs = is_lhs(compressor.self(), compressor.parent());
|
13626
13631
|
if (lhs && is_atomic(lhs, self)) return self;
|
13627
13632
|
if (compressor.option("keep_infinity")
|
@@ -13639,7 +13644,7 @@
|
|
13639
13644
|
});
|
13640
13645
|
});
|
13641
13646
|
|
13642
|
-
|
13647
|
+
def_optimize(AST_NaN, function(self, compressor) {
|
13643
13648
|
var lhs = is_lhs(compressor.self(), compressor.parent());
|
13644
13649
|
if (lhs && !is_atomic(lhs, self)
|
13645
13650
|
|| find_variable(compressor, "NaN")) {
|
@@ -13679,7 +13684,7 @@
|
|
13679
13684
|
|
13680
13685
|
var ASSIGN_OPS = [ "+", "-", "/", "*", "%", ">>", "<<", ">>>", "|", "^", "&" ];
|
13681
13686
|
var ASSIGN_OPS_COMMUTATIVE = [ "*", "|", "^", "&" ];
|
13682
|
-
|
13687
|
+
def_optimize(AST_Assign, function(self, compressor) {
|
13683
13688
|
var def;
|
13684
13689
|
if (compressor.option("dead_code")
|
13685
13690
|
&& self.left instanceof AST_SymbolRef
|
@@ -13738,7 +13743,7 @@
|
|
13738
13743
|
}
|
13739
13744
|
});
|
13740
13745
|
|
13741
|
-
|
13746
|
+
def_optimize(AST_DefaultAssign, function(self, compressor) {
|
13742
13747
|
if (!compressor.option("evaluate")) {
|
13743
13748
|
return self;
|
13744
13749
|
}
|
@@ -13755,7 +13760,7 @@
|
|
13755
13760
|
return self;
|
13756
13761
|
});
|
13757
13762
|
|
13758
|
-
|
13763
|
+
def_optimize(AST_Conditional, function(self, compressor) {
|
13759
13764
|
if (!compressor.option("conditionals")) return self;
|
13760
13765
|
// This looks like lift_sequences(), should probably be under "sequences"
|
13761
13766
|
if (self.condition instanceof AST_Sequence) {
|
@@ -13961,7 +13966,7 @@
|
|
13961
13966
|
}
|
13962
13967
|
});
|
13963
13968
|
|
13964
|
-
|
13969
|
+
def_optimize(AST_Boolean, function(self, compressor) {
|
13965
13970
|
if (compressor.in_boolean_context()) return make_node(AST_Number, self, {
|
13966
13971
|
value: +self.value
|
13967
13972
|
});
|
@@ -14008,7 +14013,7 @@
|
|
14008
14013
|
|| !value.contains_this();
|
14009
14014
|
}
|
14010
14015
|
|
14011
|
-
|
14016
|
+
def_optimize(AST_Sub, function(self, compressor) {
|
14012
14017
|
var expr = self.expression;
|
14013
14018
|
var prop = self.property;
|
14014
14019
|
if (compressor.option("properties")) {
|
@@ -14180,7 +14185,7 @@
|
|
14180
14185
|
}
|
14181
14186
|
});
|
14182
14187
|
|
14183
|
-
|
14188
|
+
def_optimize(AST_Dot, function(self, compressor) {
|
14184
14189
|
if (self.property == "arguments" || self.property == "caller") {
|
14185
14190
|
compressor.warn("Function.prototype.{prop} not supported [{file}:{line},{col}]", {
|
14186
14191
|
prop: self.property,
|
@@ -14265,7 +14270,7 @@
|
|
14265
14270
|
return self;
|
14266
14271
|
}
|
14267
14272
|
|
14268
|
-
|
14273
|
+
def_optimize(AST_Array, function(self, compressor) {
|
14269
14274
|
var optimized = literals_in_boolean_context(self, compressor);
|
14270
14275
|
if (optimized !== self) {
|
14271
14276
|
return optimized;
|
@@ -14273,7 +14278,7 @@
|
|
14273
14278
|
return inline_array_like_spread(self, compressor, self.elements);
|
14274
14279
|
});
|
14275
14280
|
|
14276
|
-
|
14281
|
+
def_optimize(AST_Object, function(self, compressor) {
|
14277
14282
|
var optimized = literals_in_boolean_context(self, compressor);
|
14278
14283
|
if (optimized !== self) {
|
14279
14284
|
return optimized;
|
@@ -14299,16 +14304,16 @@
|
|
14299
14304
|
return self;
|
14300
14305
|
});
|
14301
14306
|
|
14302
|
-
|
14307
|
+
def_optimize(AST_RegExp, literals_in_boolean_context);
|
14303
14308
|
|
14304
|
-
|
14309
|
+
def_optimize(AST_Return, function(self, compressor) {
|
14305
14310
|
if (self.value && is_undefined(self.value, compressor)) {
|
14306
14311
|
self.value = null;
|
14307
14312
|
}
|
14308
14313
|
return self;
|
14309
14314
|
});
|
14310
14315
|
|
14311
|
-
|
14316
|
+
def_optimize(AST_Arrow, function(self, compressor) {
|
14312
14317
|
if (!(self.body instanceof AST_Node)) {
|
14313
14318
|
self = opt_AST_Lambda(self, compressor);
|
14314
14319
|
}
|
@@ -14321,7 +14326,7 @@
|
|
14321
14326
|
return self;
|
14322
14327
|
});
|
14323
14328
|
|
14324
|
-
|
14329
|
+
def_optimize(AST_Function, function(self, compressor) {
|
14325
14330
|
self = opt_AST_Lambda(self, compressor);
|
14326
14331
|
if (compressor.option("unsafe_arrows")
|
14327
14332
|
&& compressor.option("ecma") >= 6
|
@@ -14342,20 +14347,20 @@
|
|
14342
14347
|
return self;
|
14343
14348
|
});
|
14344
14349
|
|
14345
|
-
|
14350
|
+
def_optimize(AST_Class, function(self, compressor) {
|
14346
14351
|
// HACK to avoid compress failure.
|
14347
14352
|
// AST_Class is not really an AST_Scope/AST_Block as it lacks a body.
|
14348
14353
|
return self;
|
14349
14354
|
});
|
14350
14355
|
|
14351
|
-
|
14356
|
+
def_optimize(AST_Yield, function(self, compressor) {
|
14352
14357
|
if (self.expression && !self.is_star && is_undefined(self.expression, compressor)) {
|
14353
14358
|
self.expression = null;
|
14354
14359
|
}
|
14355
14360
|
return self;
|
14356
14361
|
});
|
14357
14362
|
|
14358
|
-
|
14363
|
+
def_optimize(AST_TemplateString, function(self, compressor) {
|
14359
14364
|
if (!compressor.option("evaluate")
|
14360
14365
|
|| compressor.parent() instanceof AST_PrefixedTemplateString)
|
14361
14366
|
return self;
|
@@ -14380,7 +14385,7 @@
|
|
14380
14385
|
return segments.length == 1 ? make_node(AST_String, self, segments[0]) : self;
|
14381
14386
|
});
|
14382
14387
|
|
14383
|
-
|
14388
|
+
def_optimize(AST_PrefixedTemplateString, function(self, compressor) {
|
14384
14389
|
return self;
|
14385
14390
|
});
|
14386
14391
|
|
@@ -14406,9 +14411,9 @@
|
|
14406
14411
|
return self;
|
14407
14412
|
}
|
14408
14413
|
|
14409
|
-
|
14414
|
+
def_optimize(AST_ObjectProperty, lift_key);
|
14410
14415
|
|
14411
|
-
|
14416
|
+
def_optimize(AST_ConciseMethod, function(self, compressor) {
|
14412
14417
|
lift_key(self, compressor);
|
14413
14418
|
// p(){return x;} ---> p:()=>x
|
14414
14419
|
if (compressor.option("arrows")
|
@@ -14432,7 +14437,7 @@
|
|
14432
14437
|
return self;
|
14433
14438
|
});
|
14434
14439
|
|
14435
|
-
|
14440
|
+
def_optimize(AST_ObjectKeyVal, function(self, compressor) {
|
14436
14441
|
lift_key(self, compressor);
|
14437
14442
|
// p:function(){} ---> p(){}
|
14438
14443
|
// p:function*(){} ---> *p(){}
|
@@ -14463,7 +14468,7 @@
|
|
14463
14468
|
return self;
|
14464
14469
|
});
|
14465
14470
|
|
14466
|
-
|
14471
|
+
def_optimize(AST_Destructuring, function(self, compressor) {
|
14467
14472
|
if (compressor.option("pure_getters") == true
|
14468
14473
|
&& compressor.option("unused")
|
14469
14474
|
&& !self.is_array
|
@@ -17343,6 +17348,7 @@
|
|
17343
17348
|
"declare",
|
17344
17349
|
"decode",
|
17345
17350
|
"decodeAudioData",
|
17351
|
+
"decodingInfo",
|
17346
17352
|
"decodeURI",
|
17347
17353
|
"decodeURIComponent",
|
17348
17354
|
"decrypt",
|
@@ -17585,6 +17591,7 @@
|
|
17585
17591
|
"filterResY",
|
17586
17592
|
"filterUnits",
|
17587
17593
|
"filters",
|
17594
|
+
"finally",
|
17588
17595
|
"find",
|
17589
17596
|
"findIndex",
|
17590
17597
|
"findRule",
|
@@ -18308,6 +18315,7 @@
|
|
18308
18315
|
"measure",
|
18309
18316
|
"measureText",
|
18310
18317
|
"media",
|
18318
|
+
"mediaCapabilities",
|
18311
18319
|
"mediaDevices",
|
18312
18320
|
"mediaElement",
|
18313
18321
|
"mediaGroup",
|
@@ -19589,6 +19597,7 @@
|
|
19589
19597
|
"slice",
|
19590
19598
|
"slope",
|
19591
19599
|
"small",
|
19600
|
+
"smooth",
|
19592
19601
|
"smil",
|
19593
19602
|
"smoothingTimeConstant",
|
19594
19603
|
"snapToLines",
|
@@ -20255,7 +20264,7 @@
|
|
20255
20264
|
***********************************************************************/
|
20256
20265
|
|
20257
20266
|
function find_builtins(reserved) {
|
20258
|
-
|
20267
|
+
domprops.forEach(add);
|
20259
20268
|
|
20260
20269
|
// Compatibility fix for some standard defined globals not defined on every js environment
|
20261
20270
|
var new_globals = ["Symbol", "Map", "Promise", "Proxy", "Reflect", "Set", "WeakMap", "WeakSet"];
|
@@ -20293,7 +20302,7 @@
|
|
20293
20302
|
}
|
20294
20303
|
});
|
20295
20304
|
function add(name) {
|
20296
|
-
|
20305
|
+
reserved.add(name);
|
20297
20306
|
}
|
20298
20307
|
}
|
20299
20308
|
|
@@ -20338,8 +20347,9 @@
|
|
20338
20347
|
reserved: null,
|
20339
20348
|
}, true);
|
20340
20349
|
|
20341
|
-
var
|
20342
|
-
if (!Array.isArray(
|
20350
|
+
var reserved_option = options.reserved;
|
20351
|
+
if (!Array.isArray(reserved_option)) reserved_option = [reserved_option];
|
20352
|
+
var reserved = new Set(reserved_option);
|
20343
20353
|
if (!options.builtins) find_builtins(reserved);
|
20344
20354
|
|
20345
20355
|
var cname = -1;
|
@@ -20347,7 +20357,7 @@
|
|
20347
20357
|
if (options.cache) {
|
20348
20358
|
cache = options.cache.props;
|
20349
20359
|
cache.each(function(mangled_name) {
|
20350
|
-
|
20360
|
+
reserved.add(mangled_name);
|
20351
20361
|
});
|
20352
20362
|
} else {
|
20353
20363
|
cache = new Dictionary();
|
@@ -20364,8 +20374,8 @@
|
|
20364
20374
|
debug_name_suffix = (options.debug === true ? "" : options.debug);
|
20365
20375
|
}
|
20366
20376
|
|
20367
|
-
var names_to_mangle =
|
20368
|
-
var unmangleable =
|
20377
|
+
var names_to_mangle = new Set();
|
20378
|
+
var unmangleable = new Set();
|
20369
20379
|
|
20370
20380
|
// step 1: find candidates to mangle
|
20371
20381
|
ast.walk(new TreeWalker(function(node) {
|
@@ -20412,8 +20422,8 @@
|
|
20412
20422
|
// only function declarations after this line
|
20413
20423
|
|
20414
20424
|
function can_mangle(name) {
|
20415
|
-
if (unmangleable.
|
20416
|
-
if (reserved.
|
20425
|
+
if (unmangleable.has(name)) return false;
|
20426
|
+
if (reserved.has(name)) return false;
|
20417
20427
|
if (options.only_cache) {
|
20418
20428
|
return cache.has(name);
|
20419
20429
|
}
|
@@ -20423,17 +20433,17 @@
|
|
20423
20433
|
|
20424
20434
|
function should_mangle(name) {
|
20425
20435
|
if (regex && !regex.test(name)) return false;
|
20426
|
-
if (reserved.
|
20436
|
+
if (reserved.has(name)) return false;
|
20427
20437
|
return cache.has(name)
|
20428
|
-
|| names_to_mangle.
|
20438
|
+
|| names_to_mangle.has(name);
|
20429
20439
|
}
|
20430
20440
|
|
20431
20441
|
function add(name) {
|
20432
20442
|
if (can_mangle(name))
|
20433
|
-
|
20443
|
+
names_to_mangle.add(name);
|
20434
20444
|
|
20435
20445
|
if (!should_mangle(name)) {
|
20436
|
-
|
20446
|
+
unmangleable.add(name);
|
20437
20447
|
}
|
20438
20448
|
}
|
20439
20449
|
|
@@ -21144,7 +21154,7 @@
|
|
21144
21154
|
: p.type == "ExportSpecifier" ? (p.local === M ? AST_SymbolExport : AST_SymbolExportForeign)
|
21145
21155
|
: p.type == "FunctionExpression" ? (p.id === M ? AST_SymbolLambda : AST_SymbolFunarg)
|
21146
21156
|
: p.type == "FunctionDeclaration" ? (p.id === M ? AST_SymbolDefun : AST_SymbolFunarg)
|
21147
|
-
: p.type == "ArrowFunctionExpression" ? (p.params.
|
21157
|
+
: p.type == "ArrowFunctionExpression" ? (p.params.includes(M)) ? AST_SymbolFunarg : AST_SymbolRef
|
21148
21158
|
: p.type == "ClassExpression" ? (p.id === M ? AST_SymbolClass : AST_SymbolRef)
|
21149
21159
|
: p.type == "Property" ? (p.key === M && p.computed || p.value === M ? AST_SymbolRef : AST_SymbolMethod)
|
21150
21160
|
: p.type == "ClassDeclaration" ? (p.id === M ? AST_SymbolDefClass : AST_SymbolRef)
|