terser 5.0.0-beta.2 → 5.2.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.
@@ -59,6 +59,7 @@ import {
59
59
  AST_Call,
60
60
  AST_Case,
61
61
  AST_Catch,
62
+ AST_Chain,
62
63
  AST_Class,
63
64
  AST_ClassExpression,
64
65
  AST_ClassProperty,
@@ -89,6 +90,7 @@ import {
89
90
  AST_Hole,
90
91
  AST_If,
91
92
  AST_Import,
93
+ AST_ImportMeta,
92
94
  AST_Label,
93
95
  AST_LabeledStatement,
94
96
  AST_LabelRef,
@@ -418,7 +420,15 @@ import {
418
420
  start : my_start_token(M),
419
421
  end : my_end_token(M),
420
422
  property : M.computed ? from_moz(M.property) : M.property.name,
421
- expression : from_moz(M.object)
423
+ expression : from_moz(M.object),
424
+ optional : M.optional || false
425
+ });
426
+ },
427
+ ChainExpression: function(M) {
428
+ return new AST_Chain({
429
+ start : my_start_token(M),
430
+ end : my_end_token(M),
431
+ expression : from_moz(M.expression)
422
432
  });
423
433
  },
424
434
  SwitchCase: function(M) {
@@ -545,6 +555,11 @@ import {
545
555
  start: my_start_token(M),
546
556
  end: my_end_token(M)
547
557
  });
558
+ } else if (M.meta.name === "import" && M.property.name === "meta") {
559
+ return new AST_ImportMeta({
560
+ start: my_start_token(M),
561
+ end: my_end_token(M)
562
+ });
548
563
  }
549
564
  },
550
565
  Identifier: function(M) {
@@ -629,7 +644,7 @@ import {
629
644
  map("AssignmentExpression", AST_Assign, "operator=operator, left>left, right>right");
630
645
  map("ConditionalExpression", AST_Conditional, "test>condition, consequent>consequent, alternate>alternative");
631
646
  map("NewExpression", AST_New, "callee>expression, arguments@args");
632
- map("CallExpression", AST_Call, "callee>expression, arguments@args");
647
+ map("CallExpression", AST_Call, "callee>expression, optional=optional, arguments@args");
633
648
 
634
649
  def_to_moz(AST_Toplevel, function To_Moz_Program(M) {
635
650
  return to_moz_scope("Program", M);
@@ -836,6 +851,20 @@ import {
836
851
  };
837
852
  });
838
853
 
854
+ def_to_moz(AST_ImportMeta, function To_Moz_MetaProperty() {
855
+ return {
856
+ type: "MetaProperty",
857
+ meta: {
858
+ type: "Identifier",
859
+ name: "import"
860
+ },
861
+ property: {
862
+ type: "Identifier",
863
+ name: "meta"
864
+ }
865
+ };
866
+ });
867
+
839
868
  def_to_moz(AST_Sequence, function To_Moz_SequenceExpression(M) {
840
869
  return {
841
870
  type: "SequenceExpression",
@@ -849,7 +878,15 @@ import {
849
878
  type: "MemberExpression",
850
879
  object: to_moz(M.expression),
851
880
  computed: isComputed,
852
- property: isComputed ? to_moz(M.property) : {type: "Identifier", name: M.property}
881
+ property: isComputed ? to_moz(M.property) : {type: "Identifier", name: M.property},
882
+ optional: M.optional
883
+ };
884
+ });
885
+
886
+ def_to_moz(AST_Chain, function To_Moz_ChainExpression(M) {
887
+ return {
888
+ type: "ChainExpression",
889
+ expression: to_moz(M.expression)
853
890
  };
854
891
  });
855
892
 
package/lib/output.js CHANGED
@@ -65,6 +65,7 @@ import {
65
65
  AST_Call,
66
66
  AST_Case,
67
67
  AST_Catch,
68
+ AST_Chain,
68
69
  AST_Class,
69
70
  AST_ClassExpression,
70
71
  AST_ClassProperty,
@@ -94,6 +95,7 @@ import {
94
95
  AST_Hole,
95
96
  AST_If,
96
97
  AST_Import,
98
+ AST_ImportMeta,
97
99
  AST_Jump,
98
100
  AST_LabeledStatement,
99
101
  AST_Lambda,
@@ -894,8 +896,8 @@ function OutputStream(options) {
894
896
  return p instanceof AST_PropAccess && p.expression === this;
895
897
  });
896
898
 
897
- // same goes for an object literal, because otherwise it would be
898
- // interpreted as a block of code.
899
+ // same goes for an object literal (as in AST_Function), because
900
+ // otherwise {...} would be interpreted as a block of code.
899
901
  PARENS(AST_Object, function(output) {
900
902
  return !output.has_parens() && first_in_statement(output);
901
903
  });
@@ -1411,6 +1413,8 @@ function OutputStream(options) {
1411
1413
  || e instanceof AST_PropAccess
1412
1414
  || e instanceof AST_Unary
1413
1415
  || e instanceof AST_Constant
1416
+ || e instanceof AST_Await
1417
+ || e instanceof AST_Object
1414
1418
  );
1415
1419
  if (parens) output.print("(");
1416
1420
  self.expression.print(output);
@@ -1608,6 +1612,9 @@ function OutputStream(options) {
1608
1612
  self.module_name.print(output);
1609
1613
  output.semicolon();
1610
1614
  });
1615
+ DEFPRINT(AST_ImportMeta, function(self, output) {
1616
+ output.print("import.meta");
1617
+ });
1611
1618
 
1612
1619
  DEFPRINT(AST_NameMapping, function(self, output) {
1613
1620
  var is_import = output.parent() instanceof AST_Import;
@@ -1714,6 +1721,7 @@ function OutputStream(options) {
1714
1721
  if (self.expression instanceof AST_Call || self.expression instanceof AST_Lambda) {
1715
1722
  output.add_mapping(self.start);
1716
1723
  }
1724
+ if (self.optional) output.print("?.");
1717
1725
  output.with_parens(function() {
1718
1726
  self.args.forEach(function(expr, i) {
1719
1727
  if (i) output.comma();
@@ -1757,6 +1765,9 @@ function OutputStream(options) {
1757
1765
  var print_computed = RESERVED_WORDS.has(prop)
1758
1766
  ? output.option("ie8")
1759
1767
  : !is_identifier_string(prop, output.option("ecma") >= 2015);
1768
+
1769
+ if (self.optional) output.print("?.");
1770
+
1760
1771
  if (print_computed) {
1761
1772
  output.print("[");
1762
1773
  output.add_mapping(self.end);
@@ -1768,7 +1779,7 @@ function OutputStream(options) {
1768
1779
  output.print(".");
1769
1780
  }
1770
1781
  }
1771
- output.print(".");
1782
+ if (!self.optional) output.print(".");
1772
1783
  // the name after dot would be mapped about here.
1773
1784
  output.add_mapping(self.end);
1774
1785
  output.print_name(prop);
@@ -1776,10 +1787,14 @@ function OutputStream(options) {
1776
1787
  });
1777
1788
  DEFPRINT(AST_Sub, function(self, output) {
1778
1789
  self.expression.print(output);
1790
+ if (self.optional) output.print("?.");
1779
1791
  output.print("[");
1780
1792
  self.property.print(output);
1781
1793
  output.print("]");
1782
1794
  });
1795
+ DEFPRINT(AST_Chain, function(self, output) {
1796
+ self.expression.print(output);
1797
+ });
1783
1798
  DEFPRINT(AST_UnaryPrefix, function(self, output) {
1784
1799
  var op = self.operator;
1785
1800
  output.print(op);
package/lib/parse.js CHANGED
@@ -63,6 +63,7 @@ import {
63
63
  AST_Call,
64
64
  AST_Case,
65
65
  AST_Catch,
66
+ AST_Chain,
66
67
  AST_ClassExpression,
67
68
  AST_ClassProperty,
68
69
  AST_ConciseMethod,
@@ -91,6 +92,7 @@ import {
91
92
  AST_Hole,
92
93
  AST_If,
93
94
  AST_Import,
95
+ AST_ImportMeta,
94
96
  AST_IterationStatement,
95
97
  AST_Label,
96
98
  AST_LabeledStatement,
@@ -396,6 +398,15 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
396
398
 
397
399
  function peek() { return get_full_char(S.text, S.pos); }
398
400
 
401
+ // Used because parsing ?. involves a lookahead for a digit
402
+ function is_option_chain_op() {
403
+ const must_be_dot = S.text.charCodeAt(S.pos + 1) === 46;
404
+ if (!must_be_dot) return false;
405
+
406
+ const cannot_be_digit = S.text.charCodeAt(S.pos + 2);
407
+ return cannot_be_digit < 48 || cannot_be_digit > 57;
408
+ }
409
+
399
410
  function next(signal_eof, in_string) {
400
411
  var ch = get_full_char(S.text, S.pos++);
401
412
  if (signal_eof && !ch)
@@ -456,7 +467,7 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
456
467
  (type == "keyword" && KEYWORDS_BEFORE_EXPRESSION.has(value)) ||
457
468
  (type == "punc" && PUNC_BEFORE_EXPRESSION.has(value))) ||
458
469
  (type == "arrow");
459
- if (type == "punc" && value == ".") {
470
+ if (type == "punc" && (value == "." || value == "?.")) {
460
471
  prev_was_dot = true;
461
472
  } else if (!is_comment) {
462
473
  prev_was_dot = false;
@@ -503,12 +514,14 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
503
514
  }
504
515
 
505
516
  function read_num(prefix) {
506
- var has_e = false, after_e = false, has_x = false, has_dot = prefix == ".", is_big_int = false;
517
+ var has_e = false, after_e = false, has_x = false, has_dot = prefix == ".", is_big_int = false, numeric_separator = false;
507
518
  var num = read_while(function(ch, i) {
508
519
  if (is_big_int) return false;
509
520
 
510
521
  var code = ch.charCodeAt(0);
511
522
  switch (code) {
523
+ case 95: // _
524
+ return (numeric_separator = true);
512
525
  case 98: case 66: // bB
513
526
  return (has_x = true); // Can occur in hex sequence, don't return false yet
514
527
  case 111: case 79: // oO
@@ -536,6 +549,14 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
536
549
  if (RE_OCT_NUMBER.test(num) && next_token.has_directive("use strict")) {
537
550
  parse_error("Legacy octal literals are not allowed in strict mode");
538
551
  }
552
+ if (numeric_separator) {
553
+ if (num.endsWith("_")) {
554
+ parse_error("Numeric separators are not allowed at the end of numeric literals");
555
+ } else if (num.includes("__")) {
556
+ parse_error("Only one underscore is allowed as numeric separator");
557
+ }
558
+ num = num.replace(/_/g, "");
559
+ }
539
560
  if (num.endsWith("n")) {
540
561
  const without_n = num.slice(0, -1);
541
562
  const allow_e = RE_HEX_NUMBER.test(without_n);
@@ -882,6 +903,14 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
882
903
  return tok;
883
904
  }
884
905
  case 61: return handle_eq_sign();
906
+ case 63: {
907
+ if (!is_option_chain_op()) break; // Handled below
908
+
909
+ next(); // ?
910
+ next(); // .
911
+
912
+ return token("punc", "?.");
913
+ }
885
914
  case 96: return read_template_characters(true);
886
915
  case 123:
887
916
  S.brace_counter++;
@@ -1000,7 +1029,7 @@ function parse($TEXT, options) {
1000
1029
 
1001
1030
  options = defaults(options, {
1002
1031
  bare_returns : false,
1003
- ecma : 2017,
1032
+ ecma : null, // Legacy
1004
1033
  expression : false,
1005
1034
  filename : null,
1006
1035
  html5_comments : true,
@@ -1108,7 +1137,7 @@ function parse($TEXT, options) {
1108
1137
  }
1109
1138
 
1110
1139
  function embed_tokens(parser) {
1111
- return function(...args) {
1140
+ return function _embed_tokens_wrapper(...args) {
1112
1141
  const start = S.token;
1113
1142
  const expr = parser(...args);
1114
1143
  expr.start = start;
@@ -1124,7 +1153,7 @@ function parse($TEXT, options) {
1124
1153
  }
1125
1154
  }
1126
1155
 
1127
- var statement = embed_tokens(function(is_export_default, is_for_body, is_if_body) {
1156
+ var statement = embed_tokens(function statement(is_export_default, is_for_body, is_if_body) {
1128
1157
  handle_regexp();
1129
1158
  switch (S.token.type) {
1130
1159
  case "string":
@@ -1159,7 +1188,7 @@ function parse($TEXT, options) {
1159
1188
  }
1160
1189
  return function_(AST_Defun, false, true, is_export_default);
1161
1190
  }
1162
- if (S.token.value == "import" && !is_token(peek(), "punc", "(")) {
1191
+ if (S.token.value == "import" && !is_token(peek(), "punc", "(") && !is_token(peek(), "punc", ".")) {
1163
1192
  next();
1164
1193
  var node = import_();
1165
1194
  semicolon();
@@ -1580,7 +1609,6 @@ function parse($TEXT, options) {
1580
1609
 
1581
1610
  if (!is("punc", ")")) {
1582
1611
  expect(",");
1583
- if (is("punc", ")") && options.ecma < 2017) unexpected();
1584
1612
  }
1585
1613
 
1586
1614
  if (param instanceof AST_Expansion) {
@@ -1825,7 +1853,6 @@ function parse($TEXT, options) {
1825
1853
  if (!is("punc", ")")) {
1826
1854
  expect(",");
1827
1855
  if (is("punc", ")")) {
1828
- if (options.ecma < 2017) unexpected();
1829
1856
  trailing_comma = prev();
1830
1857
  if (maybe_sequence) invalid_sequence = trailing_comma;
1831
1858
  }
@@ -2094,7 +2121,7 @@ function parse($TEXT, options) {
2094
2121
  var newexp = expr_atom(false), args;
2095
2122
  if (is("punc", "(")) {
2096
2123
  next();
2097
- args = expr_list(")", options.ecma >= 2017);
2124
+ args = expr_list(")", true);
2098
2125
  } else {
2099
2126
  args = [];
2100
2127
  }
@@ -2207,6 +2234,9 @@ function parse($TEXT, options) {
2207
2234
  if (is("operator", "new")) {
2208
2235
  return new_(allow_calls);
2209
2236
  }
2237
+ if (is("operator", "import")) {
2238
+ return import_meta();
2239
+ }
2210
2240
  var start = S.token;
2211
2241
  var peeked;
2212
2242
  var async = is("name", "async")
@@ -2584,6 +2614,7 @@ function parse($TEXT, options) {
2584
2614
 
2585
2615
  function import_() {
2586
2616
  var start = prev();
2617
+
2587
2618
  var imported_name;
2588
2619
  var imported_names;
2589
2620
  if (is("name")) {
@@ -2618,6 +2649,17 @@ function parse($TEXT, options) {
2618
2649
  });
2619
2650
  }
2620
2651
 
2652
+ function import_meta() {
2653
+ var start = S.token;
2654
+ expect_token("operator", "import");
2655
+ expect_token("punc", ".");
2656
+ expect_token("name", "meta");
2657
+ return subscripts(new AST_ImportMeta({
2658
+ start: start,
2659
+ end: prev()
2660
+ }), false);
2661
+ }
2662
+
2621
2663
  function map_name(is_import) {
2622
2664
  function make_symbol(type) {
2623
2665
  return new type({
@@ -2798,15 +2840,6 @@ function parse($TEXT, options) {
2798
2840
  }
2799
2841
  /* falls through */
2800
2842
  case "name":
2801
- if (tmp.value == "yield") {
2802
- if (is_in_generator()) {
2803
- token_error(tmp, "Yield cannot be used as identifier inside generators");
2804
- } else if (!is_token(peek(), "punc", ":")
2805
- && !is_token(peek(), "punc", "(")
2806
- && S.input.has_directive("use strict")) {
2807
- token_error(tmp, "Unexpected yield identifier inside strict mode");
2808
- }
2809
- }
2810
2843
  case "string":
2811
2844
  case "num":
2812
2845
  case "big_int":
@@ -2888,16 +2921,17 @@ function parse($TEXT, options) {
2888
2921
  }
2889
2922
  }
2890
2923
 
2891
- var subscripts = function(expr, allow_calls) {
2924
+ var subscripts = function(expr, allow_calls, is_chain) {
2892
2925
  var start = expr.start;
2893
2926
  if (is("punc", ".")) {
2894
2927
  next();
2895
2928
  return subscripts(new AST_Dot({
2896
2929
  start : start,
2897
2930
  expression : expr,
2931
+ optional : false,
2898
2932
  property : as_name(),
2899
2933
  end : prev()
2900
- }), allow_calls);
2934
+ }), allow_calls, is_chain);
2901
2935
  }
2902
2936
  if (is("punc", "[")) {
2903
2937
  next();
@@ -2906,22 +2940,80 @@ function parse($TEXT, options) {
2906
2940
  return subscripts(new AST_Sub({
2907
2941
  start : start,
2908
2942
  expression : expr,
2943
+ optional : false,
2909
2944
  property : prop,
2910
2945
  end : prev()
2911
- }), allow_calls);
2946
+ }), allow_calls, is_chain);
2912
2947
  }
2913
2948
  if (allow_calls && is("punc", "(")) {
2914
2949
  next();
2915
2950
  var call = new AST_Call({
2916
2951
  start : start,
2917
2952
  expression : expr,
2953
+ optional : false,
2918
2954
  args : call_args(),
2919
2955
  end : prev()
2920
2956
  });
2921
2957
  annotate(call);
2922
- return subscripts(call, true);
2958
+ return subscripts(call, true, is_chain);
2923
2959
  }
2960
+
2961
+ if (is("punc", "?.")) {
2962
+ next();
2963
+
2964
+ let chain_contents;
2965
+
2966
+ if (allow_calls && is("punc", "(")) {
2967
+ next();
2968
+
2969
+ const call = new AST_Call({
2970
+ start,
2971
+ optional: true,
2972
+ expression: expr,
2973
+ args: call_args(),
2974
+ end: prev()
2975
+ });
2976
+ annotate(call);
2977
+
2978
+ chain_contents = subscripts(call, true, true);
2979
+ } else if (is("name")) {
2980
+ chain_contents = subscripts(new AST_Dot({
2981
+ start,
2982
+ expression: expr,
2983
+ optional: true,
2984
+ property: as_name(),
2985
+ end: prev()
2986
+ }), allow_calls, true);
2987
+ } else if (is("punc", "[")) {
2988
+ next();
2989
+ const property = expression(true);
2990
+ expect("]");
2991
+ chain_contents = subscripts(new AST_Sub({
2992
+ start,
2993
+ expression: expr,
2994
+ optional: true,
2995
+ property,
2996
+ end: prev()
2997
+ }), allow_calls, true);
2998
+ }
2999
+
3000
+ if (!chain_contents) unexpected();
3001
+
3002
+ if (chain_contents instanceof AST_Chain) return chain_contents;
3003
+
3004
+ return new AST_Chain({
3005
+ start,
3006
+ expression: chain_contents,
3007
+ end: prev()
3008
+ });
3009
+ }
3010
+
2924
3011
  if (is("template_head")) {
3012
+ if (is_chain) {
3013
+ // a?.b`c` is a syntax error
3014
+ unexpected();
3015
+ }
3016
+
2925
3017
  return subscripts(new AST_PrefixedTemplateString({
2926
3018
  start: start,
2927
3019
  prefix: expr,
@@ -2929,6 +3021,7 @@ function parse($TEXT, options) {
2929
3021
  end: prev()
2930
3022
  }), allow_calls);
2931
3023
  }
3024
+
2932
3025
  return expr;
2933
3026
  };
2934
3027
 
@@ -2947,7 +3040,6 @@ function parse($TEXT, options) {
2947
3040
  }
2948
3041
  if (!is("punc", ")")) {
2949
3042
  expect(",");
2950
- if (is("punc", ")") && options.ecma < 2017) unexpected();
2951
3043
  }
2952
3044
  }
2953
3045
  next();
@@ -3151,13 +3243,14 @@ function parse($TEXT, options) {
3151
3243
  return expression(true);
3152
3244
  }
3153
3245
 
3154
- return (function() {
3246
+ return (function parse_toplevel() {
3155
3247
  var start = S.token;
3156
3248
  var body = [];
3157
3249
  S.input.push_directives_stack();
3158
3250
  if (options.module) S.input.add_directive("use strict");
3159
- while (!is("eof"))
3251
+ while (!is("eof")) {
3160
3252
  body.push(statement());
3253
+ }
3161
3254
  S.input.pop_directives_stack();
3162
3255
  var end = prev();
3163
3256
  var toplevel = options.toplevel;
package/lib/propmangle.js CHANGED
@@ -50,6 +50,7 @@ import {
50
50
  } from "./utils/index.js";
51
51
  import { base54 } from "./scope.js";
52
52
  import {
53
+ AST_Binary,
53
54
  AST_Call,
54
55
  AST_Conditional,
55
56
  AST_Dot,
@@ -212,6 +213,8 @@ function mangle_properties(ast, options) {
212
213
  } else if (node instanceof AST_Call
213
214
  && node.expression.print_to_string() == "Object.defineProperty") {
214
215
  addStrings(node.args[1], add);
216
+ } else if (node instanceof AST_Binary && node.operator === "in") {
217
+ addStrings(node.left, add);
215
218
  }
216
219
  }));
217
220
 
@@ -236,6 +239,8 @@ function mangle_properties(ast, options) {
236
239
  } else if (node instanceof AST_Call
237
240
  && node.expression.print_to_string() == "Object.defineProperty") {
238
241
  node.args[1] = mangleStrings(node.args[1]);
242
+ } else if (node instanceof AST_Binary && node.operator === "in") {
243
+ node.left = mangleStrings(node.left);
239
244
  }
240
245
  }));
241
246
 
package/lib/size.js CHANGED
@@ -32,6 +32,7 @@ import {
32
32
  AST_Hole,
33
33
  AST_If,
34
34
  AST_Import,
35
+ AST_ImportMeta,
35
36
  AST_Infinity,
36
37
  AST_LabeledStatement,
37
38
  AST_Let,
@@ -81,7 +82,7 @@ import { first_in_statement } from "./utils/first_in_statement.js";
81
82
 
82
83
  let mangle_options = undefined;
83
84
  AST_Node.prototype.size = function (compressor, stack) {
84
- mangle_options = undefined; // TODO get mangle_options somehow
85
+ mangle_options = compressor && compressor.mangle_options;
85
86
 
86
87
  let size = 0;
87
88
  walk_parent(this, (node, info) => {
@@ -159,7 +160,7 @@ AST_Arrow.prototype._size = function () {
159
160
  args_and_arrow += 2;
160
161
  }
161
162
 
162
- return lambda_modifiers(this) + args_and_arrow + Array.isArray(this.body) ? list_overhead(this.body) : this.body._size();
163
+ return lambda_modifiers(this) + args_and_arrow + (Array.isArray(this.body) ? list_overhead(this.body) : this.body._size());
163
164
  };
164
165
 
165
166
  AST_Destructuring.prototype._size = () => 2;
@@ -257,6 +258,8 @@ AST_Import.prototype._size = function () {
257
258
  return size;
258
259
  };
259
260
 
261
+ AST_ImportMeta.prototype._size = () => 11;
262
+
260
263
  AST_Export.prototype._size = function () {
261
264
  let size = 7 + (this.is_default ? 8 : 0);
262
265
 
@@ -278,6 +281,9 @@ AST_Export.prototype._size = function () {
278
281
  };
279
282
 
280
283
  AST_Call.prototype._size = function () {
284
+ if (this.optional) {
285
+ return 4 + list_overhead(this.args);
286
+ }
281
287
  return 2 + list_overhead(this.args);
282
288
  };
283
289
 
@@ -290,10 +296,15 @@ AST_Sequence.prototype._size = function () {
290
296
  };
291
297
 
292
298
  AST_Dot.prototype._size = function () {
299
+ if (this.optional) {
300
+ return this.property.length + 2;
301
+ }
293
302
  return this.property.length + 1;
294
303
  };
295
304
 
296
- AST_Sub.prototype._size = () => 2;
305
+ AST_Sub.prototype._size = function () {
306
+ return this.optional ? 4 : 2;
307
+ };
297
308
 
298
309
  AST_Unary.prototype._size = function () {
299
310
  if (this.operator === "typeof") return 7;
@@ -376,7 +387,7 @@ AST_ClassProperty.prototype._size = function () {
376
387
  AST_Symbol.prototype._size = function () {
377
388
  return !mangle_options || this.definition().unmangleable(mangle_options)
378
389
  ? this.name.length
379
- : 2;
390
+ : 1;
380
391
  };
381
392
 
382
393
  // TODO take propmangle into account
@@ -391,7 +402,7 @@ AST_SymbolRef.prototype._size = AST_SymbolDeclaration.prototype._size = function
391
402
 
392
403
  if (name === "arguments") return 9;
393
404
 
394
- return 2;
405
+ return AST_Symbol.prototype._size.call(this);
395
406
  };
396
407
 
397
408
  AST_NewTarget.prototype._size = () => 10;
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.0.0-beta.2",
7
+ "version": "5.2.1",
8
8
  "engines": {
9
9
  "node": ">=6.0.0"
10
10
  },
@@ -14,6 +14,7 @@
14
14
  "repository": "https://github.com/terser/terser",
15
15
  "main": "dist/bundle.min.js",
16
16
  "type": "module",
17
+ "module": "./main.js",
17
18
  "exports": {
18
19
  ".": {
19
20
  "import": "./main.js",
@@ -47,7 +48,8 @@
47
48
  "source-map-support": "~0.5.12"
48
49
  },
49
50
  "devDependencies": {
50
- "acorn": "^7.1.1",
51
+ "@ls-lint/ls-lint": "^1.9.2",
52
+ "acorn": "^7.4.0",
51
53
  "astring": "^1.4.1",
52
54
  "eslint": "^7.0.0",
53
55
  "eslump": "^2.0.0",
@@ -64,6 +66,7 @@
64
66
  "test:mocha": "mocha test/mocha",
65
67
  "lint": "eslint lib",
66
68
  "lint-fix": "eslint --fix lib",
69
+ "ls-lint": "ls-lint",
67
70
  "build": "rimraf dist/bundle* && rollup --config --silent",
68
71
  "prepare": "npm run build",
69
72
  "postversion": "echo 'Remember to update the changelog!'"
@@ -140,6 +143,7 @@
140
143
  },
141
144
  "pre-commit": [
142
145
  "lint-fix",
146
+ "ls-lint",
143
147
  "test"
144
148
  ]
145
149
  }
package/tools/terser.d.ts CHANGED
@@ -98,7 +98,7 @@ export interface FormatOptions {
98
98
  ascii_only?: boolean;
99
99
  beautify?: boolean;
100
100
  braces?: boolean;
101
- comments?: boolean | 'all' | 'some' | RegExp | ( (node: AST_Node, comment: {
101
+ comments?: boolean | 'all' | 'some' | RegExp | ( (node: any, comment: {
102
102
  value: string,
103
103
  type: 'comment1' | 'comment2' | 'comment3' | 'comment4',
104
104
  pos: number,
@@ -151,7 +151,6 @@ export interface MinifyOptions {
151
151
  }
152
152
 
153
153
  export interface MinifyOutput {
154
- ast?: AST_Node;
155
154
  code?: string;
156
155
  map?: RawSourceMap | string;
157
156
  }
@@ -165,4 +164,4 @@ export interface SourceMapOptions {
165
164
  url?: string | 'inline';
166
165
  }
167
166
 
168
- export async function minify(files: string | string[] | { [file: string]: string }, options?: MinifyOptions): Promise<MinifyOutput>;
167
+ export function minify(files: string | string[] | { [file: string]: string }, options?: MinifyOptions): Promise<MinifyOutput>;