vite 2.7.0-beta.1 → 2.7.0-beta.10

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.

Potentially problematic release.


This version of vite might be problematic. Click here for more details.

@@ -4613,7 +4613,7 @@ function parse($TEXT, options) {
4613
4613
  }
4614
4614
  if (S.token.value == "import" && !is_token(peek(), "punc", "(") && !is_token(peek(), "punc", ".")) {
4615
4615
  next();
4616
- var node = import_();
4616
+ var node = import_statement();
4617
4617
  semicolon();
4618
4618
  return node;
4619
4619
  }
@@ -4765,7 +4765,7 @@ function parse($TEXT, options) {
4765
4765
  case "export":
4766
4766
  if (!is_token(peek(), "punc", "(")) {
4767
4767
  next();
4768
- var node = export_();
4768
+ var node = export_statement();
4769
4769
  if (is("punc", ";")) semicolon();
4770
4770
  return node;
4771
4771
  }
@@ -5942,7 +5942,7 @@ function parse($TEXT, options) {
5942
5942
  };
5943
5943
 
5944
5944
  const is_not_method_start = () =>
5945
- !is("punc", "(") && !is("punc", ",") && !is("punc", "}") && !is("operator", "=");
5945
+ !is("punc", "(") && !is("punc", ",") && !is("punc", "}") && !is("punc", ";") && !is("operator", "=");
5946
5946
 
5947
5947
  var is_async = false;
5948
5948
  var is_static = false;
@@ -6057,7 +6057,15 @@ function parse($TEXT, options) {
6057
6057
  }
6058
6058
  }
6059
6059
 
6060
- function import_() {
6060
+ function maybe_import_assertion() {
6061
+ if (is("name", "assert") && !has_newline_before(S.token)) {
6062
+ next();
6063
+ return object_or_destructuring_();
6064
+ }
6065
+ return null;
6066
+ }
6067
+
6068
+ function import_statement() {
6061
6069
  var start = prev();
6062
6070
 
6063
6071
  var imported_name;
@@ -6080,16 +6088,20 @@ function parse($TEXT, options) {
6080
6088
  unexpected();
6081
6089
  }
6082
6090
  next();
6091
+
6092
+ const assert_clause = maybe_import_assertion();
6093
+
6083
6094
  return new AST_Import({
6084
- start: start,
6085
- imported_name: imported_name,
6086
- imported_names: imported_names,
6095
+ start,
6096
+ imported_name,
6097
+ imported_names,
6087
6098
  module_name: new AST_String({
6088
6099
  start: mod_str,
6089
6100
  value: mod_str.value,
6090
6101
  quote: mod_str.quote,
6091
6102
  end: mod_str,
6092
6103
  }),
6104
+ assert_clause,
6093
6105
  end: S.token,
6094
6106
  });
6095
6107
  }
@@ -6197,7 +6209,7 @@ function parse($TEXT, options) {
6197
6209
  return names;
6198
6210
  }
6199
6211
 
6200
- function export_() {
6212
+ function export_statement() {
6201
6213
  var start = S.token;
6202
6214
  var is_default;
6203
6215
  var exported_names;
@@ -6215,6 +6227,8 @@ function parse($TEXT, options) {
6215
6227
  }
6216
6228
  next();
6217
6229
 
6230
+ const assert_clause = maybe_import_assertion();
6231
+
6218
6232
  return new AST_Export({
6219
6233
  start: start,
6220
6234
  is_default: is_default,
@@ -6226,6 +6240,7 @@ function parse($TEXT, options) {
6226
6240
  end: mod_str,
6227
6241
  }),
6228
6242
  end: prev(),
6243
+ assert_clause
6229
6244
  });
6230
6245
  } else {
6231
6246
  return new AST_Export({
@@ -6271,6 +6286,7 @@ function parse($TEXT, options) {
6271
6286
  exported_value: exported_value,
6272
6287
  exported_definition: exported_definition,
6273
6288
  end: prev(),
6289
+ assert_clause: null
6274
6290
  });
6275
6291
  }
6276
6292
 
@@ -7604,12 +7620,13 @@ var AST_NameMapping = DEFNODE("NameMapping", "foreign_name name", {
7604
7620
  },
7605
7621
  });
7606
7622
 
7607
- var AST_Import = DEFNODE("Import", "imported_name imported_names module_name", {
7623
+ var AST_Import = DEFNODE("Import", "imported_name imported_names module_name assert_clause", {
7608
7624
  $documentation: "An `import` statement",
7609
7625
  $propdoc: {
7610
7626
  imported_name: "[AST_SymbolImport] The name of the variable holding the module's default export.",
7611
7627
  imported_names: "[AST_NameMapping*] The names of non-default imported variables",
7612
7628
  module_name: "[AST_String] String literal describing where this module came from",
7629
+ assert_clause: "[AST_Object?] The import assertion"
7613
7630
  },
7614
7631
  _walk: function(visitor) {
7615
7632
  return visitor._visit(this, function() {
@@ -7638,14 +7655,15 @@ var AST_ImportMeta = DEFNODE("ImportMeta", null, {
7638
7655
  $documentation: "A reference to import.meta",
7639
7656
  });
7640
7657
 
7641
- var AST_Export = DEFNODE("Export", "exported_definition exported_value is_default exported_names module_name", {
7658
+ var AST_Export = DEFNODE("Export", "exported_definition exported_value is_default exported_names module_name assert_clause", {
7642
7659
  $documentation: "An `export` statement",
7643
7660
  $propdoc: {
7644
7661
  exported_definition: "[AST_Defun|AST_Definitions|AST_DefClass?] An exported definition",
7645
7662
  exported_value: "[AST_Node?] An exported value",
7646
7663
  exported_names: "[AST_NameMapping*?] List of exported names",
7647
7664
  module_name: "[AST_String?] Name of the file to load exports from",
7648
- is_default: "[Boolean] Whether this is the default exported value of this module"
7665
+ is_default: "[Boolean] Whether this is the default exported value of this module",
7666
+ assert_clause: "[AST_Object?] The import assertion"
7649
7667
  },
7650
7668
  _walk: function (visitor) {
7651
7669
  return visitor._visit(this, function () {
@@ -8898,6 +8916,24 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
8898
8916
  return body;
8899
8917
  };
8900
8918
 
8919
+ const assert_clause_from_moz = (assertions) => {
8920
+ if (assertions && assertions.length > 0) {
8921
+ return new AST_Object({
8922
+ start: my_start_token(assertions),
8923
+ end: my_end_token(assertions),
8924
+ properties: assertions.map((assertion_kv) =>
8925
+ new AST_ObjectKeyVal({
8926
+ start: my_start_token(assertion_kv),
8927
+ end: my_end_token(assertion_kv),
8928
+ key: assertion_kv.key.name || assertion_kv.key.value,
8929
+ value: from_moz(assertion_kv.value)
8930
+ })
8931
+ )
8932
+ });
8933
+ }
8934
+ return null;
8935
+ };
8936
+
8901
8937
  var MOZ_TO_ME = {
8902
8938
  Program: function(M) {
8903
8939
  return new AST_Toplevel({
@@ -9218,7 +9254,8 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
9218
9254
  end : my_end_token(M),
9219
9255
  imported_name: imported_name,
9220
9256
  imported_names : imported_names,
9221
- module_name : from_moz(M.source)
9257
+ module_name : from_moz(M.source),
9258
+ assert_clause: assert_clause_from_moz(M.assertions)
9222
9259
  });
9223
9260
  },
9224
9261
  ExportAllDeclaration: function(M) {
@@ -9231,7 +9268,8 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
9231
9268
  foreign_name: new AST_SymbolExportForeign({ name: "*" })
9232
9269
  })
9233
9270
  ],
9234
- module_name: from_moz(M.source)
9271
+ module_name: from_moz(M.source),
9272
+ assert_clause: assert_clause_from_moz(M.assertions)
9235
9273
  });
9236
9274
  },
9237
9275
  ExportNamedDeclaration: function(M) {
@@ -9245,7 +9283,8 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
9245
9283
  name: from_moz(specifier.local)
9246
9284
  });
9247
9285
  }) : null,
9248
- module_name: from_moz(M.source)
9286
+ module_name: from_moz(M.source),
9287
+ assert_clause: assert_clause_from_moz(M.assertions)
9249
9288
  });
9250
9289
  },
9251
9290
  ExportDefaultDeclaration: function(M) {
@@ -9537,12 +9576,30 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
9537
9576
  };
9538
9577
  });
9539
9578
 
9579
+ const assert_clause_to_moz = assert_clause => {
9580
+ const assertions = [];
9581
+ if (assert_clause) {
9582
+ for (const { key, value } of assert_clause.properties) {
9583
+ const key_moz = is_basic_identifier_string(key)
9584
+ ? { type: "Identifier", name: key }
9585
+ : { type: "Literal", value: key, raw: JSON.stringify(key) };
9586
+ assertions.push({
9587
+ type: "ImportAttribute",
9588
+ key: key_moz,
9589
+ value: to_moz(value)
9590
+ });
9591
+ }
9592
+ }
9593
+ return assertions;
9594
+ };
9595
+
9540
9596
  def_to_moz(AST_Export, function To_Moz_ExportDeclaration(M) {
9541
9597
  if (M.exported_names) {
9542
9598
  if (M.exported_names[0].name.name === "*") {
9543
9599
  return {
9544
9600
  type: "ExportAllDeclaration",
9545
- source: to_moz(M.module_name)
9601
+ source: to_moz(M.module_name),
9602
+ assertions: assert_clause_to_moz(M.assert_clause)
9546
9603
  };
9547
9604
  }
9548
9605
  return {
@@ -9555,7 +9612,8 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
9555
9612
  };
9556
9613
  }),
9557
9614
  declaration: to_moz(M.exported_definition),
9558
- source: to_moz(M.module_name)
9615
+ source: to_moz(M.module_name),
9616
+ assertions: assert_clause_to_moz(M.assert_clause)
9559
9617
  };
9560
9618
  }
9561
9619
  return {
@@ -9589,7 +9647,8 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
9589
9647
  return {
9590
9648
  type: "ImportDeclaration",
9591
9649
  specifiers: specifiers,
9592
- source: to_moz(M.module_name)
9650
+ source: to_moz(M.module_name),
9651
+ assertions: assert_clause_to_moz(M.assert_clause)
9593
9652
  };
9594
9653
  });
9595
9654
 
@@ -10146,6 +10205,48 @@ function is_some_comments(comment) {
10146
10205
  );
10147
10206
  }
10148
10207
 
10208
+ class Rope {
10209
+ constructor() {
10210
+ this.committed = "";
10211
+ this.current = "";
10212
+ }
10213
+
10214
+ append(str) {
10215
+ this.current += str;
10216
+ }
10217
+
10218
+ insertAt(char, index) {
10219
+ const { committed, current } = this;
10220
+ if (index < committed.length) {
10221
+ this.committed = committed.slice(0, index) + char + committed.slice(index);
10222
+ } else if (index === committed.length) {
10223
+ this.committed += char;
10224
+ } else {
10225
+ index -= committed.length;
10226
+ this.committed += current.slice(0, index) + char;
10227
+ this.current = current.slice(index);
10228
+ }
10229
+ }
10230
+
10231
+ charAt(index) {
10232
+ const { committed } = this;
10233
+ if (index < committed.length) return committed[index];
10234
+ return this.current[index - committed.length];
10235
+ }
10236
+
10237
+ curLength() {
10238
+ return this.current.length;
10239
+ }
10240
+
10241
+ length() {
10242
+ return this.committed.length + this.current.length;
10243
+ }
10244
+
10245
+ toString() {
10246
+ return this.committed + this.current;
10247
+ }
10248
+ }
10249
+
10149
10250
  function OutputStream(options) {
10150
10251
 
10151
10252
  var readonly = !options;
@@ -10210,7 +10311,7 @@ function OutputStream(options) {
10210
10311
  var current_col = 0;
10211
10312
  var current_line = 1;
10212
10313
  var current_pos = 0;
10213
- var OUTPUT = "";
10314
+ var OUTPUT = new Rope();
10214
10315
  let printed_comments = new Set();
10215
10316
 
10216
10317
  var to_utf8 = options.ascii_only ? function(str, identifier) {
@@ -10341,19 +10442,18 @@ function OutputStream(options) {
10341
10442
  var ensure_line_len = options.max_line_len ? function() {
10342
10443
  if (current_col > options.max_line_len) {
10343
10444
  if (might_add_newline) {
10344
- var left = OUTPUT.slice(0, might_add_newline);
10345
- var right = OUTPUT.slice(might_add_newline);
10445
+ OUTPUT.insertAt("\n", might_add_newline);
10446
+ const curLength = OUTPUT.curLength();
10346
10447
  if (mappings) {
10347
- var delta = right.length - current_col;
10448
+ var delta = curLength - current_col;
10348
10449
  mappings.forEach(function(mapping) {
10349
10450
  mapping.line++;
10350
10451
  mapping.col += delta;
10351
10452
  });
10352
10453
  }
10353
- OUTPUT = left + "\n" + right;
10354
10454
  current_line++;
10355
10455
  current_pos++;
10356
- current_col = right.length;
10456
+ current_col = curLength;
10357
10457
  }
10358
10458
  }
10359
10459
  if (might_add_newline) {
@@ -10387,13 +10487,13 @@ function OutputStream(options) {
10387
10487
 
10388
10488
  if (prev === ":" && ch === "}" || (!ch || !";}".includes(ch)) && prev !== ";") {
10389
10489
  if (options.semicolons || requireSemicolonChars.has(ch)) {
10390
- OUTPUT += ";";
10490
+ OUTPUT.append(";");
10391
10491
  current_col++;
10392
10492
  current_pos++;
10393
10493
  } else {
10394
10494
  ensure_line_len();
10395
10495
  if (current_col > 0) {
10396
- OUTPUT += "\n";
10496
+ OUTPUT.append("\n");
10397
10497
  current_pos++;
10398
10498
  current_line++;
10399
10499
  current_col = 0;
@@ -10417,7 +10517,7 @@ function OutputStream(options) {
10417
10517
  || (ch == "/" && ch == prev)
10418
10518
  || ((ch == "+" || ch == "-") && ch == last)
10419
10519
  ) {
10420
- OUTPUT += " ";
10520
+ OUTPUT.append(" ");
10421
10521
  current_col++;
10422
10522
  current_pos++;
10423
10523
  }
@@ -10435,7 +10535,7 @@ function OutputStream(options) {
10435
10535
  if (!might_add_newline) do_add_mapping();
10436
10536
  }
10437
10537
 
10438
- OUTPUT += str;
10538
+ OUTPUT.append(str);
10439
10539
  has_parens = str[str.length - 1] == "(";
10440
10540
  current_pos += str.length;
10441
10541
  var a = str.split(/\r?\n/), n = a.length - 1;
@@ -10475,15 +10575,15 @@ function OutputStream(options) {
10475
10575
 
10476
10576
  var newline = options.beautify ? function() {
10477
10577
  if (newline_insert < 0) return print("\n");
10478
- if (OUTPUT[newline_insert] != "\n") {
10479
- OUTPUT = OUTPUT.slice(0, newline_insert) + "\n" + OUTPUT.slice(newline_insert);
10578
+ if (OUTPUT.charAt(newline_insert) != "\n") {
10579
+ OUTPUT.insertAt("\n", newline_insert);
10480
10580
  current_pos++;
10481
10581
  current_line++;
10482
10582
  }
10483
10583
  newline_insert++;
10484
10584
  } : options.max_line_len ? function() {
10485
10585
  ensure_line_len();
10486
- might_add_newline = OUTPUT.length;
10586
+ might_add_newline = OUTPUT.length();
10487
10587
  } : noop;
10488
10588
 
10489
10589
  var semicolon = options.beautify ? function() {
@@ -10549,13 +10649,14 @@ function OutputStream(options) {
10549
10649
  if (might_add_newline) {
10550
10650
  ensure_line_len();
10551
10651
  }
10552
- return OUTPUT;
10652
+ return OUTPUT.toString();
10553
10653
  }
10554
10654
 
10555
10655
  function has_nlb() {
10556
- let n = OUTPUT.length - 1;
10656
+ const output = OUTPUT.toString();
10657
+ let n = output.length - 1;
10557
10658
  while (n >= 0) {
10558
- const code = OUTPUT.charCodeAt(n);
10659
+ const code = output.charCodeAt(n);
10559
10660
  if (code === CODE_LINE_BREAK) {
10560
10661
  return true;
10561
10662
  }
@@ -10692,7 +10793,7 @@ function OutputStream(options) {
10692
10793
  !/comment[134]/.test(c.type)
10693
10794
  ))) return;
10694
10795
  printed_comments.add(comments);
10695
- var insert = OUTPUT.length;
10796
+ var insert = OUTPUT.length();
10696
10797
  comments.filter(comment_filter, node).forEach(function(c, i) {
10697
10798
  if (printed_comments.has(c)) return;
10698
10799
  printed_comments.add(c);
@@ -10721,7 +10822,7 @@ function OutputStream(options) {
10721
10822
  need_space = true;
10722
10823
  }
10723
10824
  });
10724
- if (OUTPUT.length > insert) newline_insert = insert;
10825
+ if (OUTPUT.length() > insert) newline_insert = insert;
10725
10826
  }
10726
10827
 
10727
10828
  var stack = [];
@@ -10751,7 +10852,7 @@ function OutputStream(options) {
10751
10852
  var encoded = encode_string(str, quote);
10752
10853
  if (escape_directive === true && !encoded.includes("\\")) {
10753
10854
  // Insert semicolons to break directive prologue
10754
- if (!EXPECT_DIRECTIVE.test(OUTPUT)) {
10855
+ if (!EXPECT_DIRECTIVE.test(OUTPUT.toString())) {
10755
10856
  force_semicolon();
10756
10857
  }
10757
10858
  force_semicolon();
@@ -11607,6 +11708,10 @@ function OutputStream(options) {
11607
11708
  output.space();
11608
11709
  }
11609
11710
  self.module_name.print(output);
11711
+ if (self.assert_clause) {
11712
+ output.print("assert");
11713
+ self.assert_clause.print(output);
11714
+ }
11610
11715
  output.semicolon();
11611
11716
  });
11612
11717
  DEFPRINT(AST_ImportMeta, function(self, output) {
@@ -11672,6 +11777,10 @@ function OutputStream(options) {
11672
11777
  output.space();
11673
11778
  self.module_name.print(output);
11674
11779
  }
11780
+ if (self.assert_clause) {
11781
+ output.print("assert");
11782
+ self.assert_clause.print(output);
11783
+ }
11675
11784
  if (self.exported_value
11676
11785
  && !(self.exported_value instanceof AST_Defun ||
11677
11786
  self.exported_value instanceof AST_Function ||
@@ -13222,6 +13331,8 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options) {
13222
13331
  }
13223
13332
 
13224
13333
  const mangled_names = this.mangled_names = new Set();
13334
+ unmangleable_names = new Set();
13335
+
13225
13336
  if (options.cache) {
13226
13337
  this.globals.forEach(collect);
13227
13338
  if (options.cache.props) {
@@ -13274,7 +13385,6 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options) {
13274
13385
  this.walk(tw);
13275
13386
 
13276
13387
  if (options.keep_fnames || options.keep_classnames) {
13277
- unmangleable_names = new Set();
13278
13388
  // Collect a set of short names which are unmangleable,
13279
13389
  // for use in avoiding collisions in next_mangled.
13280
13390
  to_mangle.forEach(def => {
@@ -13290,9 +13400,9 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options) {
13290
13400
  unmangleable_names = null;
13291
13401
 
13292
13402
  function collect(symbol) {
13293
- const should_mangle = !options.reserved.has(symbol.name)
13294
- && !(symbol.export & MASK_EXPORT_DONT_MANGLE);
13295
- if (should_mangle) {
13403
+ if (symbol.export & MASK_EXPORT_DONT_MANGLE) {
13404
+ unmangleable_names.add(symbol.name);
13405
+ } else if (!options.reserved.has(symbol.name)) {
13296
13406
  to_mangle.push(symbol);
13297
13407
  }
13298
13408
  }
@@ -14330,6 +14440,7 @@ const is_pure_native_fn = make_nested_lookup({
14330
14440
  "isExtensible",
14331
14441
  "isFrozen",
14332
14442
  "isSealed",
14443
+ "hasOwn",
14333
14444
  "keys",
14334
14445
  ],
14335
14446
  String: [
@@ -19357,7 +19468,7 @@ def_optimize(AST_Switch, function(self, compressor) {
19357
19468
  // that way the next micro-optimization will merge them.
19358
19469
  // ** bail micro-optimization if not a simple switch case with breaks
19359
19470
  if (body.every((branch, i) =>
19360
- (branch === default_or_exact || !branch.expression.has_side_effects(compressor))
19471
+ (branch === default_or_exact || branch.expression instanceof AST_Constant)
19361
19472
  && (branch.body.length === 0 || aborts(branch) || body.length - 1 === i))
19362
19473
  ) {
19363
19474
  for (let i = 0; i < body.length; i++) {
@@ -19445,12 +19556,16 @@ def_optimize(AST_Switch, function(self, compressor) {
19445
19556
 
19446
19557
 
19447
19558
  // Prune side-effect free branches that fall into default.
19448
- if (default_or_exact) {
19559
+ DEFAULT: if (default_or_exact) {
19449
19560
  let default_index = body.indexOf(default_or_exact);
19450
19561
  let default_body_index = default_index;
19451
19562
  for (; default_body_index < body.length - 1; default_body_index++) {
19452
19563
  if (!is_inert_body(body[default_body_index])) break;
19453
19564
  }
19565
+ if (default_body_index < body.length - 1) {
19566
+ break DEFAULT;
19567
+ }
19568
+
19454
19569
  let side_effect_index = body.length - 1;
19455
19570
  for (; side_effect_index >= 0; side_effect_index--) {
19456
19571
  let branch = body[side_effect_index];
@@ -20497,16 +20612,16 @@ def_optimize(AST_UnaryPostfix, function(self, compressor) {
20497
20612
 
20498
20613
  def_optimize(AST_UnaryPrefix, function(self, compressor) {
20499
20614
  var e = self.expression;
20500
- if (self.operator == "delete"
20501
- && !(e instanceof AST_SymbolRef
20502
- || e instanceof AST_PropAccess
20503
- || is_identifier_atom(e))) {
20504
- if (e instanceof AST_Sequence) {
20505
- const exprs = e.expressions.slice();
20506
- exprs.push(make_node(AST_True, self));
20507
- return make_sequence(self, exprs).optimize(compressor);
20508
- }
20509
- return make_sequence(self, [ e, make_node(AST_True, self) ]).optimize(compressor);
20615
+ if (
20616
+ self.operator == "delete" &&
20617
+ !(
20618
+ e instanceof AST_SymbolRef ||
20619
+ e instanceof AST_PropAccess ||
20620
+ e instanceof AST_Chain ||
20621
+ is_identifier_atom(e)
20622
+ )
20623
+ ) {
20624
+ return make_sequence(self, [e, make_node(AST_True, self)]).optimize(compressor);
20510
20625
  }
20511
20626
  var seq = self.lift_sequences(compressor);
20512
20627
  if (seq !== self) {
@@ -21338,7 +21453,15 @@ function is_reachable(self, defs) {
21338
21453
  if (node instanceof AST_Scope && node !== self) {
21339
21454
  var parent = info.parent();
21340
21455
 
21341
- if (parent instanceof AST_Call && parent.expression === node) return;
21456
+ if (
21457
+ parent instanceof AST_Call
21458
+ && parent.expression === node
21459
+ // Async/Generators aren't guaranteed to sync evaluate all of
21460
+ // their body steps, so it's possible they close over the variable.
21461
+ && !(node.async || node.is_generator)
21462
+ ) {
21463
+ return;
21464
+ }
21342
21465
 
21343
21466
  if (walk(node, find_ref)) return walk_abort;
21344
21467
 
@@ -21990,7 +22113,16 @@ def_optimize(AST_Sub, function(self, compressor) {
21990
22113
  });
21991
22114
 
21992
22115
  def_optimize(AST_Chain, function (self, compressor) {
21993
- if (is_nullish(self.expression, compressor)) return make_node(AST_Undefined, self);
22116
+ if (is_nullish(self.expression, compressor)) {
22117
+ let parent = compressor.parent();
22118
+ // It's valid to delete a nullish optional chain, but if we optimized
22119
+ // this to `delete undefined` then it would appear to be a syntax error
22120
+ // when we try to optimize the delete. Thankfully, `delete 0` is fine.
22121
+ if (parent instanceof AST_UnaryPrefix && parent.operator === "delete") {
22122
+ return make_node_from_constant(0, self);
22123
+ }
22124
+ return make_node(AST_Undefined, self);
22125
+ }
21994
22126
  return self;
21995
22127
  });
21996
22128
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite",
3
- "version": "2.7.0-beta.1",
3
+ "version": "2.7.0-beta.10",
4
4
  "license": "MIT",
5
5
  "author": "Evan You",
6
6
  "description": "Native-ESM powered web dev build tool",
@@ -35,27 +35,27 @@
35
35
  "build-types": "run-s build-temp-types patch-types roll-types",
36
36
  "build-temp-types": "tsc --emitDeclarationOnly --outDir temp/node -p src/node",
37
37
  "ci-build": "rimraf dist && run-s build-bundle build-types",
38
- "patch-types": "node scripts/patchTypes",
38
+ "patch-types": "node scripts/patchTypes.cjs",
39
39
  "roll-types": "api-extractor run && rimraf temp",
40
40
  "lint": "eslint --ext .ts src/**",
41
41
  "format": "prettier --write --parser typescript \"src/**/*.ts\"",
42
42
  "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path .",
43
- "release": "node ../../scripts/release.js"
43
+ "release": "node ../../scripts/release.cjs"
44
44
  },
45
45
  "//": "READ CONTRIBUTING.md to understand what to put under deps vs. devDeps!",
46
46
  "dependencies": {
47
- "esbuild": "^0.13.10",
47
+ "esbuild": "^0.13.12",
48
48
  "postcss": "^8.3.11",
49
49
  "resolve": "^1.20.0",
50
- "rollup": "^2.58.3"
50
+ "rollup": "^2.59.0"
51
51
  },
52
52
  "optionalDependencies": {
53
53
  "fsevents": "~2.3.2"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@ampproject/remapping": "^1.0.1",
57
- "@babel/parser": "^7.15.8",
58
- "@babel/types": "^7.15.6",
57
+ "@babel/parser": "^7.16.4",
58
+ "@babel/types": "^7.16.0",
59
59
  "@rollup/plugin-alias": "^3.1.8",
60
60
  "@rollup/plugin-commonjs": "^21.0.1",
61
61
  "@rollup/plugin-dynamic-import-vars": "^1.4.1",
@@ -65,22 +65,21 @@
65
65
  "@rollup/pluginutils": "^4.1.1",
66
66
  "@types/convert-source-map": "^1.5.2",
67
67
  "@types/debug": "^4.1.7",
68
- "@types/es-module-lexer": "^0.4.1",
69
68
  "@types/estree": "^0.0.50",
70
69
  "@types/etag": "^1.8.1",
71
70
  "@types/less": "^3.0.3",
71
+ "@types/micromatch": "^4.0.2",
72
72
  "@types/mime": "^2.0.3",
73
- "@types/node": "^15.14.9",
73
+ "@types/node": "^16.11.9",
74
74
  "@types/resolve": "^1.20.1",
75
- "@types/sass": "~1.16.1",
75
+ "@types/sass": "~1.43.0",
76
76
  "@types/stylus": "^0.48.36",
77
- "@types/ws": "^7.4.7",
78
- "@vue/compiler-dom": "^3.2.20",
79
- "acorn": "^8.5.0",
77
+ "@types/ws": "^8.2.0",
78
+ "@vue/compiler-dom": "^3.2.22",
79
+ "acorn": "^8.6.0",
80
80
  "acorn-class-fields": "^1.0.0",
81
81
  "acorn-static-class-features": "^1.0.0",
82
- "builtin-modules": "^3.2.0",
83
- "cac": "6.7.3",
82
+ "cac": "6.7.9",
84
83
  "chalk": "^4.1.2",
85
84
  "chokidar": "^3.5.2",
86
85
  "compression": "^1.7.4",
@@ -99,8 +98,8 @@
99
98
  "http-proxy": "^1.18.1",
100
99
  "launch-editor-middleware": "^2.2.1",
101
100
  "magic-string": "^0.25.7",
102
- "mime": "^2.5.2",
103
- "minimatch": "^3.0.4",
101
+ "micromatch": "^4.0.4",
102
+ "mime": "^3.0.0",
104
103
  "okie": "^1.0.1",
105
104
  "open": "^8.4.0",
106
105
  "periscopic": "^2.0.3",
@@ -112,13 +111,13 @@
112
111
  "selfsigned": "^1.10.11",
113
112
  "sirv": "^1.0.18",
114
113
  "source-map": "^0.6.1",
115
- "source-map-support": "^0.5.20",
114
+ "source-map-support": "^0.5.21",
116
115
  "strip-ansi": "^6.0.1",
117
- "terser": "^5.9.0",
118
- "tsconfck": "1.0.0",
116
+ "terser": "^5.10.0",
117
+ "tsconfck": "1.1.1",
119
118
  "tslib": "^2.3.1",
120
119
  "types": "link:./types",
121
- "ws": "^7.5.5"
120
+ "ws": "^8.2.3"
122
121
  },
123
122
  "peerDependencies": {
124
123
  "less": "*",
@@ -78,10 +78,8 @@ async function handleMessage(payload: HMRPayload) {
78
78
  // can't use querySelector with `[href*=]` here since the link may be
79
79
  // using relative paths so we need to use link.href to grab the full
80
80
  // URL for the include check.
81
- const el = (
82
- [].slice.call(
83
- document.querySelectorAll(`link`)
84
- ) as HTMLLinkElement[]
81
+ const el = Array.from(
82
+ document.querySelectorAll<HTMLLinkElement>('link')
85
83
  ).find((e) => e.href.includes(path))
86
84
  if (el) {
87
85
  const newPath = `${base}${path.slice(1)}${
@@ -275,8 +273,6 @@ export function removeStyle(id: string): void {
275
273
  const style = sheetsMap.get(id)
276
274
  if (style) {
277
275
  if (style instanceof CSSStyleSheet) {
278
- // @ts-ignore
279
- const index = document.adoptedStyleSheets.indexOf(style)
280
276
  // @ts-ignore
281
277
  document.adoptedStyleSheets = document.adoptedStyleSheets.filter(
282
278
  (s: CSSStyleSheet) => s !== style