terser 5.35.0 → 5.37.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/lib/ast.js CHANGED
@@ -1481,13 +1481,13 @@ var AST_NameMapping = DEFNODE("NameMapping", "foreign_name name", function AST_N
1481
1481
 
1482
1482
  var AST_Import = DEFNODE(
1483
1483
  "Import",
1484
- "imported_name imported_names module_name assert_clause",
1484
+ "imported_name imported_names module_name attributes",
1485
1485
  function AST_Import(props) {
1486
1486
  if (props) {
1487
1487
  this.imported_name = props.imported_name;
1488
1488
  this.imported_names = props.imported_names;
1489
1489
  this.module_name = props.module_name;
1490
- this.assert_clause = props.assert_clause;
1490
+ this.attributes = props.attributes;
1491
1491
  this.start = props.start;
1492
1492
  this.end = props.end;
1493
1493
  }
@@ -1500,7 +1500,7 @@ var AST_Import = DEFNODE(
1500
1500
  imported_name: "[AST_SymbolImport] The name of the variable holding the module's default export.",
1501
1501
  imported_names: "[AST_NameMapping*] The names of non-default imported variables",
1502
1502
  module_name: "[AST_String] String literal describing where this module came from",
1503
- assert_clause: "[AST_Object?] The import assertion"
1503
+ attributes: "[AST_Object?] The import attributes (with {...})"
1504
1504
  },
1505
1505
  _walk: function(visitor) {
1506
1506
  return visitor._visit(this, function() {
@@ -1539,7 +1539,7 @@ var AST_ImportMeta = DEFNODE("ImportMeta", null, function AST_ImportMeta(props)
1539
1539
 
1540
1540
  var AST_Export = DEFNODE(
1541
1541
  "Export",
1542
- "exported_definition exported_value is_default exported_names module_name assert_clause",
1542
+ "exported_definition exported_value is_default exported_names module_name attributes",
1543
1543
  function AST_Export(props) {
1544
1544
  if (props) {
1545
1545
  this.exported_definition = props.exported_definition;
@@ -1547,7 +1547,7 @@ var AST_Export = DEFNODE(
1547
1547
  this.is_default = props.is_default;
1548
1548
  this.exported_names = props.exported_names;
1549
1549
  this.module_name = props.module_name;
1550
- this.assert_clause = props.assert_clause;
1550
+ this.attributes = props.attributes;
1551
1551
  this.start = props.start;
1552
1552
  this.end = props.end;
1553
1553
  }
@@ -1562,7 +1562,7 @@ var AST_Export = DEFNODE(
1562
1562
  exported_names: "[AST_NameMapping*?] List of exported names",
1563
1563
  module_name: "[AST_String?] Name of the file to load exports from",
1564
1564
  is_default: "[Boolean] Whether this is the default exported value of this module",
1565
- assert_clause: "[AST_Object?] The import assertion"
1565
+ attributes: "[AST_Object?] The import attributes"
1566
1566
  },
1567
1567
  _walk: function (visitor) {
1568
1568
  return visitor._visit(this, function () {
@@ -181,23 +181,23 @@ import { is_basic_identifier_string } from "./parse.js";
181
181
  return body;
182
182
  };
183
183
 
184
- const assert_clause_from_moz = (assertions) => {
185
- if (assertions && assertions.length > 0) {
184
+ function import_attributes_from_moz(attributes) {
185
+ if (attributes && attributes.length > 0) {
186
186
  return new AST_Object({
187
- start: my_start_token(assertions),
188
- end: my_end_token(assertions),
189
- properties: assertions.map((assertion_kv) =>
187
+ start: my_start_token(attributes),
188
+ end: my_end_token(attributes),
189
+ properties: attributes.map((attr) =>
190
190
  new AST_ObjectKeyVal({
191
- start: my_start_token(assertion_kv),
192
- end: my_end_token(assertion_kv),
193
- key: assertion_kv.key.name || assertion_kv.key.value,
194
- value: from_moz(assertion_kv.value)
191
+ start: my_start_token(attr),
192
+ end: my_end_token(attr),
193
+ key: attr.key.name || attr.key.value,
194
+ value: from_moz(attr.value)
195
195
  })
196
196
  )
197
197
  });
198
198
  }
199
199
  return null;
200
- };
200
+ }
201
201
 
202
202
  var MOZ_TO_ME = {
203
203
  Program: function(M) {
@@ -569,7 +569,7 @@ import { is_basic_identifier_string } from "./parse.js";
569
569
  imported_name: imported_name,
570
570
  imported_names : imported_names,
571
571
  module_name : from_moz(M.source),
572
- assert_clause: assert_clause_from_moz(M.assertions)
572
+ attributes: import_attributes_from_moz(M.attributes || M.assertions)
573
573
  });
574
574
  },
575
575
 
@@ -596,6 +596,10 @@ import { is_basic_identifier_string } from "./parse.js";
596
596
  },
597
597
 
598
598
  ImportExpression: function(M) {
599
+ const args = [from_moz(M.source)];
600
+ if (M.options) {
601
+ args.push(from_moz(M.options));
602
+ }
599
603
  return new AST_Call({
600
604
  start: my_start_token(M),
601
605
  end: my_end_token(M),
@@ -604,7 +608,7 @@ import { is_basic_identifier_string } from "./parse.js";
604
608
  name: "import"
605
609
  }),
606
610
  optional: false,
607
- args: [from_moz(M.source)]
611
+ args
608
612
  });
609
613
  },
610
614
 
@@ -622,7 +626,7 @@ import { is_basic_identifier_string } from "./parse.js";
622
626
  })
623
627
  ],
624
628
  module_name: from_moz(M.source),
625
- assert_clause: assert_clause_from_moz(M.assertions)
629
+ attributes: import_attributes_from_moz(M.attributes || M.assertions)
626
630
  });
627
631
  },
628
632
 
@@ -633,7 +637,7 @@ import { is_basic_identifier_string } from "./parse.js";
633
637
  exported_definition: from_moz(M.declaration),
634
638
  exported_names: M.specifiers && M.specifiers.length ? M.specifiers.map(from_moz) : null,
635
639
  module_name: from_moz(M.source),
636
- assert_clause: assert_clause_from_moz(M.assertions)
640
+ attributes: import_attributes_from_moz(M.attributes || M.assertions)
637
641
  });
638
642
  },
639
643
 
@@ -1220,10 +1224,11 @@ import { is_basic_identifier_string } from "./parse.js";
1220
1224
  });
1221
1225
  def_to_moz(AST_Call, function To_Moz_CallExpression(M) {
1222
1226
  if (M.expression instanceof AST_SymbolRef && M.expression.name === "import") {
1223
- const [source] = M.args.map(to_moz);
1227
+ const [source, options] = M.args.map(to_moz);
1224
1228
  return {
1225
1229
  type: "ImportExpression",
1226
1230
  source,
1231
+ options
1227
1232
  };
1228
1233
  }
1229
1234
 
@@ -1384,22 +1389,22 @@ import { is_basic_identifier_string } from "./parse.js";
1384
1389
  };
1385
1390
  });
1386
1391
 
1387
- const assert_clause_to_moz = assert_clause => {
1388
- const assertions = [];
1389
- if (assert_clause) {
1390
- for (const { key, value } of assert_clause.properties) {
1392
+ function import_attributes_to_moz(attribute) {
1393
+ const import_attributes = [];
1394
+ if (attribute) {
1395
+ for (const { key, value } of attribute.properties) {
1391
1396
  const key_moz = is_basic_identifier_string(key)
1392
1397
  ? { type: "Identifier", name: key }
1393
1398
  : { type: "Literal", value: key, raw: JSON.stringify(key) };
1394
- assertions.push({
1399
+ import_attributes.push({
1395
1400
  type: "ImportAttribute",
1396
1401
  key: key_moz,
1397
1402
  value: to_moz(value)
1398
1403
  });
1399
1404
  }
1400
1405
  }
1401
- return assertions;
1402
- };
1406
+ return import_attributes;
1407
+ }
1403
1408
 
1404
1409
  def_to_moz(AST_Export, function To_Moz_ExportDeclaration(M) {
1405
1410
  if (M.exported_names) {
@@ -1414,7 +1419,7 @@ import { is_basic_identifier_string } from "./parse.js";
1414
1419
  type: "ExportAllDeclaration",
1415
1420
  source: to_moz(M.module_name),
1416
1421
  exported: exported,
1417
- assertions: assert_clause_to_moz(M.assert_clause)
1422
+ attributes: import_attributes_to_moz(M.attributes)
1418
1423
  };
1419
1424
  }
1420
1425
  return {
@@ -1428,7 +1433,7 @@ import { is_basic_identifier_string } from "./parse.js";
1428
1433
  }),
1429
1434
  declaration: to_moz(M.exported_definition),
1430
1435
  source: to_moz(M.module_name),
1431
- assertions: assert_clause_to_moz(M.assert_clause)
1436
+ attributes: import_attributes_to_moz(M.attributes)
1432
1437
  };
1433
1438
  }
1434
1439
  return {
@@ -1466,7 +1471,7 @@ import { is_basic_identifier_string } from "./parse.js";
1466
1471
  type: "ImportDeclaration",
1467
1472
  specifiers: specifiers,
1468
1473
  source: to_moz(M.module_name),
1469
- assertions: assert_clause_to_moz(M.assert_clause)
1474
+ attributes: import_attributes_to_moz(M.attributes)
1470
1475
  };
1471
1476
  });
1472
1477
 
package/lib/output.js CHANGED
@@ -1792,9 +1792,9 @@ function OutputStream(options) {
1792
1792
  output.space();
1793
1793
  }
1794
1794
  self.module_name.print(output);
1795
- if (self.assert_clause) {
1796
- output.print("assert");
1797
- self.assert_clause.print(output);
1795
+ if (self.attributes) {
1796
+ output.print("with");
1797
+ self.attributes.print(output);
1798
1798
  }
1799
1799
  output.semicolon();
1800
1800
  });
@@ -1888,9 +1888,9 @@ function OutputStream(options) {
1888
1888
  output.space();
1889
1889
  self.module_name.print(output);
1890
1890
  }
1891
- if (self.assert_clause) {
1892
- output.print("assert");
1893
- self.assert_clause.print(output);
1891
+ if (self.attributes) {
1892
+ output.print("with");
1893
+ self.attributes.print(output);
1894
1894
  }
1895
1895
  if (self.exported_value
1896
1896
  && !(self.exported_value instanceof AST_Defun ||
package/lib/parse.js CHANGED
@@ -2690,6 +2690,7 @@ function parse($TEXT, options) {
2690
2690
  } else if (
2691
2691
  is("name")
2692
2692
  || is("privatename")
2693
+ || is("punc", "[")
2693
2694
  || is("operator", "*")
2694
2695
  || is("punc", ";")
2695
2696
  || is("punc", "}")
@@ -2726,8 +2727,11 @@ function parse($TEXT, options) {
2726
2727
  return new AST_ClassStaticBlock({ start, body, end: prev() });
2727
2728
  }
2728
2729
 
2729
- function maybe_import_assertion() {
2730
- if (is("name", "assert") && !has_newline_before(S.token)) {
2730
+ function maybe_import_attributes() {
2731
+ if (
2732
+ (is("keyword", "with") || is("name", "assert"))
2733
+ && !has_newline_before(S.token)
2734
+ ) {
2731
2735
  next();
2732
2736
  return object_or_destructuring_();
2733
2737
  }
@@ -2758,7 +2762,7 @@ function parse($TEXT, options) {
2758
2762
  }
2759
2763
  next();
2760
2764
 
2761
- const assert_clause = maybe_import_assertion();
2765
+ const attributes = maybe_import_attributes();
2762
2766
 
2763
2767
  return new AST_Import({
2764
2768
  start,
@@ -2770,7 +2774,7 @@ function parse($TEXT, options) {
2770
2774
  quote: mod_str.quote,
2771
2775
  end: mod_str,
2772
2776
  }),
2773
- assert_clause,
2777
+ attributes,
2774
2778
  end: S.token,
2775
2779
  });
2776
2780
  }
@@ -2903,7 +2907,7 @@ function parse($TEXT, options) {
2903
2907
  }
2904
2908
  next();
2905
2909
 
2906
- const assert_clause = maybe_import_assertion();
2910
+ const attributes = maybe_import_attributes();
2907
2911
 
2908
2912
  return new AST_Export({
2909
2913
  start: start,
@@ -2916,7 +2920,7 @@ function parse($TEXT, options) {
2916
2920
  end: mod_str,
2917
2921
  }),
2918
2922
  end: prev(),
2919
- assert_clause
2923
+ attributes
2920
2924
  });
2921
2925
  } else {
2922
2926
  return new AST_Export({
@@ -2962,7 +2966,7 @@ function parse($TEXT, options) {
2962
2966
  exported_value: exported_value,
2963
2967
  exported_definition: exported_definition,
2964
2968
  end: prev(),
2965
- assert_clause: null
2969
+ attributes: null
2966
2970
  });
2967
2971
  }
2968
2972
 
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.35.0",
7
+ "version": "5.37.0",
8
8
  "engines": {
9
9
  "node": ">=10"
10
10
  },