terser 5.0.0 → 5.1.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
@@ -864,6 +864,10 @@ var AST_Import = DEFNODE("Import", "imported_name imported_names module_name", {
864
864
  },
865
865
  });
866
866
 
867
+ var AST_ImportMeta = DEFNODE("ImportMeta", null, {
868
+ $documentation: "A reference to import.meta",
869
+ });
870
+
867
871
  var AST_Export = DEFNODE("Export", "exported_definition exported_value is_default exported_names module_name", {
868
872
  $documentation: "An `export` statement",
869
873
  $propdoc: {
@@ -1642,6 +1646,7 @@ export {
1642
1646
  AST_Hole,
1643
1647
  AST_If,
1644
1648
  AST_Import,
1649
+ AST_ImportMeta,
1645
1650
  AST_Infinity,
1646
1651
  AST_IterationStatement,
1647
1652
  AST_Jump,
@@ -26,6 +26,7 @@ import {
26
26
  AST_ForOf,
27
27
  AST_If,
28
28
  AST_Import,
29
+ AST_ImportMeta,
29
30
  AST_Jump,
30
31
  AST_LabeledStatement,
31
32
  AST_Lambda,
@@ -209,6 +210,8 @@ AST_Import.prototype.shallow_cmp = mkshallow({
209
210
  imported_names: "exist"
210
211
  });
211
212
 
213
+ AST_ImportMeta.prototype.shallow_cmp = pass_through;
214
+
212
215
  AST_Export.prototype.shallow_cmp = mkshallow({
213
216
  exported_definition: "exist",
214
217
  exported_value: "exist",
@@ -89,6 +89,7 @@ import {
89
89
  AST_Hole,
90
90
  AST_If,
91
91
  AST_Import,
92
+ AST_ImportMeta,
92
93
  AST_Label,
93
94
  AST_LabeledStatement,
94
95
  AST_LabelRef,
@@ -545,6 +546,11 @@ import {
545
546
  start: my_start_token(M),
546
547
  end: my_end_token(M)
547
548
  });
549
+ } else if (M.meta.name === "import" && M.property.name === "meta") {
550
+ return new AST_ImportMeta({
551
+ start: my_start_token(M),
552
+ end: my_end_token(M)
553
+ });
548
554
  }
549
555
  },
550
556
  Identifier: function(M) {
@@ -836,6 +842,20 @@ import {
836
842
  };
837
843
  });
838
844
 
845
+ def_to_moz(AST_ImportMeta, function To_Moz_MetaProperty() {
846
+ return {
847
+ type: "MetaProperty",
848
+ meta: {
849
+ type: "Identifier",
850
+ name: "import"
851
+ },
852
+ property: {
853
+ type: "Identifier",
854
+ name: "meta"
855
+ }
856
+ };
857
+ });
858
+
839
859
  def_to_moz(AST_Sequence, function To_Moz_SequenceExpression(M) {
840
860
  return {
841
861
  type: "SequenceExpression",
package/lib/output.js CHANGED
@@ -94,6 +94,7 @@ import {
94
94
  AST_Hole,
95
95
  AST_If,
96
96
  AST_Import,
97
+ AST_ImportMeta,
97
98
  AST_Jump,
98
99
  AST_LabeledStatement,
99
100
  AST_Lambda,
@@ -1608,6 +1609,9 @@ function OutputStream(options) {
1608
1609
  self.module_name.print(output);
1609
1610
  output.semicolon();
1610
1611
  });
1612
+ DEFPRINT(AST_ImportMeta, function(self, output) {
1613
+ output.print("import.meta");
1614
+ });
1611
1615
 
1612
1616
  DEFPRINT(AST_NameMapping, function(self, output) {
1613
1617
  var is_import = output.parent() instanceof AST_Import;
package/lib/parse.js CHANGED
@@ -91,6 +91,7 @@ import {
91
91
  AST_Hole,
92
92
  AST_If,
93
93
  AST_Import,
94
+ AST_ImportMeta,
94
95
  AST_IterationStatement,
95
96
  AST_Label,
96
97
  AST_LabeledStatement,
@@ -1169,7 +1170,7 @@ function parse($TEXT, options) {
1169
1170
  }
1170
1171
  return function_(AST_Defun, false, true, is_export_default);
1171
1172
  }
1172
- if (S.token.value == "import" && !is_token(peek(), "punc", "(")) {
1173
+ if (S.token.value == "import" && !is_token(peek(), "punc", "(") && !is_token(peek(), "punc", ".")) {
1173
1174
  next();
1174
1175
  var node = import_();
1175
1176
  semicolon();
@@ -2217,6 +2218,9 @@ function parse($TEXT, options) {
2217
2218
  if (is("operator", "new")) {
2218
2219
  return new_(allow_calls);
2219
2220
  }
2221
+ if (is("operator", "import")) {
2222
+ return import_meta();
2223
+ }
2220
2224
  var start = S.token;
2221
2225
  var peeked;
2222
2226
  var async = is("name", "async")
@@ -2594,6 +2598,7 @@ function parse($TEXT, options) {
2594
2598
 
2595
2599
  function import_() {
2596
2600
  var start = prev();
2601
+
2597
2602
  var imported_name;
2598
2603
  var imported_names;
2599
2604
  if (is("name")) {
@@ -2628,6 +2633,17 @@ function parse($TEXT, options) {
2628
2633
  });
2629
2634
  }
2630
2635
 
2636
+ function import_meta() {
2637
+ var start = S.token;
2638
+ expect_token("operator", "import");
2639
+ expect_token("punc", ".");
2640
+ expect_token("name", "meta");
2641
+ return subscripts(new AST_ImportMeta({
2642
+ start: start,
2643
+ end: prev()
2644
+ }), false);
2645
+ }
2646
+
2631
2647
  function map_name(is_import) {
2632
2648
  function make_symbol(type) {
2633
2649
  return new type({
package/lib/size.js CHANGED
@@ -32,6 +32,7 @@ import {
32
32
  AST_Hole,
33
33
  AST_If,
34
34
  AST_Import,
35
+ AST_ImportMeta,
35
36
  AST_Infinity,
36
37
  AST_LabeledStatement,
37
38
  AST_Let,
@@ -257,6 +258,8 @@ AST_Import.prototype._size = function () {
257
258
  return size;
258
259
  };
259
260
 
261
+ AST_ImportMeta.prototype._size = () => 11;
262
+
260
263
  AST_Export.prototype._size = function () {
261
264
  let size = 7 + (this.is_default ? 8 : 0);
262
265
 
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "homepage": "https://terser.org",
5
5
  "author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)",
6
6
  "license": "BSD-2-Clause",
7
- "version": "5.0.0",
7
+ "version": "5.1.0",
8
8
  "engines": {
9
9
  "node": ">=6.0.0"
10
10
  },
@@ -48,7 +48,7 @@
48
48
  },
49
49
  "devDependencies": {
50
50
  "@ls-lint/ls-lint": "^1.9.2",
51
- "acorn": "^7.1.1",
51
+ "acorn": "^7.4.0",
52
52
  "astring": "^1.4.1",
53
53
  "eslint": "^7.0.0",
54
54
  "eslump": "^2.0.0",
package/tools/terser.d.ts CHANGED
@@ -98,7 +98,7 @@ export interface FormatOptions {
98
98
  ascii_only?: boolean;
99
99
  beautify?: boolean;
100
100
  braces?: boolean;
101
- comments?: boolean | 'all' | 'some' | RegExp | ( (node: AST_Node, comment: {
101
+ comments?: boolean | 'all' | 'some' | RegExp | ( (node: any, comment: {
102
102
  value: string,
103
103
  type: 'comment1' | 'comment2' | 'comment3' | 'comment4',
104
104
  pos: number,
@@ -151,7 +151,6 @@ export interface MinifyOptions {
151
151
  }
152
152
 
153
153
  export interface MinifyOutput {
154
- ast?: AST_Node;
155
154
  code?: string;
156
155
  map?: RawSourceMap | string;
157
156
  }
@@ -165,4 +164,4 @@ export interface SourceMapOptions {
165
164
  url?: string | 'inline';
166
165
  }
167
166
 
168
- export async function minify(files: string | string[] | { [file: string]: string }, options?: MinifyOptions): Promise<MinifyOutput>;
167
+ export function minify(files: string | string[] | { [file: string]: string }, options?: MinifyOptions): Promise<MinifyOutput>;