terser 5.15.0 → 5.15.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,12 @@
1
1
  # Changelog
2
2
 
3
+ ## v5.15.1
4
+
5
+ - Fixed missing parentheses around optional chains
6
+ - Avoid bare `let` or `const` as the bodies of `if` statements (#1253)
7
+ - Small internal fixes (#1271)
8
+ - Avoid inlining a class twice and creating two equivalent but `!==` classes.
9
+
3
10
  ## v5.15.0
4
11
  - Basic support for ES2022 class static initializer blocks.
5
12
  - Add `AudioWorkletNode` constructor options to domprops list (#1230)
@@ -2969,14 +2969,14 @@ function parse($TEXT, options) {
2969
2969
  var end = prev();
2970
2970
 
2971
2971
  name = name || new type({
2972
- name: "*",
2973
2972
  start: start,
2973
+ name: "*",
2974
2974
  end: end,
2975
2975
  });
2976
2976
 
2977
2977
  foreign_name = new foreign_type({
2978
- name: "*",
2979
2978
  start: start,
2979
+ name: "*",
2980
2980
  end: end,
2981
2981
  });
2982
2982
 
@@ -8560,6 +8560,7 @@ function first_in_statement(stack) {
8560
8560
  (p instanceof AST_PrefixedTemplateString && p.prefix === node) ||
8561
8561
  (p instanceof AST_Dot && p.expression === node) ||
8562
8562
  (p instanceof AST_Sub && p.expression === node) ||
8563
+ (p instanceof AST_Chain && p.expression === node) ||
8563
8564
  (p instanceof AST_Conditional && p.condition === node) ||
8564
8565
  (p instanceof AST_Binary && p.left === node) ||
8565
8566
  (p instanceof AST_UnaryPostfix && p.expression === node)
@@ -8578,6 +8579,7 @@ function left_is_object(node) {
8578
8579
  if (node.TYPE === "Call") return left_is_object(node.expression);
8579
8580
  if (node instanceof AST_PrefixedTemplateString) return left_is_object(node.prefix);
8580
8581
  if (node instanceof AST_Dot || node instanceof AST_Sub) return left_is_object(node.expression);
8582
+ if (node instanceof AST_Chain) return left_is_object(node.expression);
8581
8583
  if (node instanceof AST_Conditional) return left_is_object(node.condition);
8582
8584
  if (node instanceof AST_Binary) return left_is_object(node.left);
8583
8585
  if (node instanceof AST_UnaryPostfix) return left_is_object(node.expression);
@@ -8719,7 +8721,7 @@ function OutputStream(options) {
8719
8721
  if (options.shorthand === undefined)
8720
8722
  options.shorthand = options.ecma > 5;
8721
8723
 
8722
- // Convert comment option to RegExp if neccessary and set up comments filter
8724
+ // Convert comment option to RegExp if necessary and set up comments filter
8723
8725
  var comment_filter = return_false; // Default case, throw all comments away
8724
8726
  if (options.comments) {
8725
8727
  let comments = options.comments;
@@ -12718,8 +12720,9 @@ function is_ref_of(ref, type) {
12718
12720
  }
12719
12721
  }
12720
12722
 
12721
- // Can we turn { block contents... } into just the block contents ?
12722
- // Not if one of these is inside.
12723
+ /**Can we turn { block contents... } into just the block contents ?
12724
+ * Not if one of these is inside.
12725
+ **/
12723
12726
  function can_be_evicted_from_block(node) {
12724
12727
  return !(
12725
12728
  node instanceof AST_DefClass ||
@@ -16306,8 +16309,7 @@ function tighten_body(statements, compressor) {
16306
16309
  }
16307
16310
 
16308
16311
  function declarations_only(node) {
16309
- return node.definitions.every((var_def) => !var_def.value
16310
- );
16312
+ return node.definitions.every((var_def) => !var_def.value);
16311
16313
  }
16312
16314
 
16313
16315
  function sequencesize(statements, compressor) {
@@ -16353,7 +16355,7 @@ function tighten_body(statements, compressor) {
16353
16355
  var line = block.body[i];
16354
16356
  if (line instanceof AST_Var && declarations_only(line)) {
16355
16357
  decls.push(line);
16356
- } else if (stat) {
16358
+ } else if (stat || line instanceof AST_Const || line instanceof AST_Let) {
16357
16359
  return false;
16358
16360
  } else {
16359
16361
  stat = line;
@@ -16713,7 +16715,7 @@ function inline_into_symbolref(self, compressor) {
16713
16715
  }
16714
16716
  }
16715
16717
 
16716
- if (single_use && fixed instanceof AST_Lambda) {
16718
+ if (single_use && (fixed instanceof AST_Lambda || fixed instanceof AST_Class)) {
16717
16719
  single_use =
16718
16720
  def.scope === self.scope
16719
16721
  && !scope_encloses_variables_in_this_scope(nearest_scope, fixed)
@@ -271,8 +271,9 @@ export function is_ref_of(ref, type) {
271
271
  }
272
272
  }
273
273
 
274
- // Can we turn { block contents... } into just the block contents ?
275
- // Not if one of these is inside.
274
+ /**Can we turn { block contents... } into just the block contents ?
275
+ * Not if one of these is inside.
276
+ **/
276
277
  export function can_be_evicted_from_block(node) {
277
278
  return !(
278
279
  node instanceof AST_DefClass ||
@@ -210,7 +210,7 @@ export function inline_into_symbolref(self, compressor) {
210
210
  }
211
211
  }
212
212
 
213
- if (single_use && fixed instanceof AST_Lambda) {
213
+ if (single_use && (fixed instanceof AST_Lambda || fixed instanceof AST_Class)) {
214
214
  single_use =
215
215
  def.scope === self.scope
216
216
  && !scope_encloses_variables_in_this_scope(nearest_scope, fixed)
@@ -1189,8 +1189,7 @@ export function tighten_body(statements, compressor) {
1189
1189
  }
1190
1190
 
1191
1191
  function declarations_only(node) {
1192
- return node.definitions.every((var_def) => !var_def.value
1193
- );
1192
+ return node.definitions.every((var_def) => !var_def.value);
1194
1193
  }
1195
1194
 
1196
1195
  function sequencesize(statements, compressor) {
@@ -1236,7 +1235,7 @@ export function tighten_body(statements, compressor) {
1236
1235
  var line = block.body[i];
1237
1236
  if (line instanceof AST_Var && declarations_only(line)) {
1238
1237
  decls.push(line);
1239
- } else if (stat) {
1238
+ } else if (stat || line instanceof AST_Const || line instanceof AST_Let) {
1240
1239
  return false;
1241
1240
  } else {
1242
1241
  stat = line;
package/lib/output.js CHANGED
@@ -255,7 +255,7 @@ function OutputStream(options) {
255
255
  if (options.shorthand === undefined)
256
256
  options.shorthand = options.ecma > 5;
257
257
 
258
- // Convert comment option to RegExp if neccessary and set up comments filter
258
+ // Convert comment option to RegExp if necessary and set up comments filter
259
259
  var comment_filter = return_false; // Default case, throw all comments away
260
260
  if (options.comments) {
261
261
  let comments = options.comments;
package/lib/parse.js CHANGED
@@ -2801,14 +2801,14 @@ function parse($TEXT, options) {
2801
2801
  var end = prev();
2802
2802
 
2803
2803
  name = name || new type({
2804
- name: "*",
2805
2804
  start: start,
2805
+ name: "*",
2806
2806
  end: end,
2807
2807
  });
2808
2808
 
2809
2809
  foreign_name = new foreign_type({
2810
- name: "*",
2811
2810
  start: start,
2811
+ name: "*",
2812
2812
  end: end,
2813
2813
  });
2814
2814
 
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  AST_Binary,
3
3
  AST_Conditional,
4
+ AST_Chain,
4
5
  AST_Dot,
5
6
  AST_Object,
6
7
  AST_Sequence,
@@ -23,6 +24,7 @@ function first_in_statement(stack) {
23
24
  (p instanceof AST_PrefixedTemplateString && p.prefix === node) ||
24
25
  (p instanceof AST_Dot && p.expression === node) ||
25
26
  (p instanceof AST_Sub && p.expression === node) ||
27
+ (p instanceof AST_Chain && p.expression === node) ||
26
28
  (p instanceof AST_Conditional && p.condition === node) ||
27
29
  (p instanceof AST_Binary && p.left === node) ||
28
30
  (p instanceof AST_UnaryPostfix && p.expression === node)
@@ -41,6 +43,7 @@ function left_is_object(node) {
41
43
  if (node.TYPE === "Call") return left_is_object(node.expression);
42
44
  if (node instanceof AST_PrefixedTemplateString) return left_is_object(node.prefix);
43
45
  if (node instanceof AST_Dot || node instanceof AST_Sub) return left_is_object(node.expression);
46
+ if (node instanceof AST_Chain) return left_is_object(node.expression);
44
47
  if (node instanceof AST_Conditional) return left_is_object(node.condition);
45
48
  if (node instanceof AST_Binary) return left_is_object(node.left);
46
49
  if (node instanceof AST_UnaryPostfix) return left_is_object(node.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.15.0",
7
+ "version": "5.15.1",
8
8
  "engines": {
9
9
  "node": ">=10"
10
10
  },