rollup 4.59.1 → 4.60.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v4.59.1
4
- Sat, 21 Mar 2026 06:45:31 GMT - commit 0cba9e079e1d6e56882558827b37557f36c52966
3
+ Rollup.js v4.60.1
4
+ Mon, 30 Mar 2026 04:32:12 GMT - commit ae871d762f6bbeb4320d28fe179211168f27a434
5
5
 
6
6
  https://github.com/rollup/rollup
7
7
 
@@ -42,7 +42,7 @@ function _mergeNamespaces(n, m) {
42
42
 
43
43
  const promises__namespace = /*#__PURE__*/_interopNamespaceDefault(promises);
44
44
 
45
- var version = "4.59.1";
45
+ var version = "4.60.1";
46
46
 
47
47
  function ensureArray$1(items) {
48
48
  if (Array.isArray(items)) {
@@ -980,6 +980,8 @@ function requireConstants () {
980
980
  const WIN_SLASH = '\\\\/';
981
981
  const WIN_NO_SLASH = `[^${WIN_SLASH}]`;
982
982
 
983
+ const DEFAULT_MAX_EXTGLOB_RECURSION = 0;
984
+
983
985
  /**
984
986
  * Posix glob regex
985
987
  */
@@ -1046,6 +1048,7 @@ function requireConstants () {
1046
1048
  */
1047
1049
 
1048
1050
  const POSIX_REGEX_SOURCE = {
1051
+ __proto__: null,
1049
1052
  alnum: 'a-zA-Z0-9',
1050
1053
  alpha: 'a-zA-Z',
1051
1054
  ascii: '\\x00-\\x7F',
@@ -1063,6 +1066,7 @@ function requireConstants () {
1063
1066
  };
1064
1067
 
1065
1068
  constants = {
1069
+ DEFAULT_MAX_EXTGLOB_RECURSION,
1066
1070
  MAX_LENGTH: 1024 * 64,
1067
1071
  POSIX_REGEX_SOURCE,
1068
1072
 
@@ -1684,6 +1688,277 @@ function requireParse () {
1684
1688
  return `Missing ${type}: "${char}" - use "\\\\${char}" to match literal characters`;
1685
1689
  };
1686
1690
 
1691
+ const splitTopLevel = input => {
1692
+ const parts = [];
1693
+ let bracket = 0;
1694
+ let paren = 0;
1695
+ let quote = 0;
1696
+ let value = '';
1697
+ let escaped = false;
1698
+
1699
+ for (const ch of input) {
1700
+ if (escaped === true) {
1701
+ value += ch;
1702
+ escaped = false;
1703
+ continue;
1704
+ }
1705
+
1706
+ if (ch === '\\') {
1707
+ value += ch;
1708
+ escaped = true;
1709
+ continue;
1710
+ }
1711
+
1712
+ if (ch === '"') {
1713
+ quote = quote === 1 ? 0 : 1;
1714
+ value += ch;
1715
+ continue;
1716
+ }
1717
+
1718
+ if (quote === 0) {
1719
+ if (ch === '[') {
1720
+ bracket++;
1721
+ } else if (ch === ']' && bracket > 0) {
1722
+ bracket--;
1723
+ } else if (bracket === 0) {
1724
+ if (ch === '(') {
1725
+ paren++;
1726
+ } else if (ch === ')' && paren > 0) {
1727
+ paren--;
1728
+ } else if (ch === '|' && paren === 0) {
1729
+ parts.push(value);
1730
+ value = '';
1731
+ continue;
1732
+ }
1733
+ }
1734
+ }
1735
+
1736
+ value += ch;
1737
+ }
1738
+
1739
+ parts.push(value);
1740
+ return parts;
1741
+ };
1742
+
1743
+ const isPlainBranch = branch => {
1744
+ let escaped = false;
1745
+
1746
+ for (const ch of branch) {
1747
+ if (escaped === true) {
1748
+ escaped = false;
1749
+ continue;
1750
+ }
1751
+
1752
+ if (ch === '\\') {
1753
+ escaped = true;
1754
+ continue;
1755
+ }
1756
+
1757
+ if (/[?*+@!()[\]{}]/.test(ch)) {
1758
+ return false;
1759
+ }
1760
+ }
1761
+
1762
+ return true;
1763
+ };
1764
+
1765
+ const normalizeSimpleBranch = branch => {
1766
+ let value = branch.trim();
1767
+ let changed = true;
1768
+
1769
+ while (changed === true) {
1770
+ changed = false;
1771
+
1772
+ if (/^@\([^\\()[\]{}|]+\)$/.test(value)) {
1773
+ value = value.slice(2, -1);
1774
+ changed = true;
1775
+ }
1776
+ }
1777
+
1778
+ if (!isPlainBranch(value)) {
1779
+ return;
1780
+ }
1781
+
1782
+ return value.replace(/\\(.)/g, '$1');
1783
+ };
1784
+
1785
+ const hasRepeatedCharPrefixOverlap = branches => {
1786
+ const values = branches.map(normalizeSimpleBranch).filter(Boolean);
1787
+
1788
+ for (let i = 0; i < values.length; i++) {
1789
+ for (let j = i + 1; j < values.length; j++) {
1790
+ const a = values[i];
1791
+ const b = values[j];
1792
+ const char = a[0];
1793
+
1794
+ if (!char || a !== char.repeat(a.length) || b !== char.repeat(b.length)) {
1795
+ continue;
1796
+ }
1797
+
1798
+ if (a === b || a.startsWith(b) || b.startsWith(a)) {
1799
+ return true;
1800
+ }
1801
+ }
1802
+ }
1803
+
1804
+ return false;
1805
+ };
1806
+
1807
+ const parseRepeatedExtglob = (pattern, requireEnd = true) => {
1808
+ if ((pattern[0] !== '+' && pattern[0] !== '*') || pattern[1] !== '(') {
1809
+ return;
1810
+ }
1811
+
1812
+ let bracket = 0;
1813
+ let paren = 0;
1814
+ let quote = 0;
1815
+ let escaped = false;
1816
+
1817
+ for (let i = 1; i < pattern.length; i++) {
1818
+ const ch = pattern[i];
1819
+
1820
+ if (escaped === true) {
1821
+ escaped = false;
1822
+ continue;
1823
+ }
1824
+
1825
+ if (ch === '\\') {
1826
+ escaped = true;
1827
+ continue;
1828
+ }
1829
+
1830
+ if (ch === '"') {
1831
+ quote = quote === 1 ? 0 : 1;
1832
+ continue;
1833
+ }
1834
+
1835
+ if (quote === 1) {
1836
+ continue;
1837
+ }
1838
+
1839
+ if (ch === '[') {
1840
+ bracket++;
1841
+ continue;
1842
+ }
1843
+
1844
+ if (ch === ']' && bracket > 0) {
1845
+ bracket--;
1846
+ continue;
1847
+ }
1848
+
1849
+ if (bracket > 0) {
1850
+ continue;
1851
+ }
1852
+
1853
+ if (ch === '(') {
1854
+ paren++;
1855
+ continue;
1856
+ }
1857
+
1858
+ if (ch === ')') {
1859
+ paren--;
1860
+
1861
+ if (paren === 0) {
1862
+ if (requireEnd === true && i !== pattern.length - 1) {
1863
+ return;
1864
+ }
1865
+
1866
+ return {
1867
+ type: pattern[0],
1868
+ body: pattern.slice(2, i),
1869
+ end: i
1870
+ };
1871
+ }
1872
+ }
1873
+ }
1874
+ };
1875
+
1876
+ const getStarExtglobSequenceOutput = pattern => {
1877
+ let index = 0;
1878
+ const chars = [];
1879
+
1880
+ while (index < pattern.length) {
1881
+ const match = parseRepeatedExtglob(pattern.slice(index), false);
1882
+
1883
+ if (!match || match.type !== '*') {
1884
+ return;
1885
+ }
1886
+
1887
+ const branches = splitTopLevel(match.body).map(branch => branch.trim());
1888
+ if (branches.length !== 1) {
1889
+ return;
1890
+ }
1891
+
1892
+ const branch = normalizeSimpleBranch(branches[0]);
1893
+ if (!branch || branch.length !== 1) {
1894
+ return;
1895
+ }
1896
+
1897
+ chars.push(branch);
1898
+ index += match.end + 1;
1899
+ }
1900
+
1901
+ if (chars.length < 1) {
1902
+ return;
1903
+ }
1904
+
1905
+ const source = chars.length === 1
1906
+ ? utils.escapeRegex(chars[0])
1907
+ : `[${chars.map(ch => utils.escapeRegex(ch)).join('')}]`;
1908
+
1909
+ return `${source}*`;
1910
+ };
1911
+
1912
+ const repeatedExtglobRecursion = pattern => {
1913
+ let depth = 0;
1914
+ let value = pattern.trim();
1915
+ let match = parseRepeatedExtglob(value);
1916
+
1917
+ while (match) {
1918
+ depth++;
1919
+ value = match.body.trim();
1920
+ match = parseRepeatedExtglob(value);
1921
+ }
1922
+
1923
+ return depth;
1924
+ };
1925
+
1926
+ const analyzeRepeatedExtglob = (body, options) => {
1927
+ if (options.maxExtglobRecursion === false) {
1928
+ return { risky: false };
1929
+ }
1930
+
1931
+ const max =
1932
+ typeof options.maxExtglobRecursion === 'number'
1933
+ ? options.maxExtglobRecursion
1934
+ : constants.DEFAULT_MAX_EXTGLOB_RECURSION;
1935
+
1936
+ const branches = splitTopLevel(body).map(branch => branch.trim());
1937
+
1938
+ if (branches.length > 1) {
1939
+ if (
1940
+ branches.some(branch => branch === '') ||
1941
+ branches.some(branch => /^[*?]+$/.test(branch)) ||
1942
+ hasRepeatedCharPrefixOverlap(branches)
1943
+ ) {
1944
+ return { risky: true };
1945
+ }
1946
+ }
1947
+
1948
+ for (const branch of branches) {
1949
+ const safeOutput = getStarExtglobSequenceOutput(branch);
1950
+ if (safeOutput) {
1951
+ return { risky: true, safeOutput };
1952
+ }
1953
+
1954
+ if (repeatedExtglobRecursion(branch) > max) {
1955
+ return { risky: true };
1956
+ }
1957
+ }
1958
+
1959
+ return { risky: false };
1960
+ };
1961
+
1687
1962
  /**
1688
1963
  * Parse the given input string.
1689
1964
  * @param {String} input
@@ -1864,6 +2139,8 @@ function requireParse () {
1864
2139
  token.prev = prev;
1865
2140
  token.parens = state.parens;
1866
2141
  token.output = state.output;
2142
+ token.startIndex = state.index;
2143
+ token.tokensIndex = tokens.length;
1867
2144
  const output = (opts.capture ? '(' : '') + token.open;
1868
2145
 
1869
2146
  increment('parens');
@@ -1873,6 +2150,34 @@ function requireParse () {
1873
2150
  };
1874
2151
 
1875
2152
  const extglobClose = token => {
2153
+ const literal = input.slice(token.startIndex, state.index + 1);
2154
+ const body = input.slice(token.startIndex + 2, state.index);
2155
+ const analysis = analyzeRepeatedExtglob(body, opts);
2156
+
2157
+ if ((token.type === 'plus' || token.type === 'star') && analysis.risky) {
2158
+ const safeOutput = analysis.safeOutput
2159
+ ? (token.output ? '' : ONE_CHAR) + (opts.capture ? `(${analysis.safeOutput})` : analysis.safeOutput)
2160
+ : undefined;
2161
+ const open = tokens[token.tokensIndex];
2162
+
2163
+ open.type = 'text';
2164
+ open.value = literal;
2165
+ open.output = safeOutput || utils.escapeRegex(literal);
2166
+
2167
+ for (let i = token.tokensIndex + 1; i < tokens.length; i++) {
2168
+ tokens[i].value = '';
2169
+ tokens[i].output = '';
2170
+ delete tokens[i].suffix;
2171
+ }
2172
+
2173
+ state.output = token.output + open.output;
2174
+ state.backtrack = true;
2175
+
2176
+ push({ type: 'paren', extglob: true, value, output: '' });
2177
+ decrement('parens');
2178
+ return;
2179
+ }
2180
+
1876
2181
  let output = token.close + (opts.capture ? ')' : '');
1877
2182
  let rest;
1878
2183
 
@@ -2965,6 +3270,14 @@ function requirePicomatch$1 () {
2965
3270
  * Compile a regular expression from the `state` object returned by the
2966
3271
  * [parse()](#parse) method.
2967
3272
  *
3273
+ * ```js
3274
+ * const picomatch = require('picomatch');
3275
+ * const state = picomatch.parse('*.js');
3276
+ * // picomatch.compileRe(state[, options]);
3277
+ *
3278
+ * console.log(picomatch.compileRe(state));
3279
+ * //=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
3280
+ * ```
2968
3281
  * @param {Object} `state`
2969
3282
  * @param {Object} `options`
2970
3283
  * @param {Boolean} `returnOutput` Intended for implementors, this argument allows you to return the raw output from the parser.
@@ -3000,10 +3313,10 @@ function requirePicomatch$1 () {
3000
3313
  *
3001
3314
  * ```js
3002
3315
  * const picomatch = require('picomatch');
3003
- * const state = picomatch.parse('*.js');
3004
- * // picomatch.compileRe(state[, options]);
3316
+ * // picomatch.makeRe(state[, options]);
3005
3317
  *
3006
- * console.log(picomatch.compileRe(state));
3318
+ * const result = picomatch.makeRe('*.js');
3319
+ * console.log(result);
3007
3320
  * //=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
3008
3321
  * ```
3009
3322
  * @param {String} `state` The object returned from the `.parse` method.
@@ -6255,12 +6568,15 @@ class Variable extends ExpressionEntity {
6255
6568
  }
6256
6569
  }
6257
6570
 
6571
+ /** Synthetic import name for source phase imports, similar to '*' for namespaces */
6572
+ const SOURCE_PHASE_IMPORT = '*source';
6258
6573
  class ExternalVariable extends Variable {
6259
6574
  constructor(module, name) {
6260
6575
  super(name);
6261
6576
  this.referenced = false;
6262
6577
  this.module = module;
6263
6578
  this.isNamespace = name === '*';
6579
+ this.isSourcePhase = name === SOURCE_PHASE_IMPORT;
6264
6580
  }
6265
6581
  addReference(identifier) {
6266
6582
  this.referenced = true;
@@ -12209,6 +12525,13 @@ function getInteropBlock(dependencies, interop, externalLiveBindings, freeze, sy
12209
12525
  return `${getHelpersBlock(neededInteropHelpers, accessedGlobals, indent, snippets, externalLiveBindings, freeze, symbols)}${interopStatements.length > 0 ? `${interopStatements.join(n)}${n}${n}` : ''}`;
12210
12526
  }
12211
12527
 
12528
+ function throwOnPhase(outputFormat, chunkId, dependencies) {
12529
+ const sourcePhaseDependency = dependencies.find(dependency => dependency.sourcePhaseImport);
12530
+ if (sourcePhaseDependency) {
12531
+ parseAst_js.error(parseAst_js.logSourcePhaseFormatUnsupported(outputFormat, chunkId, sourcePhaseDependency.importPath));
12532
+ }
12533
+ }
12534
+
12212
12535
  function addJsExtension(name) {
12213
12536
  return name.endsWith('.js') ? name : name + '.js';
12214
12537
  }
@@ -12347,6 +12670,7 @@ function warnOnBuiltins(log, dependencies) {
12347
12670
 
12348
12671
  function amd(magicString, { accessedGlobals, dependencies, exports: exports$1, hasDefaultExport, hasExports, id, indent: t, intro, isEntryFacade, isModuleFacade, namedExportsMode, log, outro, snippets }, { amd, esModule, externalLiveBindings, freeze, generatedCode: { symbols }, interop, reexportProtoFromExternal, strict }) {
12349
12672
  warnOnBuiltins(log, dependencies);
12673
+ throwOnPhase('amd', id, dependencies);
12350
12674
  const deps = dependencies.map(m => `'${updateExtensionForRelativeAmdId(m.importPath, amd.forceJsExtensionForImports)}'`);
12351
12675
  const parameters = dependencies.map(m => m.name);
12352
12676
  const { n, getNonArrowFunctionIntro, _ } = snippets;
@@ -12384,7 +12708,8 @@ function amd(magicString, { accessedGlobals, dependencies, exports: exports$1, h
12384
12708
  .append(`${n}${n}}));`);
12385
12709
  }
12386
12710
 
12387
- function cjs(magicString, { accessedGlobals, dependencies, exports: exports$1, hasDefaultExport, hasExports, indent: t, intro, isEntryFacade, isModuleFacade, namedExportsMode, outro, snippets }, { compact, esModule, externalLiveBindings, freeze, interop, generatedCode: { symbols }, reexportProtoFromExternal, strict }) {
12711
+ function cjs(magicString, { accessedGlobals, dependencies, exports: exports$1, hasDefaultExport, hasExports, id, indent: t, intro, isEntryFacade, isModuleFacade, namedExportsMode, outro, snippets }, { compact, esModule, externalLiveBindings, freeze, interop, generatedCode: { symbols }, reexportProtoFromExternal, strict }) {
12712
+ throwOnPhase('cjs', id, dependencies);
12388
12713
  const { _, n } = snippets;
12389
12714
  const useStrict = strict ? `'use strict';${n}${n}` : '';
12390
12715
  let namespaceMarkers = getNamespaceMarkers(namedExportsMode && hasExports, isEntryFacade && (esModule === true || (esModule === 'if-default-prop' && hasDefaultExport)), isModuleFacade && symbols, snippets);
@@ -12437,11 +12762,16 @@ function es(magicString, { accessedGlobals, indent: t, intro, outro, dependencie
12437
12762
  }
12438
12763
  function getImportBlock(dependencies, importAttributesKey, { _ }) {
12439
12764
  const importBlock = [];
12440
- for (const { importPath, reexports, imports, name, attributes } of dependencies) {
12765
+ for (const { importPath, reexports, imports, name, attributes, sourcePhaseImport } of dependencies) {
12441
12766
  const assertion = attributes ? `${_}${importAttributesKey}${_}${attributes}` : '';
12442
12767
  const pathWithAssertion = `'${importPath}'${assertion};`;
12768
+ if (sourcePhaseImport) {
12769
+ importBlock.push(`import source ${sourcePhaseImport} from${_}${pathWithAssertion}`);
12770
+ }
12443
12771
  if (!reexports && !imports) {
12444
- importBlock.push(`import${_}${pathWithAssertion}`);
12772
+ if (!sourcePhaseImport) {
12773
+ importBlock.push(`import${_}${pathWithAssertion}`);
12774
+ }
12445
12775
  continue;
12446
12776
  }
12447
12777
  if (imports) {
@@ -12595,7 +12925,8 @@ function trimEmptyImports(dependencies) {
12595
12925
  return [];
12596
12926
  }
12597
12927
 
12598
- function iife(magicString, { accessedGlobals, dependencies, exports: exports$1, hasDefaultExport, hasExports, indent: t, intro, namedExportsMode, log, outro, snippets }, { compact, esModule, extend, freeze, externalLiveBindings, reexportProtoFromExternal, globals, interop, name, generatedCode: { symbols }, strict }) {
12928
+ function iife(magicString, { accessedGlobals, dependencies, exports: exports$1, hasDefaultExport, hasExports, id, indent: t, intro, namedExportsMode, log, outro, snippets }, { compact, esModule, extend, freeze, externalLiveBindings, reexportProtoFromExternal, globals, interop, name, generatedCode: { symbols }, strict }) {
12929
+ throwOnPhase('iife', id, dependencies);
12599
12930
  const { _, getNonArrowFunctionIntro, getPropertyAccess, n } = snippets;
12600
12931
  const isNamespaced = name && name.includes('.');
12601
12932
  const useVariableAssignment = !extend && !isNamespaced;
@@ -12654,7 +12985,8 @@ function iife(magicString, { accessedGlobals, dependencies, exports: exports$1,
12654
12985
 
12655
12986
  const MISSING_EXPORT_SHIM_VARIABLE = '_missingExportShim';
12656
12987
 
12657
- function system(magicString, { accessedGlobals, dependencies, exports: exports$1, hasExports, indent: t, intro, snippets, outro, usesTopLevelAwait }, { externalLiveBindings, freeze, name, generatedCode: { symbols }, strict, systemNullSetters }) {
12988
+ function system(magicString, { accessedGlobals, dependencies, exports: exports$1, hasExports, id, indent: t, intro, snippets, outro, usesTopLevelAwait }, { externalLiveBindings, freeze, name, generatedCode: { symbols }, strict, systemNullSetters }) {
12989
+ throwOnPhase('system', id, dependencies);
12658
12990
  const { _, getFunctionIntro, getNonArrowFunctionIntro, n, s } = snippets;
12659
12991
  const { importBindings, setters, starExcludes } = analyzeDependencies(dependencies, exports$1, t, snippets);
12660
12992
  const registeredName = name ? `'${name}',${_}` : '';
@@ -12822,6 +13154,7 @@ function umd(magicString, { accessedGlobals, dependencies, exports: exports$1, h
12822
13154
  if (hasExports && !name) {
12823
13155
  return parseAst_js.error(parseAst_js.logMissingNameOptionForUmdExport());
12824
13156
  }
13157
+ throwOnPhase('umd', id, dependencies);
12825
13158
  warnOnBuiltins(log, dependencies);
12826
13159
  const amdDeps = dependencies.map(m => `'${updateExtensionForRelativeAmdId(m.importPath, amd.forceJsExtensionForImports)}'`);
12827
13160
  const cjsDeps = dependencies.map(m => `require('${m.importPath}')`);
@@ -17730,6 +18063,8 @@ const bufferParsers = [
17730
18063
  node.specifiers = convertNodeList(node, scope, buffer[position], buffer);
17731
18064
  node.source = convertNode(node, scope, buffer[position + 1], buffer);
17732
18065
  node.attributes = convertNodeList(node, scope, buffer[position + 2], buffer);
18066
+ const phaseIndex = buffer[position + 3];
18067
+ node.phase = phaseIndex === 0 ? undefined : parseAst_js.FIXED_STRINGS[phaseIndex];
17733
18068
  },
17734
18069
  function importDefaultSpecifier(node, position, buffer) {
17735
18070
  const { scope } = node;
@@ -17741,6 +18076,8 @@ const bufferParsers = [
17741
18076
  node.sourceAstNode = parseAst_js.convertNode(buffer[position], buffer);
17742
18077
  const optionsPosition = buffer[position + 1];
17743
18078
  node.options = optionsPosition === 0 ? null : convertNode(node, scope, optionsPosition, buffer);
18079
+ const phaseIndex = buffer[position + 2];
18080
+ node.phase = phaseIndex === 0 ? undefined : parseAst_js.FIXED_STRINGS[phaseIndex];
17744
18081
  },
17745
18082
  function importNamespaceSpecifier(node, position, buffer) {
17746
18083
  const { scope } = node;
@@ -18447,7 +18784,7 @@ const MISSING_EXPORT_SHIM_DESCRIPTION = {
18447
18784
  identifier: null,
18448
18785
  localName: MISSING_EXPORT_SHIM_VARIABLE
18449
18786
  };
18450
- function getVariableForExportNameRecursive(target, name, importerForSideEffects, isExportAllSearch, searchedNamesAndModules = new Map(), importChain) {
18787
+ function getVariableForExportNameRecursive(target, name, importerForSideEffects, isExportAllSearch, searchedNamesAndModules = new Map(), importChain, sideEffectModules, exportOrReexportModules) {
18451
18788
  const searchedModules = searchedNamesAndModules.get(name);
18452
18789
  if (searchedModules) {
18453
18790
  if (searchedModules.has(target)) {
@@ -18459,10 +18796,12 @@ function getVariableForExportNameRecursive(target, name, importerForSideEffects,
18459
18796
  searchedNamesAndModules.set(name, new Set([target]));
18460
18797
  }
18461
18798
  return target.getVariableForExportName(name, {
18799
+ exportOrReexportModules,
18462
18800
  importChain,
18463
18801
  importerForSideEffects,
18464
18802
  isExportAllSearch,
18465
- searchedNamesAndModules
18803
+ searchedNamesAndModules,
18804
+ sideEffectModules
18466
18805
  });
18467
18806
  }
18468
18807
  function getAndExtendSideEffectModules(variable, module) {
@@ -18519,6 +18858,7 @@ class Module {
18519
18858
  this.isUserDefinedEntryPoint = false;
18520
18859
  this.needsExportShim = false;
18521
18860
  this.sideEffectDependenciesByVariable = new Map();
18861
+ this.sourcePhaseSources = new Set();
18522
18862
  this.sourcesWithAttributes = new Map();
18523
18863
  this.allExportsIncluded = false;
18524
18864
  this.ast = null;
@@ -18782,7 +19122,7 @@ class Module {
18782
19122
  }
18783
19123
  return this.syntheticNamespace;
18784
19124
  }
18785
- getVariableForExportName(name, { importerForSideEffects, importChain = [], isExportAllSearch, onlyExplicit, searchedNamesAndModules } = parseAst_js.EMPTY_OBJECT) {
19125
+ getVariableForExportName(name, { importerForSideEffects, importChain = [], isExportAllSearch, onlyExplicit, searchedNamesAndModules, sideEffectModules, exportOrReexportModules } = parseAst_js.EMPTY_OBJECT) {
18786
19126
  if (name[0] === '*') {
18787
19127
  if (name.length === 1) {
18788
19128
  // export * from './other'
@@ -18797,7 +19137,7 @@ class Module {
18797
19137
  // export { foo } from './other'
18798
19138
  const reexportDeclaration = this.reexportDescriptions.get(name);
18799
19139
  if (reexportDeclaration) {
18800
- const [variable, options] = getVariableForExportNameRecursive(reexportDeclaration.module, reexportDeclaration.localName, importerForSideEffects, false, searchedNamesAndModules, [...importChain, this.id]);
19140
+ const [variable, options] = getVariableForExportNameRecursive(reexportDeclaration.module, reexportDeclaration.localName, importerForSideEffects, false, searchedNamesAndModules, [...importChain, this.id], sideEffectModules, exportOrReexportModules);
18801
19141
  if (!variable) {
18802
19142
  return this.error(parseAst_js.logMissingExport(reexportDeclaration.localName, this.id, reexportDeclaration.module.id, !!options?.missingButExportExists), reexportDeclaration.start);
18803
19143
  }
@@ -18807,6 +19147,10 @@ class Module {
18807
19147
  getOrCreate(importerForSideEffects.sideEffectDependenciesByVariable, variable, (getNewSet)).add(this);
18808
19148
  }
18809
19149
  }
19150
+ if (this.info.moduleSideEffects) {
19151
+ sideEffectModules?.add(this);
19152
+ }
19153
+ exportOrReexportModules?.add(this);
18810
19154
  return [variable];
18811
19155
  }
18812
19156
  const exportDeclaration = this.exportDescriptions.get(name);
@@ -18816,8 +19160,10 @@ class Module {
18816
19160
  }
18817
19161
  const name = exportDeclaration.localName;
18818
19162
  const variable = this.traceVariable(name, {
19163
+ exportOrReexportModules,
18819
19164
  importerForSideEffects,
18820
- searchedNamesAndModules
19165
+ searchedNamesAndModules,
19166
+ sideEffectModules
18821
19167
  });
18822
19168
  if (!variable) {
18823
19169
  return [null, { missingButExportExists: true }];
@@ -18826,6 +19172,8 @@ class Module {
18826
19172
  setAlternativeExporterIfCyclic(variable, importerForSideEffects, this);
18827
19173
  getOrCreate(importerForSideEffects.sideEffectDependenciesByVariable, variable, (getNewSet)).add(this);
18828
19174
  }
19175
+ sideEffectModules?.add(this);
19176
+ exportOrReexportModules?.add(this);
18829
19177
  return [variable];
18830
19178
  }
18831
19179
  if (onlyExplicit) {
@@ -18836,6 +19184,19 @@ class Module {
18836
19184
  this.getVariableFromNamespaceReexports(name, importerForSideEffects, searchedNamesAndModules, [...importChain, this.id]);
18837
19185
  this.namespaceReexportsByName.set(name, foundNamespaceReexport);
18838
19186
  if (foundNamespaceReexport[0]) {
19187
+ const [namespaceReexportVariable, namespaceReexportOptions] = foundNamespaceReexport;
19188
+ if (importerForSideEffects) {
19189
+ const { exportOrReexportModules, sideEffectModules } = namespaceReexportOptions;
19190
+ for (const module of exportOrReexportModules) {
19191
+ if (importerForSideEffects.alternativeReexportModules.has(namespaceReexportVariable)) {
19192
+ continue;
19193
+ }
19194
+ setAlternativeExporterIfCyclic(namespaceReexportVariable, importerForSideEffects, module);
19195
+ }
19196
+ for (const module of sideEffectModules) {
19197
+ getOrCreate(importerForSideEffects.sideEffectDependenciesByVariable, namespaceReexportVariable, (getNewSet)).add(module);
19198
+ }
19199
+ }
18839
19200
  return foundNamespaceReexport;
18840
19201
  }
18841
19202
  }
@@ -19039,7 +19400,7 @@ class Module {
19039
19400
  transformFiles: this.transformFiles
19040
19401
  };
19041
19402
  }
19042
- traceVariable(name, { importerForSideEffects, isExportAllSearch, searchedNamesAndModules } = parseAst_js.EMPTY_OBJECT) {
19403
+ traceVariable(name, { importerForSideEffects, isExportAllSearch, searchedNamesAndModules, sideEffectModules, exportOrReexportModules } = parseAst_js.EMPTY_OBJECT) {
19043
19404
  const localVariable = this.scope.variables.get(name);
19044
19405
  if (localVariable) {
19045
19406
  return localVariable;
@@ -19050,7 +19411,7 @@ class Module {
19050
19411
  if (otherModule instanceof Module && importDescription.name === '*') {
19051
19412
  return otherModule.namespace;
19052
19413
  }
19053
- const [declaration, options] = getVariableForExportNameRecursive(otherModule, importDescription.name, importerForSideEffects || this, isExportAllSearch, searchedNamesAndModules, [this.id]);
19414
+ const [declaration, options] = getVariableForExportNameRecursive(otherModule, importDescription.name, importerForSideEffects || this, isExportAllSearch, searchedNamesAndModules, [this.id], sideEffectModules, exportOrReexportModules);
19054
19415
  if (!declaration) {
19055
19416
  return this.error(parseAst_js.logMissingExport(importDescription.name, this.id, otherModule.id, !!options?.missingButExportExists), importDescription.start);
19056
19417
  }
@@ -19169,16 +19530,19 @@ class Module {
19169
19530
  if (this.scope.variables.has(localName) || this.importDescriptions.has(localName)) {
19170
19531
  this.error(parseAst_js.logRedeclarationError(localName), specifier.local.start);
19171
19532
  }
19172
- const name = specifier instanceof ImportDefaultSpecifier
19173
- ? 'default'
19174
- : specifier instanceof ImportNamespaceSpecifier
19175
- ? '*'
19176
- : specifier.imported instanceof Identifier
19177
- ? specifier.imported.name
19178
- : specifier.imported.value;
19533
+ const name = node.phase === 'source'
19534
+ ? SOURCE_PHASE_IMPORT
19535
+ : specifier instanceof ImportDefaultSpecifier
19536
+ ? 'default'
19537
+ : specifier instanceof ImportNamespaceSpecifier
19538
+ ? '*'
19539
+ : specifier.imported instanceof Identifier
19540
+ ? specifier.imported.name
19541
+ : specifier.imported.value;
19179
19542
  this.importDescriptions.set(localName, {
19180
19543
  module: null, // filled in later
19181
19544
  name,
19545
+ phase: node.phase === 'source' ? 'source' : 'instance',
19182
19546
  source,
19183
19547
  start: specifier.start
19184
19548
  });
@@ -19251,6 +19615,9 @@ class Module {
19251
19615
  else {
19252
19616
  this.sourcesWithAttributes.set(source, parsedAttributes);
19253
19617
  }
19618
+ if (declaration.phase === 'source') {
19619
+ this.sourcePhaseSources.add(source);
19620
+ }
19254
19621
  }
19255
19622
  getImportedJsxFactoryVariable(baseName, nodeStart, importSource) {
19256
19623
  const { id } = this.resolvedIds[importSource];
@@ -19265,6 +19632,8 @@ class Module {
19265
19632
  let foundSyntheticDeclaration = null;
19266
19633
  const foundInternalDeclarations = new Map();
19267
19634
  const foundExternalDeclarations = new Set();
19635
+ const sideEffectModules = new Set();
19636
+ const exportOrReexportModules = new Set();
19268
19637
  for (const module of this.exportAllModules) {
19269
19638
  // Synthetic namespaces should not hide "regular" exports of the same name
19270
19639
  if (module.info.syntheticNamedExports === name) {
@@ -19273,7 +19642,7 @@ class Module {
19273
19642
  const [variable, options] = getVariableForExportNameRecursive(module, name, importerForSideEffects, true,
19274
19643
  // We are creating a copy to handle the case where the same binding is
19275
19644
  // imported through different namespace reexports gracefully
19276
- copyNameToModulesMap(searchedNamesAndModules), importChain);
19645
+ copyNameToModulesMap(searchedNamesAndModules), importChain, sideEffectModules, exportOrReexportModules);
19277
19646
  if (module instanceof ExternalModule || options?.indirectExternal) {
19278
19647
  foundExternalDeclarations.add(variable);
19279
19648
  }
@@ -19290,7 +19659,7 @@ class Module {
19290
19659
  const foundDeclarationList = [...foundInternalDeclarations];
19291
19660
  const usedDeclaration = foundDeclarationList[0][0];
19292
19661
  if (foundDeclarationList.length === 1) {
19293
- return [usedDeclaration];
19662
+ return [usedDeclaration, { exportOrReexportModules, sideEffectModules }];
19294
19663
  }
19295
19664
  this.options.onLog(parseAst_js.LOGLEVEL_WARN, parseAst_js.logNamespaceConflict(name, this.id, foundDeclarationList.map(([, module]) => module.id)));
19296
19665
  // TODO we are pretending it was not found while it should behave like "undefined"
@@ -19302,10 +19671,13 @@ class Module {
19302
19671
  if (foundDeclarationList.length > 1) {
19303
19672
  this.options.onLog(parseAst_js.LOGLEVEL_WARN, parseAst_js.logAmbiguousExternalNamespaces(name, this.id, usedDeclaration.module.id, foundDeclarationList.map(declaration => declaration.module.id)));
19304
19673
  }
19305
- return [usedDeclaration, { indirectExternal: true }];
19674
+ return [
19675
+ usedDeclaration,
19676
+ { exportOrReexportModules, indirectExternal: true, sideEffectModules }
19677
+ ];
19306
19678
  }
19307
19679
  if (foundSyntheticDeclaration) {
19308
- return [foundSyntheticDeclaration];
19680
+ return [foundSyntheticDeclaration, { exportOrReexportModules, sideEffectModules }];
19309
19681
  }
19310
19682
  return [null];
19311
19683
  }
@@ -19464,6 +19836,9 @@ function deconflictImportsEsmOrSystem(usedNames, imports, dependenciesToBeDeconf
19464
19836
  ? externalChunkByModule.get(module)
19465
19837
  : chunkByModule.get(module)).variableName);
19466
19838
  }
19839
+ else if (module instanceof ExternalModule && variable.isSourcePhase) {
19840
+ variable.setRenderNames(null, getSafeName(module.suggestedVariableName + '__source', usedNames, variable.forbiddenNames));
19841
+ }
19467
19842
  else if (module instanceof ExternalModule && name === 'default') {
19468
19843
  variable.setRenderNames(null, getSafeName([...module.exportedVariables].some(([exportedVariable, exportedName]) => exportedName === '*' && exportedVariable.included)
19469
19844
  ? module.suggestedVariableName + '__default'
@@ -20401,10 +20776,14 @@ class Chunk {
20401
20776
  const module = variable.module;
20402
20777
  let dependency;
20403
20778
  let imported;
20779
+ const isSourcePhase = module instanceof ExternalModule && variable.isSourcePhase;
20404
20780
  if (module instanceof ExternalModule) {
20405
20781
  dependency = this.externalChunkByModule.get(module);
20406
20782
  imported = variable.name;
20407
- if (imported !== 'default' && imported !== '*' && interop(module.id) === 'defaultOnly') {
20783
+ if (!isSourcePhase &&
20784
+ imported !== 'default' &&
20785
+ imported !== '*' &&
20786
+ interop(module.id) === 'defaultOnly') {
20408
20787
  return parseAst_js.error(parseAst_js.logUnexpectedNamedImport(module.id, imported, false));
20409
20788
  }
20410
20789
  }
@@ -20414,7 +20793,8 @@ class Chunk {
20414
20793
  }
20415
20794
  getOrCreate(importsByDependency, dependency, getNewArray).push({
20416
20795
  imported,
20417
- local: variable.getName(this.snippets.getPropertyAccess)
20796
+ local: variable.getName(this.snippets.getPropertyAccess),
20797
+ phase: isSourcePhase ? 'source' : 'instance'
20418
20798
  });
20419
20799
  }
20420
20800
  return importsByDependency;
@@ -20565,6 +20945,9 @@ class Chunk {
20565
20945
  const reexports = reexportSpecifiers.get(dependency) || null;
20566
20946
  const namedExportsMode = dependency instanceof ExternalChunk || dependency.exportMode !== 'default';
20567
20947
  const importPath = dependency.getImportPath(fileName);
20948
+ // Separate source-phase imports from regular imports
20949
+ const sourcePhaseImport = imports?.find(index => index.phase === 'source');
20950
+ const instanceImports = imports?.filter(index => index.phase !== 'source') ?? null;
20568
20951
  renderedDependencies.set(dependency, {
20569
20952
  attributes: dependency instanceof ExternalChunk
20570
20953
  ? dependency.getImportAttributes(this.snippets)
@@ -20574,12 +20957,13 @@ class Chunk {
20574
20957
  (this.outputOptions.format === 'umd' || this.outputOptions.format === 'iife') &&
20575
20958
  getGlobalName(dependency, this.outputOptions.globals, (imports || reexports) !== null, this.inputOptions.onLog),
20576
20959
  importPath,
20577
- imports,
20960
+ imports: instanceImports && instanceImports.length > 0 ? instanceImports : null,
20578
20961
  isChunk: dependency instanceof Chunk,
20579
20962
  name: dependency.variableName,
20580
20963
  namedExportsMode,
20581
20964
  namespaceVariableName: dependency.namespaceVariableName,
20582
- reexports
20965
+ reexports,
20966
+ sourcePhaseImport: sourcePhaseImport?.local
20583
20967
  });
20584
20968
  }
20585
20969
  return (this.renderedDependencies = renderedDependencies);
@@ -22748,13 +23132,16 @@ class ModuleLoader {
22748
23132
  return loadNewModulesPromise;
22749
23133
  }
22750
23134
  async fetchDynamicDependencies(module, resolveDynamicImportPromises) {
22751
- const dependencies = await Promise.all(resolveDynamicImportPromises.map(resolveDynamicImportPromise => resolveDynamicImportPromise.then(async ([{ node }, resolvedId]) => {
23135
+ const dependencies = await Promise.all(resolveDynamicImportPromises.map(resolveDynamicImportPromise => resolveDynamicImportPromise.then(async ([{ argument, node }, resolvedId]) => {
22752
23136
  if (resolvedId === null)
22753
23137
  return null;
22754
23138
  if (typeof resolvedId === 'string') {
22755
23139
  node.resolution = resolvedId;
22756
23140
  return null;
22757
23141
  }
23142
+ if (node.phase === 'source' && !resolvedId.external) {
23143
+ return parseAst_js.error(parseAst_js.logNonExternalSourcePhaseImport(typeof argument === 'string' ? argument : parseAst_js.relativeId(resolvedId.id), module.id));
23144
+ }
22758
23145
  return (node.resolution = await this.fetchResolvedDependency(parseAst_js.relativeId(resolvedId.id), module.id, resolvedId));
22759
23146
  })));
22760
23147
  for (const dependency of dependencies) {
@@ -22834,7 +23221,12 @@ class ModuleLoader {
22834
23221
  return this.fetchModule(resolvedId, importer, false, false);
22835
23222
  }
22836
23223
  async fetchStaticDependencies(module, resolveStaticDependencyPromises) {
22837
- for (const dependency of await Promise.all(resolveStaticDependencyPromises.map(resolveStaticDependencyPromise => resolveStaticDependencyPromise.then(([source, resolvedId]) => this.fetchResolvedDependency(source, module.id, resolvedId))))) {
23224
+ for (const dependency of await Promise.all(resolveStaticDependencyPromises.map(resolveStaticDependencyPromise => resolveStaticDependencyPromise.then(([source, resolvedId]) => {
23225
+ if (module.sourcePhaseSources.has(source) && !resolvedId.external) {
23226
+ return parseAst_js.error(parseAst_js.logNonExternalSourcePhaseImport(source, module.id));
23227
+ }
23228
+ return this.fetchResolvedDependency(source, module.id, resolvedId);
23229
+ })))) {
22838
23230
  module.dependencies.add(dependency);
22839
23231
  dependency.importers.push(module.id);
22840
23232
  }
@@ -23246,7 +23638,7 @@ class Graph {
23246
23638
  warnForMissingExports() {
23247
23639
  for (const module of this.modules) {
23248
23640
  for (const importDescription of module.importDescriptions.values()) {
23249
- if (importDescription.name !== '*') {
23641
+ if (importDescription.name !== '*' && importDescription.phase !== 'source') {
23250
23642
  const [variable, options] = importDescription.module.getVariableForExportName(importDescription.name, { importChain: [module.id] });
23251
23643
  if (!variable) {
23252
23644
  module.log(parseAst_js.LOGLEVEL_WARN, parseAst_js.logMissingExport(importDescription.name, module.id, importDescription.module.id, !!options?.missingButExportExists), importDescription.start);