terser 5.5.1 → 5.7.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/propmangle.js CHANGED
@@ -52,10 +52,13 @@ import { base54 } from "./scope.js";
52
52
  import {
53
53
  AST_Binary,
54
54
  AST_Call,
55
+ AST_ClassPrivateProperty,
55
56
  AST_Conditional,
56
57
  AST_Dot,
58
+ AST_DotHash,
57
59
  AST_ObjectKeyVal,
58
60
  AST_ObjectProperty,
61
+ AST_PrivateMethod,
59
62
  AST_Sequence,
60
63
  AST_String,
61
64
  AST_Sub,
@@ -155,7 +158,10 @@ function mangle_properties(ast, options) {
155
158
  if (!options.builtins) find_builtins(reserved);
156
159
 
157
160
  var cname = -1;
161
+ var cprivate = -1;
162
+
158
163
  var cache;
164
+ var private_cache = new Map();
159
165
  if (options.cache) {
160
166
  cache = options.cache.props;
161
167
  cache.forEach(function(mangled_name) {
@@ -178,12 +184,20 @@ function mangle_properties(ast, options) {
178
184
 
179
185
  var names_to_mangle = new Set();
180
186
  var unmangleable = new Set();
187
+ var private_properties = new Set();
181
188
 
182
189
  var keep_quoted_strict = options.keep_quoted === "strict";
183
190
 
184
191
  // step 1: find candidates to mangle
185
192
  ast.walk(new TreeWalker(function(node) {
186
- if (node instanceof AST_ObjectKeyVal) {
193
+ if (
194
+ node instanceof AST_ClassPrivateProperty
195
+ || node instanceof AST_PrivateMethod
196
+ ) {
197
+ private_properties.add(node.key.name);
198
+ } else if (node instanceof AST_DotHash) {
199
+ private_properties.add(node.property);
200
+ } else if (node instanceof AST_ObjectKeyVal) {
187
201
  if (typeof node.key == "string" &&
188
202
  (!keep_quoted_strict || !node.quote)) {
189
203
  add(node.key);
@@ -220,7 +234,14 @@ function mangle_properties(ast, options) {
220
234
 
221
235
  // step 2: transform the tree, renaming properties
222
236
  return ast.transform(new TreeTransformer(function(node) {
223
- if (node instanceof AST_ObjectKeyVal) {
237
+ if (
238
+ node instanceof AST_ClassPrivateProperty
239
+ || node instanceof AST_PrivateMethod
240
+ ) {
241
+ node.key.name = mangle_private(node.key.name);
242
+ } else if (node instanceof AST_DotHash) {
243
+ node.property = mangle_private(node.property);
244
+ } else if (node instanceof AST_ObjectKeyVal) {
224
245
  if (typeof node.key == "string" &&
225
246
  (!keep_quoted_strict || !node.quote)) {
226
247
  node.key = mangle(node.key);
@@ -300,6 +321,16 @@ function mangle_properties(ast, options) {
300
321
  return mangled;
301
322
  }
302
323
 
324
+ function mangle_private(name) {
325
+ let mangled = private_cache.get(name);
326
+ if (!mangled) {
327
+ mangled = base54(++cprivate);
328
+ private_cache.set(name, mangled);
329
+ }
330
+
331
+ return mangled;
332
+ }
333
+
303
334
  function mangleStrings(node) {
304
335
  return node.transform(new TreeTransformer(function(node) {
305
336
  if (node instanceof AST_Sequence) {
package/lib/scope.js CHANGED
@@ -65,6 +65,7 @@ import {
65
65
  AST_Defun,
66
66
  AST_Destructuring,
67
67
  AST_Dot,
68
+ AST_DotHash,
68
69
  AST_Export,
69
70
  AST_For,
70
71
  AST_ForIn,
@@ -919,7 +920,9 @@ AST_Toplevel.DEFMETHOD("compute_char_frequency", function(options) {
919
920
  if (this instanceof AST_Symbol && !this.unmangleable(options)) {
920
921
  base54.consider(this.name, -1);
921
922
  } else if (options.properties) {
922
- if (this instanceof AST_Dot) {
923
+ if (this instanceof AST_DotHash) {
924
+ base54.consider("#" + this.property, -1);
925
+ } else if (this instanceof AST_Dot) {
923
926
  base54.consider(this.property, -1);
924
927
  } else if (this instanceof AST_Sub) {
925
928
  skip_string(this.property);
package/lib/size.js CHANGED
@@ -10,6 +10,7 @@ import {
10
10
  AST_Call,
11
11
  AST_Case,
12
12
  AST_Class,
13
+ AST_ClassPrivateProperty,
13
14
  AST_ClassProperty,
14
15
  AST_ConciseMethod,
15
16
  AST_Conditional,
@@ -22,6 +23,7 @@ import {
22
23
  AST_Directive,
23
24
  AST_Do,
24
25
  AST_Dot,
26
+ AST_DotHash,
25
27
  AST_EmptyStatement,
26
28
  AST_Expansion,
27
29
  AST_Export,
@@ -47,6 +49,9 @@ import {
47
49
  AST_ObjectKeyVal,
48
50
  AST_ObjectGetter,
49
51
  AST_ObjectSetter,
52
+ AST_PrivateGetter,
53
+ AST_PrivateMethod,
54
+ AST_PrivateSetter,
50
55
  AST_RegExp,
51
56
  AST_Return,
52
57
  AST_Sequence,
@@ -87,6 +92,12 @@ AST_Node.prototype.size = function (compressor, stack) {
87
92
  let size = 0;
88
93
  walk_parent(this, (node, info) => {
89
94
  size += node._size(info);
95
+
96
+ // Braceless arrow functions have fake "return" statements
97
+ if (node instanceof AST_Arrow && node.is_braceless()) {
98
+ size += node.body[0].value._size(info);
99
+ return true;
100
+ }
90
101
  }, stack || (compressor && compressor.stack));
91
102
 
92
103
  // just to save a bit of memory
@@ -131,7 +142,6 @@ AST_With.prototype._size = () => 6;
131
142
 
132
143
  AST_Expansion.prototype._size = () => 3;
133
144
 
134
- /*#__INLINE__*/
135
145
  const lambda_modifiers = func =>
136
146
  (func.is_generator ? 1 : 0) + (func.async ? 6 : 0);
137
147
 
@@ -160,7 +170,9 @@ AST_Arrow.prototype._size = function () {
160
170
  args_and_arrow += 2;
161
171
  }
162
172
 
163
- return lambda_modifiers(this) + args_and_arrow + (Array.isArray(this.body) ? list_overhead(this.body) : this.body._size());
173
+ const body_overhead = this.is_braceless() ? 0 : list_overhead(this.body) + 2;
174
+
175
+ return lambda_modifiers(this) + args_and_arrow + body_overhead;
164
176
  };
165
177
 
166
178
  AST_Destructuring.prototype._size = () => 2;
@@ -302,6 +314,13 @@ AST_Dot.prototype._size = function () {
302
314
  return this.property.length + 1;
303
315
  };
304
316
 
317
+ AST_DotHash.prototype._size = function () {
318
+ if (this.optional) {
319
+ return this.property.length + 3;
320
+ }
321
+ return this.property.length + 2;
322
+ };
323
+
305
324
  AST_Sub.prototype._size = function () {
306
325
  return this.optional ? 4 : 2;
307
326
  };
@@ -369,6 +388,14 @@ AST_ConciseMethod.prototype._size = function () {
369
388
  return static_size(this.static) + key_size(this.key) + lambda_modifiers(this);
370
389
  };
371
390
 
391
+ AST_PrivateMethod.prototype._size = function () {
392
+ return AST_ConciseMethod.prototype._size.call(this) + 1;
393
+ };
394
+
395
+ AST_PrivateGetter.prototype._size = AST_PrivateSetter.prototype._size = function () {
396
+ return AST_ConciseMethod.prototype._size.call(this) + 4;
397
+ };
398
+
372
399
  AST_Class.prototype._size = function () {
373
400
  return (
374
401
  (this.name ? 8 : 7)
@@ -384,6 +411,10 @@ AST_ClassProperty.prototype._size = function () {
384
411
  );
385
412
  };
386
413
 
414
+ AST_ClassPrivateProperty.prototype._size = function () {
415
+ return AST_ClassProperty.prototype._size.call(this) + 1;
416
+ };
417
+
387
418
  AST_Symbol.prototype._size = function () {
388
419
  return !mangle_options || this.definition().unmangleable(mangle_options)
389
420
  ? this.name.length
@@ -196,7 +196,7 @@ function mergeSort(array, cmp) {
196
196
  function makePredicate(words) {
197
197
  if (!Array.isArray(words)) words = words.split(" ");
198
198
 
199
- return new Set(words);
199
+ return new Set(words.sort());
200
200
  }
201
201
 
202
202
  function map_add(map, key, value) {
@@ -235,6 +235,7 @@ function keep_name(keep_setting, name) {
235
235
  }
236
236
 
237
237
  var lineTerminatorEscape = {
238
+ "\0": "0",
238
239
  "\n": "n",
239
240
  "\r": "r",
240
241
  "\u2028": "u2028",
@@ -242,7 +243,8 @@ var lineTerminatorEscape = {
242
243
  };
243
244
  function regexp_source_fix(source) {
244
245
  // V8 does not escape line terminators in regexp patterns in node 12
245
- return source.replace(/[\n\r\u2028\u2029]/g, function (match, offset) {
246
+ // We'll also remove literal \0
247
+ return source.replace(/[\0\n\r\u2028\u2029]/g, function (match, offset) {
246
248
  var escaped = source[offset - 1] == "\\"
247
249
  && (source[offset - 2] != "\\"
248
250
  || /(?:^|[^\\])(?:\\{2})*$/.test(source.slice(0, offset - 1)));
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.5.1",
7
+ "version": "5.7.0",
8
8
  "engines": {
9
9
  "node": ">=10"
10
10
  },
@@ -24,7 +24,8 @@
24
24
  "./dist/bundle.min.js"
25
25
  ],
26
26
  "./package": "./package.json",
27
- "./package.json": "./package.json"
27
+ "./package.json": "./package.json",
28
+ "./bin/terser": "./bin/terser"
28
29
  },
29
30
  "types": "tools/terser.d.ts",
30
31
  "bin": {
@@ -48,16 +49,16 @@
48
49
  },
49
50
  "devDependencies": {
50
51
  "@ls-lint/ls-lint": "^1.9.2",
51
- "acorn": "^7.4.0",
52
- "astring": "^1.4.1",
53
- "eslint": "^7.0.0",
52
+ "acorn": "^8.0.5",
53
+ "astring": "^1.6.2",
54
+ "eslint": "^7.19.0",
54
55
  "eslump": "^2.0.0",
55
56
  "esm": "^3.2.25",
56
- "mocha": "^8.0.0",
57
+ "mocha": "^8.2.1",
57
58
  "pre-commit": "^1.2.2",
58
- "rimraf": "^3.0.0",
59
- "rollup": "2.0.6",
60
- "semver": "^7.1.3"
59
+ "rimraf": "^3.0.2",
60
+ "rollup": "2.38.4",
61
+ "semver": "^7.3.4"
61
62
  },
62
63
  "scripts": {
63
64
  "test": "node test/compress.js && mocha test/mocha",
@@ -124,7 +125,7 @@
124
125
  "no-unused-vars": [
125
126
  "error",
126
127
  {
127
- "varsIgnorePattern": "^_$"
128
+ "varsIgnorePattern": "^_"
128
129
  }
129
130
  ],
130
131
  "no-tabs": "error",
package/tools/domprops.js CHANGED
@@ -4120,6 +4120,7 @@ export var domprops = [
4120
4120
  "exponent",
4121
4121
  "exponentialRampToValueAtTime",
4122
4122
  "exportKey",
4123
+ "exports",
4123
4124
  "extend",
4124
4125
  "extensions",
4125
4126
  "extentNode",
package/tools/terser.d.ts CHANGED
@@ -96,6 +96,7 @@ export interface ManglePropertiesOptions {
96
96
 
97
97
  export interface FormatOptions {
98
98
  ascii_only?: boolean;
99
+ /** @deprecated Not implemented anymore */
99
100
  beautify?: boolean;
100
101
  braces?: boolean;
101
102
  comments?: boolean | 'all' | 'some' | RegExp | ( (node: any, comment: {