terser 5.43.0 → 5.43.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,10 @@
1
1
  # Changelog
2
2
 
3
+ ## v5.43.1
4
+
5
+ - Prevent niche optimizations that would move around block declarations
6
+ - Add `lhs_constants` to `CompressOptions` type (#1621)
7
+
3
8
  ## v5.43.0
4
9
 
5
10
  - Do not wrap callbacks in parentheses (`wrap_func_args` format option is now false by default)
@@ -17830,7 +17830,7 @@ function tighten_body(statements, compressor) {
17830
17830
  stat = stat.clone();
17831
17831
  stat.condition = stat.condition.negate(compressor);
17832
17832
  stat.body = make_node(AST_BlockStatement, stat, {
17833
- body: as_statement_array(stat.alternative).concat(extract_functions())
17833
+ body: as_statement_array(stat.alternative).concat(extract_defuns())
17834
17834
  });
17835
17835
  stat.alternative = make_node(AST_BlockStatement, stat, {
17836
17836
  body: new_else
@@ -17850,7 +17850,7 @@ function tighten_body(statements, compressor) {
17850
17850
  CHANGED = true;
17851
17851
  stat = stat.clone();
17852
17852
  stat.body = make_node(AST_BlockStatement, stat.body, {
17853
- body: as_statement_array(stat.body).concat(extract_functions())
17853
+ body: as_statement_array(stat.body).concat(extract_defuns())
17854
17854
  });
17855
17855
  stat.alternative = make_node(AST_BlockStatement, stat.alternative, {
17856
17856
  body: new_else
@@ -17955,7 +17955,7 @@ function tighten_body(statements, compressor) {
17955
17955
  || ab instanceof AST_Break && lct instanceof AST_BlockStatement && self === lct;
17956
17956
  }
17957
17957
 
17958
- function extract_functions() {
17958
+ function extract_defuns() {
17959
17959
  var tail = statements.slice(i + 1);
17960
17960
  statements.length = i + 1;
17961
17961
  return tail.filter(function (stat) {
@@ -17973,6 +17973,9 @@ function tighten_body(statements, compressor) {
17973
17973
  return undefined;
17974
17974
  }
17975
17975
  body = body.slice(0, -1);
17976
+ if (!body.every(stat => can_be_evicted_from_block(stat))) {
17977
+ return undefined;
17978
+ }
17976
17979
  if (ab.value) {
17977
17980
  body.push(make_node(AST_SimpleStatement, ab.value, {
17978
17981
  body: ab.value.expression
@@ -1031,7 +1031,7 @@ export function tighten_body(statements, compressor) {
1031
1031
  stat = stat.clone();
1032
1032
  stat.condition = stat.condition.negate(compressor);
1033
1033
  stat.body = make_node(AST_BlockStatement, stat, {
1034
- body: as_statement_array(stat.alternative).concat(extract_functions())
1034
+ body: as_statement_array(stat.alternative).concat(extract_defuns())
1035
1035
  });
1036
1036
  stat.alternative = make_node(AST_BlockStatement, stat, {
1037
1037
  body: new_else
@@ -1051,7 +1051,7 @@ export function tighten_body(statements, compressor) {
1051
1051
  CHANGED = true;
1052
1052
  stat = stat.clone();
1053
1053
  stat.body = make_node(AST_BlockStatement, stat.body, {
1054
- body: as_statement_array(stat.body).concat(extract_functions())
1054
+ body: as_statement_array(stat.body).concat(extract_defuns())
1055
1055
  });
1056
1056
  stat.alternative = make_node(AST_BlockStatement, stat.alternative, {
1057
1057
  body: new_else
@@ -1156,7 +1156,7 @@ export function tighten_body(statements, compressor) {
1156
1156
  || ab instanceof AST_Break && lct instanceof AST_BlockStatement && self === lct;
1157
1157
  }
1158
1158
 
1159
- function extract_functions() {
1159
+ function extract_defuns() {
1160
1160
  var tail = statements.slice(i + 1);
1161
1161
  statements.length = i + 1;
1162
1162
  return tail.filter(function (stat) {
@@ -1174,6 +1174,9 @@ export function tighten_body(statements, compressor) {
1174
1174
  return undefined;
1175
1175
  }
1176
1176
  body = body.slice(0, -1);
1177
+ if (!body.every(stat => can_be_evicted_from_block(stat))) {
1178
+ return undefined;
1179
+ }
1177
1180
  if (ab.value) {
1178
1181
  body.push(make_node(AST_SimpleStatement, ab.value, {
1179
1182
  body: ab.value.expression
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.43.0",
7
+ "version": "5.43.1",
8
8
  "engines": {
9
9
  "node": ">=10"
10
10
  },
package/tools/terser.d.ts CHANGED
@@ -44,6 +44,7 @@ export interface CompressOptions {
44
44
  keep_fargs?: boolean;
45
45
  keep_fnames?: boolean | RegExp;
46
46
  keep_infinity?: boolean;
47
+ lhs_constants?: boolean;
47
48
  loops?: boolean;
48
49
  module?: boolean;
49
50
  negate_iife?: boolean;