terser 5.40.0 → 5.41.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## v5.41.0
4
+
5
+ - fixed semicolon insertion between class fields, when the field names are number literals
6
+ - `keep_numbers` format option now works for bigint
7
+ - internal: correctly mark accessors' is_generator property
8
+ - internal: do not read or assign quote properties without need
9
+ - internal: add missing equivalent_to comparison
10
+
3
11
  ## v5.40.0
4
12
 
5
13
  - Fix exporting AssignmentExpression (default assign pattern) to ESTree
@@ -1718,7 +1718,7 @@ function parse($TEXT, options) {
1718
1718
  return new ctor({
1719
1719
  start : args.start,
1720
1720
  end : body.end,
1721
- is_generator: is_generator,
1721
+ is_generator: is_generator || is_generator_property,
1722
1722
  async : is_async,
1723
1723
  name : name,
1724
1724
  argnames: args,
@@ -2346,7 +2346,12 @@ function parse($TEXT, options) {
2346
2346
  });
2347
2347
  break;
2348
2348
  case "big_int":
2349
- ret = new AST_BigInt({ start: tok, end: tok, value: tok.value });
2349
+ ret = new AST_BigInt({
2350
+ start: tok,
2351
+ end: tok,
2352
+ value: tok.value,
2353
+ raw: LATEST_RAW,
2354
+ });
2350
2355
  break;
2351
2356
  case "string":
2352
2357
  ret = new AST_String({
@@ -2610,7 +2615,7 @@ function parse($TEXT, options) {
2610
2615
 
2611
2616
  // Check property and fetch value
2612
2617
  if (!is("punc", ":")) {
2613
- var concise = concise_method_or_getset(name, start);
2618
+ var concise = object_or_class_property(name, start);
2614
2619
  if (concise) {
2615
2620
  a.push(concise);
2616
2621
  continue;
@@ -2645,7 +2650,7 @@ function parse($TEXT, options) {
2645
2650
  const kv = new AST_ObjectKeyVal({
2646
2651
  start: start,
2647
2652
  quote: start.quote,
2648
- key: name instanceof AST_Node ? name : "" + name,
2653
+ key: name,
2649
2654
  value: value,
2650
2655
  end: prev()
2651
2656
  });
@@ -2656,7 +2661,7 @@ function parse($TEXT, options) {
2656
2661
  });
2657
2662
 
2658
2663
  function class_(KindOfClass, is_export_default) {
2659
- var start, method, class_name, extends_, a = [];
2664
+ var start, method, class_name, extends_, properties = [];
2660
2665
 
2661
2666
  S.input.push_directives_stack(); // Push directive stack, but not scope stack
2662
2667
  S.input.add_directive("use strict");
@@ -2685,9 +2690,9 @@ function parse($TEXT, options) {
2685
2690
  while (is("punc", ";")) { next(); } // Leading semicolons are okay in class bodies.
2686
2691
  while (!is("punc", "}")) {
2687
2692
  start = S.token;
2688
- method = concise_method_or_getset(as_property_name(), start, true);
2693
+ method = object_or_class_property(as_property_name(), start, true);
2689
2694
  if (!method) { unexpected(); }
2690
- a.push(method);
2695
+ properties.push(method);
2691
2696
  while (is("punc", ";")) { next(); }
2692
2697
  }
2693
2698
  // mark in class feild,
@@ -2701,19 +2706,15 @@ function parse($TEXT, options) {
2701
2706
  start: start,
2702
2707
  name: class_name,
2703
2708
  extends: extends_,
2704
- properties: a,
2709
+ properties: properties,
2705
2710
  end: prev(),
2706
2711
  });
2707
2712
  }
2708
2713
 
2709
- function concise_method_or_getset(name, start, is_class) {
2710
- const get_symbol_ast = (name, SymbolClass = AST_SymbolMethod) => {
2711
- if (typeof name === "string" || typeof name === "number") {
2712
- return new SymbolClass({
2713
- start,
2714
- name: "" + name,
2715
- end: prev()
2716
- });
2714
+ function object_or_class_property(name, start, is_class) {
2715
+ const get_symbol_ast = (name, SymbolClass) => {
2716
+ if (typeof name === "string") {
2717
+ return new SymbolClass({ start, name, end: prev() });
2717
2718
  } else if (name === null) {
2718
2719
  unexpected();
2719
2720
  }
@@ -2761,7 +2762,7 @@ function parse($TEXT, options) {
2761
2762
  ? AST_ObjectGetter
2762
2763
  : AST_ObjectSetter;
2763
2764
 
2764
- name = get_symbol_ast(name);
2765
+ name = get_symbol_ast(name, AST_SymbolMethod);
2765
2766
  return annotate(new AccessorClass({
2766
2767
  start,
2767
2768
  static: is_static,
@@ -2778,7 +2779,7 @@ function parse($TEXT, options) {
2778
2779
  return annotate(new AccessorClass({
2779
2780
  start,
2780
2781
  static: is_static,
2781
- key: get_symbol_ast(name),
2782
+ key: get_symbol_ast(name, AST_SymbolMethod),
2782
2783
  value: create_accessor(),
2783
2784
  end: prev(),
2784
2785
  }));
@@ -2786,7 +2787,7 @@ function parse($TEXT, options) {
2786
2787
  }
2787
2788
 
2788
2789
  if (is("punc", "(")) {
2789
- name = get_symbol_ast(name);
2790
+ name = get_symbol_ast(name, AST_SymbolMethod);
2790
2791
  const AST_MethodVariant = is_private
2791
2792
  ? AST_PrivateMethod
2792
2793
  : AST_ConciseMethod;
@@ -2805,13 +2806,17 @@ function parse($TEXT, options) {
2805
2806
  }
2806
2807
 
2807
2808
  if (is_class) {
2808
- const key = get_symbol_ast(name, AST_SymbolClassProperty);
2809
- const quote = key instanceof AST_SymbolClassProperty
2810
- ? property_token.quote
2811
- : undefined;
2809
+ const AST_SymbolVariant = is_private
2810
+ ? AST_SymbolPrivateProperty
2811
+ : AST_SymbolClassProperty;
2812
2812
  const AST_ClassPropertyVariant = is_private
2813
2813
  ? AST_ClassPrivateProperty
2814
2814
  : AST_ClassProperty;
2815
+
2816
+ const key = get_symbol_ast(name, AST_SymbolVariant);
2817
+ const quote = key instanceof AST_SymbolClassProperty
2818
+ ? property_token.quote
2819
+ : undefined;
2815
2820
  if (is("operator", "=")) {
2816
2821
  next();
2817
2822
  return annotate(
@@ -2831,6 +2836,9 @@ function parse($TEXT, options) {
2831
2836
  || is("operator", "*")
2832
2837
  || is("punc", ";")
2833
2838
  || is("punc", "}")
2839
+ || is("string")
2840
+ || is("num")
2841
+ || is("big_int")
2834
2842
  ) {
2835
2843
  return annotate(
2836
2844
  new AST_ClassPropertyVariant({
@@ -2955,10 +2963,12 @@ function parse($TEXT, options) {
2955
2963
  } else {
2956
2964
  foreign_name = make_symbol(foreign_type, S.token.quote);
2957
2965
  }
2958
- } else if (is_import) {
2959
- name = new type(foreign_name);
2960
2966
  } else {
2961
- foreign_name = new foreign_type(name);
2967
+ if (is_import) {
2968
+ name = new type(foreign_name);
2969
+ } else {
2970
+ foreign_name = new foreign_type(name);
2971
+ }
2962
2972
  }
2963
2973
 
2964
2974
  return new AST_NameMapping({
@@ -3129,12 +3139,14 @@ function parse($TEXT, options) {
3129
3139
  case "name":
3130
3140
  case "privatename":
3131
3141
  case "string":
3132
- case "num":
3133
- case "big_int":
3134
3142
  case "keyword":
3135
3143
  case "atom":
3136
3144
  next();
3137
3145
  return tmp.value;
3146
+ case "num":
3147
+ case "big_int":
3148
+ next();
3149
+ return "" + tmp.value;
3138
3150
  default:
3139
3151
  unexpected(tmp);
3140
3152
  }
@@ -5792,7 +5804,6 @@ var AST_ConciseMethod = DEFNODE("ConciseMethod", "quote static is_generator asyn
5792
5804
 
5793
5805
  var AST_PrivateMethod = DEFNODE("PrivateMethod", "", function AST_PrivateMethod(props) {
5794
5806
  if (props) {
5795
- this.quote = props.quote;
5796
5807
  this.static = props.static;
5797
5808
  this.is_generator = props.is_generator;
5798
5809
  this.async = props.async;
@@ -5953,7 +5964,6 @@ var AST_ClassProperty = DEFNODE("ClassProperty", "static quote", function AST_Cl
5953
5964
  var AST_ClassPrivateProperty = DEFNODE("ClassPrivateProperty", "", function AST_ClassPrivateProperty(props) {
5954
5965
  if (props) {
5955
5966
  this.static = props.static;
5956
- this.quote = props.quote;
5957
5967
  this.key = props.key;
5958
5968
  this.value = props.value;
5959
5969
  this.start = props.start;
@@ -6313,12 +6323,12 @@ var AST_SymbolImport = DEFNODE("SymbolImport", null, function AST_SymbolImport(p
6313
6323
  $documentation: "Symbol referring to an imported name",
6314
6324
  }, AST_SymbolBlockDeclaration);
6315
6325
 
6316
- var AST_SymbolImportForeign = DEFNODE("SymbolImportForeign", null, function AST_SymbolImportForeign(props) {
6326
+ var AST_SymbolImportForeign = DEFNODE("SymbolImportForeign", "quote", function AST_SymbolImportForeign(props) {
6317
6327
  if (props) {
6328
+ this.quote = props.quote;
6318
6329
  this.scope = props.scope;
6319
6330
  this.name = props.name;
6320
6331
  this.thedef = props.thedef;
6321
- this.quote = props.quote;
6322
6332
  this.start = props.start;
6323
6333
  this.end = props.end;
6324
6334
  }
@@ -6365,12 +6375,12 @@ var AST_SymbolRef = DEFNODE("SymbolRef", null, function AST_SymbolRef(props) {
6365
6375
  $documentation: "Reference to some symbol (not definition/declaration)",
6366
6376
  }, AST_Symbol);
6367
6377
 
6368
- var AST_SymbolExport = DEFNODE("SymbolExport", null, function AST_SymbolExport(props) {
6378
+ var AST_SymbolExport = DEFNODE("SymbolExport", "quote", function AST_SymbolExport(props) {
6369
6379
  if (props) {
6380
+ this.quote = props.quote;
6370
6381
  this.scope = props.scope;
6371
6382
  this.name = props.name;
6372
6383
  this.thedef = props.thedef;
6373
- this.quote = props.quote;
6374
6384
  this.start = props.start;
6375
6385
  this.end = props.end;
6376
6386
  }
@@ -6380,12 +6390,12 @@ var AST_SymbolExport = DEFNODE("SymbolExport", null, function AST_SymbolExport(p
6380
6390
  $documentation: "Symbol referring to a name to export",
6381
6391
  }, AST_SymbolRef);
6382
6392
 
6383
- var AST_SymbolExportForeign = DEFNODE("SymbolExportForeign", null, function AST_SymbolExportForeign(props) {
6393
+ var AST_SymbolExportForeign = DEFNODE("SymbolExportForeign", "quote", function AST_SymbolExportForeign(props) {
6384
6394
  if (props) {
6395
+ this.quote = props.quote;
6385
6396
  this.scope = props.scope;
6386
6397
  this.name = props.name;
6387
6398
  this.thedef = props.thedef;
6388
- this.quote = props.quote;
6389
6399
  this.start = props.start;
6390
6400
  this.end = props.end;
6391
6401
  }
@@ -6500,9 +6510,10 @@ var AST_Number = DEFNODE("Number", "value raw", function AST_Number(props) {
6500
6510
  }
6501
6511
  }, AST_Constant);
6502
6512
 
6503
- var AST_BigInt = DEFNODE("BigInt", "value", function AST_BigInt(props) {
6513
+ var AST_BigInt = DEFNODE("BigInt", "value raw", function AST_BigInt(props) {
6504
6514
  if (props) {
6505
6515
  this.value = props.value;
6516
+ this.raw = props.raw;
6506
6517
  this.start = props.start;
6507
6518
  this.end = props.end;
6508
6519
  }
@@ -6511,7 +6522,8 @@ var AST_BigInt = DEFNODE("BigInt", "value", function AST_BigInt(props) {
6511
6522
  }, {
6512
6523
  $documentation: "A big int literal",
6513
6524
  $propdoc: {
6514
- value: "[string] big int value"
6525
+ value: "[string] big int value, represented as a string",
6526
+ raw: "[string] the original format preserved"
6515
6527
  }
6516
6528
  }, AST_Constant);
6517
6529
 
@@ -10653,11 +10665,11 @@ function OutputStream(options) {
10653
10665
  foreign_name.name;
10654
10666
  if (!names_are_different &&
10655
10667
  foreign_name.name === "*" &&
10656
- foreign_name.quote != self.name.quote) {
10668
+ !!foreign_name.quote != !!self.name.quote) {
10657
10669
  // export * as "*"
10658
10670
  names_are_different = true;
10659
10671
  }
10660
- var foreign_name_is_name = foreign_name.quote == null;
10672
+ var foreign_name_is_name = !foreign_name.quote;
10661
10673
  if (names_are_different) {
10662
10674
  if (is_import) {
10663
10675
  if (foreign_name_is_name) {
@@ -10666,7 +10678,7 @@ function OutputStream(options) {
10666
10678
  output.print_string(foreign_name.name, foreign_name.quote);
10667
10679
  }
10668
10680
  } else {
10669
- if (self.name.quote == null) {
10681
+ if (!self.name.quote) {
10670
10682
  self.name.print(output);
10671
10683
  } else {
10672
10684
  output.print_string(self.name.name, self.name.quote);
@@ -10686,7 +10698,7 @@ function OutputStream(options) {
10686
10698
  }
10687
10699
  }
10688
10700
  } else {
10689
- if (self.name.quote == null) {
10701
+ if (!self.name.quote) {
10690
10702
  self.name.print(output);
10691
10703
  } else {
10692
10704
  output.print_string(self.name.name, self.name.quote);
@@ -11075,7 +11087,7 @@ function OutputStream(options) {
11075
11087
 
11076
11088
  output.print("#");
11077
11089
 
11078
- print_property_name(self.key.name, self.quote, output);
11090
+ print_property_name(self.key.name, undefined, output);
11079
11091
 
11080
11092
  if (self.value) {
11081
11093
  output.print("=");
@@ -11203,7 +11215,11 @@ function OutputStream(options) {
11203
11215
  }
11204
11216
  });
11205
11217
  DEFPRINT(AST_BigInt, function(self, output) {
11206
- output.print(self.getValue() + "n");
11218
+ if (output.option("keep_numbers") && self.raw) {
11219
+ output.print(self.raw);
11220
+ } else {
11221
+ output.print(self.getValue() + "n");
11222
+ }
11207
11223
  });
11208
11224
 
11209
11225
  const r_slash_script = /(<\s*\/\s*script)/i;
@@ -11491,13 +11507,13 @@ AST_VarDef.prototype.shallow_cmp = function(other) {
11491
11507
  AST_NameMapping.prototype.shallow_cmp = pass_through;
11492
11508
 
11493
11509
  AST_Import.prototype.shallow_cmp = function(other) {
11494
- return (this.imported_name == null ? other.imported_name == null : this.imported_name === other.imported_name) && (this.imported_names == null ? other.imported_names == null : this.imported_names === other.imported_names);
11510
+ return (this.imported_name == null ? other.imported_name == null : this.imported_name === other.imported_name) && (this.imported_names == null ? other.imported_names == null : this.imported_names === other.imported_names) && (this.attributes == null ? other.attributes == null : this.attributes === other.attributes);
11495
11511
  };
11496
11512
 
11497
11513
  AST_ImportMeta.prototype.shallow_cmp = pass_through;
11498
11514
 
11499
11515
  AST_Export.prototype.shallow_cmp = function(other) {
11500
- return (this.exported_definition == null ? other.exported_definition == null : this.exported_definition === other.exported_definition) && (this.exported_value == null ? other.exported_value == null : this.exported_value === other.exported_value) && (this.exported_names == null ? other.exported_names == null : this.exported_names === other.exported_names) && this.module_name === other.module_name && this.is_default === other.is_default;
11516
+ return (this.exported_definition == null ? other.exported_definition == null : this.exported_definition === other.exported_definition) && (this.exported_value == null ? other.exported_value == null : this.exported_value === other.exported_value) && (this.exported_names == null ? other.exported_names == null : this.exported_names === other.exported_names) && (this.attributes == null ? other.attributes == null : this.attributes === other.attributes) && this.module_name === other.module_name && this.is_default === other.is_default;
11501
11517
  };
11502
11518
 
11503
11519
  AST_Call.prototype.shallow_cmp = pass_through;
@@ -11524,6 +11540,8 @@ AST_Binary.prototype.shallow_cmp = function(other) {
11524
11540
  return this.operator === other.operator;
11525
11541
  };
11526
11542
 
11543
+ AST_PrivateIn.prototype.shallow_cmp = pass_through;
11544
+
11527
11545
  AST_Conditional.prototype.shallow_cmp = pass_through;
11528
11546
 
11529
11547
  AST_Array.prototype.shallow_cmp = pass_through;
@@ -11533,7 +11551,7 @@ AST_Object.prototype.shallow_cmp = pass_through;
11533
11551
  AST_ObjectProperty.prototype.shallow_cmp = pass_through;
11534
11552
 
11535
11553
  AST_ObjectKeyVal.prototype.shallow_cmp = function(other) {
11536
- return this.key === other.key;
11554
+ return this.key === other.key && this.quote === other.quote;
11537
11555
  };
11538
11556
 
11539
11557
  AST_ObjectSetter.prototype.shallow_cmp = function(other) {
package/lib/ast.js CHANGED
@@ -2179,7 +2179,6 @@ var AST_ConciseMethod = DEFNODE("ConciseMethod", "quote static is_generator asyn
2179
2179
 
2180
2180
  var AST_PrivateMethod = DEFNODE("PrivateMethod", "", function AST_PrivateMethod(props) {
2181
2181
  if (props) {
2182
- this.quote = props.quote;
2183
2182
  this.static = props.static;
2184
2183
  this.is_generator = props.is_generator;
2185
2184
  this.async = props.async;
@@ -2340,7 +2339,6 @@ var AST_ClassProperty = DEFNODE("ClassProperty", "static quote", function AST_Cl
2340
2339
  var AST_ClassPrivateProperty = DEFNODE("ClassPrivateProperty", "", function AST_ClassPrivateProperty(props) {
2341
2340
  if (props) {
2342
2341
  this.static = props.static;
2343
- this.quote = props.quote;
2344
2342
  this.key = props.key;
2345
2343
  this.value = props.value;
2346
2344
  this.start = props.start;
@@ -2700,12 +2698,12 @@ var AST_SymbolImport = DEFNODE("SymbolImport", null, function AST_SymbolImport(p
2700
2698
  $documentation: "Symbol referring to an imported name",
2701
2699
  }, AST_SymbolBlockDeclaration);
2702
2700
 
2703
- var AST_SymbolImportForeign = DEFNODE("SymbolImportForeign", null, function AST_SymbolImportForeign(props) {
2701
+ var AST_SymbolImportForeign = DEFNODE("SymbolImportForeign", "quote", function AST_SymbolImportForeign(props) {
2704
2702
  if (props) {
2703
+ this.quote = props.quote;
2705
2704
  this.scope = props.scope;
2706
2705
  this.name = props.name;
2707
2706
  this.thedef = props.thedef;
2708
- this.quote = props.quote;
2709
2707
  this.start = props.start;
2710
2708
  this.end = props.end;
2711
2709
  }
@@ -2752,12 +2750,12 @@ var AST_SymbolRef = DEFNODE("SymbolRef", null, function AST_SymbolRef(props) {
2752
2750
  $documentation: "Reference to some symbol (not definition/declaration)",
2753
2751
  }, AST_Symbol);
2754
2752
 
2755
- var AST_SymbolExport = DEFNODE("SymbolExport", null, function AST_SymbolExport(props) {
2753
+ var AST_SymbolExport = DEFNODE("SymbolExport", "quote", function AST_SymbolExport(props) {
2756
2754
  if (props) {
2755
+ this.quote = props.quote;
2757
2756
  this.scope = props.scope;
2758
2757
  this.name = props.name;
2759
2758
  this.thedef = props.thedef;
2760
- this.quote = props.quote;
2761
2759
  this.start = props.start;
2762
2760
  this.end = props.end;
2763
2761
  }
@@ -2767,12 +2765,12 @@ var AST_SymbolExport = DEFNODE("SymbolExport", null, function AST_SymbolExport(p
2767
2765
  $documentation: "Symbol referring to a name to export",
2768
2766
  }, AST_SymbolRef);
2769
2767
 
2770
- var AST_SymbolExportForeign = DEFNODE("SymbolExportForeign", null, function AST_SymbolExportForeign(props) {
2768
+ var AST_SymbolExportForeign = DEFNODE("SymbolExportForeign", "quote", function AST_SymbolExportForeign(props) {
2771
2769
  if (props) {
2770
+ this.quote = props.quote;
2772
2771
  this.scope = props.scope;
2773
2772
  this.name = props.name;
2774
2773
  this.thedef = props.thedef;
2775
- this.quote = props.quote;
2776
2774
  this.start = props.start;
2777
2775
  this.end = props.end;
2778
2776
  }
@@ -2887,9 +2885,10 @@ var AST_Number = DEFNODE("Number", "value raw", function AST_Number(props) {
2887
2885
  }
2888
2886
  }, AST_Constant);
2889
2887
 
2890
- var AST_BigInt = DEFNODE("BigInt", "value", function AST_BigInt(props) {
2888
+ var AST_BigInt = DEFNODE("BigInt", "value raw", function AST_BigInt(props) {
2891
2889
  if (props) {
2892
2890
  this.value = props.value;
2891
+ this.raw = props.raw;
2893
2892
  this.start = props.start;
2894
2893
  this.end = props.end;
2895
2894
  }
@@ -2898,7 +2897,8 @@ var AST_BigInt = DEFNODE("BigInt", "value", function AST_BigInt(props) {
2898
2897
  }, {
2899
2898
  $documentation: "A big int literal",
2900
2899
  $propdoc: {
2901
- value: "[string] big int value"
2900
+ value: "[string] big int value, represented as a string",
2901
+ raw: "[string] the original format preserved"
2902
2902
  }
2903
2903
  }, AST_Constant);
2904
2904
 
@@ -44,6 +44,7 @@ import {
44
44
  AST_ObjectProperty,
45
45
  AST_ObjectSetter,
46
46
  AST_PrefixedTemplateString,
47
+ AST_PrivateIn,
47
48
  AST_PrivateMethod,
48
49
  AST_PropAccess,
49
50
  AST_RegExp,
@@ -192,13 +193,13 @@ AST_VarDef.prototype.shallow_cmp = function(other) {
192
193
  AST_NameMapping.prototype.shallow_cmp = pass_through;
193
194
 
194
195
  AST_Import.prototype.shallow_cmp = function(other) {
195
- return (this.imported_name == null ? other.imported_name == null : this.imported_name === other.imported_name) && (this.imported_names == null ? other.imported_names == null : this.imported_names === other.imported_names);
196
+ return (this.imported_name == null ? other.imported_name == null : this.imported_name === other.imported_name) && (this.imported_names == null ? other.imported_names == null : this.imported_names === other.imported_names) && (this.attributes == null ? other.attributes == null : this.attributes === other.attributes);
196
197
  };
197
198
 
198
199
  AST_ImportMeta.prototype.shallow_cmp = pass_through;
199
200
 
200
201
  AST_Export.prototype.shallow_cmp = function(other) {
201
- return (this.exported_definition == null ? other.exported_definition == null : this.exported_definition === other.exported_definition) && (this.exported_value == null ? other.exported_value == null : this.exported_value === other.exported_value) && (this.exported_names == null ? other.exported_names == null : this.exported_names === other.exported_names) && this.module_name === other.module_name && this.is_default === other.is_default;
202
+ return (this.exported_definition == null ? other.exported_definition == null : this.exported_definition === other.exported_definition) && (this.exported_value == null ? other.exported_value == null : this.exported_value === other.exported_value) && (this.exported_names == null ? other.exported_names == null : this.exported_names === other.exported_names) && (this.attributes == null ? other.attributes == null : this.attributes === other.attributes) && this.module_name === other.module_name && this.is_default === other.is_default;
202
203
  };
203
204
 
204
205
  AST_Call.prototype.shallow_cmp = pass_through;
@@ -225,6 +226,8 @@ AST_Binary.prototype.shallow_cmp = function(other) {
225
226
  return this.operator === other.operator;
226
227
  };
227
228
 
229
+ AST_PrivateIn.prototype.shallow_cmp = pass_through;
230
+
228
231
  AST_Conditional.prototype.shallow_cmp = pass_through;
229
232
 
230
233
  AST_Array.prototype.shallow_cmp = pass_through;
@@ -234,7 +237,7 @@ AST_Object.prototype.shallow_cmp = pass_through;
234
237
  AST_ObjectProperty.prototype.shallow_cmp = pass_through;
235
238
 
236
239
  AST_ObjectKeyVal.prototype.shallow_cmp = function(other) {
237
- return this.key === other.key;
240
+ return this.key === other.key && this.quote === other.quote;
238
241
  };
239
242
 
240
243
  AST_ObjectSetter.prototype.shallow_cmp = function(other) {
package/lib/output.js CHANGED
@@ -1811,11 +1811,11 @@ function OutputStream(options) {
1811
1811
  foreign_name.name;
1812
1812
  if (!names_are_different &&
1813
1813
  foreign_name.name === "*" &&
1814
- foreign_name.quote != self.name.quote) {
1814
+ !!foreign_name.quote != !!self.name.quote) {
1815
1815
  // export * as "*"
1816
1816
  names_are_different = true;
1817
1817
  }
1818
- var foreign_name_is_name = foreign_name.quote == null;
1818
+ var foreign_name_is_name = !foreign_name.quote;
1819
1819
  if (names_are_different) {
1820
1820
  if (is_import) {
1821
1821
  if (foreign_name_is_name) {
@@ -1824,7 +1824,7 @@ function OutputStream(options) {
1824
1824
  output.print_string(foreign_name.name, foreign_name.quote);
1825
1825
  }
1826
1826
  } else {
1827
- if (self.name.quote == null) {
1827
+ if (!self.name.quote) {
1828
1828
  self.name.print(output);
1829
1829
  } else {
1830
1830
  output.print_string(self.name.name, self.name.quote);
@@ -1844,7 +1844,7 @@ function OutputStream(options) {
1844
1844
  }
1845
1845
  }
1846
1846
  } else {
1847
- if (self.name.quote == null) {
1847
+ if (!self.name.quote) {
1848
1848
  self.name.print(output);
1849
1849
  } else {
1850
1850
  output.print_string(self.name.name, self.name.quote);
@@ -2233,7 +2233,7 @@ function OutputStream(options) {
2233
2233
 
2234
2234
  output.print("#");
2235
2235
 
2236
- print_property_name(self.key.name, self.quote, output);
2236
+ print_property_name(self.key.name, undefined, output);
2237
2237
 
2238
2238
  if (self.value) {
2239
2239
  output.print("=");
@@ -2361,7 +2361,11 @@ function OutputStream(options) {
2361
2361
  }
2362
2362
  });
2363
2363
  DEFPRINT(AST_BigInt, function(self, output) {
2364
- output.print(self.getValue() + "n");
2364
+ if (output.option("keep_numbers") && self.raw) {
2365
+ output.print(self.raw);
2366
+ } else {
2367
+ output.print(self.getValue() + "n");
2368
+ }
2365
2369
  });
2366
2370
 
2367
2371
  const r_slash_script = /(<\s*\/\s*script)/i;
package/lib/parse.js CHANGED
@@ -108,7 +108,6 @@ import {
108
108
  AST_NameMapping,
109
109
  AST_New,
110
110
  AST_NewTarget,
111
- AST_Node,
112
111
  AST_Null,
113
112
  AST_Number,
114
113
  AST_Object,
@@ -1573,7 +1572,7 @@ function parse($TEXT, options) {
1573
1572
  return new ctor({
1574
1573
  start : args.start,
1575
1574
  end : body.end,
1576
- is_generator: is_generator,
1575
+ is_generator: is_generator || is_generator_property,
1577
1576
  async : is_async,
1578
1577
  name : name,
1579
1578
  argnames: args,
@@ -2201,7 +2200,12 @@ function parse($TEXT, options) {
2201
2200
  });
2202
2201
  break;
2203
2202
  case "big_int":
2204
- ret = new AST_BigInt({ start: tok, end: tok, value: tok.value });
2203
+ ret = new AST_BigInt({
2204
+ start: tok,
2205
+ end: tok,
2206
+ value: tok.value,
2207
+ raw: LATEST_RAW,
2208
+ });
2205
2209
  break;
2206
2210
  case "string":
2207
2211
  ret = new AST_String({
@@ -2465,7 +2469,7 @@ function parse($TEXT, options) {
2465
2469
 
2466
2470
  // Check property and fetch value
2467
2471
  if (!is("punc", ":")) {
2468
- var concise = concise_method_or_getset(name, start);
2472
+ var concise = object_or_class_property(name, start);
2469
2473
  if (concise) {
2470
2474
  a.push(concise);
2471
2475
  continue;
@@ -2500,7 +2504,7 @@ function parse($TEXT, options) {
2500
2504
  const kv = new AST_ObjectKeyVal({
2501
2505
  start: start,
2502
2506
  quote: start.quote,
2503
- key: name instanceof AST_Node ? name : "" + name,
2507
+ key: name,
2504
2508
  value: value,
2505
2509
  end: prev()
2506
2510
  });
@@ -2511,7 +2515,7 @@ function parse($TEXT, options) {
2511
2515
  });
2512
2516
 
2513
2517
  function class_(KindOfClass, is_export_default) {
2514
- var start, method, class_name, extends_, a = [];
2518
+ var start, method, class_name, extends_, properties = [];
2515
2519
 
2516
2520
  S.input.push_directives_stack(); // Push directive stack, but not scope stack
2517
2521
  S.input.add_directive("use strict");
@@ -2540,9 +2544,9 @@ function parse($TEXT, options) {
2540
2544
  while (is("punc", ";")) { next(); } // Leading semicolons are okay in class bodies.
2541
2545
  while (!is("punc", "}")) {
2542
2546
  start = S.token;
2543
- method = concise_method_or_getset(as_property_name(), start, true);
2547
+ method = object_or_class_property(as_property_name(), start, true);
2544
2548
  if (!method) { unexpected(); }
2545
- a.push(method);
2549
+ properties.push(method);
2546
2550
  while (is("punc", ";")) { next(); }
2547
2551
  }
2548
2552
  // mark in class feild,
@@ -2556,19 +2560,15 @@ function parse($TEXT, options) {
2556
2560
  start: start,
2557
2561
  name: class_name,
2558
2562
  extends: extends_,
2559
- properties: a,
2563
+ properties: properties,
2560
2564
  end: prev(),
2561
2565
  });
2562
2566
  }
2563
2567
 
2564
- function concise_method_or_getset(name, start, is_class) {
2565
- const get_symbol_ast = (name, SymbolClass = AST_SymbolMethod) => {
2566
- if (typeof name === "string" || typeof name === "number") {
2567
- return new SymbolClass({
2568
- start,
2569
- name: "" + name,
2570
- end: prev()
2571
- });
2568
+ function object_or_class_property(name, start, is_class) {
2569
+ const get_symbol_ast = (name, SymbolClass) => {
2570
+ if (typeof name === "string") {
2571
+ return new SymbolClass({ start, name, end: prev() });
2572
2572
  } else if (name === null) {
2573
2573
  unexpected();
2574
2574
  }
@@ -2616,7 +2616,7 @@ function parse($TEXT, options) {
2616
2616
  ? AST_ObjectGetter
2617
2617
  : AST_ObjectSetter;
2618
2618
 
2619
- name = get_symbol_ast(name);
2619
+ name = get_symbol_ast(name, AST_SymbolMethod);
2620
2620
  return annotate(new AccessorClass({
2621
2621
  start,
2622
2622
  static: is_static,
@@ -2633,7 +2633,7 @@ function parse($TEXT, options) {
2633
2633
  return annotate(new AccessorClass({
2634
2634
  start,
2635
2635
  static: is_static,
2636
- key: get_symbol_ast(name),
2636
+ key: get_symbol_ast(name, AST_SymbolMethod),
2637
2637
  value: create_accessor(),
2638
2638
  end: prev(),
2639
2639
  }));
@@ -2641,7 +2641,7 @@ function parse($TEXT, options) {
2641
2641
  }
2642
2642
 
2643
2643
  if (is("punc", "(")) {
2644
- name = get_symbol_ast(name);
2644
+ name = get_symbol_ast(name, AST_SymbolMethod);
2645
2645
  const AST_MethodVariant = is_private
2646
2646
  ? AST_PrivateMethod
2647
2647
  : AST_ConciseMethod;
@@ -2660,13 +2660,17 @@ function parse($TEXT, options) {
2660
2660
  }
2661
2661
 
2662
2662
  if (is_class) {
2663
- const key = get_symbol_ast(name, AST_SymbolClassProperty);
2664
- const quote = key instanceof AST_SymbolClassProperty
2665
- ? property_token.quote
2666
- : undefined;
2663
+ const AST_SymbolVariant = is_private
2664
+ ? AST_SymbolPrivateProperty
2665
+ : AST_SymbolClassProperty;
2667
2666
  const AST_ClassPropertyVariant = is_private
2668
2667
  ? AST_ClassPrivateProperty
2669
2668
  : AST_ClassProperty;
2669
+
2670
+ const key = get_symbol_ast(name, AST_SymbolVariant);
2671
+ const quote = key instanceof AST_SymbolClassProperty
2672
+ ? property_token.quote
2673
+ : undefined;
2670
2674
  if (is("operator", "=")) {
2671
2675
  next();
2672
2676
  return annotate(
@@ -2686,6 +2690,9 @@ function parse($TEXT, options) {
2686
2690
  || is("operator", "*")
2687
2691
  || is("punc", ";")
2688
2692
  || is("punc", "}")
2693
+ || is("string")
2694
+ || is("num")
2695
+ || is("big_int")
2689
2696
  ) {
2690
2697
  return annotate(
2691
2698
  new AST_ClassPropertyVariant({
@@ -2810,10 +2817,12 @@ function parse($TEXT, options) {
2810
2817
  } else {
2811
2818
  foreign_name = make_symbol(foreign_type, S.token.quote);
2812
2819
  }
2813
- } else if (is_import) {
2814
- name = new type(foreign_name);
2815
2820
  } else {
2816
- foreign_name = new foreign_type(name);
2821
+ if (is_import) {
2822
+ name = new type(foreign_name);
2823
+ } else {
2824
+ foreign_name = new foreign_type(name);
2825
+ }
2817
2826
  }
2818
2827
 
2819
2828
  return new AST_NameMapping({
@@ -2984,12 +2993,14 @@ function parse($TEXT, options) {
2984
2993
  case "name":
2985
2994
  case "privatename":
2986
2995
  case "string":
2987
- case "num":
2988
- case "big_int":
2989
2996
  case "keyword":
2990
2997
  case "atom":
2991
2998
  next();
2992
2999
  return tmp.value;
3000
+ case "num":
3001
+ case "big_int":
3002
+ next();
3003
+ return "" + tmp.value;
2993
3004
  default:
2994
3005
  unexpected(tmp);
2995
3006
  }
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.40.0",
7
+ "version": "5.41.0",
8
8
  "engines": {
9
9
  "node": ">=10"
10
10
  },