terser 5.40.0 → 5.42.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.
@@ -329,7 +329,6 @@ ALL_RESERVED_WORDS = makePredicate(ALL_RESERVED_WORDS);
329
329
 
330
330
  var OPERATOR_CHARS = makePredicate(characters("+-*&%=<>!?|~^"));
331
331
 
332
- var RE_NUM_LITERAL = /[0-9a-f]/i;
333
332
  var RE_HEX_NUMBER = /^0x[0-9a-f]+$/i;
334
333
  var RE_OCT_NUMBER = /^0[0-7]+$/;
335
334
  var RE_ES6_OCT_NUMBER = /^0o[0-7]+$/i;
@@ -694,15 +693,16 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
694
693
  return after_e;
695
694
  case (after_e = false, 46): // .
696
695
  return (!has_dot && !has_x && !has_e) ? (has_dot = true) : false;
697
- }
698
-
699
- if (ch === "n") {
696
+ case 110: // n
700
697
  is_big_int = true;
701
-
702
698
  return true;
703
699
  }
704
700
 
705
- return RE_NUM_LITERAL.test(ch);
701
+ return (
702
+ code >= 48 && code <= 57 // 0-9
703
+ || code >= 97 && code <= 102 // a-f
704
+ || code >= 65 && code <= 70 // A-F
705
+ );
706
706
  });
707
707
  if (prefix) num = prefix + num;
708
708
 
@@ -719,7 +719,7 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
719
719
  }
720
720
  num = num.replace(/_/g, "");
721
721
  }
722
- if (num.endsWith("n")) {
722
+ if (is_big_int) {
723
723
  const without_n = num.slice(0, -1);
724
724
  const allow_e = RE_HEX_NUMBER.test(without_n);
725
725
  const valid = parse_js_number(without_n, allow_e);
@@ -894,7 +894,24 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
894
894
  return next_token;
895
895
  });
896
896
 
897
- var read_name = with_eof_error("Unterminated identifier name", function() {
897
+ var read_name = function () {
898
+ let start = S.pos, end = start - 1, ch = "c";
899
+
900
+ while (
901
+ (ch = S.text.charAt(++end))
902
+ && (ch >= "a" && ch <= "z" || ch >= "A" && ch <= "Z")
903
+ );
904
+
905
+ if (end > start + 1 && ch && ch !== "\\" && !is_identifier_char(ch)) {
906
+ S.pos += end - start;
907
+ S.col += end - start;
908
+ return S.text.slice(start, S.pos);
909
+ }
910
+
911
+ return read_name_hard();
912
+ };
913
+
914
+ var read_name_hard = with_eof_error("Unterminated identifier name", function() {
898
915
  var name = [], ch, escaped = false;
899
916
  var read_escaped_identifier_char = function() {
900
917
  escaped = true;
@@ -1718,7 +1735,7 @@ function parse($TEXT, options) {
1718
1735
  return new ctor({
1719
1736
  start : args.start,
1720
1737
  end : body.end,
1721
- is_generator: is_generator,
1738
+ is_generator: is_generator || is_generator_property,
1722
1739
  async : is_async,
1723
1740
  name : name,
1724
1741
  argnames: args,
@@ -2346,7 +2363,12 @@ function parse($TEXT, options) {
2346
2363
  });
2347
2364
  break;
2348
2365
  case "big_int":
2349
- ret = new AST_BigInt({ start: tok, end: tok, value: tok.value });
2366
+ ret = new AST_BigInt({
2367
+ start: tok,
2368
+ end: tok,
2369
+ value: tok.value,
2370
+ raw: LATEST_RAW,
2371
+ });
2350
2372
  break;
2351
2373
  case "string":
2352
2374
  ret = new AST_String({
@@ -2610,7 +2632,7 @@ function parse($TEXT, options) {
2610
2632
 
2611
2633
  // Check property and fetch value
2612
2634
  if (!is("punc", ":")) {
2613
- var concise = concise_method_or_getset(name, start);
2635
+ var concise = object_or_class_property(name, start);
2614
2636
  if (concise) {
2615
2637
  a.push(concise);
2616
2638
  continue;
@@ -2645,7 +2667,7 @@ function parse($TEXT, options) {
2645
2667
  const kv = new AST_ObjectKeyVal({
2646
2668
  start: start,
2647
2669
  quote: start.quote,
2648
- key: name instanceof AST_Node ? name : "" + name,
2670
+ key: name,
2649
2671
  value: value,
2650
2672
  end: prev()
2651
2673
  });
@@ -2656,7 +2678,7 @@ function parse($TEXT, options) {
2656
2678
  });
2657
2679
 
2658
2680
  function class_(KindOfClass, is_export_default) {
2659
- var start, method, class_name, extends_, a = [];
2681
+ var start, method, class_name, extends_, properties = [];
2660
2682
 
2661
2683
  S.input.push_directives_stack(); // Push directive stack, but not scope stack
2662
2684
  S.input.add_directive("use strict");
@@ -2685,9 +2707,9 @@ function parse($TEXT, options) {
2685
2707
  while (is("punc", ";")) { next(); } // Leading semicolons are okay in class bodies.
2686
2708
  while (!is("punc", "}")) {
2687
2709
  start = S.token;
2688
- method = concise_method_or_getset(as_property_name(), start, true);
2710
+ method = object_or_class_property(as_property_name(), start, true);
2689
2711
  if (!method) { unexpected(); }
2690
- a.push(method);
2712
+ properties.push(method);
2691
2713
  while (is("punc", ";")) { next(); }
2692
2714
  }
2693
2715
  // mark in class feild,
@@ -2701,19 +2723,15 @@ function parse($TEXT, options) {
2701
2723
  start: start,
2702
2724
  name: class_name,
2703
2725
  extends: extends_,
2704
- properties: a,
2726
+ properties: properties,
2705
2727
  end: prev(),
2706
2728
  });
2707
2729
  }
2708
2730
 
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
- });
2731
+ function object_or_class_property(name, start, is_class) {
2732
+ const get_symbol_ast = (name, SymbolClass) => {
2733
+ if (typeof name === "string") {
2734
+ return new SymbolClass({ start, name, end: prev() });
2717
2735
  } else if (name === null) {
2718
2736
  unexpected();
2719
2737
  }
@@ -2761,7 +2779,7 @@ function parse($TEXT, options) {
2761
2779
  ? AST_ObjectGetter
2762
2780
  : AST_ObjectSetter;
2763
2781
 
2764
- name = get_symbol_ast(name);
2782
+ name = get_symbol_ast(name, AST_SymbolMethod);
2765
2783
  return annotate(new AccessorClass({
2766
2784
  start,
2767
2785
  static: is_static,
@@ -2778,7 +2796,7 @@ function parse($TEXT, options) {
2778
2796
  return annotate(new AccessorClass({
2779
2797
  start,
2780
2798
  static: is_static,
2781
- key: get_symbol_ast(name),
2799
+ key: get_symbol_ast(name, AST_SymbolMethod),
2782
2800
  value: create_accessor(),
2783
2801
  end: prev(),
2784
2802
  }));
@@ -2786,7 +2804,7 @@ function parse($TEXT, options) {
2786
2804
  }
2787
2805
 
2788
2806
  if (is("punc", "(")) {
2789
- name = get_symbol_ast(name);
2807
+ name = get_symbol_ast(name, AST_SymbolMethod);
2790
2808
  const AST_MethodVariant = is_private
2791
2809
  ? AST_PrivateMethod
2792
2810
  : AST_ConciseMethod;
@@ -2805,13 +2823,17 @@ function parse($TEXT, options) {
2805
2823
  }
2806
2824
 
2807
2825
  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;
2826
+ const AST_SymbolVariant = is_private
2827
+ ? AST_SymbolPrivateProperty
2828
+ : AST_SymbolClassProperty;
2812
2829
  const AST_ClassPropertyVariant = is_private
2813
2830
  ? AST_ClassPrivateProperty
2814
2831
  : AST_ClassProperty;
2832
+
2833
+ const key = get_symbol_ast(name, AST_SymbolVariant);
2834
+ const quote = key instanceof AST_SymbolClassProperty
2835
+ ? property_token.quote
2836
+ : undefined;
2815
2837
  if (is("operator", "=")) {
2816
2838
  next();
2817
2839
  return annotate(
@@ -2831,6 +2853,9 @@ function parse($TEXT, options) {
2831
2853
  || is("operator", "*")
2832
2854
  || is("punc", ";")
2833
2855
  || is("punc", "}")
2856
+ || is("string")
2857
+ || is("num")
2858
+ || is("big_int")
2834
2859
  ) {
2835
2860
  return annotate(
2836
2861
  new AST_ClassPropertyVariant({
@@ -2955,10 +2980,12 @@ function parse($TEXT, options) {
2955
2980
  } else {
2956
2981
  foreign_name = make_symbol(foreign_type, S.token.quote);
2957
2982
  }
2958
- } else if (is_import) {
2959
- name = new type(foreign_name);
2960
2983
  } else {
2961
- foreign_name = new foreign_type(name);
2984
+ if (is_import) {
2985
+ name = new type(foreign_name);
2986
+ } else {
2987
+ foreign_name = new foreign_type(name);
2988
+ }
2962
2989
  }
2963
2990
 
2964
2991
  return new AST_NameMapping({
@@ -3129,12 +3156,14 @@ function parse($TEXT, options) {
3129
3156
  case "name":
3130
3157
  case "privatename":
3131
3158
  case "string":
3132
- case "num":
3133
- case "big_int":
3134
3159
  case "keyword":
3135
3160
  case "atom":
3136
3161
  next();
3137
3162
  return tmp.value;
3163
+ case "num":
3164
+ case "big_int":
3165
+ next();
3166
+ return "" + tmp.value;
3138
3167
  default:
3139
3168
  unexpected(tmp);
3140
3169
  }
@@ -5792,7 +5821,6 @@ var AST_ConciseMethod = DEFNODE("ConciseMethod", "quote static is_generator asyn
5792
5821
 
5793
5822
  var AST_PrivateMethod = DEFNODE("PrivateMethod", "", function AST_PrivateMethod(props) {
5794
5823
  if (props) {
5795
- this.quote = props.quote;
5796
5824
  this.static = props.static;
5797
5825
  this.is_generator = props.is_generator;
5798
5826
  this.async = props.async;
@@ -5953,7 +5981,6 @@ var AST_ClassProperty = DEFNODE("ClassProperty", "static quote", function AST_Cl
5953
5981
  var AST_ClassPrivateProperty = DEFNODE("ClassPrivateProperty", "", function AST_ClassPrivateProperty(props) {
5954
5982
  if (props) {
5955
5983
  this.static = props.static;
5956
- this.quote = props.quote;
5957
5984
  this.key = props.key;
5958
5985
  this.value = props.value;
5959
5986
  this.start = props.start;
@@ -6313,12 +6340,12 @@ var AST_SymbolImport = DEFNODE("SymbolImport", null, function AST_SymbolImport(p
6313
6340
  $documentation: "Symbol referring to an imported name",
6314
6341
  }, AST_SymbolBlockDeclaration);
6315
6342
 
6316
- var AST_SymbolImportForeign = DEFNODE("SymbolImportForeign", null, function AST_SymbolImportForeign(props) {
6343
+ var AST_SymbolImportForeign = DEFNODE("SymbolImportForeign", "quote", function AST_SymbolImportForeign(props) {
6317
6344
  if (props) {
6345
+ this.quote = props.quote;
6318
6346
  this.scope = props.scope;
6319
6347
  this.name = props.name;
6320
6348
  this.thedef = props.thedef;
6321
- this.quote = props.quote;
6322
6349
  this.start = props.start;
6323
6350
  this.end = props.end;
6324
6351
  }
@@ -6365,12 +6392,12 @@ var AST_SymbolRef = DEFNODE("SymbolRef", null, function AST_SymbolRef(props) {
6365
6392
  $documentation: "Reference to some symbol (not definition/declaration)",
6366
6393
  }, AST_Symbol);
6367
6394
 
6368
- var AST_SymbolExport = DEFNODE("SymbolExport", null, function AST_SymbolExport(props) {
6395
+ var AST_SymbolExport = DEFNODE("SymbolExport", "quote", function AST_SymbolExport(props) {
6369
6396
  if (props) {
6397
+ this.quote = props.quote;
6370
6398
  this.scope = props.scope;
6371
6399
  this.name = props.name;
6372
6400
  this.thedef = props.thedef;
6373
- this.quote = props.quote;
6374
6401
  this.start = props.start;
6375
6402
  this.end = props.end;
6376
6403
  }
@@ -6380,12 +6407,12 @@ var AST_SymbolExport = DEFNODE("SymbolExport", null, function AST_SymbolExport(p
6380
6407
  $documentation: "Symbol referring to a name to export",
6381
6408
  }, AST_SymbolRef);
6382
6409
 
6383
- var AST_SymbolExportForeign = DEFNODE("SymbolExportForeign", null, function AST_SymbolExportForeign(props) {
6410
+ var AST_SymbolExportForeign = DEFNODE("SymbolExportForeign", "quote", function AST_SymbolExportForeign(props) {
6384
6411
  if (props) {
6412
+ this.quote = props.quote;
6385
6413
  this.scope = props.scope;
6386
6414
  this.name = props.name;
6387
6415
  this.thedef = props.thedef;
6388
- this.quote = props.quote;
6389
6416
  this.start = props.start;
6390
6417
  this.end = props.end;
6391
6418
  }
@@ -6500,9 +6527,10 @@ var AST_Number = DEFNODE("Number", "value raw", function AST_Number(props) {
6500
6527
  }
6501
6528
  }, AST_Constant);
6502
6529
 
6503
- var AST_BigInt = DEFNODE("BigInt", "value", function AST_BigInt(props) {
6530
+ var AST_BigInt = DEFNODE("BigInt", "value raw", function AST_BigInt(props) {
6504
6531
  if (props) {
6505
6532
  this.value = props.value;
6533
+ this.raw = props.raw;
6506
6534
  this.start = props.start;
6507
6535
  this.end = props.end;
6508
6536
  }
@@ -6511,7 +6539,8 @@ var AST_BigInt = DEFNODE("BigInt", "value", function AST_BigInt(props) {
6511
6539
  }, {
6512
6540
  $documentation: "A big int literal",
6513
6541
  $propdoc: {
6514
- value: "[string] big int value"
6542
+ value: "[string] big int value, represented as a string",
6543
+ raw: "[string] the original format preserved"
6515
6544
  }
6516
6545
  }, AST_Constant);
6517
6546
 
@@ -7169,6 +7198,7 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
7169
7198
  body[i] = new AST_Directive({
7170
7199
  start: body[i].start,
7171
7200
  end: body[i].end,
7201
+ quote: '"',
7172
7202
  value: body[i].body.value
7173
7203
  });
7174
7204
  } else {
@@ -7292,8 +7322,8 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
7292
7322
  return new AST_Defun({
7293
7323
  start: my_start_token(M),
7294
7324
  end: my_end_token(M),
7295
- name: from_moz(M.id),
7296
- argnames: M.params.map(from_moz),
7325
+ name: M.id && from_moz_symbol(AST_SymbolDefun, M.id),
7326
+ argnames: M.params.map(M => from_moz_pattern(M, AST_SymbolFunarg)),
7297
7327
  is_generator: M.generator,
7298
7328
  async: M.async,
7299
7329
  body: normalize_directives(from_moz(M.body).body)
@@ -7301,15 +7331,7 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
7301
7331
  },
7302
7332
 
7303
7333
  FunctionExpression: function(M) {
7304
- return new AST_Function({
7305
- start: my_start_token(M),
7306
- end: my_end_token(M),
7307
- name: from_moz(M.id),
7308
- argnames: M.params.map(from_moz),
7309
- is_generator: M.generator,
7310
- async: M.async,
7311
- body: normalize_directives(from_moz(M.body).body)
7312
- });
7334
+ return from_moz_lambda(M, /*is_method=*/false);
7313
7335
  },
7314
7336
 
7315
7337
  ArrowFunctionExpression: function(M) {
@@ -7319,7 +7341,7 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
7319
7341
  return new AST_Arrow({
7320
7342
  start: my_start_token(M),
7321
7343
  end: my_end_token(M),
7322
- argnames: M.params.map(from_moz),
7344
+ argnames: M.params.map(p => from_moz_pattern(p, AST_SymbolFunarg)),
7323
7345
  body,
7324
7346
  async: M.async,
7325
7347
  });
@@ -7348,59 +7370,50 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
7348
7370
  },
7349
7371
 
7350
7372
  Property: function(M) {
7351
- var key = M.key;
7352
- var args = {
7353
- start : my_start_token(key || M.value),
7354
- end : my_end_token(M.value),
7355
- key : key.type == "Identifier" ? key.name : key.value,
7356
- quote : !key.computed && key.type === "Literal" && typeof key.value === "string"
7357
- ? '"'
7358
- : null,
7359
- value : from_moz(M.value)
7360
- };
7361
- if (M.computed) {
7362
- args.key = from_moz(M.key);
7363
- }
7364
- if (M.method) {
7365
- args.is_generator = M.value.generator;
7366
- args.async = M.value.async;
7367
- if (!M.computed) {
7368
- args.key = new AST_SymbolMethod({ name: args.key });
7369
- } else {
7370
- args.key = from_moz(M.key);
7371
- }
7372
- return new AST_ConciseMethod(args);
7373
- }
7374
- if (M.kind == "init") {
7375
- if (key.type != "Identifier" && key.type != "Literal") {
7376
- args.key = from_moz(key);
7377
- }
7373
+ if (M.kind == "init" && !M.method) {
7374
+ var args = {
7375
+ start : my_start_token(M.key || M.value),
7376
+ end : my_end_token(M.value),
7377
+ key : M.computed
7378
+ ? from_moz(M.key)
7379
+ : M.key.name || String(M.key.value),
7380
+ quote : from_moz_quote(M.key, M.computed),
7381
+ static : false, // always an object
7382
+ value : from_moz(M.value)
7383
+ };
7384
+
7378
7385
  return new AST_ObjectKeyVal(args);
7379
- }
7380
- if (typeof args.key === "string" || typeof args.key === "number") {
7381
- args.key = new AST_SymbolMethod({
7382
- name: args.key
7383
- });
7384
- }
7385
- args.value = new AST_Accessor(args.value);
7386
- if (M.kind == "get") return new AST_ObjectGetter(args);
7387
- if (M.kind == "set") return new AST_ObjectSetter(args);
7388
- if (M.kind == "method") {
7389
- args.async = M.value.async;
7390
- args.is_generator = M.value.generator;
7391
- return new AST_ConciseMethod(args);
7386
+ } else {
7387
+ var value = from_moz_lambda(M.value, /*is_method=*/true);
7388
+ var args = {
7389
+ start : my_start_token(M.key || M.value),
7390
+ end : my_end_token(M.value),
7391
+ key : M.computed
7392
+ ? from_moz(M.key)
7393
+ : from_moz_symbol(AST_SymbolMethod, M.key),
7394
+ quote : from_moz_quote(M.key, M.computed),
7395
+ is_generator: value.is_generator,
7396
+ async : value.async,
7397
+ static : false, // always an object
7398
+ value,
7399
+ };
7400
+
7401
+ if (M.kind == "get") return new AST_ObjectGetter(args);
7402
+ if (M.kind == "set") return new AST_ObjectSetter(args);
7403
+ if (M.method) return new AST_ConciseMethod(args);
7392
7404
  }
7393
7405
  },
7394
7406
 
7395
7407
  MethodDefinition: function(M) {
7396
7408
  const is_private = M.key.type === "PrivateIdentifier";
7397
- const key = M.computed ? from_moz(M.key) : new AST_SymbolMethod({ name: M.key.name || M.key.value });
7409
+ const key = M.computed ? from_moz(M.key) : new AST_SymbolMethod({ name: M.key.name || String(M.key.value) });
7398
7410
 
7399
7411
  var args = {
7400
7412
  start : my_start_token(M),
7401
7413
  end : my_end_token(M),
7402
7414
  key,
7403
- value : from_moz(M.value),
7415
+ quote : from_moz_quote(M.key, M.computed),
7416
+ value : from_moz_lambda(M.value, /*is_method=*/true),
7404
7417
  static : M.static,
7405
7418
  };
7406
7419
  if (M.kind == "get") {
@@ -7425,6 +7438,7 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
7425
7438
  return new AST_ClassProperty({
7426
7439
  start : my_start_token(M),
7427
7440
  end : my_end_token(M),
7441
+ quote : from_moz_quote(M.key, M.computed),
7428
7442
  key,
7429
7443
  value : from_moz(M.value),
7430
7444
  static : M.static,
@@ -7444,15 +7458,13 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
7444
7458
  static : M.static,
7445
7459
  });
7446
7460
  } else {
7447
- if (M.key.type !== "Identifier") {
7448
- throw new Error("Non-Identifier key in PropertyDefinition");
7449
- }
7450
- key = from_moz(M.key);
7461
+ key = from_moz_symbol(AST_SymbolClassProperty, M.key);
7451
7462
  }
7452
7463
 
7453
7464
  return new AST_ClassProperty({
7454
7465
  start : my_start_token(M),
7455
7466
  end : my_end_token(M),
7467
+ quote : from_moz_quote(M.key, M.computed),
7456
7468
  key,
7457
7469
  value : from_moz(M.value),
7458
7470
  static : M.static,
@@ -7544,11 +7556,30 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
7544
7556
  },
7545
7557
 
7546
7558
  VariableDeclaration: function(M) {
7547
- return new (M.kind === "const" ? AST_Const :
7548
- M.kind === "let" ? AST_Let : AST_Var)({
7559
+ let decl_type;
7560
+ let sym_type;
7561
+ if (M.kind === "const") {
7562
+ decl_type = AST_Const;
7563
+ sym_type = AST_SymbolConst;
7564
+ } else if (M.kind === "let") {
7565
+ decl_type = AST_Let;
7566
+ sym_type = AST_SymbolLet;
7567
+ } else {
7568
+ decl_type = AST_Var;
7569
+ sym_type = AST_SymbolVar;
7570
+ }
7571
+ const definitions = M.declarations.map(M => {
7572
+ return new AST_VarDef({
7573
+ start: my_start_token(M),
7574
+ end: my_end_token(M),
7575
+ name: from_moz_pattern(M.id, sym_type),
7576
+ value: from_moz(M.init),
7577
+ });
7578
+ });
7579
+ return new decl_type({
7549
7580
  start : my_start_token(M),
7550
7581
  end : my_end_token(M),
7551
- definitions : M.declarations.map(from_moz)
7582
+ definitions : definitions,
7552
7583
  });
7553
7584
  },
7554
7585
 
@@ -7577,13 +7608,13 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
7577
7608
  return new AST_NameMapping({
7578
7609
  start: my_start_token(M),
7579
7610
  end: my_end_token(M),
7580
- foreign_name: from_moz(M.imported),
7581
- name: from_moz(M.local)
7611
+ foreign_name: from_moz_symbol(AST_SymbolImportForeign, M.imported, M.imported.type === "Literal"),
7612
+ name: from_moz_symbol(AST_SymbolImport, M.local)
7582
7613
  });
7583
7614
  },
7584
7615
 
7585
7616
  ImportDefaultSpecifier: function(M) {
7586
- return from_moz(M.local);
7617
+ return from_moz_symbol(AST_SymbolImport, M.local);
7587
7618
  },
7588
7619
 
7589
7620
  ImportNamespaceSpecifier: function(M) {
@@ -7591,7 +7622,7 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
7591
7622
  start: my_start_token(M),
7592
7623
  end: my_end_token(M),
7593
7624
  foreign_name: new AST_SymbolImportForeign({ name: "*" }),
7594
- name: from_moz(M.local)
7625
+ name: from_moz_symbol(AST_SymbolImport, M.local)
7595
7626
  });
7596
7627
  },
7597
7628
 
@@ -7613,15 +7644,17 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
7613
7644
  },
7614
7645
 
7615
7646
  ExportAllDeclaration: function(M) {
7616
- var foreign_name = M.exported == null ?
7647
+ var foreign_name = M.exported == null ?
7617
7648
  new AST_SymbolExportForeign({ name: "*" }) :
7618
- from_moz(M.exported);
7649
+ from_moz_symbol(AST_SymbolExportForeign, M.exported, M.exported.type === "Literal");
7619
7650
  return new AST_Export({
7620
7651
  start: my_start_token(M),
7621
7652
  end: my_end_token(M),
7622
7653
  exported_names: [
7623
7654
  new AST_NameMapping({
7624
- name: new AST_SymbolExportForeign({ name: "*" }),
7655
+ start: my_start_token(M),
7656
+ end: my_end_token(M),
7657
+ name: new AST_SymbolExport({ name: "*" }),
7625
7658
  foreign_name: foreign_name
7626
7659
  })
7627
7660
  ],
@@ -7664,8 +7697,10 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
7664
7697
 
7665
7698
  ExportSpecifier: function(M) {
7666
7699
  return new AST_NameMapping({
7667
- foreign_name: from_moz(M.exported),
7668
- name: from_moz(M.local)
7700
+ start: my_start_token(M),
7701
+ end: my_end_token(M),
7702
+ foreign_name: from_moz_symbol(AST_SymbolExportForeign, M.exported, M.exported.type === "Literal"),
7703
+ name: from_moz_symbol(AST_SymbolExport, M.local, M.local.type === "Literal"),
7669
7704
  });
7670
7705
  },
7671
7706
 
@@ -7694,27 +7729,13 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
7694
7729
  const bi = typeof M.value === "bigint" ? M.value.toString() : M.bigint;
7695
7730
  if (typeof bi === "string") {
7696
7731
  args.value = bi;
7732
+ args.raw = M.raw;
7697
7733
  return new AST_BigInt(args);
7698
7734
  }
7699
7735
  if (val === null) return new AST_Null(args);
7700
7736
  switch (typeof val) {
7701
7737
  case "string":
7702
7738
  args.quote = "\"";
7703
- var p = FROM_MOZ_STACK[FROM_MOZ_STACK.length - 2];
7704
- if (p.type == "ImportSpecifier") {
7705
- args.name = val;
7706
- return new AST_SymbolImportForeign(args);
7707
- } else if (p.type == "ExportSpecifier") {
7708
- args.name = val;
7709
- if (M == p.exported) {
7710
- return new AST_SymbolExportForeign(args);
7711
- } else {
7712
- return new AST_SymbolExport(args);
7713
- }
7714
- } else if (p.type == "ExportAllDeclaration" && M == p.exported) {
7715
- args.name = val;
7716
- return new AST_SymbolExportForeign(args);
7717
- }
7718
7739
  args.value = val;
7719
7740
  return new AST_String(args);
7720
7741
  case "number":
@@ -7741,27 +7762,11 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
7741
7762
  },
7742
7763
 
7743
7764
  Identifier: function(M) {
7744
- var p = FROM_MOZ_STACK[FROM_MOZ_STACK.length - 2];
7745
- var q = FROM_MOZ_STACK[FROM_MOZ_STACK.length - 3];
7746
- return new ( p.type == "LabeledStatement" ? AST_Label
7747
- : p.type == "VariableDeclarator" && p.id === M ? (q.kind == "const" ? AST_SymbolConst : q.kind == "let" ? AST_SymbolLet : AST_SymbolVar)
7748
- : /Import.*Specifier/.test(p.type) ? (p.local === M ? AST_SymbolImport : AST_SymbolImportForeign)
7749
- : p.type == "ExportSpecifier" ? (p.local === M ? AST_SymbolExport : AST_SymbolExportForeign)
7750
- : p.type == "FunctionExpression" ? (p.id === M ? AST_SymbolLambda : AST_SymbolFunarg)
7751
- : p.type == "FunctionDeclaration" ? (p.id === M ? AST_SymbolDefun : AST_SymbolFunarg)
7752
- : p.type == "ArrowFunctionExpression" ? (p.params.includes(M)) ? AST_SymbolFunarg : AST_SymbolRef
7753
- : p.type == "ClassExpression" ? (p.id === M ? AST_SymbolClass : AST_SymbolRef)
7754
- : p.type == "Property" ? (p.key === M && p.computed || p.value === M ? AST_SymbolRef : AST_SymbolMethod)
7755
- : p.type == "PropertyDefinition" || p.type === "FieldDefinition" ? (p.key === M && p.computed || p.value === M ? AST_SymbolRef : AST_SymbolClassProperty)
7756
- : p.type == "ClassDeclaration" ? (p.id === M ? AST_SymbolDefClass : AST_SymbolRef)
7757
- : p.type == "MethodDefinition" ? (p.computed ? AST_SymbolRef : AST_SymbolMethod)
7758
- : p.type == "CatchClause" ? AST_SymbolCatch
7759
- : p.type == "BreakStatement" || p.type == "ContinueStatement" ? AST_LabelRef
7760
- : AST_SymbolRef)({
7761
- start : my_start_token(M),
7762
- end : my_end_token(M),
7763
- name : M.name
7764
- });
7765
+ return new AST_SymbolRef({
7766
+ start : my_start_token(M),
7767
+ end : my_end_token(M),
7768
+ name : M.name
7769
+ });
7765
7770
  },
7766
7771
 
7767
7772
  EmptyStatement: function(M) {
@@ -7790,19 +7795,28 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
7790
7795
  },
7791
7796
 
7792
7797
  LabeledStatement: function(M) {
7793
- return new AST_LabeledStatement({
7794
- start: my_start_token(M),
7795
- end: my_end_token(M),
7796
- label: from_moz(M.label),
7797
- body: from_moz(M.body)
7798
- });
7798
+ try {
7799
+ const label = from_moz_symbol(AST_Label, M.label);
7800
+ FROM_MOZ_LABELS.push(label);
7801
+
7802
+ const stat = new AST_LabeledStatement({
7803
+ start: my_start_token(M),
7804
+ end: my_end_token(M),
7805
+ label,
7806
+ body: from_moz(M.body)
7807
+ });
7808
+
7809
+ return stat;
7810
+ } finally {
7811
+ FROM_MOZ_LABELS.pop();
7812
+ }
7799
7813
  },
7800
7814
 
7801
7815
  BreakStatement: function(M) {
7802
7816
  return new AST_Break({
7803
7817
  start: my_start_token(M),
7804
7818
  end: my_end_token(M),
7805
- label: from_moz(M.label)
7819
+ label: from_moz_label_ref(M.label),
7806
7820
  });
7807
7821
  },
7808
7822
 
@@ -7810,7 +7824,7 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
7810
7824
  return new AST_Continue({
7811
7825
  start: my_start_token(M),
7812
7826
  end: my_end_token(M),
7813
- label: from_moz(M.label)
7827
+ label: from_moz_label_ref(M.label),
7814
7828
  });
7815
7829
  },
7816
7830
 
@@ -7922,20 +7936,11 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
7922
7936
  });
7923
7937
  },
7924
7938
 
7925
- VariableDeclarator: function(M) {
7926
- return new AST_VarDef({
7927
- start: my_start_token(M),
7928
- end: my_end_token(M),
7929
- name: from_moz(M.id),
7930
- value: from_moz(M.init)
7931
- });
7932
- },
7933
-
7934
7939
  CatchClause: function(M) {
7935
7940
  return new AST_Catch({
7936
7941
  start: my_start_token(M),
7937
7942
  end: my_end_token(M),
7938
- argname: from_moz(M.param),
7943
+ argname: M.param ? from_moz_pattern(M.param, AST_SymbolCatch) : null,
7939
7944
  body: from_moz(M.body).body
7940
7945
  });
7941
7946
  },
@@ -7943,6 +7948,7 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
7943
7948
  ThisExpression: function(M) {
7944
7949
  return new AST_This({
7945
7950
  start: my_start_token(M),
7951
+ name: "this",
7946
7952
  end: my_end_token(M)
7947
7953
  });
7948
7954
  },
@@ -7950,7 +7956,8 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
7950
7956
  Super: function(M) {
7951
7957
  return new AST_Super({
7952
7958
  start: my_start_token(M),
7953
- end: my_end_token(M)
7959
+ end: my_end_token(M),
7960
+ name: "super",
7954
7961
  });
7955
7962
  },
7956
7963
 
@@ -7991,6 +7998,7 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
7991
7998
  start: my_start_token(M),
7992
7999
  end: my_end_token(M),
7993
8000
  operator: M.operator,
8001
+ logical: M.operator === "??=" || M.operator === "&&=" || M.operator === "||=",
7994
8002
  left: from_moz(M.left),
7995
8003
  right: from_moz(M.right)
7996
8004
  });
@@ -8043,7 +8051,7 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
8043
8051
  return new (M.type === "ClassDeclaration" ? AST_DefClass : AST_ClassExpression)({
8044
8052
  start : my_start_token(M),
8045
8053
  end : my_end_token(M),
8046
- name : from_moz(M.id),
8054
+ name : M.id && from_moz_symbol(M.type === "ClassDeclaration" ? AST_SymbolDefClass : AST_SymbolClass, M.id),
8047
8055
  extends : from_moz(M.superClass),
8048
8056
  properties: M.body.body.map(from_moz)
8049
8057
  });
@@ -8178,13 +8186,6 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
8178
8186
  init: to_moz(M.value)
8179
8187
  };
8180
8188
  });
8181
- def_to_moz(AST_Catch, function To_Moz_CatchClause(M) {
8182
- return {
8183
- type: "CatchClause",
8184
- param: to_moz(M.argname),
8185
- body: to_moz_block(M)
8186
- };
8187
- });
8188
8189
 
8189
8190
  def_to_moz(AST_This, function To_Moz_ThisExpression() {
8190
8191
  return {
@@ -8217,7 +8218,7 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
8217
8218
  return {
8218
8219
  type: "ImportExpression",
8219
8220
  source,
8220
- options
8221
+ options: options || null
8221
8222
  };
8222
8223
  }
8223
8224
 
@@ -8276,7 +8277,7 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
8276
8277
  return {
8277
8278
  type: "FunctionDeclaration",
8278
8279
  id: to_moz(M.name),
8279
- params: M.argnames.map(to_moz),
8280
+ params: M.argnames.map(to_moz_pattern),
8280
8281
  generator: M.is_generator,
8281
8282
  async: M.async,
8282
8283
  body: to_moz_scope("BlockStatement", M)
@@ -8284,28 +8285,31 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
8284
8285
  });
8285
8286
 
8286
8287
  def_to_moz(AST_Function, function To_Moz_FunctionExpression(M, parent) {
8287
- var is_generator = parent.is_generator !== undefined ?
8288
- parent.is_generator : M.is_generator;
8288
+ var is_generator = parent.is_generator !== undefined
8289
+ ? parent.is_generator
8290
+ : M.is_generator;
8289
8291
  return {
8290
8292
  type: "FunctionExpression",
8291
8293
  id: to_moz(M.name),
8292
- params: M.argnames.map(to_moz),
8293
- generator: is_generator,
8294
- async: M.async,
8294
+ params: M.argnames.map(to_moz_pattern),
8295
+ generator: is_generator || false,
8296
+ async: M.async || false,
8295
8297
  body: to_moz_scope("BlockStatement", M)
8296
8298
  };
8297
8299
  });
8298
8300
 
8299
8301
  def_to_moz(AST_Arrow, function To_Moz_ArrowFunctionExpression(M) {
8300
- var body = {
8301
- type: "BlockStatement",
8302
- body: M.body.map(to_moz)
8303
- };
8302
+ var body = M.body.length === 1 && M.body[0] instanceof AST_Return && M.body[0].value
8303
+ ? to_moz(M.body[0].value)
8304
+ : {
8305
+ type: "BlockStatement",
8306
+ body: M.body.map(to_moz)
8307
+ };
8304
8308
  return {
8305
8309
  type: "ArrowFunctionExpression",
8306
- params: M.argnames.map(to_moz),
8310
+ params: M.argnames.map(to_moz_pattern),
8307
8311
  async: M.async,
8308
- body: body
8312
+ body: body,
8309
8313
  };
8310
8314
  });
8311
8315
 
@@ -8313,19 +8317,38 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
8313
8317
  if (M.is_array) {
8314
8318
  return {
8315
8319
  type: "ArrayPattern",
8316
- elements: M.names.map(to_moz)
8320
+ elements: M.names.map(
8321
+ M => M instanceof AST_Hole ? null : to_moz_pattern(M)
8322
+ ),
8317
8323
  };
8318
8324
  }
8319
8325
  return {
8320
8326
  type: "ObjectPattern",
8321
- properties: M.names.map(to_moz)
8327
+ properties: M.names.map(M => {
8328
+ if (M instanceof AST_ObjectKeyVal) {
8329
+ var computed = M.computed_key();
8330
+ const [shorthand, key] = to_moz_property_key(M.key, computed, M.quote, M.value);
8331
+
8332
+ return {
8333
+ type: "Property",
8334
+ computed,
8335
+ kind: "init",
8336
+ key: key,
8337
+ method: false,
8338
+ shorthand,
8339
+ value: to_moz_pattern(M.value)
8340
+ };
8341
+ } else {
8342
+ return to_moz_pattern(M);
8343
+ }
8344
+ }),
8322
8345
  };
8323
8346
  });
8324
8347
 
8325
8348
  def_to_moz(AST_DefaultAssign, function To_Moz_AssignmentExpression(M) {
8326
8349
  return {
8327
8350
  type: "AssignmentPattern",
8328
- left: to_moz(M.left),
8351
+ left: to_moz_pattern(M.left),
8329
8352
  right: to_moz(M.right),
8330
8353
  };
8331
8354
  });
@@ -8370,8 +8393,7 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
8370
8393
  def_to_moz(AST_Catch, function To_Moz_CatchClause(M) {
8371
8394
  return {
8372
8395
  type: "CatchClause",
8373
- param: to_moz(M.argname),
8374
- guard: null,
8396
+ param: M.argname != null ? to_moz_pattern(M.argname) : null,
8375
8397
  body: to_moz_block(M)
8376
8398
  };
8377
8399
  });
@@ -8432,10 +8454,20 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
8432
8454
  attributes: import_attributes_to_moz(M.attributes)
8433
8455
  };
8434
8456
  }
8435
- return {
8436
- type: M.is_default ? "ExportDefaultDeclaration" : "ExportNamedDeclaration",
8437
- declaration: to_moz(M.exported_value || M.exported_definition)
8438
- };
8457
+
8458
+ if (M.is_default) {
8459
+ return {
8460
+ type: "ExportDefaultDeclaration",
8461
+ declaration: to_moz(M.exported_value || M.exported_definition),
8462
+ };
8463
+ } else {
8464
+ return {
8465
+ type: "ExportNamedDeclaration",
8466
+ declaration: to_moz(M.exported_value || M.exported_definition),
8467
+ specifiers: [],
8468
+ source: null,
8469
+ };
8470
+ }
8439
8471
  });
8440
8472
 
8441
8473
  def_to_moz(AST_Import, function To_Moz_ImportDeclaration(M) {
@@ -8586,35 +8618,10 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
8586
8618
  });
8587
8619
 
8588
8620
  def_to_moz(AST_ObjectProperty, function To_Moz_Property(M, parent) {
8589
- var key = M.key instanceof AST_Node ? to_moz(M.key) : {
8590
- type: "Identifier",
8591
- value: M.key,
8592
- };
8593
- if (typeof M.key === "number") {
8594
- key = {
8595
- type: "Literal",
8596
- value: Number(M.key)
8597
- };
8598
- }
8599
- if (typeof M.key === "string") {
8600
- key = M.quote
8601
- ? {
8602
- type: "Literal",
8603
- value: M.key,
8604
- raw: JSON.stringify(M.key),
8605
- }
8606
- : {
8607
- type: "Identifier",
8608
- name: M.key,
8609
- };
8610
- }
8621
+ var computed = M.computed_key();
8622
+ const [shorthand, key] = to_moz_property_key(M.key, computed, M.quote, M.value);
8623
+
8611
8624
  var kind;
8612
- var string_or_num = typeof M.key === "string" || typeof M.key === "number";
8613
- var computed = string_or_num ? false : !(M.key instanceof AST_Symbol) || M.key instanceof AST_SymbolRef;
8614
- if (M instanceof AST_ObjectKeyVal) {
8615
- kind = "init";
8616
- computed = !string_or_num;
8617
- } else
8618
8625
  if (M instanceof AST_ObjectGetter) {
8619
8626
  kind = "get";
8620
8627
  } else
@@ -8669,31 +8676,51 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
8669
8676
  return {
8670
8677
  type: "Property",
8671
8678
  computed: computed,
8679
+ method: false,
8680
+ shorthand,
8672
8681
  kind: kind,
8673
8682
  key: key,
8674
8683
  value: to_moz(M.value)
8675
8684
  };
8676
8685
  });
8677
8686
 
8687
+ def_to_moz(AST_ObjectKeyVal, function To_Moz_Property(M) {
8688
+ var computed = M.computed_key();
8689
+ const [shorthand, key] = to_moz_property_key(M.key, computed, M.quote, M.value);
8690
+
8691
+ return {
8692
+ type: "Property",
8693
+ computed: computed,
8694
+ shorthand: shorthand,
8695
+ method: false,
8696
+ kind: "init",
8697
+ key: key,
8698
+ value: to_moz(M.value)
8699
+ };
8700
+ });
8701
+
8678
8702
  def_to_moz(AST_ConciseMethod, function To_Moz_MethodDefinition(M, parent) {
8703
+ const computed = M.computed_key();
8704
+ const [_always_false, key] = to_moz_property_key(M.key, computed, M.quote, M.value);
8705
+
8679
8706
  if (parent instanceof AST_Object) {
8680
8707
  return {
8681
8708
  type: "Property",
8682
- computed: !(M.key instanceof AST_Symbol) || M.key instanceof AST_SymbolRef,
8683
8709
  kind: "init",
8710
+ computed,
8684
8711
  method: true,
8685
8712
  shorthand: false,
8686
- key: to_moz(M.key),
8687
- value: to_moz(M.value)
8713
+ key,
8714
+ value: to_moz(M.value),
8688
8715
  };
8689
8716
  }
8690
8717
 
8691
8718
  return {
8692
8719
  type: "MethodDefinition",
8693
- kind: M.key === "constructor" ? "constructor" : "method",
8694
- key: to_moz(M.key),
8720
+ kind: !computed && M.key.name === "constructor" ? "constructor" : "method",
8721
+ computed,
8722
+ key,
8695
8723
  value: to_moz(M.value),
8696
- computed: !(M.key instanceof AST_Symbol) || M.key instanceof AST_SymbolRef,
8697
8724
  static: M.static,
8698
8725
  };
8699
8726
  });
@@ -8799,6 +8826,7 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
8799
8826
  // `M.value` is a string that may be a hex number representation.
8800
8827
  // but "bigint" property should have only decimal digits
8801
8828
  bigint: typeof BigInt === "function" ? BigInt(M.value).toString() : M.value,
8829
+ raw: M.raw,
8802
8830
  }));
8803
8831
 
8804
8832
  AST_Boolean.DEFMETHOD("to_mozilla_ast", AST_Constant.prototype.to_mozilla_ast);
@@ -8842,20 +8870,133 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
8842
8870
  );
8843
8871
  }
8844
8872
 
8845
- var FROM_MOZ_STACK = null;
8873
+ var FROM_MOZ_LABELS = null;
8846
8874
 
8847
8875
  function from_moz(node) {
8848
- FROM_MOZ_STACK.push(node);
8849
- var ret = node != null ? MOZ_TO_ME[node.type](node) : null;
8850
- FROM_MOZ_STACK.pop();
8851
- return ret;
8876
+ if (node == null) return null;
8877
+ return MOZ_TO_ME[node.type](node);
8878
+ }
8879
+
8880
+ function from_moz_quote(moz_key, computed) {
8881
+ if (!computed && moz_key.type === "Literal" && typeof moz_key.value === "string") {
8882
+ return '"';
8883
+ } else {
8884
+ return "";
8885
+ }
8886
+ }
8887
+
8888
+ function from_moz_symbol(symbol_type, M, has_quote) {
8889
+ return new symbol_type({
8890
+ start: my_start_token(M),
8891
+ quote: has_quote ? '"' : undefined,
8892
+ name: M.type === "Identifier" ? M.name : String(M.value),
8893
+ end: my_end_token(M),
8894
+ });
8895
+ }
8896
+
8897
+ function from_moz_lambda(M, is_method) {
8898
+ return new (is_method ? AST_Accessor : AST_Function)({
8899
+ start: my_start_token(M),
8900
+ end: my_end_token(M),
8901
+ name: M.id && from_moz_symbol(is_method ? AST_SymbolMethod : AST_SymbolLambda, M.id),
8902
+ argnames: M.params.map(M => from_moz_pattern(M, AST_SymbolFunarg)),
8903
+ is_generator: M.generator,
8904
+ async: M.async,
8905
+ body: normalize_directives(from_moz(M.body).body)
8906
+ });
8907
+ }
8908
+
8909
+ function from_moz_pattern(M, sym_type) {
8910
+ switch (M.type) {
8911
+ case "ObjectPattern":
8912
+ return new AST_Destructuring({
8913
+ start: my_start_token(M),
8914
+ end: my_end_token(M),
8915
+ names: M.properties.map(p => from_moz_pattern(p, sym_type)),
8916
+ is_array: false
8917
+ });
8918
+
8919
+ case "Property":
8920
+ var key = M.key;
8921
+ var args = {
8922
+ start : my_start_token(key || M.value),
8923
+ end : my_end_token(M.value),
8924
+ key : key.type == "Identifier" ? key.name : String(key.value),
8925
+ quote : !M.computed && key.type === "Literal" && typeof key.value === "string"
8926
+ ? '"'
8927
+ : "",
8928
+ value : from_moz_pattern(M.value, sym_type)
8929
+ };
8930
+ if (M.computed) {
8931
+ args.key = from_moz(M.key);
8932
+ }
8933
+ return new AST_ObjectKeyVal(args);
8934
+
8935
+ case "ArrayPattern":
8936
+ return new AST_Destructuring({
8937
+ start: my_start_token(M),
8938
+ end: my_end_token(M),
8939
+ names: M.elements.map(function(elm) {
8940
+ if (elm === null) {
8941
+ return new AST_Hole();
8942
+ }
8943
+ return from_moz_pattern(elm, sym_type);
8944
+ }),
8945
+ is_array: true
8946
+ });
8947
+
8948
+ case "SpreadElement":
8949
+ case "RestElement":
8950
+ return new AST_Expansion({
8951
+ start: my_start_token(M),
8952
+ end: my_end_token(M),
8953
+ expression: from_moz_pattern(M.argument, sym_type),
8954
+ });
8955
+
8956
+ case "AssignmentPattern":
8957
+ return new AST_DefaultAssign({
8958
+ start : my_start_token(M),
8959
+ end : my_end_token(M),
8960
+ left : from_moz_pattern(M.left, sym_type),
8961
+ operator: "=",
8962
+ right : from_moz(M.right),
8963
+ });
8964
+
8965
+ case "Identifier":
8966
+ return new sym_type({
8967
+ start : my_start_token(M),
8968
+ end : my_end_token(M),
8969
+ name : M.name,
8970
+ });
8971
+
8972
+ default:
8973
+ throw new Error("Invalid node type for destructuring: " + M.type);
8974
+ }
8975
+ }
8976
+
8977
+ function from_moz_label_ref(m_label) {
8978
+ if (!m_label) return null;
8979
+
8980
+ const label = from_moz_symbol(AST_LabelRef, m_label);
8981
+
8982
+ let i = FROM_MOZ_LABELS.length;
8983
+ while (i--) {
8984
+ const label_origin = FROM_MOZ_LABELS[i];
8985
+
8986
+ if (label.name === label_origin.name) {
8987
+ label.thedef = label_origin;
8988
+ break;
8989
+ }
8990
+ }
8991
+
8992
+ return label;
8852
8993
  }
8853
8994
 
8854
8995
  AST_Node.from_mozilla_ast = function(node) {
8855
- var save_stack = FROM_MOZ_STACK;
8856
- FROM_MOZ_STACK = [];
8996
+ var save_labels = FROM_MOZ_LABELS;
8997
+ FROM_MOZ_LABELS = [];
8857
8998
  var ast = from_moz(node);
8858
- FROM_MOZ_STACK = save_stack;
8999
+ FROM_MOZ_LABELS = save_labels;
8859
9000
  return ast;
8860
9001
  };
8861
9002
 
@@ -8897,6 +9038,52 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
8897
9038
  return ast;
8898
9039
  }
8899
9040
 
9041
+ /** Object property keys can be number literals, string literals, or raw names. Additionally they can be shorthand. We decide that here. */
9042
+ function to_moz_property_key(key, computed = false, quote = false, value = null) {
9043
+ if (computed) {
9044
+ return [false, to_moz(key)];
9045
+ }
9046
+
9047
+ const key_name = typeof key === "string" ? key : key.name;
9048
+ let moz_key;
9049
+ if (quote) {
9050
+ moz_key = { type: "Literal", value: key_name, raw: JSON.stringify(key_name) };
9051
+ } else if ("" + +key_name === key_name && +key_name >= 0) {
9052
+ // representable as a number
9053
+ moz_key = { type: "Literal", value: +key_name, raw: JSON.stringify(+key_name) };
9054
+ } else {
9055
+ moz_key = { type: "Identifier", name: key_name };
9056
+ }
9057
+
9058
+ const shorthand =
9059
+ moz_key.type === "Identifier"
9060
+ && moz_key.name === key_name
9061
+ && (value instanceof AST_Symbol && value.name === key_name
9062
+ || value instanceof AST_DefaultAssign && value.left.name === key_name);
9063
+ return [shorthand, moz_key];
9064
+ }
9065
+
9066
+ function to_moz_pattern(node) {
9067
+ if (node instanceof AST_Expansion) {
9068
+ return {
9069
+ type: "RestElement",
9070
+ argument: to_moz_pattern(node.expression),
9071
+ };
9072
+ }
9073
+
9074
+ if ((
9075
+ node instanceof AST_Symbol
9076
+ || node instanceof AST_Destructuring
9077
+ || node instanceof AST_DefaultAssign
9078
+ || node instanceof AST_PropAccess
9079
+ )) {
9080
+ // Plain translation
9081
+ return to_moz(node);
9082
+ }
9083
+
9084
+ throw new Error(node.TYPE);
9085
+ }
9086
+
8900
9087
  function to_moz_in_destructuring() {
8901
9088
  var i = TO_MOZ_STACK.length;
8902
9089
  while (i--) {
@@ -10653,11 +10840,11 @@ function OutputStream(options) {
10653
10840
  foreign_name.name;
10654
10841
  if (!names_are_different &&
10655
10842
  foreign_name.name === "*" &&
10656
- foreign_name.quote != self.name.quote) {
10843
+ !!foreign_name.quote != !!self.name.quote) {
10657
10844
  // export * as "*"
10658
10845
  names_are_different = true;
10659
10846
  }
10660
- var foreign_name_is_name = foreign_name.quote == null;
10847
+ var foreign_name_is_name = !foreign_name.quote;
10661
10848
  if (names_are_different) {
10662
10849
  if (is_import) {
10663
10850
  if (foreign_name_is_name) {
@@ -10666,7 +10853,7 @@ function OutputStream(options) {
10666
10853
  output.print_string(foreign_name.name, foreign_name.quote);
10667
10854
  }
10668
10855
  } else {
10669
- if (self.name.quote == null) {
10856
+ if (!self.name.quote) {
10670
10857
  self.name.print(output);
10671
10858
  } else {
10672
10859
  output.print_string(self.name.name, self.name.quote);
@@ -10686,7 +10873,7 @@ function OutputStream(options) {
10686
10873
  }
10687
10874
  }
10688
10875
  } else {
10689
- if (self.name.quote == null) {
10876
+ if (!self.name.quote) {
10690
10877
  self.name.print(output);
10691
10878
  } else {
10692
10879
  output.print_string(self.name.name, self.name.quote);
@@ -11075,7 +11262,7 @@ function OutputStream(options) {
11075
11262
 
11076
11263
  output.print("#");
11077
11264
 
11078
- print_property_name(self.key.name, self.quote, output);
11265
+ print_property_name(self.key.name, undefined, output);
11079
11266
 
11080
11267
  if (self.value) {
11081
11268
  output.print("=");
@@ -11203,7 +11390,11 @@ function OutputStream(options) {
11203
11390
  }
11204
11391
  });
11205
11392
  DEFPRINT(AST_BigInt, function(self, output) {
11206
- output.print(self.getValue() + "n");
11393
+ if (output.option("keep_numbers") && self.raw) {
11394
+ output.print(self.raw);
11395
+ } else {
11396
+ output.print(self.getValue() + "n");
11397
+ }
11207
11398
  });
11208
11399
 
11209
11400
  const r_slash_script = /(<\s*\/\s*script)/i;
@@ -11491,13 +11682,13 @@ AST_VarDef.prototype.shallow_cmp = function(other) {
11491
11682
  AST_NameMapping.prototype.shallow_cmp = pass_through;
11492
11683
 
11493
11684
  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);
11685
+ 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
11686
  };
11496
11687
 
11497
11688
  AST_ImportMeta.prototype.shallow_cmp = pass_through;
11498
11689
 
11499
11690
  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;
11691
+ 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
11692
  };
11502
11693
 
11503
11694
  AST_Call.prototype.shallow_cmp = pass_through;
@@ -11524,6 +11715,8 @@ AST_Binary.prototype.shallow_cmp = function(other) {
11524
11715
  return this.operator === other.operator;
11525
11716
  };
11526
11717
 
11718
+ AST_PrivateIn.prototype.shallow_cmp = pass_through;
11719
+
11527
11720
  AST_Conditional.prototype.shallow_cmp = pass_through;
11528
11721
 
11529
11722
  AST_Array.prototype.shallow_cmp = pass_through;
@@ -11533,7 +11726,7 @@ AST_Object.prototype.shallow_cmp = pass_through;
11533
11726
  AST_ObjectProperty.prototype.shallow_cmp = pass_through;
11534
11727
 
11535
11728
  AST_ObjectKeyVal.prototype.shallow_cmp = function(other) {
11536
- return this.key === other.key;
11729
+ return this.key === other.key && this.quote === other.quote;
11537
11730
  };
11538
11731
 
11539
11732
  AST_ObjectSetter.prototype.shallow_cmp = function(other) {