terser 5.3.3 → 5.3.4

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.3.4
4
+
5
+ - Fixed a crash when hoisting (with `hoist_vars`) a destructuring variable declaration
6
+
3
7
  ## v5.3.3
4
8
 
5
9
  - `source-map` library has been updated, bringing memory usage and CPU time improvements when reading input source maps (the SourceMapConsumer is now WASM based).
@@ -14242,9 +14242,12 @@ AST_Scope.DEFMETHOD("hoist_declarations", function(compressor) {
14242
14242
  hoisted.push(node);
14243
14243
  return make_node(AST_EmptyStatement, node);
14244
14244
  }
14245
- if (hoist_vars && node instanceof AST_Var) {
14245
+ if (
14246
+ hoist_vars
14247
+ && node instanceof AST_Var
14248
+ && !node.definitions.some(def => def.name instanceof AST_Destructuring)
14249
+ ) {
14246
14250
  node.definitions.forEach(function(def) {
14247
- if (def.name instanceof AST_Destructuring) return;
14248
14251
  vars.set(def.name.name, def);
14249
14252
  ++vars_found;
14250
14253
  });
@@ -14324,8 +14327,7 @@ AST_Scope.DEFMETHOD("hoist_declarations", function(compressor) {
14324
14327
  continue;
14325
14328
  }
14326
14329
  if (self.body[i] instanceof AST_BlockStatement) {
14327
- var tmp = [ i, 1 ].concat(self.body[i].body);
14328
- self.body.splice.apply(self.body, tmp);
14330
+ self.body.splice(i, 1, ...self.body[i].body);
14329
14331
  continue;
14330
14332
  }
14331
14333
  break;
@@ -15071,10 +15073,12 @@ AST_Definitions.DEFMETHOD("remove_initializers", function() {
15071
15073
 
15072
15074
  AST_Definitions.DEFMETHOD("to_assignments", function(compressor) {
15073
15075
  var reduce_vars = compressor.option("reduce_vars");
15074
- var assignments = this.definitions.reduce(function(a, def) {
15075
- if (def.value && !(def.name instanceof AST_Destructuring)) {
15076
+ var assignments = [];
15077
+
15078
+ for (const def of this.definitions) {
15079
+ if (def.value) {
15076
15080
  var name = make_node(AST_SymbolRef, def.name, def.name);
15077
- a.push(make_node(AST_Assign, def, {
15081
+ assignments.push(make_node(AST_Assign, def, {
15078
15082
  operator : "=",
15079
15083
  left : name,
15080
15084
  right : def.value
@@ -15089,13 +15093,13 @@ AST_Definitions.DEFMETHOD("to_assignments", function(compressor) {
15089
15093
  var var_ = make_node(AST_Var, def, {
15090
15094
  definitions: [ varDef ]
15091
15095
  });
15092
- a.push(var_);
15096
+ assignments.push(var_);
15093
15097
  }
15094
- def = def.name.definition();
15095
- def.eliminated++;
15096
- def.replaced--;
15097
- return a;
15098
- }, []);
15098
+ const thedef = def.name.definition();
15099
+ thedef.eliminated++;
15100
+ thedef.replaced--;
15101
+ }
15102
+
15099
15103
  if (assignments.length == 0) return null;
15100
15104
  return make_sequence(this, assignments);
15101
15105
  });