terser 5.25.0 → 5.26.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/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## v5.26.0
4
+ - Do not take the `/*#__PURE__*/` annotation into account when the `side_effects` compress option is off.
5
+ - The `preserve_annotations` option now automatically opts annotation comments in, instead of requiring the `comments` option to be configured for this.
6
+ - Refuse to parse empty parenthesized expressions (`()`)
7
+
3
8
  ## v5.25.0
4
9
  - Regex properties added to reserved property mangler (#1471)
5
10
  - `pure_new` option added to drop unused `new` expressions.
@@ -2,7 +2,7 @@
2
2
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@jridgewell/source-map')) :
3
3
  typeof define === 'function' && define.amd ? define(['exports', '@jridgewell/source-map'], factory) :
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Terser = {}, global.sourceMap));
5
- }(this, (function (exports, sourceMap) { 'use strict';
5
+ })(this, (function (exports, sourceMap) { 'use strict';
6
6
 
7
7
  /***********************************************************************
8
8
 
@@ -2475,9 +2475,7 @@ function parse($TEXT, options) {
2475
2475
  var ex = async ? new AST_Call({
2476
2476
  expression: async,
2477
2477
  args: exprs
2478
- }) : exprs.length == 1 ? exprs[0] : new AST_Sequence({
2479
- expressions: exprs
2480
- });
2478
+ }) : to_expr_or_sequence(start, exprs);
2481
2479
  if (ex.start) {
2482
2480
  const outer_comments_before = start.comments_before.length;
2483
2481
  outer_comments_before_counts.set(start, outer_comments_before);
@@ -3574,6 +3572,16 @@ function parse($TEXT, options) {
3574
3572
  return left;
3575
3573
  };
3576
3574
 
3575
+ var to_expr_or_sequence = function(start, exprs) {
3576
+ if (exprs.length === 1) {
3577
+ return exprs[0];
3578
+ } else if (exprs.length > 1) {
3579
+ return new AST_Sequence({ start, expressions: exprs, end: peek() });
3580
+ } else {
3581
+ croak("Invalid parenthesized expression");
3582
+ }
3583
+ };
3584
+
3577
3585
  var expression = function(commas, no_in) {
3578
3586
  var start = S.token;
3579
3587
  var exprs = [];
@@ -3583,11 +3591,7 @@ function parse($TEXT, options) {
3583
3591
  next();
3584
3592
  commas = true;
3585
3593
  }
3586
- return exprs.length == 1 ? exprs[0] : new AST_Sequence({
3587
- start : start,
3588
- expressions : exprs,
3589
- end : peek()
3590
- });
3594
+ return to_expr_or_sequence(start, exprs);
3591
3595
  };
3592
3596
 
3593
3597
  function in_loop(cont) {
@@ -8931,7 +8935,7 @@ function left_is_object(node) {
8931
8935
  const CODE_LINE_BREAK = 10;
8932
8936
  const CODE_SPACE = 32;
8933
8937
 
8934
- const r_annotation = /[@#]__(PURE|INLINE|NOINLINE)__/g;
8938
+ const r_annotation = /[@#]__(PURE|INLINE|NOINLINE)__/;
8935
8939
 
8936
8940
  function is_some_comments(comment) {
8937
8941
  // multiline comment
@@ -9083,6 +9087,13 @@ function OutputStream(options) {
9083
9087
  }
9084
9088
  }
9085
9089
 
9090
+ if (options.preserve_annotations) {
9091
+ let prev_comment_filter = comment_filter;
9092
+ comment_filter = function (comment) {
9093
+ return r_annotation.test(comment.value) || prev_comment_filter.apply(this, arguments);
9094
+ };
9095
+ }
9096
+
9086
9097
  var indentation = 0;
9087
9098
  var current_col = 0;
9088
9099
  var current_line = 1;
@@ -14173,7 +14184,10 @@ AST_Call.DEFMETHOD("is_callee_pure", function(compressor) {
14173
14184
  if ((this instanceof AST_New) && compressor.option("pure_new")) {
14174
14185
  return true;
14175
14186
  }
14176
- return !!has_annotation(this, _PURE) || !compressor.pure_funcs(this);
14187
+ if (compressor.option("side_effects") && has_annotation(this, _PURE)) {
14188
+ return true;
14189
+ }
14190
+ return !compressor.pure_funcs(this);
14177
14191
  });
14178
14192
 
14179
14193
  // If I call this, is it a pure function?
@@ -31321,4 +31335,4 @@ exports._default_options = _default_options;
31321
31335
  exports._run_cli = run_cli;
31322
31336
  exports.minify = minify;
31323
31337
 
31324
- })));
31338
+ }));
@@ -831,7 +831,10 @@ AST_Call.DEFMETHOD("is_callee_pure", function(compressor) {
831
831
  if ((this instanceof AST_New) && compressor.option("pure_new")) {
832
832
  return true;
833
833
  }
834
- return !!has_annotation(this, _PURE) || !compressor.pure_funcs(this);
834
+ if (compressor.option("side_effects") && has_annotation(this, _PURE)) {
835
+ return true;
836
+ }
837
+ return !compressor.pure_funcs(this);
835
838
  });
836
839
 
837
840
  // If I call this, is it a pure function?
package/lib/output.js CHANGED
@@ -169,7 +169,7 @@ import {
169
169
  const CODE_LINE_BREAK = 10;
170
170
  const CODE_SPACE = 32;
171
171
 
172
- const r_annotation = /[@#]__(PURE|INLINE|NOINLINE)__/g;
172
+ const r_annotation = /[@#]__(PURE|INLINE|NOINLINE)__/;
173
173
 
174
174
  function is_some_comments(comment) {
175
175
  // multiline comment
@@ -321,6 +321,13 @@ function OutputStream(options) {
321
321
  }
322
322
  }
323
323
 
324
+ if (options.preserve_annotations) {
325
+ let prev_comment_filter = comment_filter;
326
+ comment_filter = function (comment) {
327
+ return r_annotation.test(comment.value) || prev_comment_filter.apply(this, arguments);
328
+ };
329
+ }
330
+
324
331
  var indentation = 0;
325
332
  var current_col = 0;
326
333
  var current_line = 1;
package/lib/parse.js CHANGED
@@ -2330,9 +2330,7 @@ function parse($TEXT, options) {
2330
2330
  var ex = async ? new AST_Call({
2331
2331
  expression: async,
2332
2332
  args: exprs
2333
- }) : exprs.length == 1 ? exprs[0] : new AST_Sequence({
2334
- expressions: exprs
2335
- });
2333
+ }) : to_expr_or_sequence(start, exprs);
2336
2334
  if (ex.start) {
2337
2335
  const outer_comments_before = start.comments_before.length;
2338
2336
  outer_comments_before_counts.set(start, outer_comments_before);
@@ -3429,6 +3427,16 @@ function parse($TEXT, options) {
3429
3427
  return left;
3430
3428
  };
3431
3429
 
3430
+ var to_expr_or_sequence = function(start, exprs) {
3431
+ if (exprs.length === 1) {
3432
+ return exprs[0];
3433
+ } else if (exprs.length > 1) {
3434
+ return new AST_Sequence({ start, expressions: exprs, end: peek() });
3435
+ } else {
3436
+ croak("Invalid parenthesized expression");
3437
+ }
3438
+ };
3439
+
3432
3440
  var expression = function(commas, no_in) {
3433
3441
  var start = S.token;
3434
3442
  var exprs = [];
@@ -3438,11 +3446,7 @@ function parse($TEXT, options) {
3438
3446
  next();
3439
3447
  commas = true;
3440
3448
  }
3441
- return exprs.length == 1 ? exprs[0] : new AST_Sequence({
3442
- start : start,
3443
- expressions : exprs,
3444
- end : peek()
3445
- });
3449
+ return to_expr_or_sequence(start, exprs);
3446
3450
  };
3447
3451
 
3448
3452
  function in_loop(cont) {
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.25.0",
7
+ "version": "5.26.0",
8
8
  "engines": {
9
9
  "node": ">=10"
10
10
  },