vite 2.7.0-beta.5 → 2.7.0-beta.9

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.

package/dist/node/cli.js CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var require$$0 = require('events');
4
- var build = require('./chunks/dep-6920cd01.js');
4
+ var build = require('./chunks/dep-9aea22f6.js');
5
5
  var perf_hooks = require('perf_hooks');
6
6
  require('fs');
7
7
  require('path');
@@ -683,7 +683,7 @@ cli
683
683
  .action(async (root, options) => {
684
684
  // output structure is preserved even after bundling so require()
685
685
  // is ok here
686
- const { createServer } = await Promise.resolve().then(function () { return require('./chunks/dep-6920cd01.js'); }).then(function (n) { return n.index$1; });
686
+ const { createServer } = await Promise.resolve().then(function () { return require('./chunks/dep-9aea22f6.js'); }).then(function (n) { return n.index$1; });
687
687
  try {
688
688
  const server = await createServer({
689
689
  root,
@@ -732,7 +732,7 @@ cli
732
732
  .option('--emptyOutDir', `[boolean] force empty outDir when it's outside of root`)
733
733
  .option('-w, --watch', `[boolean] rebuilds when modules have changed on disk`)
734
734
  .action(async (root, options) => {
735
- const { build: build$1 } = await Promise.resolve().then(function () { return require('./chunks/dep-6920cd01.js'); }).then(function (n) { return n.build$1; });
735
+ const { build: build$1 } = await Promise.resolve().then(function () { return require('./chunks/dep-9aea22f6.js'); }).then(function (n) { return n.build$1; });
736
736
  const buildOptions = cleanOptions(options);
737
737
  try {
738
738
  await build$1({
@@ -755,7 +755,7 @@ cli
755
755
  .command('optimize [root]')
756
756
  .option('--force', `[boolean] force the optimizer to ignore the cache and re-bundle`)
757
757
  .action(async (root, options) => {
758
- const { optimizeDeps } = await Promise.resolve().then(function () { return require('./chunks/dep-6920cd01.js'); }).then(function (n) { return n.index; });
758
+ const { optimizeDeps } = await Promise.resolve().then(function () { return require('./chunks/dep-9aea22f6.js'); }).then(function (n) { return n.index; });
759
759
  try {
760
760
  const config = await build.resolveConfig({
761
761
  root,
@@ -575,7 +575,6 @@ export declare interface FileSystemServeOptions {
575
575
  * Strictly restrict file accessing outside of allowing paths.
576
576
  *
577
577
  * Set to `false` to disable the warning
578
- * Default to false at this moment, will enabled by default in the future versions.
579
578
  *
580
579
  * @default true
581
580
  */
@@ -973,6 +972,7 @@ export declare interface InternalResolveOptions extends ResolveOptions {
973
972
  isBuild: boolean;
974
973
  isProduction: boolean;
975
974
  ssrConfig?: SSROptions;
975
+ packageCache?: PackageCache;
976
976
  /**
977
977
  * src code mode also attempts the following:
978
978
  * - resolving /xxx as URLs
@@ -986,6 +986,7 @@ export declare interface InternalResolveOptions extends ResolveOptions {
986
986
  preserveSymlinks?: boolean;
987
987
  isRequire?: boolean;
988
988
  isFromTsImporter?: boolean;
989
+ tryEsmOnly?: boolean;
989
990
  }
990
991
 
991
992
  export declare interface JsonOptions {
@@ -1118,9 +1119,12 @@ export declare function normalizePath(id: string): string;
1118
1119
  export declare function optimizeDeps(config: ResolvedConfig, force?: boolean | undefined, asCommand?: boolean, newDeps?: Record<string, string>, // missing imports encountered after server has started
1119
1120
  ssr?: boolean): Promise<DepOptimizationMetadata | null>;
1120
1121
 
1122
+ /** Cache for package.json resolution and package.json contents */
1123
+ export declare type PackageCache = Map<string, PackageData>;
1124
+
1121
1125
  export declare interface PackageData {
1122
1126
  dir: string;
1123
- hasSideEffects: (id: string) => boolean;
1127
+ hasSideEffects: (id: string) => boolean | 'no-treeshake';
1124
1128
  webResolvedImports: Record<string, string | undefined>;
1125
1129
  nodeResolvedImports: Record<string, string | undefined>;
1126
1130
  setResolvedCache: (key: string, entry: string, targetWeb: boolean) => void;
@@ -1342,6 +1346,7 @@ export declare type ResolvedConfig = Readonly<Omit<UserConfig, 'plugins' | 'alia
1342
1346
  logger: Logger;
1343
1347
  createResolver: (options?: Partial<InternalResolveOptions>) => ResolveFn;
1344
1348
  optimizeDeps: Omit<DepOptimizationOptions, 'keepNames'>;
1349
+ /* Excluded from this release type: packageCache */
1345
1350
  }>;
1346
1351
 
1347
1352
  export declare interface ResolvedPreviewOptions extends PreviewOptions {
@@ -1369,9 +1374,9 @@ export declare interface ResolveOptions {
1369
1374
  preserveSymlinks?: boolean;
1370
1375
  }
1371
1376
 
1372
- export declare function resolvePackageData(id: string, basedir: string, preserveSymlinks?: boolean): PackageData | undefined;
1377
+ export declare function resolvePackageData(id: string, basedir: string, preserveSymlinks?: boolean, packageCache?: PackageCache): PackageData | null;
1373
1378
 
1374
- export declare function resolvePackageEntry(id: string, { dir, data, setResolvedCache, getResolvedCache }: PackageData, options: InternalResolveOptions, targetWeb: boolean, preserveSymlinks?: boolean): string | undefined;
1379
+ export declare function resolvePackageEntry(id: string, { dir, data, setResolvedCache, getResolvedCache }: PackageData, targetWeb: boolean, options: InternalResolveOptions): string | undefined;
1375
1380
 
1376
1381
  export declare type ResolverFunction = PluginHooks['resolveId']
1377
1382
 
@@ -2041,9 +2046,17 @@ export declare interface ViteDevServer {
2041
2046
  * Print server urls
2042
2047
  */
2043
2048
  printUrls(): void;
2049
+ /**
2050
+ * Restart the server.
2051
+ *
2052
+ * @param forceOptimize - force the optimizer to re-bundle, same as --force cli flag
2053
+ */
2054
+ restart(forceOptimize?: boolean): Promise<void>;
2044
2055
  /* Excluded from this release type: _optimizeDepsMetadata */
2045
2056
  /* Excluded from this release type: _ssrExternals */
2046
2057
  /* Excluded from this release type: _globImporters */
2058
+ /* Excluded from this release type: _restartPromise */
2059
+ /* Excluded from this release type: _forceOptimizeOnRestart */
2047
2060
  /* Excluded from this release type: _isRunningOptimizer */
2048
2061
  /* Excluded from this release type: _registerMissingImport */
2049
2062
  /* Excluded from this release type: _pendingReload */
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var build = require('./chunks/dep-6920cd01.js');
5
+ var build = require('./chunks/dep-9aea22f6.js');
6
6
  require('fs');
7
7
  require('path');
8
8
  require('os');
@@ -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