rollup 3.0.0-3 → 3.0.0-6

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.
@@ -1,20 +1,21 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v3.0.0-2
4
- Sat, 30 Jul 2022 12:51:34 GMT - commit 41906cedefbc03640d6e8ca23ce6975f3bb5c6a1
3
+ Rollup.js v3.0.0-5
4
+ Tue, 06 Sep 2022 05:29:28 GMT - commit 1d085668121abe6be83c28c212a02c181c16d2b8
5
5
 
6
6
  https://github.com/rollup/rollup
7
7
 
8
8
  Released under the MIT License.
9
9
  */
10
- import require$$0, { resolve, basename, extname, dirname, relative as relative$1, win32, posix, isAbsolute as isAbsolute$1 } from 'path';
11
- import process$1 from 'process';
12
- import { performance } from 'perf_hooks';
13
- import { createHash as createHash$1 } from 'crypto';
14
- import { promises } from 'fs';
15
- import { EventEmitter } from 'events';
10
+ import { resolve, basename, extname, dirname, relative as relative$1 } from 'node:path';
11
+ import require$$0, { win32, posix, isAbsolute as isAbsolute$1, resolve as resolve$1 } from 'path';
12
+ import process$1 from 'node:process';
13
+ import { performance } from 'node:perf_hooks';
14
+ import { createHash as createHash$1 } from 'node:crypto';
15
+ import { promises } from 'node:fs';
16
+ import { EventEmitter } from 'node:events';
16
17
 
17
- var version$1 = "3.0.0-2";
18
+ var version$1 = "3.0.0-5";
18
19
 
19
20
  var charToInteger = {};
20
21
  var chars$1 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
@@ -307,15 +308,20 @@ class Chunk$1 {
307
308
  }
308
309
  }
309
310
 
310
- let btoa = () => {
311
- throw new Error('Unsupported environment: `window.btoa` or `Buffer` should be supported.');
312
- };
313
- if (typeof window !== 'undefined' && typeof window.btoa === 'function') {
314
- btoa = (str) => window.btoa(unescape(encodeURIComponent(str)));
315
- } else if (typeof Buffer === 'function') {
316
- btoa = (str) => Buffer.from(str, 'utf-8').toString('base64');
311
+ function getBtoa () {
312
+ if (typeof window !== 'undefined' && typeof window.btoa === 'function') {
313
+ return (str) => window.btoa(unescape(encodeURIComponent(str)));
314
+ } else if (typeof Buffer === 'function') {
315
+ return (str) => Buffer.from(str, 'utf-8').toString('base64');
316
+ } else {
317
+ return () => {
318
+ throw new Error('Unsupported environment: `window.btoa` or `Buffer` should be supported.');
319
+ };
320
+ }
317
321
  }
318
322
 
323
+ const btoa = /*#__PURE__*/ getBtoa();
324
+
319
325
  class SourceMap {
320
326
  constructor(properties) {
321
327
  this.version = 3;
@@ -507,7 +513,7 @@ class MagicString {
507
513
  indentExclusionRanges: { writable: true, value: options.indentExclusionRanges },
508
514
  sourcemapLocations: { writable: true, value: new BitSet() },
509
515
  storedNames: { writable: true, value: {} },
510
- indentStr: { writable: true, value: guessIndent(string) },
516
+ indentStr: { writable: true, value: undefined },
511
517
  });
512
518
 
513
519
  this.byStart[0] = chunk;
@@ -637,7 +643,19 @@ class MagicString {
637
643
  return new SourceMap(this.generateDecodedMap(options));
638
644
  }
639
645
 
646
+ _ensureindentStr() {
647
+ if (this.indentStr === undefined) {
648
+ this.indentStr = guessIndent(this.original);
649
+ }
650
+ }
651
+
652
+ _getRawIndentString() {
653
+ this._ensureindentStr();
654
+ return this.indentStr;
655
+ }
656
+
640
657
  getIndentString() {
658
+ this._ensureindentStr();
641
659
  return this.indentStr === null ? '\t' : this.indentStr;
642
660
  }
643
661
 
@@ -649,7 +667,10 @@ class MagicString {
649
667
  indentStr = undefined;
650
668
  }
651
669
 
652
- indentStr = indentStr !== undefined ? indentStr : this.indentStr || '\t';
670
+ if (indentStr === undefined) {
671
+ this._ensureindentStr();
672
+ indentStr = this.indentStr || '\t';
673
+ }
653
674
 
654
675
  if (indentStr === '') return this; // noop
655
676
 
@@ -1365,7 +1386,7 @@ class Bundle$1 {
1365
1386
  const indentStringCounts = {};
1366
1387
 
1367
1388
  this.sources.forEach((source) => {
1368
- const indentStr = source.content.indentStr;
1389
+ const indentStr = source.content._getRawIndentString();
1369
1390
 
1370
1391
  if (indentStr === null) return;
1371
1392
 
@@ -1605,6 +1626,7 @@ function getOrCreate(map, key, init) {
1605
1626
  const UnknownKey = Symbol('Unknown Key');
1606
1627
  const UnknownNonAccessorKey = Symbol('Unknown Non-Accessor Key');
1607
1628
  const UnknownInteger = Symbol('Unknown Integer');
1629
+ const SymbolToStringTag = Symbol('Symbol.toStringTag');
1608
1630
  const EMPTY_PATH = [];
1609
1631
  const UNKNOWN_PATH = [UnknownKey];
1610
1632
  // For deoptimizations, this means we are modifying an unknown property but did
@@ -1682,7 +1704,7 @@ class ExpressionEntity {
1682
1704
  /**
1683
1705
  * If possible it returns a stringifyable literal value for this node that can be used
1684
1706
  * for inlining or comparing values.
1685
- * Otherwise it should return UnknownValue.
1707
+ * Otherwise, it should return UnknownValue.
1686
1708
  */
1687
1709
  getLiteralValueAtPath(_path, _recursionTracker, _origin) {
1688
1710
  return UnknownValue;
@@ -1914,7 +1936,7 @@ function augmentCodeLocation(props, pos, source, id) {
1914
1936
  }
1915
1937
  // Error codes should be sorted alphabetically while errors should be sorted by
1916
1938
  // error code below
1917
- const ADDON_ERROR = 'ADDON_ERROR', ALREADY_CLOSED = 'ALREADY_CLOSED', AMBIGUOUS_EXTERNAL_NAMESPACES = 'AMBIGUOUS_EXTERNAL_NAMESPACES', ANONYMOUS_PLUGIN_CACHE = 'ANONYMOUS_PLUGIN_CACHE', ASSET_NOT_FINALISED = 'ASSET_NOT_FINALISED', ASSET_NOT_FOUND = 'ASSET_NOT_FOUND', ASSET_SOURCE_ALREADY_SET = 'ASSET_SOURCE_ALREADY_SET', ASSET_SOURCE_MISSING = 'ASSET_SOURCE_MISSING', BAD_LOADER = 'BAD_LOADER', CANNOT_CALL_NAMESPACE = 'CANNOT_CALL_NAMESPACE', CANNOT_EMIT_FROM_OPTIONS_HOOK = 'CANNOT_EMIT_FROM_OPTIONS_HOOK', CHUNK_NOT_GENERATED = 'CHUNK_NOT_GENERATED', CHUNK_INVALID = 'CHUNK_INVALID', CIRCULAR_DEPENDENCY = 'CIRCULAR_DEPENDENCY', CIRCULAR_REEXPORT = 'CIRCULAR_REEXPORT', CYCLIC_CROSS_CHUNK_REEXPORT = 'CYCLIC_CROSS_CHUNK_REEXPORT', DEPRECATED_FEATURE = 'DEPRECATED_FEATURE', DUPLICATE_PLUGIN_NAME = 'DUPLICATE_PLUGIN_NAME', EMPTY_BUNDLE = 'EMPTY_BUNDLE', EVAL = 'EVAL', EXTERNAL_SYNTHETIC_EXPORTS = 'EXTERNAL_SYNTHETIC_EXPORTS', FILE_NAME_CONFLICT = 'FILE_NAME_CONFLICT', FILE_NOT_FOUND = 'FILE_NOT_FOUND', ILLEGAL_IDENTIFIER_AS_NAME = 'ILLEGAL_IDENTIFIER_AS_NAME', ILLEGAL_REASSIGNMENT = 'ILLEGAL_REASSIGNMENT', INPUT_HOOK_IN_OUTPUT_PLUGIN = 'INPUT_HOOK_IN_OUTPUT_PLUGIN', INVALID_CHUNK = 'INVALID_CHUNK', INVALID_EXPORT_OPTION = 'INVALID_EXPORT_OPTION', INVALID_EXTERNAL_ID = 'INVALID_EXTERNAL_ID', INVALID_OPTION = 'INVALID_OPTION', INVALID_PLUGIN_HOOK = 'INVALID_PLUGIN_HOOK', INVALID_ROLLUP_PHASE = 'INVALID_ROLLUP_PHASE', INVALID_SETASSETSOURCE = 'INVALID_SETASSETSOURCE', INVALID_TLA_FORMAT = 'INVALID_TLA_FORMAT', MISSING_EXPORT = 'MISSING_EXPORT', MISSING_GLOBAL_NAME = 'MISSING_GLOBAL_NAME', MISSING_IMPLICIT_DEPENDANT = 'MISSING_IMPLICIT_DEPENDANT', MISSING_NAME_OPTION_FOR_IIFE_EXPORT = 'MISSING_NAME_OPTION_FOR_IIFE_EXPORT', MISSING_NODE_BUILTINS = 'MISSING_NODE_BUILTINS', MISSING_OPTION = 'MISSING_OPTION', MIXED_EXPORTS = 'MIXED_EXPORTS', MODULE_LEVEL_DIRECTIVE = 'MODULE_LEVEL_DIRECTIVE', NAMESPACE_CONFLICT = 'NAMESPACE_CONFLICT', NO_TRANSFORM_MAP_OR_AST_WITHOUT_CODE = 'NO_TRANSFORM_MAP_OR_AST_WITHOUT_CODE', PARSE_ERROR = 'PARSE_ERROR', PLUGIN_ERROR = 'PLUGIN_ERROR', PREFER_NAMED_EXPORTS = 'PREFER_NAMED_EXPORTS', SHIMMED_EXPORT = 'SHIMMED_EXPORT', SOURCEMAP_BROKEN = 'SOURCEMAP_BROKEN', SOURCEMAP_ERROR = 'SOURCEMAP_ERROR', SYNTHETIC_NAMED_EXPORTS_NEED_NAMESPACE_EXPORT = 'SYNTHETIC_NAMED_EXPORTS_NEED_NAMESPACE_EXPORT', THIS_IS_UNDEFINED = 'THIS_IS_UNDEFINED', UNEXPECTED_NAMED_IMPORT = 'UNEXPECTED_NAMED_IMPORT', UNKNOWN_OPTION = 'UNKNOWN_OPTION', UNRESOLVED_ENTRY = 'UNRESOLVED_ENTRY', UNRESOLVED_IMPORT = 'UNRESOLVED_IMPORT', UNUSED_EXTERNAL_IMPORT = 'UNUSED_EXTERNAL_IMPORT', VALIDATION_ERROR = 'VALIDATION_ERROR';
1939
+ const ADDON_ERROR = 'ADDON_ERROR', ALREADY_CLOSED = 'ALREADY_CLOSED', AMBIGUOUS_EXTERNAL_NAMESPACES = 'AMBIGUOUS_EXTERNAL_NAMESPACES', ANONYMOUS_PLUGIN_CACHE = 'ANONYMOUS_PLUGIN_CACHE', ASSET_NOT_FINALISED = 'ASSET_NOT_FINALISED', ASSET_NOT_FOUND = 'ASSET_NOT_FOUND', ASSET_SOURCE_ALREADY_SET = 'ASSET_SOURCE_ALREADY_SET', ASSET_SOURCE_MISSING = 'ASSET_SOURCE_MISSING', BAD_LOADER = 'BAD_LOADER', CANNOT_CALL_NAMESPACE = 'CANNOT_CALL_NAMESPACE', CANNOT_EMIT_FROM_OPTIONS_HOOK = 'CANNOT_EMIT_FROM_OPTIONS_HOOK', CHUNK_NOT_GENERATED = 'CHUNK_NOT_GENERATED', CHUNK_INVALID = 'CHUNK_INVALID', CIRCULAR_DEPENDENCY = 'CIRCULAR_DEPENDENCY', CIRCULAR_REEXPORT = 'CIRCULAR_REEXPORT', CYCLIC_CROSS_CHUNK_REEXPORT = 'CYCLIC_CROSS_CHUNK_REEXPORT', DEPRECATED_FEATURE = 'DEPRECATED_FEATURE', DUPLICATE_PLUGIN_NAME = 'DUPLICATE_PLUGIN_NAME', EMPTY_BUNDLE = 'EMPTY_BUNDLE', EVAL = 'EVAL', EXTERNAL_SYNTHETIC_EXPORTS = 'EXTERNAL_SYNTHETIC_EXPORTS', FILE_NAME_CONFLICT = 'FILE_NAME_CONFLICT', FILE_NOT_FOUND = 'FILE_NOT_FOUND', ILLEGAL_IDENTIFIER_AS_NAME = 'ILLEGAL_IDENTIFIER_AS_NAME', ILLEGAL_REASSIGNMENT = 'ILLEGAL_REASSIGNMENT', INPUT_HOOK_IN_OUTPUT_PLUGIN = 'INPUT_HOOK_IN_OUTPUT_PLUGIN', INVALID_CHUNK = 'INVALID_CHUNK', INVALID_EXPORT_OPTION = 'INVALID_EXPORT_OPTION', INVALID_EXTERNAL_ID = 'INVALID_EXTERNAL_ID', INVALID_OPTION = 'INVALID_OPTION', INVALID_PLUGIN_HOOK = 'INVALID_PLUGIN_HOOK', INVALID_ROLLUP_PHASE = 'INVALID_ROLLUP_PHASE', INVALID_SETASSETSOURCE = 'INVALID_SETASSETSOURCE', INVALID_TLA_FORMAT = 'INVALID_TLA_FORMAT', MISSING_EXPORT = 'MISSING_EXPORT', MISSING_GLOBAL_NAME = 'MISSING_GLOBAL_NAME', MISSING_IMPLICIT_DEPENDANT = 'MISSING_IMPLICIT_DEPENDANT', MISSING_NAME_OPTION_FOR_IIFE_EXPORT = 'MISSING_NAME_OPTION_FOR_IIFE_EXPORT', MISSING_NODE_BUILTINS = 'MISSING_NODE_BUILTINS', MISSING_OPTION = 'MISSING_OPTION', MIXED_EXPORTS = 'MIXED_EXPORTS', MODULE_LEVEL_DIRECTIVE = 'MODULE_LEVEL_DIRECTIVE', NAMESPACE_CONFLICT = 'NAMESPACE_CONFLICT', NO_TRANSFORM_MAP_OR_AST_WITHOUT_CODE = 'NO_TRANSFORM_MAP_OR_AST_WITHOUT_CODE', PARSE_ERROR = 'PARSE_ERROR', PLUGIN_ERROR = 'PLUGIN_ERROR', SHIMMED_EXPORT = 'SHIMMED_EXPORT', SOURCEMAP_BROKEN = 'SOURCEMAP_BROKEN', SOURCEMAP_ERROR = 'SOURCEMAP_ERROR', SYNTHETIC_NAMED_EXPORTS_NEED_NAMESPACE_EXPORT = 'SYNTHETIC_NAMED_EXPORTS_NEED_NAMESPACE_EXPORT', THIS_IS_UNDEFINED = 'THIS_IS_UNDEFINED', UNEXPECTED_NAMED_IMPORT = 'UNEXPECTED_NAMED_IMPORT', UNKNOWN_OPTION = 'UNKNOWN_OPTION', UNRESOLVED_ENTRY = 'UNRESOLVED_ENTRY', UNRESOLVED_IMPORT = 'UNRESOLVED_IMPORT', UNUSED_EXTERNAL_IMPORT = 'UNUSED_EXTERNAL_IMPORT', VALIDATION_ERROR = 'VALIDATION_ERROR';
1918
1940
  function errAddonNotGenerated(message, hook, plugin) {
1919
1941
  return {
1920
1942
  code: ADDON_ERROR,
@@ -2120,11 +2142,19 @@ function errInvalidOption(option, urlHash, explanation, value) {
2120
2142
  url: `https://rollupjs.org/guide/en/#${urlHash}`
2121
2143
  };
2122
2144
  }
2123
- function errInvalidPluginHook(hook, plugin) {
2145
+ function errInvalidAddonPluginHook(hook, plugin) {
2146
+ return {
2147
+ code: INVALID_PLUGIN_HOOK,
2148
+ hook,
2149
+ message: `Error running plugin hook "${hook}" for plugin "${plugin}", expected a string, a function hook or an object with a "handler" string or function.`,
2150
+ plugin
2151
+ };
2152
+ }
2153
+ function errInvalidFunctionPluginHook(hook, plugin) {
2124
2154
  return {
2125
2155
  code: INVALID_PLUGIN_HOOK,
2126
2156
  hook,
2127
- message: `Error running plugin hook "${hook}" for "${plugin}", expected a function hook.`,
2157
+ message: `Error running plugin hook "${hook}" for plugin "${plugin}", expected a function hook or an object with a "handler" function.`,
2128
2158
  plugin
2129
2159
  };
2130
2160
  }
@@ -2281,15 +2311,6 @@ function errPluginError(error, plugin, { hook, id } = {}) {
2281
2311
  }
2282
2312
  return error;
2283
2313
  }
2284
- function errPreferNamedExports(facadeModuleId) {
2285
- const file = relativeId(facadeModuleId);
2286
- return {
2287
- code: PREFER_NAMED_EXPORTS,
2288
- id: facadeModuleId,
2289
- message: `Entry module "${file}" is implicitly using "default" export mode, which means for CommonJS output that its default export is assigned to "module.exports". For many tools, such CommonJS output will not be interchangeable with the original ES module. If this is intended, explicitly set "output.exports" to either "auto" or "default", otherwise you might want to consider changing the signature of "${file}" to use named exports only.`,
2290
- url: `https://rollupjs.org/guide/en/#outputexports`
2291
- };
2292
- }
2293
2314
  function errShimmedExport(id, binding) {
2294
2315
  return {
2295
2316
  binding,
@@ -2474,15 +2495,16 @@ const RESERVED_NAMES$1 = RESERVED_NAMES;
2474
2495
 
2475
2496
  const illegalCharacters = /[^$_a-zA-Z0-9]/g;
2476
2497
  const startsWithDigit = (str) => /\d/.test(str[0]);
2498
+ const needsEscape = (str) => startsWithDigit(str) || RESERVED_NAMES$1.has(str) || str === 'arguments';
2477
2499
  function isLegal(str) {
2478
- if (startsWithDigit(str) || RESERVED_NAMES$1.has(str)) {
2500
+ if (needsEscape(str)) {
2479
2501
  return false;
2480
2502
  }
2481
2503
  return !illegalCharacters.test(str);
2482
2504
  }
2483
2505
  function makeLegal(str) {
2484
2506
  str = str.replace(/-(\w)/g, (_, letter) => letter.toUpperCase()).replace(illegalCharacters, '_');
2485
- if (startsWithDigit(str) || RESERVED_NAMES$1.has(str))
2507
+ if (needsEscape(str))
2486
2508
  str = `_${str}`;
2487
2509
  return str || '_';
2488
2510
  }
@@ -4721,7 +4743,7 @@ function getMatcherString(id, resolutionBase) {
4721
4743
  return normalizePath(id);
4722
4744
  }
4723
4745
  // resolve('') is valid and will default to process.cwd()
4724
- const basePath = normalizePath(resolve(resolutionBase || ''))
4746
+ const basePath = normalizePath(resolve$1(resolutionBase || ''))
4725
4747
  // escape all possible (posix + win) path characters that might interfere with regex
4726
4748
  .replace(/[-^$*+?.()|[\]{}]/g, '\\$&');
4727
4749
  // Note that we use posix.join because:
@@ -6436,7 +6458,7 @@ function toBase64(num) {
6436
6458
  let outStr = '';
6437
6459
  do {
6438
6460
  const curDigit = num % base;
6439
- num = Math.floor(num / base);
6461
+ num = (num / base) | 0;
6440
6462
  outStr = chars[curDigit] + outStr;
6441
6463
  } while (num !== 0);
6442
6464
  return outStr;
@@ -6714,15 +6736,16 @@ function is_reference (node, parent) {
6714
6736
 
6715
6737
  /* eslint sort-keys: "off" */
6716
6738
  const ValueProperties = Symbol('Value Properties');
6739
+ const getTruthyLiteralValue = () => UnknownTruthyValue;
6740
+ const returnFalse = () => false;
6741
+ const returnTrue = () => true;
6717
6742
  const PURE = {
6718
- hasEffectsWhenCalled() {
6719
- return false;
6720
- }
6743
+ getLiteralValue: getTruthyLiteralValue,
6744
+ hasEffectsWhenCalled: returnFalse
6721
6745
  };
6722
6746
  const IMPURE = {
6723
- hasEffectsWhenCalled() {
6724
- return true;
6725
- }
6747
+ getLiteralValue: getTruthyLiteralValue,
6748
+ hasEffectsWhenCalled: returnTrue
6726
6749
  };
6727
6750
  // We use shortened variables to reduce file size here
6728
6751
  /* OBJECT */
@@ -6739,6 +6762,7 @@ const PF = {
6739
6762
  const MUTATES_ARG_WITHOUT_ACCESSOR = {
6740
6763
  __proto__: null,
6741
6764
  [ValueProperties]: {
6765
+ getLiteralValue: getTruthyLiteralValue,
6742
6766
  hasEffectsWhenCalled({ args }, context) {
6743
6767
  return (!args.length ||
6744
6768
  args[0].hasEffectsOnInteractionAtPath(UNKNOWN_NON_ACCESSOR_PATH, NODE_INTERACTION_UNKNOWN_ASSIGNMENT, context));
@@ -6934,7 +6958,16 @@ const knownGlobals = {
6934
6958
  [ValueProperties]: PURE,
6935
6959
  for: PF,
6936
6960
  keyFor: PF,
6937
- prototype: O
6961
+ prototype: O,
6962
+ toStringTag: {
6963
+ __proto__: null,
6964
+ [ValueProperties]: {
6965
+ getLiteralValue() {
6966
+ return SymbolToStringTag;
6967
+ },
6968
+ hasEffectsWhenCalled: returnTrue
6969
+ }
6970
+ }
6938
6971
  },
6939
6972
  SyntaxError: PC,
6940
6973
  toLocaleString: O,
@@ -7580,7 +7613,8 @@ class GlobalVariable extends Variable {
7580
7613
  this.isReassigned = true;
7581
7614
  }
7582
7615
  getLiteralValueAtPath(path, _recursionTracker, _origin) {
7583
- return getGlobalAtPath([this.name, ...path]) ? UnknownTruthyValue : UnknownValue;
7616
+ const globalAtPath = getGlobalAtPath([this.name, ...path]);
7617
+ return globalAtPath ? globalAtPath.getLiteralValue() : UnknownValue;
7584
7618
  }
7585
7619
  hasEffectsOnInteractionAtPath(path, interaction, context) {
7586
7620
  switch (interaction.type) {
@@ -8771,7 +8805,7 @@ class MemberExpression extends NodeBase {
8771
8805
  this.assignmentDeoptimized = false;
8772
8806
  this.bound = false;
8773
8807
  this.expressionsToBeDeoptimized = [];
8774
- this.replacement = null;
8808
+ this.isUndefined = false;
8775
8809
  }
8776
8810
  bind() {
8777
8811
  this.bound = true;
@@ -8782,8 +8816,8 @@ class MemberExpression extends NodeBase {
8782
8816
  if (!resolvedVariable) {
8783
8817
  super.bind();
8784
8818
  }
8785
- else if (typeof resolvedVariable === 'string') {
8786
- this.replacement = resolvedVariable;
8819
+ else if (resolvedVariable === 'undefined') {
8820
+ this.isUndefined = true;
8787
8821
  }
8788
8822
  else {
8789
8823
  this.variable = resolvedVariable;
@@ -8809,7 +8843,7 @@ class MemberExpression extends NodeBase {
8809
8843
  if (this.variable) {
8810
8844
  this.variable.deoptimizePath(path);
8811
8845
  }
8812
- else if (!this.replacement) {
8846
+ else if (!this.isUndefined) {
8813
8847
  if (path.length < MAX_PATH_DEPTH) {
8814
8848
  const propertyKey = this.getPropertyKey();
8815
8849
  this.object.deoptimizePath([
@@ -8823,7 +8857,7 @@ class MemberExpression extends NodeBase {
8823
8857
  if (this.variable) {
8824
8858
  this.variable.deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker);
8825
8859
  }
8826
- else if (!this.replacement) {
8860
+ else if (!this.isUndefined) {
8827
8861
  if (path.length < MAX_PATH_DEPTH) {
8828
8862
  this.object.deoptimizeThisOnInteractionAtPath(interaction, [this.getPropertyKey(), ...path], recursionTracker);
8829
8863
  }
@@ -8836,8 +8870,8 @@ class MemberExpression extends NodeBase {
8836
8870
  if (this.variable) {
8837
8871
  return this.variable.getLiteralValueAtPath(path, recursionTracker, origin);
8838
8872
  }
8839
- if (this.replacement) {
8840
- return UnknownValue;
8873
+ if (this.isUndefined) {
8874
+ return undefined;
8841
8875
  }
8842
8876
  this.expressionsToBeDeoptimized.push(origin);
8843
8877
  if (path.length < MAX_PATH_DEPTH) {
@@ -8849,8 +8883,8 @@ class MemberExpression extends NodeBase {
8849
8883
  if (this.variable) {
8850
8884
  return this.variable.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
8851
8885
  }
8852
- if (this.replacement) {
8853
- return UNKNOWN_EXPRESSION;
8886
+ if (this.isUndefined) {
8887
+ return UNDEFINED_EXPRESSION;
8854
8888
  }
8855
8889
  this.expressionsToBeDeoptimized.push(origin);
8856
8890
  if (path.length < MAX_PATH_DEPTH) {
@@ -8879,7 +8913,7 @@ class MemberExpression extends NodeBase {
8879
8913
  if (this.variable) {
8880
8914
  return this.variable.hasEffectsOnInteractionAtPath(path, interaction, context);
8881
8915
  }
8882
- if (this.replacement) {
8916
+ if (this.isUndefined) {
8883
8917
  return true;
8884
8918
  }
8885
8919
  if (path.length < MAX_PATH_DEPTH) {
@@ -8915,9 +8949,9 @@ class MemberExpression extends NodeBase {
8915
8949
  this.accessInteraction = { thisArg: this.object, type: INTERACTION_ACCESSED };
8916
8950
  }
8917
8951
  render(code, options, { renderedParentType, isCalleeOfRenderedParent, renderedSurroundingElement } = BLANK) {
8918
- if (this.variable || this.replacement) {
8952
+ if (this.variable || this.isUndefined) {
8919
8953
  const { snippets: { getPropertyAccess } } = options;
8920
- let replacement = this.variable ? this.variable.getName(getPropertyAccess) : this.replacement;
8954
+ let replacement = this.variable ? this.variable.getName(getPropertyAccess) : 'undefined';
8921
8955
  if (renderedParentType && isCalleeOfRenderedParent)
8922
8956
  replacement = '0, ' + replacement;
8923
8957
  code.overwrite(this.start, this.end, replacement, {
@@ -8948,7 +8982,7 @@ class MemberExpression extends NodeBase {
8948
8982
  // Namespaces are not bound and should not be deoptimized
8949
8983
  this.bound &&
8950
8984
  propertyReadSideEffects &&
8951
- !(this.variable || this.replacement)) {
8985
+ !(this.variable || this.isUndefined)) {
8952
8986
  const propertyKey = this.getPropertyKey();
8953
8987
  this.object.deoptimizeThisOnInteractionAtPath(this.accessInteraction, [propertyKey], SHARED_RECURSION_TRACKER);
8954
8988
  this.context.requestTreeshakingPass();
@@ -8962,7 +8996,7 @@ class MemberExpression extends NodeBase {
8962
8996
  // Namespaces are not bound and should not be deoptimized
8963
8997
  this.bound &&
8964
8998
  propertyReadSideEffects &&
8965
- !(this.variable || this.replacement)) {
8999
+ !(this.variable || this.isUndefined)) {
8966
9000
  this.object.deoptimizeThisOnInteractionAtPath(this.assignmentInteraction, [this.getPropertyKey()], SHARED_RECURSION_TRACKER);
8967
9001
  this.context.requestTreeshakingPass();
8968
9002
  }
@@ -8982,14 +9016,19 @@ class MemberExpression extends NodeBase {
8982
9016
  if (this.propertyKey === null) {
8983
9017
  this.propertyKey = UnknownKey;
8984
9018
  const value = this.property.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
8985
- return (this.propertyKey = typeof value === 'symbol' ? UnknownKey : String(value));
9019
+ return (this.propertyKey =
9020
+ value === SymbolToStringTag
9021
+ ? value
9022
+ : typeof value === 'symbol'
9023
+ ? UnknownKey
9024
+ : String(value));
8986
9025
  }
8987
9026
  return this.propertyKey;
8988
9027
  }
8989
9028
  hasAccessEffect(context) {
8990
9029
  const { propertyReadSideEffects } = this.context.options
8991
9030
  .treeshake;
8992
- return (!(this.variable || this.replacement) &&
9031
+ return (!(this.variable || this.isUndefined) &&
8993
9032
  propertyReadSideEffects &&
8994
9033
  (propertyReadSideEffects === 'always' ||
8995
9034
  this.object.hasEffectsOnInteractionAtPath([this.getPropertyKey()], this.accessInteraction, context)));
@@ -10196,31 +10235,29 @@ class ImportDefaultSpecifier extends NodeBase {
10196
10235
  }
10197
10236
 
10198
10237
  const INTEROP_DEFAULT_VARIABLE = '_interopDefault';
10199
- const INTEROP_DEFAULT_LEGACY_VARIABLE = '_interopDefaultLegacy';
10238
+ const INTEROP_DEFAULT_COMPAT_VARIABLE = '_interopDefaultCompat';
10200
10239
  const INTEROP_NAMESPACE_VARIABLE = '_interopNamespace';
10240
+ const INTEROP_NAMESPACE_COMPAT_VARIABLE = '_interopNamespaceCompat';
10201
10241
  const INTEROP_NAMESPACE_DEFAULT_VARIABLE = '_interopNamespaceDefault';
10202
10242
  const INTEROP_NAMESPACE_DEFAULT_ONLY_VARIABLE = '_interopNamespaceDefaultOnly';
10203
10243
  const MERGE_NAMESPACES_VARIABLE = '_mergeNamespaces';
10204
10244
  const defaultInteropHelpersByInteropType = {
10205
10245
  auto: INTEROP_DEFAULT_VARIABLE,
10246
+ compat: INTEROP_DEFAULT_COMPAT_VARIABLE,
10206
10247
  default: null,
10207
10248
  defaultOnly: null,
10208
- esModule: null,
10209
- false: null,
10210
- true: INTEROP_DEFAULT_LEGACY_VARIABLE
10249
+ esModule: null
10211
10250
  };
10212
10251
  const isDefaultAProperty = (interopType, externalLiveBindings) => interopType === 'esModule' ||
10213
- (externalLiveBindings && (interopType === 'auto' || interopType === 'true'));
10252
+ (externalLiveBindings && (interopType === 'auto' || interopType === 'compat'));
10214
10253
  const namespaceInteropHelpersByInteropType = {
10215
10254
  auto: INTEROP_NAMESPACE_VARIABLE,
10255
+ compat: INTEROP_NAMESPACE_COMPAT_VARIABLE,
10216
10256
  default: INTEROP_NAMESPACE_DEFAULT_VARIABLE,
10217
10257
  defaultOnly: INTEROP_NAMESPACE_DEFAULT_ONLY_VARIABLE,
10218
- esModule: null,
10219
- false: null,
10220
- true: INTEROP_NAMESPACE_VARIABLE
10258
+ esModule: null
10221
10259
  };
10222
- const canDefaultBeTakenFromNamespace = (interopType, externalLiveBindings) => isDefaultAProperty(interopType, externalLiveBindings) &&
10223
- defaultInteropHelpersByInteropType[interopType] === INTEROP_DEFAULT_VARIABLE;
10260
+ const canDefaultBeTakenFromNamespace = (interopType, externalLiveBindings) => interopType !== 'esModule' && isDefaultAProperty(interopType, externalLiveBindings);
10224
10261
  const getHelpersBlock = (additionalHelpers, accessedGlobals, indent, snippets, liveBindings, freeze, namespaceToStringTag) => {
10225
10262
  const usedHelpers = new Set(additionalHelpers);
10226
10263
  for (const variable of HELPER_NAMES) {
@@ -10233,14 +10270,14 @@ const getHelpersBlock = (additionalHelpers, accessedGlobals, indent, snippets, l
10233
10270
  : '').join('');
10234
10271
  };
10235
10272
  const HELPER_GENERATORS = {
10236
- [INTEROP_DEFAULT_LEGACY_VARIABLE](_t, snippets, liveBindings) {
10273
+ [INTEROP_DEFAULT_COMPAT_VARIABLE](_t, snippets, liveBindings) {
10237
10274
  const { _, getDirectReturnFunction, n } = snippets;
10238
10275
  const [left, right] = getDirectReturnFunction(['e'], {
10239
10276
  functionReturn: true,
10240
10277
  lineBreakIndent: null,
10241
- name: INTEROP_DEFAULT_LEGACY_VARIABLE
10278
+ name: INTEROP_DEFAULT_COMPAT_VARIABLE
10242
10279
  });
10243
- return (`${left}e${_}&&${_}typeof e${_}===${_}'object'${_}&&${_}'default'${_}in e${_}?${_}` +
10280
+ return (`${left}${getIsCompatNamespace(snippets)}${_}?${_}` +
10244
10281
  `${liveBindings ? getDefaultLiveBinding(snippets) : getDefaultStatic(snippets)}${right}${n}${n}`);
10245
10282
  },
10246
10283
  [INTEROP_DEFAULT_VARIABLE](_t, snippets, liveBindings) {
@@ -10253,6 +10290,21 @@ const HELPER_GENERATORS = {
10253
10290
  return (`${left}e${_}&&${_}e.__esModule${_}?${_}` +
10254
10291
  `${liveBindings ? getDefaultLiveBinding(snippets) : getDefaultStatic(snippets)}${right}${n}${n}`);
10255
10292
  },
10293
+ [INTEROP_NAMESPACE_COMPAT_VARIABLE](t, snippets, liveBindings, freeze, namespaceToStringTag, usedHelpers) {
10294
+ const { _, getDirectReturnFunction, n } = snippets;
10295
+ if (usedHelpers.has(INTEROP_NAMESPACE_DEFAULT_VARIABLE)) {
10296
+ const [left, right] = getDirectReturnFunction(['e'], {
10297
+ functionReturn: true,
10298
+ lineBreakIndent: null,
10299
+ name: INTEROP_NAMESPACE_COMPAT_VARIABLE
10300
+ });
10301
+ return `${left}${getIsCompatNamespace(snippets)}${_}?${_}e${_}:${_}${INTEROP_NAMESPACE_DEFAULT_VARIABLE}(e)${right}${n}${n}`;
10302
+ }
10303
+ return (`function ${INTEROP_NAMESPACE_COMPAT_VARIABLE}(e)${_}{${n}` +
10304
+ `${t}if${_}(${getIsCompatNamespace(snippets)})${_}return e;${n}` +
10305
+ createNamespaceObject(t, t, snippets, liveBindings, freeze, namespaceToStringTag) +
10306
+ `}${n}${n}`);
10307
+ },
10256
10308
  [INTEROP_NAMESPACE_DEFAULT_ONLY_VARIABLE](_t, snippets, _liveBindings, freeze, namespaceToStringTag) {
10257
10309
  const { getDirectReturnFunction, getObject, n } = snippets;
10258
10310
  const [left, right] = getDirectReturnFunction(['e'], {
@@ -10305,6 +10357,7 @@ const HELPER_GENERATORS = {
10305
10357
  };
10306
10358
  const getDefaultLiveBinding = ({ _, getObject }) => `e${_}:${_}${getObject([['default', 'e']], { lineBreakIndent: null })}`;
10307
10359
  const getDefaultStatic = ({ _, getPropertyAccess }) => `e${getPropertyAccess('default')}${_}:${_}e`;
10360
+ const getIsCompatNamespace = ({ _ }) => `e${_}&&${_}typeof e${_}===${_}'object'${_}&&${_}'default'${_}in e`;
10308
10361
  const createNamespaceObject = (t, i, snippets, liveBindings, freeze, namespaceToStringTag) => {
10309
10362
  const { _, cnst, getObject, getPropertyAccess, n, s } = snippets;
10310
10363
  const copyProperty = `{${n}` +
@@ -10555,7 +10608,7 @@ class ImportExpression extends NodeBase {
10555
10608
  }
10556
10609
  function getInteropHelper(resolution, exportMode, interop) {
10557
10610
  return exportMode === 'external'
10558
- ? namespaceInteropHelpersByInteropType[String(interop(resolution instanceof ExternalModule ? resolution.id : null))]
10611
+ ? namespaceInteropHelpersByInteropType[interop(resolution instanceof ExternalModule ? resolution.id : null)]
10559
10612
  : exportMode === 'default'
10560
10613
  ? INTEROP_NAMESPACE_DEFAULT_ONLY_VARIABLE
10561
10614
  : null;
@@ -12126,6 +12179,10 @@ class NamespaceVariable extends Variable {
12126
12179
  this.references.push(identifier);
12127
12180
  this.name = identifier.name;
12128
12181
  }
12182
+ getLiteralValueAtPath() {
12183
+ // This can only happen for Symbol.toStringTag right now
12184
+ return 'Module';
12185
+ }
12129
12186
  getMemberVariables() {
12130
12187
  if (this.memberVariables) {
12131
12188
  return this.memberVariables;
@@ -12141,6 +12198,9 @@ class NamespaceVariable extends Variable {
12141
12198
  }
12142
12199
  return (this.memberVariables = memberVariables);
12143
12200
  }
12201
+ hasEffectsOnInteractionAtPath() {
12202
+ return false;
12203
+ }
12144
12204
  include() {
12145
12205
  this.included = true;
12146
12206
  this.context.includeAllExports();
@@ -13314,7 +13374,7 @@ function getSingleDefaultExport(exports, dependencies, interop, externalLiveBind
13314
13374
  function getReexportedImportName(moduleVariableName, imported, depNamedExportsMode, isChunk, defaultVariableName, namespaceVariableName, interop, moduleId, externalLiveBindings, getPropertyAccess) {
13315
13375
  if (imported === 'default') {
13316
13376
  if (!isChunk) {
13317
- const moduleInterop = String(interop(moduleId));
13377
+ const moduleInterop = interop(moduleId);
13318
13378
  const variableName = defaultInteropHelpersByInteropType[moduleInterop]
13319
13379
  ? defaultVariableName
13320
13380
  : moduleVariableName;
@@ -13327,9 +13387,7 @@ function getReexportedImportName(moduleVariableName, imported, depNamedExportsMo
13327
13387
  : moduleVariableName;
13328
13388
  }
13329
13389
  if (imported === '*') {
13330
- return (isChunk
13331
- ? !depNamedExportsMode
13332
- : namespaceInteropHelpersByInteropType[String(interop(moduleId))])
13390
+ return (isChunk ? !depNamedExportsMode : namespaceInteropHelpersByInteropType[interop(moduleId)])
13333
13391
  ? namespaceVariableName
13334
13392
  : moduleVariableName;
13335
13393
  }
@@ -13396,7 +13454,7 @@ function getInteropBlock(dependencies, interop, externalLiveBindings, freeze, na
13396
13454
  }
13397
13455
  }
13398
13456
  else {
13399
- const moduleInterop = String(interop(importPath));
13457
+ const moduleInterop = interop(importPath);
13400
13458
  let hasDefault = false;
13401
13459
  let hasNamespace = false;
13402
13460
  for (const { imported, reexported } of [
@@ -13430,48 +13488,55 @@ function getInteropBlock(dependencies, interop, externalLiveBindings, freeze, na
13430
13488
  return `${getHelpersBlock(neededInteropHelpers, accessedGlobals, indent, snippets, externalLiveBindings, freeze, namespaceToStringTag)}${interopStatements.length > 0 ? `${interopStatements.join(n)}${n}${n}` : ''}`;
13431
13489
  }
13432
13490
 
13491
+ function addJsExtension(name) {
13492
+ return name.endsWith('.js') ? name : name + '.js';
13493
+ }
13494
+
13433
13495
  // AMD resolution will only respect the AMD baseUrl if the .js extension is omitted.
13434
13496
  // The assumption is that this makes sense for all relative ids:
13435
13497
  // https://requirejs.org/docs/api.html#jsfiles
13436
- function removeExtensionFromRelativeAmdId(id) {
13437
- return id[0] === '.' ? removeJsExtension(id) : id;
13498
+ function updateExtensionForRelativeAmdId(id, forceJsExtensionForImports) {
13499
+ if (id[0] !== '.') {
13500
+ return id;
13501
+ }
13502
+ return forceJsExtensionForImports ? addJsExtension(id) : removeJsExtension(id);
13438
13503
  }
13439
13504
 
13440
13505
  const builtins = {
13441
- assert: true,
13442
- buffer: true,
13443
- console: true,
13444
- constants: true,
13445
- domain: true,
13446
- events: true,
13447
- http: true,
13448
- https: true,
13449
- os: true,
13450
- path: true,
13451
- process: true,
13452
- punycode: true,
13453
- querystring: true,
13454
- stream: true,
13455
- string_decoder: true,
13456
- timers: true,
13457
- tty: true,
13458
- url: true,
13459
- util: true,
13460
- vm: true,
13461
- zlib: true
13506
+ assert: 1,
13507
+ buffer: 1,
13508
+ console: 1,
13509
+ constants: 1,
13510
+ domain: 1,
13511
+ events: 1,
13512
+ http: 1,
13513
+ https: 1,
13514
+ os: 1,
13515
+ path: 1,
13516
+ process: 1,
13517
+ punycode: 1,
13518
+ querystring: 1,
13519
+ stream: 1,
13520
+ string_decoder: 1,
13521
+ timers: 1,
13522
+ tty: 1,
13523
+ url: 1,
13524
+ util: 1,
13525
+ vm: 1,
13526
+ zlib: 1
13462
13527
  };
13463
13528
  function warnOnBuiltins(warn, dependencies) {
13464
13529
  const externalBuiltins = dependencies
13465
13530
  .map(({ importPath }) => importPath)
13466
- .filter(importPath => importPath in builtins);
13531
+ .filter(importPath => importPath in builtins || importPath.startsWith('node:'));
13467
13532
  if (!externalBuiltins.length)
13468
13533
  return;
13469
13534
  warn(errMissingNodeBuiltins(externalBuiltins));
13470
13535
  }
13471
13536
 
13472
- function amd(magicString, { accessedGlobals, dependencies, exports, hasExports, id, indent: t, intro, isEntryFacade, isModuleFacade, namedExportsMode, outro, snippets, onwarn }, { amd, esModule, externalLiveBindings, freeze, interop, namespaceToStringTag, strict }) {
13537
+ function amd(magicString, { accessedGlobals, dependencies, exports, hasDefaultExport, hasExports, id, indent: t, intro, isEntryFacade, isModuleFacade, namedExportsMode, outro, snippets, onwarn }, { amd, esModule, externalLiveBindings, freeze, interop, namespaceToStringTag, strict }) {
13473
13538
  warnOnBuiltins(onwarn, dependencies);
13474
- const deps = dependencies.map(m => `'${removeExtensionFromRelativeAmdId(m.importPath)}'`);
13539
+ const deps = dependencies.map(m => `'${updateExtensionForRelativeAmdId(m.importPath, amd.forceJsExtensionForImports)}'`);
13475
13540
  const args = dependencies.map(m => m.name);
13476
13541
  const { n, getNonArrowFunctionIntro, _ } = snippets;
13477
13542
  if (namedExportsMode && hasExports) {
@@ -13492,7 +13557,7 @@ function amd(magicString, { accessedGlobals, dependencies, exports, hasExports,
13492
13557
  const useStrict = strict ? `${_}'use strict';` : '';
13493
13558
  magicString.prepend(`${intro}${getInteropBlock(dependencies, interop, externalLiveBindings, freeze, namespaceToStringTag, accessedGlobals, t, snippets)}`);
13494
13559
  const exportBlock = getExportBlock$1(exports, dependencies, namedExportsMode, interop, snippets, t, externalLiveBindings);
13495
- let namespaceMarkers = getNamespaceMarkers(namedExportsMode && hasExports, isEntryFacade && esModule, isModuleFacade && namespaceToStringTag, snippets);
13560
+ let namespaceMarkers = getNamespaceMarkers(namedExportsMode && hasExports, isEntryFacade && (esModule === true || (esModule === 'if-default-prop' && hasDefaultExport)), isModuleFacade && namespaceToStringTag, snippets);
13496
13561
  if (namespaceMarkers) {
13497
13562
  namespaceMarkers = n + n + namespaceMarkers;
13498
13563
  }
@@ -13508,10 +13573,10 @@ function amd(magicString, { accessedGlobals, dependencies, exports, hasExports,
13508
13573
  .append(`${n}${n}}));`);
13509
13574
  }
13510
13575
 
13511
- function cjs(magicString, { accessedGlobals, dependencies, exports, hasExports, indent: t, intro, isEntryFacade, isModuleFacade, namedExportsMode, outro, snippets }, { compact, esModule, externalLiveBindings, freeze, interop, namespaceToStringTag, strict }) {
13576
+ function cjs(magicString, { accessedGlobals, dependencies, exports, hasDefaultExport, hasExports, indent: t, intro, isEntryFacade, isModuleFacade, namedExportsMode, outro, snippets }, { compact, esModule, externalLiveBindings, freeze, interop, namespaceToStringTag, strict }) {
13512
13577
  const { _, n } = snippets;
13513
13578
  const useStrict = strict ? `'use strict';${n}${n}` : '';
13514
- let namespaceMarkers = getNamespaceMarkers(namedExportsMode && hasExports, isEntryFacade && esModule, isModuleFacade && namespaceToStringTag, snippets);
13579
+ let namespaceMarkers = getNamespaceMarkers(namedExportsMode && hasExports, isEntryFacade && (esModule === true || (esModule === 'if-default-prop' && hasDefaultExport)), isModuleFacade && namespaceToStringTag, snippets);
13515
13580
  if (namespaceMarkers) {
13516
13581
  namespaceMarkers += n + n;
13517
13582
  }
@@ -13703,7 +13768,7 @@ function trimEmptyImports(dependencies) {
13703
13768
  return [];
13704
13769
  }
13705
13770
 
13706
- function iife(magicString, { accessedGlobals, dependencies, exports, hasExports, indent: t, intro, namedExportsMode, outro, snippets, onwarn }, { compact, esModule, extend, freeze, externalLiveBindings, globals, interop, name, namespaceToStringTag, strict }) {
13771
+ function iife(magicString, { accessedGlobals, dependencies, exports, hasDefaultExport, hasExports, indent: t, intro, namedExportsMode, outro, snippets, onwarn }, { compact, esModule, extend, freeze, externalLiveBindings, globals, interop, name, namespaceToStringTag, strict }) {
13707
13772
  const { _, getNonArrowFunctionIntro, getPropertyAccess, n } = snippets;
13708
13773
  const isNamespaced = name && name.includes('.');
13709
13774
  const useVariableAssignment = !extend && !isNamespaced;
@@ -13749,7 +13814,7 @@ function iife(magicString, { accessedGlobals, dependencies, exports, hasExports,
13749
13814
  wrapperOutro = `${n}${n}${t}return exports;${wrapperOutro}`;
13750
13815
  }
13751
13816
  const exportBlock = getExportBlock$1(exports, dependencies, namedExportsMode, interop, snippets, t, externalLiveBindings);
13752
- let namespaceMarkers = getNamespaceMarkers(namedExportsMode && hasExports, esModule, namespaceToStringTag, snippets);
13817
+ let namespaceMarkers = getNamespaceMarkers(namedExportsMode && hasExports, esModule === true || (esModule === 'if-default-prop' && hasDefaultExport), namespaceToStringTag, snippets);
13753
13818
  if (namespaceMarkers) {
13754
13819
  namespaceMarkers = n + n + namespaceMarkers;
13755
13820
  }
@@ -13904,7 +13969,7 @@ function safeAccess(name, globalVar, { _, getPropertyAccess }) {
13904
13969
  .map(part => (propertyPath += getPropertyAccess(part)))
13905
13970
  .join(`${_}&&${_}`);
13906
13971
  }
13907
- function umd(magicString, { accessedGlobals, dependencies, exports, hasExports, id, indent: t, intro, namedExportsMode, outro, snippets, onwarn }, { amd, compact, esModule, extend, externalLiveBindings, freeze, interop, name, namespaceToStringTag, globals, noConflict, strict }) {
13972
+ function umd(magicString, { accessedGlobals, dependencies, exports, hasDefaultExport, hasExports, id, indent: t, intro, namedExportsMode, outro, snippets, onwarn }, { amd, compact, esModule, extend, externalLiveBindings, freeze, interop, name, namespaceToStringTag, globals, noConflict, strict }) {
13908
13973
  const { _, cnst, getFunctionIntro, getNonArrowFunctionIntro, getPropertyAccess, n, s } = snippets;
13909
13974
  const factoryVar = compact ? 'f' : 'factory';
13910
13975
  const globalVar = compact ? 'g' : 'global';
@@ -13912,7 +13977,7 @@ function umd(magicString, { accessedGlobals, dependencies, exports, hasExports,
13912
13977
  return error(errMissingNameOptionForUmdExport());
13913
13978
  }
13914
13979
  warnOnBuiltins(onwarn, dependencies);
13915
- const amdDeps = dependencies.map(m => `'${removeExtensionFromRelativeAmdId(m.importPath)}'`);
13980
+ const amdDeps = dependencies.map(m => `'${updateExtensionForRelativeAmdId(m.importPath, amd.forceJsExtensionForImports)}'`);
13916
13981
  const cjsDeps = dependencies.map(m => `require('${m.importPath}')`);
13917
13982
  const trimmedImports = trimEmptyImports(dependencies);
13918
13983
  const globalDeps = trimmedImports.map(module => globalProp(module.globalName, globalVar, getPropertyAccess));
@@ -13986,7 +14051,7 @@ function umd(magicString, { accessedGlobals, dependencies, exports, hasExports,
13986
14051
  const wrapperOutro = n + n + '}));';
13987
14052
  magicString.prepend(`${intro}${getInteropBlock(dependencies, interop, externalLiveBindings, freeze, namespaceToStringTag, accessedGlobals, t, snippets)}`);
13988
14053
  const exportBlock = getExportBlock$1(exports, dependencies, namedExportsMode, interop, snippets, t, externalLiveBindings);
13989
- let namespaceMarkers = getNamespaceMarkers(namedExportsMode && hasExports, esModule, namespaceToStringTag, snippets);
14054
+ let namespaceMarkers = getNamespaceMarkers(namedExportsMode && hasExports, esModule === true || (esModule === 'if-default-prop' && hasDefaultExport), namespaceToStringTag, snippets);
13990
14055
  if (namespaceMarkers) {
13991
14056
  namespaceMarkers = n + n + namespaceMarkers;
13992
14057
  }
@@ -14003,8 +14068,8 @@ const finalisers = { amd, cjs, es, iife, system, umd };
14003
14068
  const createHash = () => createHash$1('sha256');
14004
14069
 
14005
14070
  // Four random characters from the private use area to minimize risk of conflicts
14006
- const hashPlaceholderLeft = '\uf7f9\ue4d3';
14007
- const hashPlaceholderRight = '\ue3cc\uf1fe';
14071
+ const hashPlaceholderLeft = '!~{';
14072
+ const hashPlaceholderRight = '}~';
14008
14073
  const hashPlaceholderOverhead = hashPlaceholderLeft.length + hashPlaceholderRight.length;
14009
14074
  // This is the size of a sha256
14010
14075
  const maxHashSize = 64;
@@ -14015,15 +14080,14 @@ const getHashPlaceholderGenerator = () => {
14015
14080
  if (hashSize > maxHashSize) {
14016
14081
  return error(errFailedValidation(`Hashes cannot be longer than ${maxHashSize} characters, received ${hashSize}. Check the "${optionName}" option.`));
14017
14082
  }
14018
- const placeholder = `${hashPlaceholderLeft}${String(++nextIndex).padStart(hashSize - hashPlaceholderOverhead, '0')}${hashPlaceholderRight}`;
14083
+ const placeholder = `${hashPlaceholderLeft}${toBase64(++nextIndex).padStart(hashSize - hashPlaceholderOverhead, '0')}${hashPlaceholderRight}`;
14019
14084
  if (placeholder.length > hashSize) {
14020
14085
  return error(errFailedValidation(`To generate hashes for this number of chunks (currently ${nextIndex}), you need a minimum hash size of ${placeholder.length}, received ${hashSize}. Check the "${optionName}" option.`));
14021
14086
  }
14022
- nextIndex++;
14023
14087
  return placeholder;
14024
14088
  };
14025
14089
  };
14026
- const REPLACER_REGEX = new RegExp(`${hashPlaceholderLeft}\\d{1,${maxHashSize - hashPlaceholderOverhead}}${hashPlaceholderRight}`, 'g');
14090
+ const REPLACER_REGEX = new RegExp(`${hashPlaceholderLeft}[0-9a-zA-Z_$]{1,${maxHashSize - hashPlaceholderOverhead}}${hashPlaceholderRight}`, 'g');
14027
14091
  const replacePlaceholders = (code, hashesByPlaceholder) => code.replace(REPLACER_REGEX, placeholder => hashesByPlaceholder.get(placeholder) || placeholder);
14028
14092
  const replaceSinglePlaceholder = (code, placeholder, value) => code.replace(REPLACER_REGEX, match => (match === placeholder ? value : match));
14029
14093
  const replacePlaceholdersWithDefaultAndGetContainedPlaceholders = (code, placeholders) => {
@@ -14369,7 +14433,7 @@ function deconflictImportsOther(usedNames, imports, { deconflictedDefault, decon
14369
14433
  }
14370
14434
  for (const externalModule of deconflictedDefault) {
14371
14435
  if (deconflictedNamespace.has(externalModule) &&
14372
- canDefaultBeTakenFromNamespace(String(interop(externalModule.id)), externalLiveBindings)) {
14436
+ canDefaultBeTakenFromNamespace(interop(externalModule.id), externalLiveBindings)) {
14373
14437
  externalModule.defaultVariableName = externalModule.namespaceVariableName;
14374
14438
  }
14375
14439
  else {
@@ -14382,7 +14446,7 @@ function deconflictImportsOther(usedNames, imports, { deconflictedDefault, decon
14382
14446
  const chunk = externalChunkByModule.get(module);
14383
14447
  const name = variable.name;
14384
14448
  if (name === 'default') {
14385
- const moduleInterop = String(interop(module.id));
14449
+ const moduleInterop = interop(module.id);
14386
14450
  const variableName = defaultInteropHelpersByInteropType[moduleInterop]
14387
14451
  ? chunk.defaultVariableName
14388
14452
  : chunk.variableName;
@@ -14394,7 +14458,7 @@ function deconflictImportsOther(usedNames, imports, { deconflictedDefault, decon
14394
14458
  }
14395
14459
  }
14396
14460
  else if (name === '*') {
14397
- variable.setRenderNames(null, namespaceInteropHelpersByInteropType[String(interop(module.id))]
14461
+ variable.setRenderNames(null, namespaceInteropHelpersByInteropType[interop(module.id)]
14398
14462
  ? chunk.namespaceVariableName
14399
14463
  : chunk.variableName);
14400
14464
  }
@@ -14464,7 +14528,7 @@ function assignExportsToNames(exports, exportsByName, exportNamesByVariable) {
14464
14528
  }
14465
14529
  }
14466
14530
 
14467
- function getExportMode(chunk, { exports: exportMode, name, format }, unsetOptions, facadeModuleId, warn) {
14531
+ function getExportMode(chunk, { exports: exportMode, name, format }, facadeModuleId, warn) {
14468
14532
  const exportKeys = chunk.getExportNames();
14469
14533
  if (exportMode === 'default') {
14470
14534
  if (exportKeys.length !== 1 || exportKeys[0] !== 'default') {
@@ -14479,9 +14543,6 @@ function getExportMode(chunk, { exports: exportMode, name, format }, unsetOption
14479
14543
  exportMode = 'none';
14480
14544
  }
14481
14545
  else if (exportKeys.length === 1 && exportKeys[0] === 'default') {
14482
- if (format === 'cjs' && unsetOptions.has('exports')) {
14483
- warn(errPreferNamedExports(facadeModuleId));
14484
- }
14485
14546
  exportMode = 'default';
14486
14547
  }
14487
14548
  else {
@@ -14706,7 +14767,7 @@ class Chunk {
14706
14767
  assignExportsToNames(remainingExports, this.exportsByName, this.exportNamesByVariable);
14707
14768
  }
14708
14769
  if (this.outputOptions.preserveModules || (this.facadeModule && this.facadeModule.info.isEntry))
14709
- this.exportMode = getExportMode(this, this.outputOptions, this.unsetOptions, this.facadeModule.id, this.inputOptions.onwarn);
14770
+ this.exportMode = getExportMode(this, this.outputOptions, this.facadeModule.id, this.inputOptions.onwarn);
14710
14771
  }
14711
14772
  generateFacades() {
14712
14773
  var _a;
@@ -14807,7 +14868,7 @@ class Chunk {
14807
14868
  return ((_a = this.preliminaryFileName) === null || _a === void 0 ? void 0 : _a.fileName) || this.getPreliminaryFileName().fileName;
14808
14869
  }
14809
14870
  getImportPath(importer) {
14810
- return escapeId(getImportPath(importer, this.getFileName(), this.outputOptions.format === 'amd', true));
14871
+ return escapeId(getImportPath(importer, this.getFileName(), this.outputOptions.format === 'amd' && !this.outputOptions.amd.forceJsExtensionForImports, true));
14811
14872
  }
14812
14873
  getPreliminaryFileName() {
14813
14874
  var _a;
@@ -14886,13 +14947,31 @@ class Chunk {
14886
14947
  const { accessedGlobals, indent, magicString, renderedSource, usedModules, usesTopLevelAwait } = this.renderModules(preliminaryFileName.fileName);
14887
14948
  const renderedDependencies = [...this.getRenderedDependencies().values()];
14888
14949
  const renderedExports = exportMode === 'none' ? [] : this.getChunkExportDeclarations(format);
14889
- const hasExports = renderedExports.length !== 0 ||
14890
- renderedDependencies.some(dep => (dep.reexports && dep.reexports.length !== 0));
14950
+ let hasExports = renderedExports.length !== 0;
14951
+ let hasDefaultExport = false;
14952
+ for (const { reexports } of renderedDependencies) {
14953
+ if (reexports === null || reexports === void 0 ? void 0 : reexports.length) {
14954
+ hasExports = true;
14955
+ if (reexports.some(reexport => reexport.reexported === 'default')) {
14956
+ hasDefaultExport = true;
14957
+ break;
14958
+ }
14959
+ }
14960
+ }
14961
+ if (!hasDefaultExport) {
14962
+ for (const { exported } of renderedExports) {
14963
+ if (exported === 'default') {
14964
+ hasDefaultExport = true;
14965
+ break;
14966
+ }
14967
+ }
14968
+ }
14891
14969
  const { intro, outro, banner, footer } = await createAddons(outputOptions, pluginDriver, this.getRenderedChunkInfo());
14892
14970
  finalisers[format](renderedSource, {
14893
14971
  accessedGlobals,
14894
14972
  dependencies: renderedDependencies,
14895
14973
  exports: renderedExports,
14974
+ hasDefaultExport,
14896
14975
  hasExports,
14897
14976
  id: preliminaryFileName.fileName,
14898
14977
  indent,
@@ -15053,12 +15132,12 @@ class Chunk {
15053
15132
  dependencies.add(chunk);
15054
15133
  if (addNonNamespacesAndInteropHelpers) {
15055
15134
  if (variable.name === 'default') {
15056
- if (defaultInteropHelpersByInteropType[String(interop(module.id))]) {
15135
+ if (defaultInteropHelpersByInteropType[interop(module.id)]) {
15057
15136
  deconflictedDefault.add(chunk);
15058
15137
  }
15059
15138
  }
15060
15139
  else if (variable.name === '*') {
15061
- if (namespaceInteropHelpersByInteropType[String(interop(module.id))]) {
15140
+ if (namespaceInteropHelpersByInteropType[interop(module.id)]) {
15062
15141
  deconflictedNamespace.add(chunk);
15063
15142
  }
15064
15143
  }
@@ -15188,7 +15267,7 @@ class Chunk {
15188
15267
  ? sanitizedId.slice(0, -extName.length)
15189
15268
  : sanitizedId;
15190
15269
  if (isAbsolute(idWithoutExtension)) {
15191
- return preserveModulesRoot && idWithoutExtension.startsWith(preserveModulesRoot)
15270
+ return preserveModulesRoot && resolve(idWithoutExtension).startsWith(preserveModulesRoot)
15192
15271
  ? idWithoutExtension.slice(preserveModulesRoot.length).replace(/^[\\/]/, '')
15193
15272
  : relative(this.inputBase, idWithoutExtension);
15194
15273
  }
@@ -15232,7 +15311,7 @@ class Chunk {
15232
15311
  }
15233
15312
  needsLiveBinding =
15234
15313
  externalLiveBindings &&
15235
- (imported !== 'default' || isDefaultAProperty(String(interop(module.id)), true));
15314
+ (imported !== 'default' || isDefaultAProperty(interop(module.id), true));
15236
15315
  }
15237
15316
  }
15238
15317
  getOrCreate(reexportSpecifiers, dependency, () => []).push({
@@ -15981,7 +16060,7 @@ async function renderChunks(chunks, outputBundle, pluginDriver, outputOptions, o
15981
16060
  const chunkGraph = getChunkGraph(chunks);
15982
16061
  const { nonHashedChunksWithPlaceholders, renderedChunksByPlaceholder, hashDependenciesByPlaceholder } = await transformChunksAndGenerateContentHashes(renderedChunks, chunkGraph, outputOptions, pluginDriver, onwarn);
15983
16062
  const hashesByPlaceholder = generateFinalHashes(renderedChunksByPlaceholder, hashDependenciesByPlaceholder, outputBundle);
15984
- addChunksToBundle(renderedChunksByPlaceholder, hashesByPlaceholder, outputBundle, nonHashedChunksWithPlaceholders);
16063
+ addChunksToBundle(renderedChunksByPlaceholder, hashesByPlaceholder, outputBundle, nonHashedChunksWithPlaceholders, pluginDriver, outputOptions);
15985
16064
  timeEnd('transform chunks', 2);
15986
16065
  }
15987
16066
  function reserveEntryChunksInBundle(chunks) {
@@ -16125,22 +16204,40 @@ function generateFinalHashes(renderedChunksByPlaceholder, hashDependenciesByPlac
16125
16204
  }
16126
16205
  return hashesByPlaceholder;
16127
16206
  }
16128
- function addChunksToBundle(renderedChunksByPlaceholder, hashesByPlaceholder, outputBundle, nonHashedChunksWithPlaceholders) {
16207
+ function addChunksToBundle(renderedChunksByPlaceholder, hashesByPlaceholder, outputBundle, nonHashedChunksWithPlaceholders, pluginDriver, options) {
16129
16208
  for (const { chunk, code, fileName, map } of renderedChunksByPlaceholder.values()) {
16130
- const updatedCode = replacePlaceholders(code, hashesByPlaceholder);
16209
+ let updatedCode = replacePlaceholders(code, hashesByPlaceholder);
16131
16210
  const finalFileName = replacePlaceholders(fileName, hashesByPlaceholder);
16132
16211
  if (map) {
16133
16212
  map.file = replacePlaceholders(map.file, hashesByPlaceholder);
16213
+ updatedCode += emitSourceMapAndGetComment(finalFileName, map, pluginDriver, options);
16134
16214
  }
16135
16215
  outputBundle[finalFileName] = chunk.generateOutputChunk(updatedCode, map, hashesByPlaceholder);
16136
16216
  }
16137
16217
  for (const { chunk, code, fileName, map } of nonHashedChunksWithPlaceholders) {
16138
- const updatedCode = hashesByPlaceholder.size
16218
+ let updatedCode = hashesByPlaceholder.size
16139
16219
  ? replacePlaceholders(code, hashesByPlaceholder)
16140
16220
  : code;
16221
+ if (map) {
16222
+ updatedCode += emitSourceMapAndGetComment(fileName, map, pluginDriver, options);
16223
+ }
16141
16224
  outputBundle[fileName] = chunk.generateOutputChunk(updatedCode, map, hashesByPlaceholder);
16142
16225
  }
16143
16226
  }
16227
+ function emitSourceMapAndGetComment(fileName, map, pluginDriver, { sourcemap, sourcemapBaseUrl }) {
16228
+ let url;
16229
+ if (sourcemap === 'inline') {
16230
+ url = map.toUrl();
16231
+ }
16232
+ else {
16233
+ const sourcemapFileName = `${basename(fileName)}.map`;
16234
+ url = sourcemapBaseUrl
16235
+ ? new URL(sourcemapFileName, sourcemapBaseUrl).toString()
16236
+ : sourcemapFileName;
16237
+ pluginDriver.emitFile({ fileName: `${fileName}.map`, source: map.toString(), type: 'asset' });
16238
+ }
16239
+ return sourcemap === 'hidden' ? '' : `//# ${SOURCEMAPPING_URL}=${url}\n`;
16240
+ }
16144
16241
 
16145
16242
  class Bundle {
16146
16243
  constructor(outputOptions, unsetOptions, inputOptions, pluginDriver, graph) {
@@ -16637,10 +16734,10 @@ function getLineInfo(input, offset) {
16637
16734
  var defaultOptions = {
16638
16735
  // `ecmaVersion` indicates the ECMAScript version to parse. Must be
16639
16736
  // either 3, 5, 6 (or 2015), 7 (2016), 8 (2017), 9 (2018), 10
16640
- // (2019), 11 (2020), 12 (2021), 13 (2022), or `"latest"` (the
16641
- // latest version the library supports). This influences support
16642
- // for strict mode, the set of reserved words, and support for
16643
- // new syntax features.
16737
+ // (2019), 11 (2020), 12 (2021), 13 (2022), 14 (2023), or `"latest"`
16738
+ // (the latest version the library supports). This influences
16739
+ // support for strict mode, the set of reserved words, and support
16740
+ // for new syntax features.
16644
16741
  ecmaVersion: null,
16645
16742
  // `sourceType` indicates the mode the code should be parsed in.
16646
16743
  // Can be either `"script"` or `"module"`. This influences global
@@ -16674,8 +16771,9 @@ var defaultOptions = {
16674
16771
  // When enabled, super identifiers are not constrained to
16675
16772
  // appearing in methods and do not raise an error when they appear elsewhere.
16676
16773
  allowSuperOutsideMethod: null,
16677
- // When enabled, hashbang directive in the beginning of file
16678
- // is allowed and treated as a line comment.
16774
+ // When enabled, hashbang directive in the beginning of file is
16775
+ // allowed and treated as a line comment. Enabled by default when
16776
+ // `ecmaVersion` >= 2023.
16679
16777
  allowHashBang: false,
16680
16778
  // When `locations` is on, `loc` properties holding objects with
16681
16779
  // `start` and `end` properties in `{line, column}` form (with
@@ -16750,6 +16848,9 @@ function getOptions(opts) {
16750
16848
  if (options.allowReserved == null)
16751
16849
  { options.allowReserved = options.ecmaVersion < 5; }
16752
16850
 
16851
+ if (opts.allowHashBang == null)
16852
+ { options.allowHashBang = options.ecmaVersion >= 14; }
16853
+
16753
16854
  if (isArray(options.onToken)) {
16754
16855
  var tokens = options.onToken;
16755
16856
  options.onToken = function (token) { return tokens.push(token); };
@@ -17080,7 +17181,7 @@ pp$9.checkPatternErrors = function(refDestructuringErrors, isAssign) {
17080
17181
  if (refDestructuringErrors.trailingComma > -1)
17081
17182
  { this.raiseRecoverable(refDestructuringErrors.trailingComma, "Comma is not permitted after the rest element"); }
17082
17183
  var parens = isAssign ? refDestructuringErrors.parenthesizedAssign : refDestructuringErrors.parenthesizedBind;
17083
- if (parens > -1) { this.raiseRecoverable(parens, "Parenthesized pattern"); }
17184
+ if (parens > -1) { this.raiseRecoverable(parens, isAssign ? "Assigning to rvalue" : "Parenthesized pattern"); }
17084
17185
  };
17085
17186
 
17086
17187
  pp$9.checkExpressionErrors = function(refDestructuringErrors, andThrow) {
@@ -18176,6 +18277,7 @@ pp$8.adaptDirectivePrologue = function(statements) {
18176
18277
  };
18177
18278
  pp$8.isDirectiveCandidate = function(statement) {
18178
18279
  return (
18280
+ this.options.ecmaVersion >= 5 &&
18179
18281
  statement.type === "ExpressionStatement" &&
18180
18282
  statement.expression.type === "Literal" &&
18181
18283
  typeof statement.expression.value === "string" &&
@@ -18586,7 +18688,8 @@ pp$6.updateContext = function(prevType) {
18586
18688
  { this.exprAllowed = type.beforeExpr; }
18587
18689
  };
18588
18690
 
18589
- // Used to handle egde case when token context could not be inferred correctly in tokenize phase
18691
+ // Used to handle egde cases when token context could not be inferred correctly during tokenization phase
18692
+
18590
18693
  pp$6.overrideContext = function(tokenCtx) {
18591
18694
  if (this.curContext() !== tokenCtx) {
18592
18695
  this.context[this.context.length - 1] = tokenCtx;
@@ -19402,15 +19505,6 @@ pp$5.parseProperty = function(isPattern, refDestructuringErrors) {
19402
19505
  }
19403
19506
  return this.finishNode(prop, "RestElement")
19404
19507
  }
19405
- // To disallow parenthesized identifier via `this.toAssignable()`.
19406
- if (this.type === types$1.parenL && refDestructuringErrors) {
19407
- if (refDestructuringErrors.parenthesizedAssign < 0) {
19408
- refDestructuringErrors.parenthesizedAssign = this.start;
19409
- }
19410
- if (refDestructuringErrors.parenthesizedBind < 0) {
19411
- refDestructuringErrors.parenthesizedBind = this.start;
19412
- }
19413
- }
19414
19508
  // Parse argument.
19415
19509
  prop.argument = this.parseMaybeAssign(false, refDestructuringErrors);
19416
19510
  // To disallow trailing comma via `this.toAssignable()`.
@@ -21840,7 +21934,7 @@ pp.readWord = function() {
21840
21934
 
21841
21935
  // Acorn is a tiny, fast JavaScript parser written in JavaScript.
21842
21936
 
21843
- var version = "8.7.1";
21937
+ var version = "8.8.0";
21844
21938
 
21845
21939
  Parser.acorn = {
21846
21940
  Parser: Parser,
@@ -22582,7 +22676,7 @@ function getPluginContext(plugin, pluginCache, graph, options, fileEmitter, exis
22582
22676
  else {
22583
22677
  cacheInstance = getCacheForUncacheablePlugin(plugin.name);
22584
22678
  }
22585
- const context = {
22679
+ return {
22586
22680
  addWatchFile(id) {
22587
22681
  if (graph.phase >= BuildPhase.GENERATE) {
22588
22682
  return this.error(errInvalidRollupPhaseForAddWatchFile());
@@ -22632,9 +22726,9 @@ function getPluginContext(plugin, pluginCache, graph, options, fileEmitter, exis
22632
22726
  options.onwarn(warning);
22633
22727
  }
22634
22728
  };
22635
- return context;
22636
22729
  }
22637
22730
 
22731
+ // This will make sure no input hook is omitted
22638
22732
  const inputHookNames = {
22639
22733
  buildEnd: 1,
22640
22734
  buildStart: 1,
@@ -22654,8 +22748,9 @@ class PluginDriver {
22654
22748
  constructor(graph, options, userPlugins, pluginCache, basePluginDriver) {
22655
22749
  this.graph = graph;
22656
22750
  this.options = options;
22657
- this.unfulfilledActions = new Set();
22658
22751
  this.pluginCache = pluginCache;
22752
+ this.sortedPlugins = new Map();
22753
+ this.unfulfilledActions = new Set();
22659
22754
  this.fileEmitter = new FileEmitter(graph, options, basePluginDriver && basePluginDriver.fileEmitter);
22660
22755
  this.emitFile = this.fileEmitter.emitFile.bind(this.fileEmitter);
22661
22756
  this.getFileName = this.fileEmitter.getFileName.bind(this.fileEmitter);
@@ -22686,21 +22781,21 @@ class PluginDriver {
22686
22781
  }
22687
22782
  // chains, first non-null result stops and returns
22688
22783
  hookFirst(hookName, args, replaceContext, skipped) {
22689
- let promise = Promise.resolve(undefined);
22690
- for (const plugin of this.plugins) {
22784
+ let promise = Promise.resolve(null);
22785
+ for (const plugin of this.getSortedPlugins(hookName)) {
22691
22786
  if (skipped && skipped.has(plugin))
22692
22787
  continue;
22693
22788
  promise = promise.then(result => {
22694
22789
  if (result != null)
22695
22790
  return result;
22696
- return this.runHook(hookName, args, plugin, false, replaceContext);
22791
+ return this.runHook(hookName, args, plugin, replaceContext);
22697
22792
  });
22698
22793
  }
22699
22794
  return promise;
22700
22795
  }
22701
22796
  // chains synchronously, first non-null result stops and returns
22702
22797
  hookFirstSync(hookName, args, replaceContext) {
22703
- for (const plugin of this.plugins) {
22798
+ for (const plugin of this.getSortedPlugins(hookName)) {
22704
22799
  const result = this.runHookSync(hookName, args, plugin, replaceContext);
22705
22800
  if (result != null)
22706
22801
  return result;
@@ -22708,56 +22803,58 @@ class PluginDriver {
22708
22803
  return null;
22709
22804
  }
22710
22805
  // parallel, ignores returns
22711
- hookParallel(hookName, args, replaceContext) {
22712
- const promises = [];
22713
- for (const plugin of this.plugins) {
22714
- const hookPromise = this.runHook(hookName, args, plugin, false, replaceContext);
22715
- if (!hookPromise)
22716
- continue;
22717
- promises.push(hookPromise);
22806
+ async hookParallel(hookName, args, replaceContext) {
22807
+ const parallelPromises = [];
22808
+ for (const plugin of this.getSortedPlugins(hookName)) {
22809
+ if (plugin[hookName].sequential) {
22810
+ await Promise.all(parallelPromises);
22811
+ parallelPromises.length = 0;
22812
+ await this.runHook(hookName, args, plugin, replaceContext);
22813
+ }
22814
+ else {
22815
+ parallelPromises.push(this.runHook(hookName, args, plugin, replaceContext));
22816
+ }
22718
22817
  }
22719
- return Promise.all(promises).then(() => { });
22818
+ await Promise.all(parallelPromises);
22720
22819
  }
22721
22820
  // chains, reduces returned value, handling the reduced value as the first hook argument
22722
22821
  hookReduceArg0(hookName, [arg0, ...rest], reduce, replaceContext) {
22723
22822
  let promise = Promise.resolve(arg0);
22724
- for (const plugin of this.plugins) {
22725
- promise = promise.then(arg0 => {
22726
- const args = [arg0, ...rest];
22727
- const hookPromise = this.runHook(hookName, args, plugin, false, replaceContext);
22728
- if (!hookPromise)
22729
- return arg0;
22730
- return hookPromise.then(result => reduce.call(this.pluginContexts.get(plugin), arg0, result, plugin));
22731
- });
22823
+ for (const plugin of this.getSortedPlugins(hookName)) {
22824
+ promise = promise.then(arg0 => this.runHook(hookName, [arg0, ...rest], plugin, replaceContext).then(result => reduce.call(this.pluginContexts.get(plugin), arg0, result, plugin)));
22732
22825
  }
22733
22826
  return promise;
22734
22827
  }
22735
22828
  // chains synchronously, reduces returned value, handling the reduced value as the first hook argument
22736
22829
  hookReduceArg0Sync(hookName, [arg0, ...rest], reduce, replaceContext) {
22737
- for (const plugin of this.plugins) {
22830
+ for (const plugin of this.getSortedPlugins(hookName)) {
22738
22831
  const args = [arg0, ...rest];
22739
22832
  const result = this.runHookSync(hookName, args, plugin, replaceContext);
22740
22833
  arg0 = reduce.call(this.pluginContexts.get(plugin), arg0, result, plugin);
22741
22834
  }
22742
22835
  return arg0;
22743
22836
  }
22744
- // chains, reduces returned value to type T, handling the reduced value separately. permits hooks as values.
22745
- hookReduceValue(hookName, initialValue, args, reduce, replaceContext) {
22746
- let promise = Promise.resolve(initialValue);
22747
- for (const plugin of this.plugins) {
22748
- promise = promise.then(value => {
22749
- const hookPromise = this.runHook(hookName, args, plugin, true, replaceContext);
22750
- if (!hookPromise)
22751
- return value;
22752
- return hookPromise.then(result => reduce.call(this.pluginContexts.get(plugin), value, result, plugin));
22753
- });
22837
+ // chains, reduces returned value to type string, handling the reduced value separately. permits hooks as values.
22838
+ async hookReduceValue(hookName, initialValue, args, reducer) {
22839
+ const results = [];
22840
+ const parallelResults = [];
22841
+ for (const plugin of this.getSortedPlugins(hookName, validateAddonPluginHandler)) {
22842
+ if (plugin[hookName].sequential) {
22843
+ results.push(...(await Promise.all(parallelResults)));
22844
+ parallelResults.length = 0;
22845
+ results.push(await this.runHook(hookName, args, plugin));
22846
+ }
22847
+ else {
22848
+ parallelResults.push(this.runHook(hookName, args, plugin));
22849
+ }
22754
22850
  }
22755
- return promise;
22851
+ results.push(...(await Promise.all(parallelResults)));
22852
+ return results.reduce(reducer, await initialValue);
22756
22853
  }
22757
22854
  // chains synchronously, reduces returned value to type T, handling the reduced value separately. permits hooks as values.
22758
22855
  hookReduceValueSync(hookName, initialValue, args, reduce, replaceContext) {
22759
22856
  let acc = initialValue;
22760
- for (const plugin of this.plugins) {
22857
+ for (const plugin of this.getSortedPlugins(hookName)) {
22761
22858
  const result = this.runHookSync(hookName, args, plugin, replaceContext);
22762
22859
  acc = reduce.call(this.pluginContexts.get(plugin), acc, result, plugin);
22763
22860
  }
@@ -22766,31 +22863,32 @@ class PluginDriver {
22766
22863
  // chains, ignores returns
22767
22864
  hookSeq(hookName, args, replaceContext) {
22768
22865
  let promise = Promise.resolve();
22769
- for (const plugin of this.plugins) {
22770
- promise = promise.then(() => this.runHook(hookName, args, plugin, false, replaceContext));
22866
+ for (const plugin of this.getSortedPlugins(hookName)) {
22867
+ promise = promise.then(() => this.runHook(hookName, args, plugin, replaceContext));
22771
22868
  }
22772
- return promise;
22869
+ return promise.then(noReturn);
22773
22870
  }
22774
- runHook(hookName, args, plugin, permitValues, hookContext) {
22871
+ getSortedPlugins(hookName, validateHandler) {
22872
+ return getOrCreate(this.sortedPlugins, hookName, () => getSortedValidatedPlugins(hookName, this.plugins, validateHandler));
22873
+ }
22874
+ // Implementation signature
22875
+ runHook(hookName, args, plugin, replaceContext) {
22876
+ // We always filter for plugins that support the hook before running it
22775
22877
  const hook = plugin[hookName];
22776
- if (!hook)
22777
- return undefined;
22878
+ const handler = typeof hook === 'object' ? hook.handler : hook;
22778
22879
  let context = this.pluginContexts.get(plugin);
22779
- if (hookContext) {
22780
- context = hookContext(context, plugin);
22880
+ if (replaceContext) {
22881
+ context = replaceContext(context, plugin);
22781
22882
  }
22782
22883
  let action = null;
22783
22884
  return Promise.resolve()
22784
22885
  .then(() => {
22785
- // permit values allows values to be returned instead of a functional hook
22786
- if (typeof hook !== 'function') {
22787
- if (permitValues)
22788
- return hook;
22789
- return error(errInvalidPluginHook(hookName, plugin.name));
22886
+ if (typeof handler !== 'function') {
22887
+ return handler;
22790
22888
  }
22791
22889
  // eslint-disable-next-line @typescript-eslint/ban-types
22792
- const hookResult = hook.apply(context, args);
22793
- if (!hookResult || !hookResult.then) {
22890
+ const hookResult = handler.apply(context, args);
22891
+ if (!(hookResult === null || hookResult === void 0 ? void 0 : hookResult.then)) {
22794
22892
  // short circuit for non-thenables and non-Promises
22795
22893
  return hookResult;
22796
22894
  }
@@ -22823,29 +22921,61 @@ class PluginDriver {
22823
22921
  * @param hookName Name of the plugin hook. Must be in `PluginHooks`.
22824
22922
  * @param args Arguments passed to the plugin hook.
22825
22923
  * @param plugin The acutal plugin
22826
- * @param hookContext When passed, the plugin context can be overridden.
22924
+ * @param replaceContext When passed, the plugin context can be overridden.
22827
22925
  */
22828
- runHookSync(hookName, args, plugin, hookContext) {
22926
+ runHookSync(hookName, args, plugin, replaceContext) {
22829
22927
  const hook = plugin[hookName];
22830
- if (!hook)
22831
- return undefined;
22928
+ const handler = typeof hook === 'object' ? hook.handler : hook;
22832
22929
  let context = this.pluginContexts.get(plugin);
22833
- if (hookContext) {
22834
- context = hookContext(context, plugin);
22930
+ if (replaceContext) {
22931
+ context = replaceContext(context, plugin);
22835
22932
  }
22836
22933
  try {
22837
- // permit values allows values to be returned instead of a functional hook
22838
- if (typeof hook !== 'function') {
22839
- return error(errInvalidPluginHook(hookName, plugin.name));
22840
- }
22841
22934
  // eslint-disable-next-line @typescript-eslint/ban-types
22842
- return hook.apply(context, args);
22935
+ return handler.apply(context, args);
22843
22936
  }
22844
22937
  catch (err) {
22845
22938
  return error(errPluginError(err, plugin.name, { hook: hookName }));
22846
22939
  }
22847
22940
  }
22848
22941
  }
22942
+ function getSortedValidatedPlugins(hookName, plugins, validateHandler = validateFunctionPluginHandler) {
22943
+ const pre = [];
22944
+ const normal = [];
22945
+ const post = [];
22946
+ for (const plugin of plugins) {
22947
+ const hook = plugin[hookName];
22948
+ if (hook) {
22949
+ if (typeof hook === 'object') {
22950
+ validateHandler(hook.handler, hookName, plugin);
22951
+ if (hook.order === 'pre') {
22952
+ pre.push(plugin);
22953
+ continue;
22954
+ }
22955
+ if (hook.order === 'post') {
22956
+ post.push(plugin);
22957
+ continue;
22958
+ }
22959
+ }
22960
+ else {
22961
+ validateHandler(hook, hookName, plugin);
22962
+ }
22963
+ normal.push(plugin);
22964
+ }
22965
+ }
22966
+ return [...pre, ...normal, ...post];
22967
+ }
22968
+ function validateFunctionPluginHandler(handler, hookName, plugin) {
22969
+ if (typeof handler !== 'function') {
22970
+ error(errInvalidFunctionPluginHook(hookName, plugin.name));
22971
+ }
22972
+ }
22973
+ function validateAddonPluginHandler(handler, hookName, plugin) {
22974
+ if (typeof handler !== 'string' && typeof handler !== 'function') {
22975
+ return error(errInvalidAddonPluginHook(hookName, plugin.name));
22976
+ }
22977
+ }
22978
+ function noReturn() { }
22849
22979
 
22850
22980
  class Queue {
22851
22981
  constructor(maxParallel) {
@@ -22935,8 +23065,8 @@ class Graph {
22935
23065
  this.watchMode = true;
22936
23066
  const handleChange = (...args) => this.pluginDriver.hookParallel('watchChange', args);
22937
23067
  const handleClose = () => this.pluginDriver.hookParallel('closeWatcher', []);
22938
- watcher.onCurrentAwaited('change', handleChange);
22939
- watcher.onCurrentAwaited('close', handleClose);
23068
+ watcher.onCurrentRun('change', handleChange);
23069
+ watcher.onCurrentRun('close', handleClose);
22940
23070
  }
22941
23071
  this.pluginDriver = new PluginDriver(this, options, options.plugins, this.pluginCache);
22942
23072
  this.acornParser = Parser.extend(...options.acornInjectPlugins);
@@ -23423,7 +23553,7 @@ function normalizeOutputOptions(config, inputOptions, unsetInputOptions) {
23423
23553
  dir: getDir(config, file),
23424
23554
  dynamicImportFunction: getDynamicImportFunction(config, inputOptions, format),
23425
23555
  entryFileNames: getEntryFileNames(config, unsetOptions),
23426
- esModule: (_c = config.esModule) !== null && _c !== void 0 ? _c : true,
23556
+ esModule: (_c = config.esModule) !== null && _c !== void 0 ? _c : 'if-default-prop',
23427
23557
  exports: getExports(config, unsetOptions),
23428
23558
  extend: config.extend || false,
23429
23559
  externalLiveBindings: (_d = config.externalLiveBindings) !== null && _d !== void 0 ? _d : true,
@@ -23436,7 +23566,7 @@ function normalizeOutputOptions(config, inputOptions, unsetInputOptions) {
23436
23566
  hoistTransitiveImports: (_f = config.hoistTransitiveImports) !== null && _f !== void 0 ? _f : true,
23437
23567
  indent: getIndent(config, compact),
23438
23568
  inlineDynamicImports,
23439
- interop: getInterop(config, inputOptions),
23569
+ interop: getInterop(config),
23440
23570
  intro: getAddon(config, 'intro'),
23441
23571
  manualChunks: getManualChunks(config, inlineDynamicImports, preserveModules, inputOptions),
23442
23572
  minifyInternalExports: getMinifyInternalExports(config, format, compact),
@@ -23543,6 +23673,7 @@ const getAmd = (config) => {
23543
23673
  autoId: false,
23544
23674
  basePath: '',
23545
23675
  define: 'define',
23676
+ forceJsExtensionForImports: false,
23546
23677
  ...config.amd
23547
23678
  };
23548
23679
  if ((mergedOption.autoId || mergedOption.basePath) && mergedOption.id) {
@@ -23556,13 +23687,15 @@ const getAmd = (config) => {
23556
23687
  normalized = {
23557
23688
  autoId: true,
23558
23689
  basePath: mergedOption.basePath,
23559
- define: mergedOption.define
23690
+ define: mergedOption.define,
23691
+ forceJsExtensionForImports: mergedOption.forceJsExtensionForImports
23560
23692
  };
23561
23693
  }
23562
23694
  else {
23563
23695
  normalized = {
23564
23696
  autoId: false,
23565
23697
  define: mergedOption.define,
23698
+ forceJsExtensionForImports: mergedOption.forceJsExtensionForImports,
23566
23699
  id: mergedOption.id
23567
23700
  };
23568
23701
  }
@@ -23627,28 +23760,17 @@ const getIndent = (config, compact) => {
23627
23760
  return configIndent === false ? '' : configIndent !== null && configIndent !== void 0 ? configIndent : true;
23628
23761
  };
23629
23762
  const ALLOWED_INTEROP_TYPES = new Set([
23763
+ 'compat',
23630
23764
  'auto',
23631
23765
  'esModule',
23632
23766
  'default',
23633
- 'defaultOnly',
23634
- true,
23635
- false
23767
+ 'defaultOnly'
23636
23768
  ]);
23637
- const getInterop = (config, inputOptions) => {
23769
+ const getInterop = (config) => {
23638
23770
  const configInterop = config.interop;
23639
- const validatedInteropTypes = new Set();
23640
23771
  const validateInterop = (interop) => {
23641
- if (!validatedInteropTypes.has(interop)) {
23642
- validatedInteropTypes.add(interop);
23643
- if (!ALLOWED_INTEROP_TYPES.has(interop)) {
23644
- return error(errInvalidOption('output.interop', 'outputinterop', `use one of ${Array.from(ALLOWED_INTEROP_TYPES, value => JSON.stringify(value)).join(', ')}`, interop));
23645
- }
23646
- if (typeof interop === 'boolean') {
23647
- warnDeprecation({
23648
- message: `The boolean value "${interop}" for the "output.interop" option is deprecated. Use ${interop ? '"auto"' : '"esModule", "default" or "defaultOnly"'} instead.`,
23649
- url: 'https://rollupjs.org/guide/en/#outputinterop'
23650
- }, true, inputOptions);
23651
- }
23772
+ if (!ALLOWED_INTEROP_TYPES.has(interop)) {
23773
+ return error(errInvalidOption('output.interop', 'outputinterop', `use one of ${Array.from(ALLOWED_INTEROP_TYPES, value => JSON.stringify(value)).join(', ')}`, interop));
23652
23774
  }
23653
23775
  return interop;
23654
23776
  };
@@ -23661,7 +23783,7 @@ const getInterop = (config, inputOptions) => {
23661
23783
  ? interopPerId[id]
23662
23784
  : validateInterop((interopPerId[id] = configInterop(id)));
23663
23785
  }
23664
- return configInterop === undefined ? () => true : () => validateInterop(configInterop);
23786
+ return configInterop === undefined ? () => 'default' : () => validateInterop(configInterop);
23665
23787
  };
23666
23788
  const getManualChunks = (config, inlineDynamicImports, preserveModules, inputOptions) => {
23667
23789
  const configManualChunks = config.manualChunks || inputOptions.manualChunks;
@@ -23754,17 +23876,15 @@ async function getInputOptions(rawInputOptions, watchMode) {
23754
23876
  if (!rawInputOptions) {
23755
23877
  throw new Error('You must supply an options object to rollup');
23756
23878
  }
23757
- const rawPlugins = ensureArray(rawInputOptions.plugins);
23879
+ const rawPlugins = getSortedValidatedPlugins('options', ensureArray(rawInputOptions.plugins));
23758
23880
  const { options, unsetOptions } = normalizeInputOptions(await rawPlugins.reduce(applyOptionHook(watchMode), Promise.resolve(rawInputOptions)));
23759
23881
  normalizePlugins(options.plugins, ANONYMOUS_PLUGIN_PREFIX);
23760
23882
  return { options, unsetOptions };
23761
23883
  }
23762
23884
  function applyOptionHook(watchMode) {
23763
23885
  return async (inputOptions, plugin) => {
23764
- if (plugin.options) {
23765
- return ((await plugin.options.call({ meta: { rollupVersion: version$1, watchMode } }, await inputOptions)) || inputOptions);
23766
- }
23767
- return inputOptions;
23886
+ const handler = 'handler' in plugin.options ? plugin.options.handler : plugin.options;
23887
+ return ((await handler.call({ meta: { rollupVersion: version$1, watchMode } }, await inputOptions)) || inputOptions);
23768
23888
  };
23769
23889
  }
23770
23890
  function normalizePlugins(plugins, anonymousPrefix) {
@@ -23843,32 +23963,7 @@ async function writeOutputFile(outputFile, outputOptions) {
23843
23963
  const fileName = resolve(outputOptions.dir || dirname(outputOptions.file), outputFile.fileName);
23844
23964
  // 'recursive: true' does not throw if the folder structure, or parts of it, already exist
23845
23965
  await promises.mkdir(dirname(fileName), { recursive: true });
23846
- let writeSourceMapPromise;
23847
- let source;
23848
- if (outputFile.type === 'asset') {
23849
- source = outputFile.source;
23850
- }
23851
- else {
23852
- source = outputFile.code;
23853
- if (outputOptions.sourcemap && outputFile.map) {
23854
- let url;
23855
- if (outputOptions.sourcemap === 'inline') {
23856
- url = outputFile.map.toUrl();
23857
- }
23858
- else {
23859
- const { sourcemapBaseUrl } = outputOptions;
23860
- const sourcemapFileName = `${basename(outputFile.fileName)}.map`;
23861
- url = sourcemapBaseUrl
23862
- ? new URL(sourcemapFileName, sourcemapBaseUrl).toString()
23863
- : sourcemapFileName;
23864
- writeSourceMapPromise = promises.writeFile(`${fileName}.map`, outputFile.map.toString());
23865
- }
23866
- if (outputOptions.sourcemap !== 'hidden') {
23867
- source += `//# ${SOURCEMAPPING_URL}=${url}\n`;
23868
- }
23869
- }
23870
- }
23871
- return Promise.all([promises.writeFile(fileName, source), writeSourceMapPromise]);
23966
+ return promises.writeFile(fileName, outputFile.type === 'asset' ? outputFile.source : outputFile.code);
23872
23967
  }
23873
23968
  /**
23874
23969
  * Auxiliary function for defining rollup configuration
@@ -23879,30 +23974,58 @@ function defineConfig(options) {
23879
23974
  return options;
23880
23975
  }
23881
23976
 
23882
- class WatchEmitter extends EventEmitter {
23977
+ class WatchEmitter {
23883
23978
  constructor() {
23884
- super();
23885
- this.awaitedHandlers = Object.create(null);
23886
- // Allows more than 10 bundles to be watched without
23887
- // showing the `MaxListenersExceededWarning` to the user.
23888
- this.setMaxListeners(Infinity);
23979
+ this.currentHandlers = Object.create(null);
23980
+ this.persistentHandlers = Object.create(null);
23889
23981
  }
23890
23982
  // Will be overwritten by Rollup
23891
23983
  async close() { }
23892
- emitAndAwait(event, ...args) {
23893
- this.emit(event, ...args);
23894
- return Promise.all(this.getHandlers(event).map(handler => handler(...args)));
23984
+ emit(event, ...args) {
23985
+ return Promise.all(this.getCurrentHandlers(event)
23986
+ .concat(this.getPersistentHandlers(event))
23987
+ .map(handler => handler(...args)));
23988
+ }
23989
+ off(event, listener) {
23990
+ const listeners = this.persistentHandlers[event];
23991
+ if (listeners) {
23992
+ // A hack stolen from "mitt": ">>> 0" does not change numbers >= 0, but -1
23993
+ // (which would remove the last array element if used unchanged) is turned
23994
+ // into max_int, which is outside the array and does not change anything.
23995
+ listeners.splice(listeners.indexOf(listener) >>> 0, 1);
23996
+ }
23997
+ return this;
23895
23998
  }
23896
- onCurrentAwaited(event, listener) {
23897
- this.getHandlers(event).push(listener);
23999
+ on(event, listener) {
24000
+ this.getPersistentHandlers(event).push(listener);
23898
24001
  return this;
23899
24002
  }
23900
- removeAwaited() {
23901
- this.awaitedHandlers = {};
24003
+ onCurrentRun(event, listener) {
24004
+ this.getCurrentHandlers(event).push(listener);
23902
24005
  return this;
23903
24006
  }
23904
- getHandlers(event) {
23905
- return this.awaitedHandlers[event] || (this.awaitedHandlers[event] = []);
24007
+ once(event, listener) {
24008
+ const selfRemovingListener = (...args) => {
24009
+ this.off(event, selfRemovingListener);
24010
+ return listener(...args);
24011
+ };
24012
+ this.on(event, selfRemovingListener);
24013
+ return this;
24014
+ }
24015
+ removeAllListeners() {
24016
+ this.removeListenersForCurrentRun();
24017
+ this.persistentHandlers = Object.create(null);
24018
+ return this;
24019
+ }
24020
+ removeListenersForCurrentRun() {
24021
+ this.currentHandlers = Object.create(null);
24022
+ return this;
24023
+ }
24024
+ getCurrentHandlers(event) {
24025
+ return this.currentHandlers[event] || (this.currentHandlers[event] = []);
24026
+ }
24027
+ getPersistentHandlers(event) {
24028
+ return this.persistentHandlers[event] || (this.persistentHandlers[event] = []);
23906
24029
  }
23907
24030
  }
23908
24031