terser 5.16.0 → 5.16.2

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/scope.js CHANGED
@@ -69,6 +69,7 @@ import {
69
69
  AST_Export,
70
70
  AST_For,
71
71
  AST_ForIn,
72
+ AST_ForOf,
72
73
  AST_Function,
73
74
  AST_Import,
74
75
  AST_IterationStatement,
@@ -104,7 +105,8 @@ import {
104
105
  AST_VarDef,
105
106
  AST_With,
106
107
  TreeWalker,
107
- walk
108
+ walk,
109
+ walk_abort
108
110
  } from "./ast.js";
109
111
  import {
110
112
  ALL_RESERVED_WORDS,
@@ -229,8 +231,9 @@ AST_Scope.DEFMETHOD("figure_out_scope", function(options, { parent_scope = null,
229
231
  scope.init_scope_vars(parent_scope);
230
232
  scope.uses_with = save_scope.uses_with;
231
233
  scope.uses_eval = save_scope.uses_eval;
234
+
232
235
  if (options.safari10) {
233
- if (node instanceof AST_For || node instanceof AST_ForIn) {
236
+ if (node instanceof AST_For || node instanceof AST_ForIn || node instanceof AST_ForOf) {
234
237
  for_scopes.push(scope);
235
238
  }
236
239
  }
@@ -418,7 +421,7 @@ AST_Scope.DEFMETHOD("figure_out_scope", function(options, { parent_scope = null,
418
421
  sym = toplevel.def_global(node);
419
422
  if (node instanceof AST_SymbolExport) sym.export = MASK_EXPORT_DONT_MANGLE;
420
423
  } else if (sym.scope instanceof AST_Lambda && name == "arguments") {
421
- sym.scope.uses_arguments = true;
424
+ sym.scope.get_defun_scope().uses_arguments = true;
422
425
  }
423
426
  node.thedef = sym;
424
427
  node.reference();
@@ -520,7 +523,25 @@ AST_Scope.DEFMETHOD("add_child_scope", function (scope) {
520
523
 
521
524
  scope.parent_scope = this;
522
525
 
523
- // TODO uses_with, uses_eval, etc
526
+ // Propagate to this.uses_arguments from arrow functions
527
+ if ((scope instanceof AST_Arrow) && !this.uses_arguments) {
528
+ this.uses_arguments = walk(scope, node => {
529
+ if (
530
+ node instanceof AST_SymbolRef
531
+ && node.scope instanceof AST_Lambda
532
+ && node.name === "arguments"
533
+ ) {
534
+ return walk_abort;
535
+ }
536
+
537
+ if (node instanceof AST_Lambda && !(node instanceof AST_Arrow)) {
538
+ return true;
539
+ }
540
+ });
541
+ }
542
+
543
+ this.uses_with = this.uses_with || scope.uses_with;
544
+ this.uses_eval = this.uses_eval || scope.uses_eval;
524
545
 
525
546
  const scope_ancestry = (() => {
526
547
  const ancestry = [];
@@ -756,7 +777,10 @@ AST_Symbol.DEFMETHOD("global", function() {
756
777
  return this.thedef.global;
757
778
  });
758
779
 
759
- AST_Toplevel.DEFMETHOD("_default_mangler_options", function(options) {
780
+ /**
781
+ * Format the mangler options (if any) into their appropriate types
782
+ */
783
+ export function format_mangler_options(options) {
760
784
  options = defaults(options, {
761
785
  eval : false,
762
786
  nth_identifier : base54,
@@ -777,10 +801,10 @@ AST_Toplevel.DEFMETHOD("_default_mangler_options", function(options) {
777
801
  // Never mangle arguments
778
802
  options.reserved.add("arguments");
779
803
  return options;
780
- });
804
+ }
781
805
 
782
806
  AST_Toplevel.DEFMETHOD("mangle_names", function(options) {
783
- options = this._default_mangler_options(options);
807
+ options = format_mangler_options(options);
784
808
  var nth_identifier = options.nth_identifier;
785
809
 
786
810
  // We only need to mangle declaration nodes. Special logic wired
@@ -904,7 +928,7 @@ AST_Toplevel.DEFMETHOD("find_colliding_names", function(options) {
904
928
  });
905
929
 
906
930
  AST_Toplevel.DEFMETHOD("expand_names", function(options) {
907
- options = this._default_mangler_options(options);
931
+ options = format_mangler_options(options);
908
932
  var nth_identifier = options.nth_identifier;
909
933
  if (nth_identifier.reset && nth_identifier.sort) {
910
934
  nth_identifier.reset();
@@ -947,7 +971,7 @@ AST_Sequence.DEFMETHOD("tail_node", function() {
947
971
  });
948
972
 
949
973
  AST_Toplevel.DEFMETHOD("compute_char_frequency", function(options) {
950
- options = this._default_mangler_options(options);
974
+ options = format_mangler_options(options);
951
975
  var nth_identifier = options.nth_identifier;
952
976
  if (!nth_identifier.reset || !nth_identifier.consider || !nth_identifier.sort) {
953
977
  // If the identifier mangler is invariant, skip computing character frequency.
package/lib/size.js CHANGED
@@ -425,9 +425,11 @@ AST_ClassPrivateProperty.prototype._size = function () {
425
425
  };
426
426
 
427
427
  AST_Symbol.prototype._size = function () {
428
- return !mangle_options || this.definition().unmangleable(mangle_options)
429
- ? this.name.length
430
- : 1;
428
+ if (!(mangle_options && this.thedef && !this.thedef.unmangleable(mangle_options))) {
429
+ return this.name.length;
430
+ } else {
431
+ return 1;
432
+ }
431
433
  };
432
434
 
433
435
  // TODO take propmangle into account
@@ -436,11 +438,7 @@ AST_SymbolClassProperty.prototype._size = function () {
436
438
  };
437
439
 
438
440
  AST_SymbolRef.prototype._size = AST_SymbolDeclaration.prototype._size = function () {
439
- const { name, thedef } = this;
440
-
441
- if (thedef && thedef.global) return name.length;
442
-
443
- if (name === "arguments") return 9;
441
+ if (this.name === "arguments") return 9;
444
442
 
445
443
  return AST_Symbol.prototype._size.call(this);
446
444
  };
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.16.0",
7
+ "version": "5.16.2",
8
8
  "engines": {
9
9
  "node": ">=10"
10
10
  },
package/tools/terser.d.ts CHANGED
@@ -204,6 +204,7 @@ export interface SourceMapOptions {
204
204
  includeSources?: boolean;
205
205
  filename?: string;
206
206
  root?: string;
207
+ asObject?: boolean;
207
208
  url?: string | 'inline';
208
209
  }
209
210
 
package/bin/terser.mjs DELETED
@@ -1,21 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- "use strict";
4
-
5
- import "../tools/exit.cjs";
6
-
7
- import fs from "fs"
8
- import path from "path"
9
- import program from "commander"
10
-
11
- import { run_cli } from "../lib/cli.js"
12
-
13
- const packageJson = {
14
- name: "terser",
15
- version: "experimental module CLI"
16
- }
17
-
18
- run_cli({ program, packageJson, fs, path }).catch((error) => {
19
- console.error(error);
20
- process.exitCode = 1;
21
- });