terser 5.17.5 → 5.17.6

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,10 @@
1
1
  # Changelog
2
2
 
3
+ ## v5.17.6
4
+ - Fixes to mozilla AST input and output, for class properties, private properties and static blocks
5
+ - Fix outputting a shorthand property in quotes when safari10 and ecma=2015 options are enabled
6
+ - `configurable` and `enumerable`, used in Object.defineProperty, added to domprops (#1393)
7
+
3
8
  ## v5.17.5
4
9
  - Take into account the non-deferred bits of a class, such as static properties, while dropping unused code.
5
10
 
@@ -7338,22 +7338,25 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
7338
7338
  },
7339
7339
 
7340
7340
  MethodDefinition: function(M) {
7341
+ const is_private = M.key.type === "PrivateIdentifier";
7342
+ const key = M.computed ? from_moz(M.key) : new AST_SymbolMethod({ name: M.key.name || M.key.value });
7343
+
7341
7344
  var args = {
7342
7345
  start : my_start_token(M),
7343
7346
  end : my_end_token(M),
7344
- key : M.computed ? from_moz(M.key) : new AST_SymbolMethod({ name: M.key.name || M.key.value }),
7347
+ key,
7345
7348
  value : from_moz(M.value),
7346
7349
  static : M.static,
7347
7350
  };
7348
7351
  if (M.kind == "get") {
7349
- return new AST_ObjectGetter(args);
7352
+ return new (is_private ? AST_PrivateGetter : AST_ObjectGetter)(args);
7350
7353
  }
7351
7354
  if (M.kind == "set") {
7352
- return new AST_ObjectSetter(args);
7355
+ return new (is_private ? AST_PrivateSetter : AST_ObjectSetter)(args);
7353
7356
  }
7354
7357
  args.is_generator = M.value.generator;
7355
7358
  args.async = M.value.async;
7356
- return new AST_ConciseMethod(args);
7359
+ return new (is_private ? AST_PrivateMethod : AST_ConciseMethod)(args);
7357
7360
  },
7358
7361
 
7359
7362
  FieldDefinition: function(M) {
@@ -7377,8 +7380,16 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
7377
7380
  let key;
7378
7381
  if (M.computed) {
7379
7382
  key = from_moz(M.key);
7383
+ } else if (M.key.type === "PrivateIdentifier") {
7384
+ return new AST_ClassPrivateProperty({
7385
+ start : my_start_token(M),
7386
+ end : my_end_token(M),
7387
+ key : from_moz(M.key),
7388
+ value : from_moz(M.value),
7389
+ static : M.static,
7390
+ });
7380
7391
  } else {
7381
- if (M.key.type !== "Identifier" && M.key.type !== "PrivateIdentifier") {
7392
+ if (M.key.type !== "Identifier") {
7382
7393
  throw new Error("Non-Identifier key in PropertyDefinition");
7383
7394
  }
7384
7395
  key = from_moz(M.key);
@@ -7393,6 +7404,14 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
7393
7404
  });
7394
7405
  },
7395
7406
 
7407
+ PrivateIdentifier: function (M) {
7408
+ return new AST_SymbolPrivateProperty({
7409
+ start: my_start_token(M),
7410
+ end: my_end_token(M),
7411
+ name: M.name
7412
+ });
7413
+ },
7414
+
7396
7415
  StaticBlock: function(M) {
7397
7416
  return new AST_ClassStaticBlock({
7398
7417
  start : my_start_token(M),
@@ -7434,6 +7453,15 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
7434
7453
  },
7435
7454
 
7436
7455
  MemberExpression: function(M) {
7456
+ if (M.property.type === "PrivateIdentifier") {
7457
+ return new AST_DotHash({
7458
+ start : my_start_token(M),
7459
+ end : my_end_token(M),
7460
+ property : M.property.name,
7461
+ expression : from_moz(M.object),
7462
+ optional : M.optional || false
7463
+ });
7464
+ }
7437
7465
  return new (M.computed ? AST_Sub : AST_Dot)({
7438
7466
  start : my_start_token(M),
7439
7467
  end : my_end_token(M),
@@ -10635,7 +10663,7 @@ function OutputStream(options) {
10635
10663
  ? output.option("ie8")
10636
10664
  : !is_identifier_string(
10637
10665
  prop,
10638
- output.option("ecma") >= 2015 || output.option("safari10")
10666
+ output.option("ecma") >= 2015 && !output.option("safari10")
10639
10667
  );
10640
10668
 
10641
10669
  if (self.optional) output.print("?.");
@@ -10803,15 +10831,19 @@ function OutputStream(options) {
10803
10831
  output.print("new.target");
10804
10832
  });
10805
10833
 
10834
+ /** Prints a prop name. Returns whether it can be used as a shorthand. */
10806
10835
  function print_property_name(key, quote, output) {
10807
10836
  if (output.option("quote_keys")) {
10808
- return output.print_string(key);
10837
+ output.print_string(key);
10838
+ return false;
10809
10839
  }
10810
10840
  if ("" + +key == key && key >= 0) {
10811
10841
  if (output.option("keep_numbers")) {
10812
- return output.print(key);
10842
+ output.print(key);
10843
+ return false;
10813
10844
  }
10814
- return output.print(make_num(key));
10845
+ output.print(make_num(key));
10846
+ return false;
10815
10847
  }
10816
10848
  var print_string = ALL_RESERVED_WORDS.has(key)
10817
10849
  ? output.option("ie8")
@@ -10821,9 +10853,11 @@ function OutputStream(options) {
10821
10853
  : !is_identifier_string(key, true)
10822
10854
  );
10823
10855
  if (print_string || (quote && output.option("keep_quoted_props"))) {
10824
- return output.print_string(key, quote);
10856
+ output.print_string(key, quote);
10857
+ return false;
10825
10858
  }
10826
- return output.print_name(key);
10859
+ output.print_name(key);
10860
+ return true;
10827
10861
  }
10828
10862
 
10829
10863
  DEFPRINT(AST_ObjectKeyVal, function(self, output) {
@@ -10832,28 +10866,29 @@ function OutputStream(options) {
10832
10866
  return def ? def.mangled_name || def.name : self.name;
10833
10867
  }
10834
10868
 
10835
- var allowShortHand = output.option("shorthand");
10836
- if (allowShortHand &&
10837
- self.value instanceof AST_Symbol &&
10838
- is_identifier_string(
10839
- self.key,
10840
- output.option("ecma") >= 2015 || output.option("safari10")
10841
- ) &&
10842
- get_name(self.value) === self.key &&
10843
- !ALL_RESERVED_WORDS.has(self.key)
10869
+ const try_shorthand = output.option("shorthand") && !(self.key instanceof AST_Node);
10870
+ if (
10871
+ try_shorthand
10872
+ && self.value instanceof AST_Symbol
10873
+ && get_name(self.value) === self.key
10874
+ && !ALL_RESERVED_WORDS.has(self.key)
10844
10875
  ) {
10845
- print_property_name(self.key, self.quote, output);
10846
-
10847
- } else if (allowShortHand &&
10848
- self.value instanceof AST_DefaultAssign &&
10849
- self.value.left instanceof AST_Symbol &&
10850
- is_identifier_string(
10851
- self.key,
10852
- output.option("ecma") >= 2015 || output.option("safari10")
10853
- ) &&
10854
- get_name(self.value.left) === self.key
10876
+ const was_shorthand = print_property_name(self.key, self.quote, output);
10877
+ if (!was_shorthand) {
10878
+ output.colon();
10879
+ self.value.print(output);
10880
+ }
10881
+ } else if (
10882
+ try_shorthand
10883
+ && self.value instanceof AST_DefaultAssign
10884
+ && self.value.left instanceof AST_Symbol
10885
+ && get_name(self.value.left) === self.key
10855
10886
  ) {
10856
- print_property_name(self.key, self.quote, output);
10887
+ const was_shorthand = print_property_name(self.key, self.quote, output);
10888
+ if (!was_shorthand) {
10889
+ output.colon();
10890
+ self.value.left.print(output);
10891
+ }
10857
10892
  output.space();
10858
10893
  output.print("=");
10859
10894
  output.space();
@@ -25413,6 +25448,7 @@ var domprops = [
25413
25448
  "coneInnerAngle",
25414
25449
  "coneOuterAngle",
25415
25450
  "coneOuterGain",
25451
+ "configurable",
25416
25452
  "configuration",
25417
25453
  "configurationName",
25418
25454
  "configurationValue",
@@ -25922,6 +25958,7 @@ var domprops = [
25922
25958
  "entities",
25923
25959
  "entries",
25924
25960
  "entryType",
25961
+ "enumerable",
25925
25962
  "enumerate",
25926
25963
  "enumerateDevices",
25927
25964
  "enumerateEditable",
@@ -395,22 +395,25 @@ import { is_basic_identifier_string } from "./parse.js";
395
395
  },
396
396
 
397
397
  MethodDefinition: function(M) {
398
+ const is_private = M.key.type === "PrivateIdentifier";
399
+ const key = M.computed ? from_moz(M.key) : new AST_SymbolMethod({ name: M.key.name || M.key.value });
400
+
398
401
  var args = {
399
402
  start : my_start_token(M),
400
403
  end : my_end_token(M),
401
- key : M.computed ? from_moz(M.key) : new AST_SymbolMethod({ name: M.key.name || M.key.value }),
404
+ key,
402
405
  value : from_moz(M.value),
403
406
  static : M.static,
404
407
  };
405
408
  if (M.kind == "get") {
406
- return new AST_ObjectGetter(args);
409
+ return new (is_private ? AST_PrivateGetter : AST_ObjectGetter)(args);
407
410
  }
408
411
  if (M.kind == "set") {
409
- return new AST_ObjectSetter(args);
412
+ return new (is_private ? AST_PrivateSetter : AST_ObjectSetter)(args);
410
413
  }
411
414
  args.is_generator = M.value.generator;
412
415
  args.async = M.value.async;
413
- return new AST_ConciseMethod(args);
416
+ return new (is_private ? AST_PrivateMethod : AST_ConciseMethod)(args);
414
417
  },
415
418
 
416
419
  FieldDefinition: function(M) {
@@ -434,8 +437,16 @@ import { is_basic_identifier_string } from "./parse.js";
434
437
  let key;
435
438
  if (M.computed) {
436
439
  key = from_moz(M.key);
440
+ } else if (M.key.type === "PrivateIdentifier") {
441
+ return new AST_ClassPrivateProperty({
442
+ start : my_start_token(M),
443
+ end : my_end_token(M),
444
+ key : from_moz(M.key),
445
+ value : from_moz(M.value),
446
+ static : M.static,
447
+ });
437
448
  } else {
438
- if (M.key.type !== "Identifier" && M.key.type !== "PrivateIdentifier") {
449
+ if (M.key.type !== "Identifier") {
439
450
  throw new Error("Non-Identifier key in PropertyDefinition");
440
451
  }
441
452
  key = from_moz(M.key);
@@ -450,6 +461,14 @@ import { is_basic_identifier_string } from "./parse.js";
450
461
  });
451
462
  },
452
463
 
464
+ PrivateIdentifier: function (M) {
465
+ return new AST_SymbolPrivateProperty({
466
+ start: my_start_token(M),
467
+ end: my_end_token(M),
468
+ name: M.name
469
+ });
470
+ },
471
+
453
472
  StaticBlock: function(M) {
454
473
  return new AST_ClassStaticBlock({
455
474
  start : my_start_token(M),
@@ -491,6 +510,15 @@ import { is_basic_identifier_string } from "./parse.js";
491
510
  },
492
511
 
493
512
  MemberExpression: function(M) {
513
+ if (M.property.type === "PrivateIdentifier") {
514
+ return new AST_DotHash({
515
+ start : my_start_token(M),
516
+ end : my_end_token(M),
517
+ property : M.property.name,
518
+ expression : from_moz(M.object),
519
+ optional : M.optional || false
520
+ });
521
+ }
494
522
  return new (M.computed ? AST_Sub : AST_Dot)({
495
523
  start : my_start_token(M),
496
524
  end : my_end_token(M),
package/lib/output.js CHANGED
@@ -1917,7 +1917,7 @@ function OutputStream(options) {
1917
1917
  ? output.option("ie8")
1918
1918
  : !is_identifier_string(
1919
1919
  prop,
1920
- output.option("ecma") >= 2015 || output.option("safari10")
1920
+ output.option("ecma") >= 2015 && !output.option("safari10")
1921
1921
  );
1922
1922
 
1923
1923
  if (self.optional) output.print("?.");
@@ -2085,15 +2085,19 @@ function OutputStream(options) {
2085
2085
  output.print("new.target");
2086
2086
  });
2087
2087
 
2088
+ /** Prints a prop name. Returns whether it can be used as a shorthand. */
2088
2089
  function print_property_name(key, quote, output) {
2089
2090
  if (output.option("quote_keys")) {
2090
- return output.print_string(key);
2091
+ output.print_string(key);
2092
+ return false;
2091
2093
  }
2092
2094
  if ("" + +key == key && key >= 0) {
2093
2095
  if (output.option("keep_numbers")) {
2094
- return output.print(key);
2096
+ output.print(key);
2097
+ return false;
2095
2098
  }
2096
- return output.print(make_num(key));
2099
+ output.print(make_num(key));
2100
+ return false;
2097
2101
  }
2098
2102
  var print_string = ALL_RESERVED_WORDS.has(key)
2099
2103
  ? output.option("ie8")
@@ -2103,9 +2107,11 @@ function OutputStream(options) {
2103
2107
  : !is_identifier_string(key, true)
2104
2108
  );
2105
2109
  if (print_string || (quote && output.option("keep_quoted_props"))) {
2106
- return output.print_string(key, quote);
2110
+ output.print_string(key, quote);
2111
+ return false;
2107
2112
  }
2108
- return output.print_name(key);
2113
+ output.print_name(key);
2114
+ return true;
2109
2115
  }
2110
2116
 
2111
2117
  DEFPRINT(AST_ObjectKeyVal, function(self, output) {
@@ -2114,28 +2120,29 @@ function OutputStream(options) {
2114
2120
  return def ? def.mangled_name || def.name : self.name;
2115
2121
  }
2116
2122
 
2117
- var allowShortHand = output.option("shorthand");
2118
- if (allowShortHand &&
2119
- self.value instanceof AST_Symbol &&
2120
- is_identifier_string(
2121
- self.key,
2122
- output.option("ecma") >= 2015 || output.option("safari10")
2123
- ) &&
2124
- get_name(self.value) === self.key &&
2125
- !ALL_RESERVED_WORDS.has(self.key)
2123
+ const try_shorthand = output.option("shorthand") && !(self.key instanceof AST_Node);
2124
+ if (
2125
+ try_shorthand
2126
+ && self.value instanceof AST_Symbol
2127
+ && get_name(self.value) === self.key
2128
+ && !ALL_RESERVED_WORDS.has(self.key)
2126
2129
  ) {
2127
- print_property_name(self.key, self.quote, output);
2128
-
2129
- } else if (allowShortHand &&
2130
- self.value instanceof AST_DefaultAssign &&
2131
- self.value.left instanceof AST_Symbol &&
2132
- is_identifier_string(
2133
- self.key,
2134
- output.option("ecma") >= 2015 || output.option("safari10")
2135
- ) &&
2136
- get_name(self.value.left) === self.key
2130
+ const was_shorthand = print_property_name(self.key, self.quote, output);
2131
+ if (!was_shorthand) {
2132
+ output.colon();
2133
+ self.value.print(output);
2134
+ }
2135
+ } else if (
2136
+ try_shorthand
2137
+ && self.value instanceof AST_DefaultAssign
2138
+ && self.value.left instanceof AST_Symbol
2139
+ && get_name(self.value.left) === self.key
2137
2140
  ) {
2138
- print_property_name(self.key, self.quote, output);
2141
+ const was_shorthand = print_property_name(self.key, self.quote, output);
2142
+ if (!was_shorthand) {
2143
+ output.colon();
2144
+ self.value.left.print(output);
2145
+ }
2139
2146
  output.space();
2140
2147
  output.print("=");
2141
2148
  output.space();
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.17.5",
7
+ "version": "5.17.6",
8
8
  "engines": {
9
9
  "node": ">=10"
10
10
  },
package/tools/domprops.js CHANGED
@@ -3575,6 +3575,7 @@ export var domprops = [
3575
3575
  "coneInnerAngle",
3576
3576
  "coneOuterAngle",
3577
3577
  "coneOuterGain",
3578
+ "configurable",
3578
3579
  "configuration",
3579
3580
  "configurationName",
3580
3581
  "configurationValue",
@@ -4084,6 +4085,7 @@ export var domprops = [
4084
4085
  "entities",
4085
4086
  "entries",
4086
4087
  "entryType",
4088
+ "enumerable",
4087
4089
  "enumerate",
4088
4090
  "enumerateDevices",
4089
4091
  "enumerateEditable",