terser 5.19.4 → 5.20.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.
@@ -385,7 +385,7 @@ class Compressor extends TreeWalker {
385
385
  this._toplevel.figure_out_scope(mangle);
386
386
  if (pass === 0 && this.option("drop_console")) {
387
387
  // must be run before reduce_vars and compress pass
388
- this._toplevel = this._toplevel.drop_console();
388
+ this._toplevel = this._toplevel.drop_console(this.option("drop_console"));
389
389
  }
390
390
  if (pass > 0 || this.option("reduce_vars")) {
391
391
  this._toplevel.reset_opt_flags(this);
@@ -464,19 +464,30 @@ def_optimize(AST_Node, function(self) {
464
464
  return self;
465
465
  });
466
466
 
467
- AST_Toplevel.DEFMETHOD("drop_console", function() {
467
+ AST_Toplevel.DEFMETHOD("drop_console", function(options) {
468
+ var isArray = Array.isArray(options);
469
+
468
470
  return this.transform(new TreeTransformer(function(self) {
469
- if (self.TYPE == "Call") {
470
- var exp = self.expression;
471
- if (exp instanceof AST_PropAccess) {
472
- var name = exp.expression;
473
- while (name.expression) {
474
- name = name.expression;
475
- }
476
- if (is_undeclared_ref(name) && name.name == "console") {
477
- return make_node(AST_Undefined, self);
478
- }
479
- }
471
+ if (self.TYPE !== "Call") {
472
+ return;
473
+ }
474
+
475
+ var exp = self.expression;
476
+
477
+ if (!(exp instanceof AST_PropAccess)) {
478
+ return;
479
+ }
480
+
481
+ if (isArray && options.indexOf(exp.property) === -1) {
482
+ return;
483
+ }
484
+
485
+ var name = exp.expression;
486
+ while (name.expression) {
487
+ name = name.expression;
488
+ }
489
+ if (is_undeclared_ref(name) && name.name == "console") {
490
+ return make_node(AST_Undefined, self);
480
491
  }
481
492
  }));
482
493
  });
package/lib/minify.js CHANGED
@@ -230,6 +230,9 @@ async function minify(files, options, _fs_module) {
230
230
  }
231
231
  }
232
232
  }
233
+ if (options.parse.toplevel === null) {
234
+ throw new Error("no source file given");
235
+ }
233
236
 
234
237
  toplevel = options.parse.toplevel;
235
238
  }
@@ -166,17 +166,15 @@ import { is_basic_identifier_string } from "./parse.js";
166
166
  (function() {
167
167
 
168
168
  var normalize_directives = function(body) {
169
- var in_directive = true;
170
-
171
169
  for (var i = 0; i < body.length; i++) {
172
- if (in_directive && body[i] instanceof AST_Statement && body[i].body instanceof AST_String) {
170
+ if (body[i] instanceof AST_Statement && body[i].body instanceof AST_String) {
173
171
  body[i] = new AST_Directive({
174
172
  start: body[i].start,
175
173
  end: body[i].end,
176
174
  value: body[i].body.value
177
175
  });
178
- } else if (in_directive && !(body[i] instanceof AST_Statement && body[i].body instanceof AST_String)) {
179
- in_directive = false;
176
+ } else {
177
+ return body;
180
178
  }
181
179
  }
182
180
 
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.19.4",
7
+ "version": "5.20.0",
8
8
  "engines": {
9
9
  "node": ">=10"
10
10
  },