terser 5.38.0 → 5.38.1

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,9 @@
1
1
  # Changelog
2
2
 
3
+ ## v5.38.1
4
+
5
+ - Fix inlining non-call expressions into an `optional_call?.()`
6
+
3
7
  ## v5.38.0
4
8
 
5
9
  - Remove `console` method-of-method calls (eg `console.log.apply()`) when `drop_console` option is used (#1585)
@@ -3286,6 +3286,7 @@ function parse($TEXT, options) {
3286
3286
  return subscripts(call, true, is_chain);
3287
3287
  }
3288
3288
 
3289
+ // Optional chain
3289
3290
  if (is("punc", "?.")) {
3290
3291
  next();
3291
3292
 
@@ -22137,7 +22138,15 @@ def_optimize(AST_Chain, function (self, compressor) {
22137
22138
  }
22138
22139
  return make_node(AST_Undefined, self);
22139
22140
  }
22140
- return self;
22141
+ if (
22142
+ self.expression instanceof AST_PropAccess
22143
+ || self.expression instanceof AST_Call
22144
+ ) {
22145
+ return self;
22146
+ } else {
22147
+ // Keep the AST valid, in case the child swapped itself
22148
+ return self.expression;
22149
+ }
22141
22150
  });
22142
22151
 
22143
22152
  def_optimize(AST_Dot, function(self, compressor) {
@@ -3674,7 +3674,15 @@ def_optimize(AST_Chain, function (self, compressor) {
3674
3674
  }
3675
3675
  return make_node(AST_Undefined, self);
3676
3676
  }
3677
- return self;
3677
+ if (
3678
+ self.expression instanceof AST_PropAccess
3679
+ || self.expression instanceof AST_Call
3680
+ ) {
3681
+ return self;
3682
+ } else {
3683
+ // Keep the AST valid, in case the child swapped itself
3684
+ return self.expression;
3685
+ }
3678
3686
  });
3679
3687
 
3680
3688
  def_optimize(AST_Dot, function(self, compressor) {
package/lib/parse.js CHANGED
@@ -3141,6 +3141,7 @@ function parse($TEXT, options) {
3141
3141
  return subscripts(call, true, is_chain);
3142
3142
  }
3143
3143
 
3144
+ // Optional chain
3144
3145
  if (is("punc", "?.")) {
3145
3146
  next();
3146
3147
 
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.38.0",
7
+ "version": "5.38.1",
8
8
  "engines": {
9
9
  "node": ">=10"
10
10
  },