terser 5.13.0 → 5.13.1
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.
- package/CHANGELOG.md +5 -0
- package/dist/bundle.min.js +2645 -2531
- package/lib/ast.js +24 -0
- package/lib/compress/common.js +48 -0
- package/lib/compress/index.js +23 -546
- package/lib/compress/inline.js +641 -0
- package/lib/compress/tighten-body.js +1 -1
- package/lib/parse.js +58 -56
- package/lib/size.js +6 -8
- package/package.json +1 -1
package/lib/parse.js
CHANGED
@@ -1572,66 +1572,66 @@ function parse($TEXT, options) {
|
|
1572
1572
|
});
|
1573
1573
|
};
|
1574
1574
|
|
1575
|
-
|
1576
|
-
|
1577
|
-
|
1578
|
-
|
1579
|
-
|
1580
|
-
|
1581
|
-
|
1582
|
-
|
1583
|
-
|
1584
|
-
|
1585
|
-
|
1586
|
-
|
1587
|
-
|
1588
|
-
|
1589
|
-
|
1590
|
-
|
1591
|
-
|
1592
|
-
|
1593
|
-
|
1594
|
-
|
1595
|
-
|
1596
|
-
|
1597
|
-
|
1598
|
-
|
1599
|
-
|
1600
|
-
|
1601
|
-
|
1602
|
-
|
1575
|
+
class UsedParametersTracker {
|
1576
|
+
constructor(is_parameter, strict, duplicates_ok = false) {
|
1577
|
+
this.is_parameter = is_parameter;
|
1578
|
+
this.duplicates_ok = duplicates_ok;
|
1579
|
+
this.parameters = new Set();
|
1580
|
+
this.duplicate = null;
|
1581
|
+
this.default_assignment = false;
|
1582
|
+
this.spread = false;
|
1583
|
+
this.strict_mode = !!strict;
|
1584
|
+
}
|
1585
|
+
add_parameter(token) {
|
1586
|
+
if (this.parameters.has(token.value)) {
|
1587
|
+
if (this.duplicate === null) {
|
1588
|
+
this.duplicate = token;
|
1589
|
+
}
|
1590
|
+
this.check_strict();
|
1591
|
+
} else {
|
1592
|
+
this.parameters.add(token.value);
|
1593
|
+
if (this.is_parameter) {
|
1594
|
+
switch (token.value) {
|
1595
|
+
case "arguments":
|
1596
|
+
case "eval":
|
1597
|
+
case "yield":
|
1598
|
+
if (this.strict_mode) {
|
1599
|
+
token_error(token, "Unexpected " + token.value + " identifier as parameter inside strict mode");
|
1600
|
+
}
|
1601
|
+
break;
|
1602
|
+
default:
|
1603
|
+
if (RESERVED_WORDS.has(token.value)) {
|
1604
|
+
unexpected();
|
1603
1605
|
}
|
1604
1606
|
}
|
1605
1607
|
}
|
1606
|
-
},
|
1607
|
-
mark_default_assignment: function(token) {
|
1608
|
-
if (default_assignment === false) {
|
1609
|
-
default_assignment = token;
|
1610
|
-
}
|
1611
|
-
},
|
1612
|
-
mark_spread: function(token) {
|
1613
|
-
if (spread === false) {
|
1614
|
-
spread = token;
|
1615
|
-
}
|
1616
|
-
},
|
1617
|
-
mark_strict_mode: function() {
|
1618
|
-
strict_mode = true;
|
1619
|
-
},
|
1620
|
-
is_strict: function() {
|
1621
|
-
return default_assignment !== false || spread !== false || strict_mode;
|
1622
|
-
},
|
1623
|
-
check_strict: function() {
|
1624
|
-
if (tracker.is_strict() && duplicate !== false) {
|
1625
|
-
token_error(duplicate, "Parameter " + duplicate.value + " was used already");
|
1626
|
-
}
|
1627
1608
|
}
|
1628
|
-
}
|
1629
|
-
|
1630
|
-
|
1609
|
+
}
|
1610
|
+
mark_default_assignment(token) {
|
1611
|
+
if (this.default_assignment === false) {
|
1612
|
+
this.default_assignment = token;
|
1613
|
+
}
|
1614
|
+
}
|
1615
|
+
mark_spread(token) {
|
1616
|
+
if (this.spread === false) {
|
1617
|
+
this.spread = token;
|
1618
|
+
}
|
1619
|
+
}
|
1620
|
+
mark_strict_mode() {
|
1621
|
+
this.strict_mode = true;
|
1622
|
+
}
|
1623
|
+
is_strict() {
|
1624
|
+
return this.default_assignment !== false || this.spread !== false || this.strict_mode;
|
1625
|
+
}
|
1626
|
+
check_strict() {
|
1627
|
+
if (this.is_strict() && this.duplicate !== null && !this.duplicates_ok) {
|
1628
|
+
token_error(this.duplicate, "Parameter " + this.duplicate.value + " was used already");
|
1629
|
+
}
|
1630
|
+
}
|
1631
1631
|
}
|
1632
1632
|
|
1633
1633
|
function parameters(params) {
|
1634
|
-
var used_parameters =
|
1634
|
+
var used_parameters = new UsedParametersTracker(true, S.input.has_directive("use strict"));
|
1635
1635
|
|
1636
1636
|
expect("(");
|
1637
1637
|
|
@@ -1655,7 +1655,7 @@ function parse($TEXT, options) {
|
|
1655
1655
|
var param;
|
1656
1656
|
var expand = false;
|
1657
1657
|
if (used_parameters === undefined) {
|
1658
|
-
used_parameters =
|
1658
|
+
used_parameters = new UsedParametersTracker(true, S.input.has_directive("use strict"));
|
1659
1659
|
}
|
1660
1660
|
if (is("expand", "...")) {
|
1661
1661
|
expand = S.token;
|
@@ -1698,7 +1698,9 @@ function parse($TEXT, options) {
|
|
1698
1698
|
var expand_token;
|
1699
1699
|
var first_token = S.token;
|
1700
1700
|
if (used_parameters === undefined) {
|
1701
|
-
|
1701
|
+
const strict = S.input.has_directive("use strict");
|
1702
|
+
const duplicates_ok = symbol_type === AST_SymbolVar;
|
1703
|
+
used_parameters = new UsedParametersTracker(false, strict, duplicates_ok);
|
1702
1704
|
}
|
1703
1705
|
symbol_type = symbol_type === undefined ? AST_SymbolFunarg : symbol_type;
|
1704
1706
|
if (is("punc", "[")) {
|
@@ -2091,7 +2093,7 @@ function parse($TEXT, options) {
|
|
2091
2093
|
if (is("punc", "{") || is("punc", "[")) {
|
2092
2094
|
def = new AST_VarDef({
|
2093
2095
|
start: S.token,
|
2094
|
-
name: binding_element(undefined
|
2096
|
+
name: binding_element(undefined, sym_type),
|
2095
2097
|
value: is("operator", "=") ? (expect_token("operator", "="), expression(false, no_in)) : null,
|
2096
2098
|
end: prev()
|
2097
2099
|
});
|
package/lib/size.js
CHANGED
@@ -115,6 +115,7 @@ AST_Directive.prototype._size = function () {
|
|
115
115
|
return 2 + this.value.length;
|
116
116
|
};
|
117
117
|
|
118
|
+
/** Count commas/semicolons necessary to show a list of expressions/statements */
|
118
119
|
const list_overhead = (array) => array.length && array.length - 1;
|
119
120
|
|
120
121
|
AST_Block.prototype._size = function () {
|
@@ -167,7 +168,7 @@ AST_Arrow.prototype._size = function () {
|
|
167
168
|
&& this.argnames[0] instanceof AST_Symbol
|
168
169
|
)
|
169
170
|
) {
|
170
|
-
args_and_arrow += 2;
|
171
|
+
args_and_arrow += 2; // parens around the args
|
171
172
|
}
|
172
173
|
|
173
174
|
const body_overhead = this.is_braceless() ? 0 : list_overhead(this.body) + 2;
|
@@ -229,19 +230,16 @@ AST_Finally.prototype._size = function () {
|
|
229
230
|
return 7 + list_overhead(this.body);
|
230
231
|
};
|
231
232
|
|
232
|
-
/*#__INLINE__*/
|
233
|
-
const def_size = (size, def) => size + list_overhead(def.definitions);
|
234
|
-
|
235
233
|
AST_Var.prototype._size = function () {
|
236
|
-
return
|
234
|
+
return 4 + list_overhead(this.definitions);
|
237
235
|
};
|
238
236
|
|
239
237
|
AST_Let.prototype._size = function () {
|
240
|
-
return
|
238
|
+
return 4 + list_overhead(this.definitions);
|
241
239
|
};
|
242
240
|
|
243
241
|
AST_Const.prototype._size = function () {
|
244
|
-
return
|
242
|
+
return 6 + list_overhead(this.definitions);
|
245
243
|
};
|
246
244
|
|
247
245
|
AST_VarDef.prototype._size = function () {
|
@@ -477,7 +475,7 @@ AST_NaN.prototype._size = () => 3;
|
|
477
475
|
|
478
476
|
AST_Undefined.prototype._size = () => 6; // "void 0"
|
479
477
|
|
480
|
-
AST_Hole.prototype._size = () => 0; // comma is taken into account
|
478
|
+
AST_Hole.prototype._size = () => 0; // comma is taken into account by list_overhead()
|
481
479
|
|
482
480
|
AST_Infinity.prototype._size = () => 8;
|
483
481
|
|