terser 5.6.0 → 5.6.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 CHANGED
@@ -1,5 +1,21 @@
1
1
  # Changelog
2
2
 
3
+ ## v5.6.1
4
+
5
+ - Mark assignments to the `.prototype` of a class as pure
6
+ - Parenthesize `await` on the left of `**` (while accepting legacy non-parenthesised input)
7
+ - Avoided outputting NUL bytes in optimized RegExps, to stop the output from breaking other tools
8
+ - Added `exports` to domprops (#939)
9
+ - Fixed a crash when spreading `...this`
10
+ - Fixed the computed size of arrow functions, which improves their inlining
11
+
12
+ ## v5.6.0
13
+
14
+ - Added top-level await
15
+ - Beautify option has been removed in #895
16
+ - Private properties, getters and setters have been added in #913 and some more commits
17
+ - Docs improvements: #896, #903, #916
18
+
3
19
  ## v5.5.1
4
20
 
5
21
  - Fixed object properties with unicode surrogates on safari.
@@ -243,6 +243,7 @@ function keep_name(keep_setting, name) {
243
243
  }
244
244
 
245
245
  var lineTerminatorEscape = {
246
+ "\0": "0",
246
247
  "\n": "n",
247
248
  "\r": "r",
248
249
  "\u2028": "u2028",
@@ -250,7 +251,8 @@ var lineTerminatorEscape = {
250
251
  };
251
252
  function regexp_source_fix(source) {
252
253
  // V8 does not escape line terminators in regexp patterns in node 12
253
- return source.replace(/[\n\r\u2028\u2029]/g, function (match, offset) {
254
+ // We'll also remove literal \0
255
+ return source.replace(/[\0\n\r\u2028\u2029]/g, function (match, offset) {
254
256
  var escaped = source[offset - 1] == "\\"
255
257
  && (source[offset - 2] != "\\"
256
258
  || /(?:^|[^\\])(?:\\{2})*$/.test(source.slice(0, offset - 1)));
@@ -4014,6 +4016,9 @@ var AST_Lambda = DEFNODE("Lambda", "name argnames uses_arguments is_generator as
4014
4016
 
4015
4017
  if (this.name) push(this.name);
4016
4018
  },
4019
+ is_braceless() {
4020
+ return this.body[0] instanceof AST_Return && this.body[0].value;
4021
+ }
4017
4022
  }, AST_Scope);
4018
4023
 
4019
4024
  var AST_Accessor = DEFNODE("Accessor", null, {
@@ -7671,6 +7676,7 @@ function OutputStream(options) {
7671
7676
  var p = output.parent();
7672
7677
  return p instanceof AST_PropAccess && p.expression === this
7673
7678
  || p instanceof AST_Call && p.expression === this
7679
+ || p instanceof AST_Binary && p.operator === "**" && p.left === this
7674
7680
  || output.option("safari10") && p instanceof AST_UnaryPrefix;
7675
7681
  });
7676
7682
 
@@ -8888,7 +8894,9 @@ function OutputStream(options) {
8888
8894
  source = regexp_source_fix(source);
8889
8895
  flags = flags ? sort_regexp_flags(flags) : "";
8890
8896
  source = source.replace(r_slash_script, slash_script_replace);
8897
+
8891
8898
  output.print(output.to_utf8(`/${source}/${flags}`));
8899
+
8892
8900
  const parent = output.parent();
8893
8901
  if (
8894
8902
  parent instanceof AST_Binary
@@ -10184,6 +10192,12 @@ AST_Node.prototype.size = function (compressor, stack) {
10184
10192
  let size = 0;
10185
10193
  walk_parent(this, (node, info) => {
10186
10194
  size += node._size(info);
10195
+
10196
+ // Braceless arrow functions have fake "return" statements
10197
+ if (node instanceof AST_Arrow && node.is_braceless()) {
10198
+ size += node.body[0].value._size(info);
10199
+ return true;
10200
+ }
10187
10201
  }, stack || (compressor && compressor.stack));
10188
10202
 
10189
10203
  // just to save a bit of memory
@@ -10228,7 +10242,6 @@ AST_With.prototype._size = () => 6;
10228
10242
 
10229
10243
  AST_Expansion.prototype._size = () => 3;
10230
10244
 
10231
- /*#__INLINE__*/
10232
10245
  const lambda_modifiers = func =>
10233
10246
  (func.is_generator ? 1 : 0) + (func.async ? 6 : 0);
10234
10247
 
@@ -10257,7 +10270,9 @@ AST_Arrow.prototype._size = function () {
10257
10270
  args_and_arrow += 2;
10258
10271
  }
10259
10272
 
10260
- return lambda_modifiers(this) + args_and_arrow + (Array.isArray(this.body) ? list_overhead(this.body) : this.body._size());
10273
+ const body_overhead = this.is_braceless() ? 0 : list_overhead(this.body) + 2;
10274
+
10275
+ return lambda_modifiers(this) + args_and_arrow + body_overhead;
10261
10276
  };
10262
10277
 
10263
10278
  AST_Destructuring.prototype._size = () => 2;
@@ -11839,8 +11854,11 @@ function tighten_body(statements, compressor) {
11839
11854
  || node instanceof AST_Debugger
11840
11855
  || node instanceof AST_Destructuring
11841
11856
  || node instanceof AST_Expansion
11842
- && node.expression instanceof AST_Symbol
11843
- && node.expression.definition().references.length > 1
11857
+ && node.expression instanceof AST_Symbol
11858
+ && (
11859
+ node.expression instanceof AST_This
11860
+ || node.expression.definition().references.length > 1
11861
+ )
11844
11862
  || node instanceof AST_IterationStatement && !(node instanceof AST_For)
11845
11863
  || node instanceof AST_LoopControl
11846
11864
  || node instanceof AST_Try
@@ -13009,7 +13027,13 @@ function is_undefined(node, compressor) {
13009
13027
  });
13010
13028
  def_may_throw_on_access(AST_Dot, function(compressor) {
13011
13029
  if (!is_strict(compressor)) return false;
13012
- if (this.expression instanceof AST_Function && this.property == "prototype") return false;
13030
+
13031
+ if (this.property == "prototype") {
13032
+ return !(
13033
+ this.expression instanceof AST_Function
13034
+ || this.expression instanceof AST_Class
13035
+ );
13036
+ }
13013
13037
  return true;
13014
13038
  });
13015
13039
  def_may_throw_on_access(AST_Chain, function(compressor) {
@@ -22374,6 +22398,7 @@ var domprops = [
22374
22398
  "exponent",
22375
22399
  "exponentialRampToValueAtTime",
22376
22400
  "exportKey",
22401
+ "exports",
22377
22402
  "extend",
22378
22403
  "extensions",
22379
22404
  "extentNode",
package/lib/ast.js CHANGED
@@ -522,6 +522,9 @@ var AST_Lambda = DEFNODE("Lambda", "name argnames uses_arguments is_generator as
522
522
 
523
523
  if (this.name) push(this.name);
524
524
  },
525
+ is_braceless() {
526
+ return this.body[0] instanceof AST_Return && this.body[0].value;
527
+ }
525
528
  }, AST_Scope);
526
529
 
527
530
  var AST_Accessor = DEFNODE("Accessor", null, {
@@ -1416,8 +1416,11 @@ function tighten_body(statements, compressor) {
1416
1416
  || node instanceof AST_Debugger
1417
1417
  || node instanceof AST_Destructuring
1418
1418
  || node instanceof AST_Expansion
1419
- && node.expression instanceof AST_Symbol
1420
- && node.expression.definition().references.length > 1
1419
+ && node.expression instanceof AST_Symbol
1420
+ && (
1421
+ node.expression instanceof AST_This
1422
+ || node.expression.definition().references.length > 1
1423
+ )
1421
1424
  || node instanceof AST_IterationStatement && !(node instanceof AST_For)
1422
1425
  || node instanceof AST_LoopControl
1423
1426
  || node instanceof AST_Try
@@ -2586,7 +2589,13 @@ function is_undefined(node, compressor) {
2586
2589
  });
2587
2590
  def_may_throw_on_access(AST_Dot, function(compressor) {
2588
2591
  if (!is_strict(compressor)) return false;
2589
- if (this.expression instanceof AST_Function && this.property == "prototype") return false;
2592
+
2593
+ if (this.property == "prototype") {
2594
+ return !(
2595
+ this.expression instanceof AST_Function
2596
+ || this.expression instanceof AST_Class
2597
+ );
2598
+ }
2590
2599
  return true;
2591
2600
  });
2592
2601
  def_may_throw_on_access(AST_Chain, function(compressor) {
package/lib/output.js CHANGED
@@ -933,6 +933,7 @@ function OutputStream(options) {
933
933
  var p = output.parent();
934
934
  return p instanceof AST_PropAccess && p.expression === this
935
935
  || p instanceof AST_Call && p.expression === this
936
+ || p instanceof AST_Binary && p.operator === "**" && p.left === this
936
937
  || output.option("safari10") && p instanceof AST_UnaryPrefix;
937
938
  });
938
939
 
@@ -2150,7 +2151,9 @@ function OutputStream(options) {
2150
2151
  source = regexp_source_fix(source);
2151
2152
  flags = flags ? sort_regexp_flags(flags) : "";
2152
2153
  source = source.replace(r_slash_script, slash_script_replace);
2154
+
2153
2155
  output.print(output.to_utf8(`/${source}/${flags}`));
2156
+
2154
2157
  const parent = output.parent();
2155
2158
  if (
2156
2159
  parent instanceof AST_Binary
package/lib/size.js CHANGED
@@ -92,6 +92,12 @@ AST_Node.prototype.size = function (compressor, stack) {
92
92
  let size = 0;
93
93
  walk_parent(this, (node, info) => {
94
94
  size += node._size(info);
95
+
96
+ // Braceless arrow functions have fake "return" statements
97
+ if (node instanceof AST_Arrow && node.is_braceless()) {
98
+ size += node.body[0].value._size(info);
99
+ return true;
100
+ }
95
101
  }, stack || (compressor && compressor.stack));
96
102
 
97
103
  // just to save a bit of memory
@@ -136,7 +142,6 @@ AST_With.prototype._size = () => 6;
136
142
 
137
143
  AST_Expansion.prototype._size = () => 3;
138
144
 
139
- /*#__INLINE__*/
140
145
  const lambda_modifiers = func =>
141
146
  (func.is_generator ? 1 : 0) + (func.async ? 6 : 0);
142
147
 
@@ -165,7 +170,9 @@ AST_Arrow.prototype._size = function () {
165
170
  args_and_arrow += 2;
166
171
  }
167
172
 
168
- return lambda_modifiers(this) + args_and_arrow + (Array.isArray(this.body) ? list_overhead(this.body) : this.body._size());
173
+ const body_overhead = this.is_braceless() ? 0 : list_overhead(this.body) + 2;
174
+
175
+ return lambda_modifiers(this) + args_and_arrow + body_overhead;
169
176
  };
170
177
 
171
178
  AST_Destructuring.prototype._size = () => 2;
@@ -235,6 +235,7 @@ function keep_name(keep_setting, name) {
235
235
  }
236
236
 
237
237
  var lineTerminatorEscape = {
238
+ "\0": "0",
238
239
  "\n": "n",
239
240
  "\r": "r",
240
241
  "\u2028": "u2028",
@@ -242,7 +243,8 @@ var lineTerminatorEscape = {
242
243
  };
243
244
  function regexp_source_fix(source) {
244
245
  // V8 does not escape line terminators in regexp patterns in node 12
245
- return source.replace(/[\n\r\u2028\u2029]/g, function (match, offset) {
246
+ // We'll also remove literal \0
247
+ return source.replace(/[\0\n\r\u2028\u2029]/g, function (match, offset) {
246
248
  var escaped = source[offset - 1] == "\\"
247
249
  && (source[offset - 2] != "\\"
248
250
  || /(?:^|[^\\])(?:\\{2})*$/.test(source.slice(0, offset - 1)));
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "homepage": "https://terser.org",
5
5
  "author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)",
6
6
  "license": "BSD-2-Clause",
7
- "version": "5.6.0",
7
+ "version": "5.6.1",
8
8
  "engines": {
9
9
  "node": ">=10"
10
10
  },
package/tools/domprops.js CHANGED
@@ -4120,6 +4120,7 @@ export var domprops = [
4120
4120
  "exponent",
4121
4121
  "exponentialRampToValueAtTime",
4122
4122
  "exportKey",
4123
+ "exports",
4123
4124
  "extend",
4124
4125
  "extensions",
4125
4126
  "extentNode",