terser 5.6.0-beta → 5.7.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/lib/parse.js CHANGED
@@ -102,7 +102,6 @@ import {
102
102
  AST_Label,
103
103
  AST_LabeledStatement,
104
104
  AST_LabelRef,
105
- AST_Lambda,
106
105
  AST_Let,
107
106
  AST_NameMapping,
108
107
  AST_New,
@@ -1293,7 +1292,7 @@ function parse($TEXT, options) {
1293
1292
  if (is_if_body) {
1294
1293
  croak("classes are not allowed as the body of an if");
1295
1294
  }
1296
- return class_(AST_DefClass);
1295
+ return class_(AST_DefClass, is_export_default);
1297
1296
 
1298
1297
  case "function":
1299
1298
  next();
@@ -2488,7 +2487,7 @@ function parse($TEXT, options) {
2488
2487
  return new AST_Object({ properties: a });
2489
2488
  });
2490
2489
 
2491
- function class_(KindOfClass) {
2490
+ function class_(KindOfClass, is_export_default) {
2492
2491
  var start, method, class_name, extends_, a = [];
2493
2492
 
2494
2493
  S.input.push_directives_stack(); // Push directive stack, but not scope stack
@@ -2499,7 +2498,11 @@ function parse($TEXT, options) {
2499
2498
  }
2500
2499
 
2501
2500
  if (KindOfClass === AST_DefClass && !class_name) {
2502
- unexpected();
2501
+ if (is_export_default) {
2502
+ KindOfClass = AST_ClassExpression;
2503
+ } else {
2504
+ unexpected();
2505
+ }
2503
2506
  }
2504
2507
 
2505
2508
  if (S.token.value == "extends") {
@@ -2532,9 +2535,9 @@ function parse($TEXT, options) {
2532
2535
  }
2533
2536
 
2534
2537
  function concise_method_or_getset(name, start, is_class) {
2535
- var get_method_name_ast = function(name, start) {
2538
+ const get_symbol_ast = (name, SymbolClass = AST_SymbolMethod) => {
2536
2539
  if (typeof name === "string" || typeof name === "number") {
2537
- return new AST_SymbolMethod({
2540
+ return new SymbolClass({
2538
2541
  start,
2539
2542
  name: "" + name,
2540
2543
  end: prev()
@@ -2544,47 +2547,71 @@ function parse($TEXT, options) {
2544
2547
  }
2545
2548
  return name;
2546
2549
  };
2547
- const get_class_property_key_ast = (name) => {
2548
- if (typeof name === "string" || typeof name === "number") {
2549
- return new AST_SymbolClassProperty({
2550
- start: property_token,
2551
- end: property_token,
2552
- name: "" + name
2553
- });
2554
- } else if (name === null) {
2555
- unexpected();
2556
- }
2557
- return name;
2558
- };
2559
- var privatename = start.type == "privatename";
2550
+
2551
+ const is_not_method_start = () =>
2552
+ !is("punc", "(") && !is("punc", ",") && !is("punc", "}") && !is("operator", "=");
2553
+
2560
2554
  var is_async = false;
2561
2555
  var is_static = false;
2562
2556
  var is_generator = false;
2563
- var property_token = start;
2564
- if (is_class && name === "static" && !is("punc", "(")) {
2557
+ var is_private = false;
2558
+ var accessor_type = null;
2559
+
2560
+ if (is_class && name === "static" && is_not_method_start()) {
2565
2561
  is_static = true;
2566
- property_token = S.token;
2567
- privatename = property_token.type == "privatename";
2568
2562
  name = as_property_name();
2569
2563
  }
2570
- if (name === "async" && !is("punc", "(") && !is("punc", ",") && !is("punc", "}") && !is("operator", "=")) {
2564
+ if (name === "async" && is_not_method_start()) {
2571
2565
  is_async = true;
2572
- property_token = S.token;
2573
- privatename = property_token.type == "privatename";
2574
2566
  name = as_property_name();
2575
2567
  }
2576
- if (name === null) {
2568
+ if (prev().type === "operator" && prev().value === "*") {
2577
2569
  is_generator = true;
2578
- property_token = S.token;
2579
- privatename = property_token.type == "privatename";
2580
2570
  name = as_property_name();
2581
- if (name === null) {
2582
- unexpected();
2571
+ }
2572
+ if ((name === "get" || name === "set") && is_not_method_start()) {
2573
+ accessor_type = name;
2574
+ name = as_property_name();
2575
+ }
2576
+ if (prev().type === "privatename") {
2577
+ is_private = true;
2578
+ }
2579
+
2580
+ const property_token = prev();
2581
+
2582
+ if (accessor_type != null) {
2583
+ if (!is_private) {
2584
+ const AccessorClass = accessor_type === "get"
2585
+ ? AST_ObjectGetter
2586
+ : AST_ObjectSetter;
2587
+
2588
+ name = get_symbol_ast(name);
2589
+ return new AccessorClass({
2590
+ start,
2591
+ static: is_static,
2592
+ key: name,
2593
+ quote: name instanceof AST_SymbolMethod ? property_token.quote : undefined,
2594
+ value: create_accessor(),
2595
+ end: prev()
2596
+ });
2597
+ } else {
2598
+ const AccessorClass = accessor_type === "get"
2599
+ ? AST_PrivateGetter
2600
+ : AST_PrivateSetter;
2601
+
2602
+ return new AccessorClass({
2603
+ start,
2604
+ static: is_static,
2605
+ key: get_symbol_ast(name),
2606
+ value: create_accessor(),
2607
+ end: prev(),
2608
+ });
2583
2609
  }
2584
2610
  }
2611
+
2585
2612
  if (is("punc", "(")) {
2586
- name = get_method_name_ast(name, start);
2587
- const AST_MethodVariant = privatename
2613
+ name = get_symbol_ast(name);
2614
+ const AST_MethodVariant = is_private
2588
2615
  ? AST_PrivateMethod
2589
2616
  : AST_ConciseMethod;
2590
2617
  var node = new AST_MethodVariant({
@@ -2600,57 +2627,13 @@ function parse($TEXT, options) {
2600
2627
  });
2601
2628
  return node;
2602
2629
  }
2603
- const setter_token = S.token;
2604
- if ((name === "get" || name === "set") && setter_token.type === "privatename") {
2605
- next();
2606
-
2607
- const AST_AccessorVariant =
2608
- name === "get"
2609
- ? AST_PrivateGetter
2610
- : AST_PrivateSetter;
2611
-
2612
- return new AST_AccessorVariant({
2613
- start,
2614
- static: is_static,
2615
- key: get_method_name_ast(setter_token.value, start),
2616
- value: create_accessor(),
2617
- end: prev(),
2618
- });
2619
- }
2620
2630
 
2621
- if (name == "get") {
2622
- if (!is("punc") || is("punc", "[")) {
2623
- name = get_method_name_ast(as_property_name(), start);
2624
- return new AST_ObjectGetter({
2625
- start : start,
2626
- static: is_static,
2627
- key : name,
2628
- quote : name instanceof AST_SymbolMethod ?
2629
- setter_token.quote : undefined,
2630
- value : create_accessor(),
2631
- end : prev()
2632
- });
2633
- }
2634
- } else if (name == "set") {
2635
- if (!is("punc") || is("punc", "[")) {
2636
- name = get_method_name_ast(as_property_name(), start);
2637
- return new AST_ObjectSetter({
2638
- start : start,
2639
- static: is_static,
2640
- key : name,
2641
- quote : name instanceof AST_SymbolMethod ?
2642
- setter_token.quote : undefined,
2643
- value : create_accessor(),
2644
- end : prev()
2645
- });
2646
- }
2647
- }
2648
2631
  if (is_class) {
2649
- const key = get_class_property_key_ast(name, property_token);
2632
+ const key = get_symbol_ast(name, AST_SymbolClassProperty);
2650
2633
  const quote = key instanceof AST_SymbolClassProperty
2651
2634
  ? property_token.quote
2652
2635
  : undefined;
2653
- const AST_ClassPropertyVariant = privatename
2636
+ const AST_ClassPropertyVariant = is_private
2654
2637
  ? AST_ClassPrivateProperty
2655
2638
  : AST_ClassProperty;
2656
2639
  if (is("operator", "=")) {
@@ -2872,8 +2855,17 @@ function parse($TEXT, options) {
2872
2855
  semicolon();
2873
2856
  } else if ((node = statement(is_default)) instanceof AST_Definitions && is_default) {
2874
2857
  unexpected(node.start);
2875
- } else if (node instanceof AST_Definitions || node instanceof AST_Lambda || node instanceof AST_DefClass) {
2858
+ } else if (
2859
+ node instanceof AST_Definitions
2860
+ || node instanceof AST_Defun
2861
+ || node instanceof AST_DefClass
2862
+ ) {
2876
2863
  exported_definition = node;
2864
+ } else if (
2865
+ node instanceof AST_ClassExpression
2866
+ || node instanceof AST_Function
2867
+ ) {
2868
+ exported_value = node;
2877
2869
  } else if (node instanceof AST_SimpleStatement) {
2878
2870
  exported_value = node.body;
2879
2871
  } else {
package/lib/scope.js CHANGED
@@ -299,7 +299,14 @@ AST_Scope.DEFMETHOD("figure_out_scope", function(options, { parent_scope = null,
299
299
  // scope when we encounter the AST_Defun node (which is
300
300
  // instanceof AST_Scope) but we get to the symbol a bit
301
301
  // later.
302
- mark_export((node.scope = defun.parent_scope.get_defun_scope()).def_function(node, defun), 1);
302
+ const closest_scope = defun.parent_scope;
303
+
304
+ // In strict mode, function definitions are block-scoped
305
+ node.scope = tw.directives["use strict"]
306
+ ? closest_scope
307
+ : closest_scope.get_defun_scope();
308
+
309
+ mark_export(node.scope.def_function(node, defun), 1);
303
310
  } else if (node instanceof AST_SymbolClass) {
304
311
  mark_export(defun.def_variable(node, defun), 1);
305
312
  } else if (node instanceof AST_SymbolImport) {
@@ -478,7 +485,6 @@ AST_Toplevel.DEFMETHOD("def_global", function(node) {
478
485
 
479
486
  AST_Scope.DEFMETHOD("init_scope_vars", function(parent_scope) {
480
487
  this.variables = new Map(); // map name to AST_SymbolVar (variables defined in this scope; includes functions)
481
- this.functions = new Map(); // map name to AST_SymbolDefun (functions defined in this scope)
482
488
  this.uses_with = false; // will be set to true if this or some nested scope uses the `with` statement
483
489
  this.uses_eval = false; // will be set to true if this or nested scope uses the global `eval`
484
490
  this.parent_scope = parent_scope; // the parent scope
@@ -641,7 +647,6 @@ AST_Scope.DEFMETHOD("find_variable", function(name) {
641
647
  AST_Scope.DEFMETHOD("def_function", function(symbol, init) {
642
648
  var def = this.def_variable(symbol, init);
643
649
  if (!def.init || def.init instanceof AST_Defun) def.init = init;
644
- this.functions.set(symbol.name, def);
645
650
  return def;
646
651
  });
647
652
 
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;
@@ -64,10 +64,8 @@ class DefaultsError extends Error {
64
64
  function defaults(args, defs, croak) {
65
65
  if (args === true) {
66
66
  args = {};
67
- }
68
-
69
- if (args != null && typeof args === "object") {
70
- args = Object.assign({}, args);
67
+ } else if (args != null && typeof args === "object") {
68
+ args = {...args};
71
69
  }
72
70
 
73
71
  const ret = args || {};
@@ -196,7 +194,7 @@ function mergeSort(array, cmp) {
196
194
  function makePredicate(words) {
197
195
  if (!Array.isArray(words)) words = words.split(" ");
198
196
 
199
- return new Set(words);
197
+ return new Set(words.sort());
200
198
  }
201
199
 
202
200
  function map_add(map, key, value) {
@@ -235,6 +233,7 @@ function keep_name(keep_setting, name) {
235
233
  }
236
234
 
237
235
  var lineTerminatorEscape = {
236
+ "\0": "0",
238
237
  "\n": "n",
239
238
  "\r": "r",
240
239
  "\u2028": "u2028",
@@ -242,7 +241,8 @@ var lineTerminatorEscape = {
242
241
  };
243
242
  function regexp_source_fix(source) {
244
243
  // V8 does not escape line terminators in regexp patterns in node 12
245
- return source.replace(/[\n\r\u2028\u2029]/g, function (match, offset) {
244
+ // We'll also remove literal \0
245
+ return source.replace(/[\0\n\r\u2028\u2029]/g, function (match, offset) {
246
246
  var escaped = source[offset - 1] == "\\"
247
247
  && (source[offset - 2] != "\\"
248
248
  || /(?:^|[^\\])(?:\\{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-beta",
7
+ "version": "5.7.1",
8
8
  "engines": {
9
9
  "node": ">=10"
10
10
  },
@@ -24,7 +24,8 @@
24
24
  "./dist/bundle.min.js"
25
25
  ],
26
26
  "./package": "./package.json",
27
- "./package.json": "./package.json"
27
+ "./package.json": "./package.json",
28
+ "./bin/terser": "./bin/terser"
28
29
  },
29
30
  "types": "tools/terser.d.ts",
30
31
  "bin": {
@@ -124,7 +125,7 @@
124
125
  "no-unused-vars": [
125
126
  "error",
126
127
  {
127
- "varsIgnorePattern": "^_$"
128
+ "varsIgnorePattern": "^_"
128
129
  }
129
130
  ],
130
131
  "no-tabs": "error",
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",