rollup 3.0.0-2 → 3.0.0-3

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,13 +1,13 @@
1
1
  /*
2
2
  @license
3
3
  Rollup.js v3.0.0-2
4
- Fri, 15 Jul 2022 15:25:15 GMT - commit 13b0ef8778ca5ccfd54b113ef545bf235a4c7e34
4
+ Sat, 30 Jul 2022 12:51:34 GMT - commit 41906cedefbc03640d6e8ca23ce6975f3bb5c6a1
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, extname, basename, dirname, relative as relative$1, win32, posix, isAbsolute as isAbsolute$1 } from 'path';
10
+ import require$$0, { resolve, basename, extname, dirname, relative as relative$1, win32, posix, isAbsolute as isAbsolute$1 } from 'path';
11
11
  import process$1 from 'process';
12
12
  import { performance } from 'perf_hooks';
13
13
  import { createHash as createHash$1 } from 'crypto';
@@ -1891,8 +1891,10 @@ function printQuotedStringList(list, verbs) {
1891
1891
  }
1892
1892
 
1893
1893
  function error(base) {
1894
- if (!(base instanceof Error))
1894
+ if (!(base instanceof Error)) {
1895
1895
  base = Object.assign(new Error(base.message), base);
1896
+ Object.defineProperty(base, 'name', { value: 'RollupError' });
1897
+ }
1896
1898
  throw base;
1897
1899
  }
1898
1900
  function augmentCodeLocation(props, pos, source, id) {
@@ -1910,335 +1912,500 @@ function augmentCodeLocation(props, pos, source, id) {
1910
1912
  props.frame = getCodeFrame(source, line, column);
1911
1913
  }
1912
1914
  }
1913
- var Errors;
1914
- (function (Errors) {
1915
- Errors["ADDON_ERROR"] = "ADDON_ERROR";
1916
- Errors["ALREADY_CLOSED"] = "ALREADY_CLOSED";
1917
- Errors["ASSET_NOT_FINALISED"] = "ASSET_NOT_FINALISED";
1918
- Errors["ASSET_NOT_FOUND"] = "ASSET_NOT_FOUND";
1919
- Errors["ASSET_SOURCE_ALREADY_SET"] = "ASSET_SOURCE_ALREADY_SET";
1920
- Errors["ASSET_SOURCE_MISSING"] = "ASSET_SOURCE_MISSING";
1921
- Errors["BAD_LOADER"] = "BAD_LOADER";
1922
- Errors["CANNOT_EMIT_FROM_OPTIONS_HOOK"] = "CANNOT_EMIT_FROM_OPTIONS_HOOK";
1923
- Errors["CHUNK_NOT_GENERATED"] = "CHUNK_NOT_GENERATED";
1924
- Errors["CHUNK_INVALID"] = "CHUNK_INVALID";
1925
- Errors["CIRCULAR_REEXPORT"] = "CIRCULAR_REEXPORT";
1926
- Errors["CYCLIC_CROSS_CHUNK_REEXPORT"] = "CYCLIC_CROSS_CHUNK_REEXPORT";
1927
- Errors["DEPRECATED_FEATURE"] = "DEPRECATED_FEATURE";
1928
- Errors["EXTERNAL_SYNTHETIC_EXPORTS"] = "EXTERNAL_SYNTHETIC_EXPORTS";
1929
- Errors["FILE_NAME_CONFLICT"] = "FILE_NAME_CONFLICT";
1930
- Errors["FILE_NOT_FOUND"] = "FILE_NOT_FOUND";
1931
- Errors["INPUT_HOOK_IN_OUTPUT_PLUGIN"] = "INPUT_HOOK_IN_OUTPUT_PLUGIN";
1932
- Errors["INVALID_CHUNK"] = "INVALID_CHUNK";
1933
- Errors["INVALID_EXPORT_OPTION"] = "INVALID_EXPORT_OPTION";
1934
- Errors["INVALID_EXTERNAL_ID"] = "INVALID_EXTERNAL_ID";
1935
- Errors["INVALID_OPTION"] = "INVALID_OPTION";
1936
- Errors["INVALID_PLUGIN_HOOK"] = "INVALID_PLUGIN_HOOK";
1937
- Errors["INVALID_ROLLUP_PHASE"] = "INVALID_ROLLUP_PHASE";
1938
- Errors["INVALID_TLA_FORMAT"] = "INVALID_TLA_FORMAT";
1939
- Errors["MISSING_EXPORT"] = "MISSING_EXPORT";
1940
- Errors["MISSING_IMPLICIT_DEPENDANT"] = "MISSING_IMPLICIT_DEPENDANT";
1941
- Errors["MIXED_EXPORTS"] = "MIXED_EXPORTS";
1942
- Errors["NAMESPACE_CONFLICT"] = "NAMESPACE_CONFLICT";
1943
- Errors["AMBIGUOUS_EXTERNAL_NAMESPACES"] = "AMBIGUOUS_EXTERNAL_NAMESPACES";
1944
- Errors["NO_TRANSFORM_MAP_OR_AST_WITHOUT_CODE"] = "NO_TRANSFORM_MAP_OR_AST_WITHOUT_CODE";
1945
- Errors["PLUGIN_ERROR"] = "PLUGIN_ERROR";
1946
- Errors["PREFER_NAMED_EXPORTS"] = "PREFER_NAMED_EXPORTS";
1947
- Errors["SYNTHETIC_NAMED_EXPORTS_NEED_NAMESPACE_EXPORT"] = "SYNTHETIC_NAMED_EXPORTS_NEED_NAMESPACE_EXPORT";
1948
- Errors["UNEXPECTED_NAMED_IMPORT"] = "UNEXPECTED_NAMED_IMPORT";
1949
- Errors["UNRESOLVED_ENTRY"] = "UNRESOLVED_ENTRY";
1950
- Errors["UNRESOLVED_IMPORT"] = "UNRESOLVED_IMPORT";
1951
- Errors["VALIDATION_ERROR"] = "VALIDATION_ERROR";
1952
- })(Errors || (Errors = {}));
1915
+ // Error codes should be sorted alphabetically while errors should be sorted by
1916
+ // 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';
1953
1918
  function errAddonNotGenerated(message, hook, plugin) {
1954
1919
  return {
1955
- code: Errors.ADDON_ERROR,
1956
- message: `Could not retrieve ${hook}. Check configuration of plugin ${plugin}.
1920
+ code: ADDON_ERROR,
1921
+ message: `Could not retrieve "${hook}". Check configuration of plugin "${plugin}".
1957
1922
  \tError Message: ${message}`
1958
1923
  };
1959
1924
  }
1925
+ function errAlreadyClosed() {
1926
+ return {
1927
+ code: ALREADY_CLOSED,
1928
+ message: 'Bundle is already closed, no more calls to "generate" or "write" are allowed.'
1929
+ };
1930
+ }
1931
+ function errAmbiguousExternalNamespaces(binding, reexportingModule, usedModule, sources) {
1932
+ return {
1933
+ binding,
1934
+ code: AMBIGUOUS_EXTERNAL_NAMESPACES,
1935
+ ids: sources,
1936
+ message: `Ambiguous external namespace resolution: "${relativeId(reexportingModule)}" re-exports "${binding}" from one of the external modules ${printQuotedStringList(sources.map(module => relativeId(module)))}, guessing "${relativeId(usedModule)}".`,
1937
+ reexporter: reexportingModule
1938
+ };
1939
+ }
1940
+ function errAnonymousPluginCache() {
1941
+ return {
1942
+ code: ANONYMOUS_PLUGIN_CACHE,
1943
+ message: 'A plugin is trying to use the Rollup cache but is not declaring a plugin name or cacheKey.'
1944
+ };
1945
+ }
1960
1946
  function errAssetNotFinalisedForFileName(name) {
1961
1947
  return {
1962
- code: Errors.ASSET_NOT_FINALISED,
1948
+ code: ASSET_NOT_FINALISED,
1963
1949
  message: `Plugin error - Unable to get file name for asset "${name}". Ensure that the source is set and that generate is called first. If you reference assets via import.meta.ROLLUP_FILE_URL_<referenceId>, you need to either have set their source after "renderStart" or need to provide an explicit "fileName" when emitting them.`
1964
1950
  };
1965
1951
  }
1952
+ function errAssetReferenceIdNotFoundForSetSource(assetReferenceId) {
1953
+ return {
1954
+ code: ASSET_NOT_FOUND,
1955
+ message: `Plugin error - Unable to set the source for unknown asset "${assetReferenceId}".`
1956
+ };
1957
+ }
1958
+ function errAssetSourceAlreadySet(name) {
1959
+ return {
1960
+ code: ASSET_SOURCE_ALREADY_SET,
1961
+ message: `Unable to set the source for asset "${name}", source already set.`
1962
+ };
1963
+ }
1964
+ function errNoAssetSourceSet(assetName) {
1965
+ return {
1966
+ code: ASSET_SOURCE_MISSING,
1967
+ message: `Plugin error creating asset "${assetName}" - no asset source set.`
1968
+ };
1969
+ }
1970
+ function errBadLoader(id) {
1971
+ return {
1972
+ code: BAD_LOADER,
1973
+ message: `Error loading "${relativeId(id)}": plugin load hook should return a string, a { code, map } object, or nothing/null.`
1974
+ };
1975
+ }
1976
+ function errCannotCallNamespace(name) {
1977
+ return {
1978
+ code: CANNOT_CALL_NAMESPACE,
1979
+ message: `Cannot call a namespace ("${name}").`
1980
+ };
1981
+ }
1966
1982
  function errCannotEmitFromOptionsHook() {
1967
1983
  return {
1968
- code: Errors.CANNOT_EMIT_FROM_OPTIONS_HOOK,
1984
+ code: CANNOT_EMIT_FROM_OPTIONS_HOOK,
1969
1985
  message: `Cannot emit files or set asset sources in the "outputOptions" hook, use the "renderStart" hook instead.`
1970
1986
  };
1971
1987
  }
1972
1988
  function errChunkNotGeneratedForFileName(name) {
1973
1989
  return {
1974
- code: Errors.CHUNK_NOT_GENERATED,
1990
+ code: CHUNK_NOT_GENERATED,
1975
1991
  message: `Plugin error - Unable to get file name for emitted chunk "${name}". You can only get file names once chunks have been generated after the "renderStart" hook.`
1976
1992
  };
1977
1993
  }
1978
1994
  function errChunkInvalid({ fileName, code }, exception) {
1979
1995
  const errorProps = {
1980
- code: Errors.CHUNK_INVALID,
1996
+ code: CHUNK_INVALID,
1981
1997
  message: `Chunk "${fileName}" is not valid JavaScript: ${exception.message}.`
1982
1998
  };
1983
1999
  augmentCodeLocation(errorProps, exception.loc, code, fileName);
1984
2000
  return errorProps;
1985
2001
  }
1986
- function errCircularReexport(exportName, importedModule) {
2002
+ function errCircularDependency(cyclePath) {
2003
+ return {
2004
+ code: CIRCULAR_DEPENDENCY,
2005
+ ids: cyclePath,
2006
+ message: `Circular dependency: ${cyclePath.map(relativeId).join(' -> ')}`
2007
+ };
2008
+ }
2009
+ function errCircularReexport(exportName, exporter) {
1987
2010
  return {
1988
- code: Errors.CIRCULAR_REEXPORT,
1989
- id: importedModule,
1990
- message: `"${exportName}" cannot be exported from ${relativeId(importedModule)} as it is a reexport that references itself.`
2011
+ code: CIRCULAR_REEXPORT,
2012
+ exporter,
2013
+ message: `"${exportName}" cannot be exported from "${relativeId(exporter)}" as it is a reexport that references itself.`
1991
2014
  };
1992
2015
  }
1993
2016
  function errCyclicCrossChunkReexport(exportName, exporter, reexporter, importer) {
1994
2017
  return {
1995
- code: Errors.CYCLIC_CROSS_CHUNK_REEXPORT,
2018
+ code: CYCLIC_CROSS_CHUNK_REEXPORT,
1996
2019
  exporter,
1997
- importer,
1998
- message: `Export "${exportName}" of module ${relativeId(exporter)} was reexported through module ${relativeId(reexporter)} while both modules are dependencies of each other and will end up in different chunks by current Rollup settings. This scenario is not well supported at the moment as it will produce a circular dependency between chunks and will likely lead to broken execution order.\nEither change the import in ${relativeId(importer)} to point directly to the exporting module or do not use "preserveModules" to ensure these modules end up in the same chunk.`,
2020
+ id: importer,
2021
+ message: `Export "${exportName}" of module "${relativeId(exporter)}" was reexported through module "${relativeId(reexporter)}" while both modules are dependencies of each other and will end up in different chunks by current Rollup settings. This scenario is not well supported at the moment as it will produce a circular dependency between chunks and will likely lead to broken execution order.\nEither change the import in "${relativeId(importer)}" to point directly to the exporting module or do not use "preserveModules" to ensure these modules end up in the same chunk.`,
1999
2022
  reexporter
2000
2023
  };
2001
2024
  }
2002
- function errAssetReferenceIdNotFoundForSetSource(assetReferenceId) {
2025
+ function errDeprecation(deprecation) {
2003
2026
  return {
2004
- code: Errors.ASSET_NOT_FOUND,
2005
- message: `Plugin error - Unable to set the source for unknown asset "${assetReferenceId}".`
2027
+ code: DEPRECATED_FEATURE,
2028
+ ...(typeof deprecation === 'string' ? { message: deprecation } : deprecation)
2006
2029
  };
2007
2030
  }
2008
- function errAssetSourceAlreadySet(name) {
2031
+ function errDuplicatePluginName(plugin) {
2009
2032
  return {
2010
- code: Errors.ASSET_SOURCE_ALREADY_SET,
2011
- message: `Unable to set the source for asset "${name}", source already set.`
2033
+ code: DUPLICATE_PLUGIN_NAME,
2034
+ message: `The plugin name ${plugin} is being used twice in the same build. Plugin names must be distinct or provide a cacheKey (please post an issue to the plugin if you are a plugin user).`
2012
2035
  };
2013
2036
  }
2014
- function errNoAssetSourceSet(assetName) {
2037
+ function errEmptyChunk(chunkName) {
2015
2038
  return {
2016
- code: Errors.ASSET_SOURCE_MISSING,
2017
- message: `Plugin error creating asset "${assetName}" - no asset source set.`
2039
+ code: EMPTY_BUNDLE,
2040
+ message: `Generated an empty chunk: "${chunkName}".`,
2041
+ names: [chunkName]
2018
2042
  };
2019
2043
  }
2020
- function errBadLoader(id) {
2044
+ function errEval(id) {
2021
2045
  return {
2022
- code: Errors.BAD_LOADER,
2023
- message: `Error loading ${relativeId(id)}: plugin load hook should return a string, a { code, map } object, or nothing/null`
2046
+ code: EVAL,
2047
+ id,
2048
+ message: `Use of eval in "${relativeId(id)}" is strongly discouraged as it poses security risks and may cause issues with minification.`,
2049
+ url: 'https://rollupjs.org/guide/en/#avoiding-eval'
2024
2050
  };
2025
2051
  }
2026
- function errDeprecation(deprecation) {
2052
+ function errExternalSyntheticExports(id, importer) {
2027
2053
  return {
2028
- code: Errors.DEPRECATED_FEATURE,
2029
- ...(typeof deprecation === 'string' ? { message: deprecation } : deprecation)
2054
+ code: EXTERNAL_SYNTHETIC_EXPORTS,
2055
+ exporter: id,
2056
+ message: `External "${id}" cannot have "syntheticNamedExports" enabled (imported by "${relativeId(importer)}").`
2057
+ };
2058
+ }
2059
+ function errFileNameConflict(fileName) {
2060
+ return {
2061
+ code: FILE_NAME_CONFLICT,
2062
+ message: `The emitted file "${fileName}" overwrites a previously emitted file of the same name.`
2030
2063
  };
2031
2064
  }
2032
2065
  function errFileReferenceIdNotFoundForFilename(assetReferenceId) {
2033
2066
  return {
2034
- code: Errors.FILE_NOT_FOUND,
2067
+ code: FILE_NOT_FOUND,
2035
2068
  message: `Plugin error - Unable to get file name for unknown file "${assetReferenceId}".`
2036
2069
  };
2037
2070
  }
2038
- function errFileNameConflict(fileName) {
2071
+ function errIllegalIdentifierAsName(name) {
2039
2072
  return {
2040
- code: Errors.FILE_NAME_CONFLICT,
2041
- message: `The emitted file "${fileName}" overwrites a previously emitted file of the same name.`
2073
+ code: ILLEGAL_IDENTIFIER_AS_NAME,
2074
+ message: `Given name "${name}" is not a legal JS identifier. If you need this, you can try "output.extend: true".`,
2075
+ url: 'https://rollupjs.org/guide/en/#outputextend'
2076
+ };
2077
+ }
2078
+ function errIllegalImportReassignment(name, importingId) {
2079
+ return {
2080
+ code: ILLEGAL_REASSIGNMENT,
2081
+ message: `Illegal reassignment of import "${name}" in "${relativeId(importingId)}".`
2042
2082
  };
2043
2083
  }
2044
2084
  function errInputHookInOutputPlugin(pluginName, hookName) {
2045
2085
  return {
2046
- code: Errors.INPUT_HOOK_IN_OUTPUT_PLUGIN,
2086
+ code: INPUT_HOOK_IN_OUTPUT_PLUGIN,
2047
2087
  message: `The "${hookName}" hook used by the output plugin ${pluginName} is a build time hook and will not be run for that plugin. Either this plugin cannot be used as an output plugin, or it should have an option to configure it as an output plugin.`
2048
2088
  };
2049
2089
  }
2050
2090
  function errCannotAssignModuleToChunk(moduleId, assignToAlias, currentAlias) {
2051
2091
  return {
2052
- code: Errors.INVALID_CHUNK,
2053
- message: `Cannot assign ${relativeId(moduleId)} to the "${assignToAlias}" chunk as it is already in the "${currentAlias}" chunk.`
2092
+ code: INVALID_CHUNK,
2093
+ message: `Cannot assign "${relativeId(moduleId)}" to the "${assignToAlias}" chunk as it is already in the "${currentAlias}" chunk.`
2054
2094
  };
2055
2095
  }
2056
2096
  function errInvalidExportOptionValue(optionValue) {
2057
2097
  return {
2058
- code: Errors.INVALID_EXPORT_OPTION,
2059
- message: `"output.exports" must be "default", "named", "none", "auto", or left unspecified (defaults to "auto"), received "${optionValue}"`,
2098
+ code: INVALID_EXPORT_OPTION,
2099
+ message: `"output.exports" must be "default", "named", "none", "auto", or left unspecified (defaults to "auto"), received "${optionValue}".`,
2060
2100
  url: `https://rollupjs.org/guide/en/#outputexports`
2061
2101
  };
2062
2102
  }
2063
2103
  function errIncompatibleExportOptionValue(optionValue, keys, entryModule) {
2064
2104
  return {
2065
- code: 'INVALID_EXPORT_OPTION',
2066
- message: `"${optionValue}" was specified for "output.exports", but entry module "${relativeId(entryModule)}" has the following exports: ${keys.join(', ')}`
2105
+ code: INVALID_EXPORT_OPTION,
2106
+ message: `"${optionValue}" was specified for "output.exports", but entry module "${relativeId(entryModule)}" has the following exports: ${printQuotedStringList(keys)}`,
2107
+ url: 'https://rollupjs.org/guide/en/#outputexports'
2067
2108
  };
2068
2109
  }
2069
2110
  function errInternalIdCannotBeExternal(source, importer) {
2070
2111
  return {
2071
- code: Errors.INVALID_EXTERNAL_ID,
2072
- message: `'${source}' is imported as an external by ${relativeId(importer)}, but is already an existing non-external module id.`
2112
+ code: INVALID_EXTERNAL_ID,
2113
+ message: `"${source}" is imported as an external by "${relativeId(importer)}", but is already an existing non-external module id.`
2073
2114
  };
2074
2115
  }
2075
2116
  function errInvalidOption(option, urlHash, explanation, value) {
2076
2117
  return {
2077
- code: Errors.INVALID_OPTION,
2118
+ code: INVALID_OPTION,
2078
2119
  message: `Invalid value ${value !== undefined ? `${JSON.stringify(value)} ` : ''}for option "${option}" - ${explanation}.`,
2079
2120
  url: `https://rollupjs.org/guide/en/#${urlHash}`
2080
2121
  };
2081
2122
  }
2123
+ function errInvalidPluginHook(hook, plugin) {
2124
+ return {
2125
+ code: INVALID_PLUGIN_HOOK,
2126
+ hook,
2127
+ message: `Error running plugin hook "${hook}" for "${plugin}", expected a function hook.`,
2128
+ plugin
2129
+ };
2130
+ }
2082
2131
  function errInvalidRollupPhaseForAddWatchFile() {
2083
2132
  return {
2084
- code: Errors.INVALID_ROLLUP_PHASE,
2085
- message: `Cannot call addWatchFile after the build has finished.`
2133
+ code: INVALID_ROLLUP_PHASE,
2134
+ message: `Cannot call "addWatchFile" after the build has finished.`
2086
2135
  };
2087
2136
  }
2088
2137
  function errInvalidRollupPhaseForChunkEmission() {
2089
2138
  return {
2090
- code: Errors.INVALID_ROLLUP_PHASE,
2139
+ code: INVALID_ROLLUP_PHASE,
2091
2140
  message: `Cannot emit chunks after module loading has finished.`
2092
2141
  };
2093
2142
  }
2143
+ function errInvalidSetAssetSourceCall() {
2144
+ return {
2145
+ code: INVALID_SETASSETSOURCE,
2146
+ message: `setAssetSource cannot be called in transform for caching reasons. Use emitFile with a source, or call setAssetSource in another hook.`
2147
+ };
2148
+ }
2094
2149
  function errInvalidFormatForTopLevelAwait(id, format) {
2095
2150
  return {
2096
- code: Errors.INVALID_TLA_FORMAT,
2151
+ code: INVALID_TLA_FORMAT,
2097
2152
  id,
2098
- message: `Module format ${format} does not support top-level await. Use the "es" or "system" output formats rather.`
2153
+ message: `Module format "${format}" does not support top-level await. Use the "es" or "system" output formats rather.`
2099
2154
  };
2100
2155
  }
2101
- function errMissingExport(exportName, importingModule, importedModule) {
2156
+ function errMissingExport(binding, importingModule, exporter) {
2102
2157
  return {
2103
- code: Errors.MISSING_EXPORT,
2104
- message: `'${exportName}' is not exported by ${relativeId(importedModule)}, imported by ${relativeId(importingModule)}`,
2158
+ binding,
2159
+ code: MISSING_EXPORT,
2160
+ exporter,
2161
+ id: importingModule,
2162
+ message: `"${binding}" is not exported by "${relativeId(exporter)}", imported by "${relativeId(importingModule)}".`,
2105
2163
  url: `https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module`
2106
2164
  };
2107
2165
  }
2166
+ function errMissingGlobalName(externalId, guess) {
2167
+ return {
2168
+ code: MISSING_GLOBAL_NAME,
2169
+ id: externalId,
2170
+ message: `No name was provided for external module "${externalId}" in "output.globals" – guessing "${guess}".`,
2171
+ names: [guess],
2172
+ url: 'https://rollupjs.org/guide/en/#outputglobals'
2173
+ };
2174
+ }
2108
2175
  function errImplicitDependantCannotBeExternal(unresolvedId, implicitlyLoadedBefore) {
2109
2176
  return {
2110
- code: Errors.MISSING_IMPLICIT_DEPENDANT,
2177
+ code: MISSING_IMPLICIT_DEPENDANT,
2111
2178
  message: `Module "${relativeId(unresolvedId)}" that should be implicitly loaded before "${relativeId(implicitlyLoadedBefore)}" cannot be external.`
2112
2179
  };
2113
2180
  }
2114
2181
  function errUnresolvedImplicitDependant(unresolvedId, implicitlyLoadedBefore) {
2115
2182
  return {
2116
- code: Errors.MISSING_IMPLICIT_DEPENDANT,
2183
+ code: MISSING_IMPLICIT_DEPENDANT,
2117
2184
  message: `Module "${relativeId(unresolvedId)}" that should be implicitly loaded before "${relativeId(implicitlyLoadedBefore)}" could not be resolved.`
2118
2185
  };
2119
2186
  }
2120
2187
  function errImplicitDependantIsNotIncluded(module) {
2121
2188
  const implicitDependencies = Array.from(module.implicitlyLoadedBefore, dependency => relativeId(dependency.id)).sort();
2122
2189
  return {
2123
- code: Errors.MISSING_IMPLICIT_DEPENDANT,
2190
+ code: MISSING_IMPLICIT_DEPENDANT,
2124
2191
  message: `Module "${relativeId(module.id)}" that should be implicitly loaded before ${printQuotedStringList(implicitDependencies)} is not included in the module graph. Either it was not imported by an included module or only via a tree-shaken dynamic import, or no imported bindings were used and it had otherwise no side-effects.`
2125
2192
  };
2126
2193
  }
2194
+ function errMissingNameOptionForIifeExport() {
2195
+ return {
2196
+ code: MISSING_NAME_OPTION_FOR_IIFE_EXPORT,
2197
+ message: `If you do not supply "output.name", you may not be able to access the exports of an IIFE bundle.`,
2198
+ url: 'https://rollupjs.org/guide/en/#outputname'
2199
+ };
2200
+ }
2201
+ function errMissingNameOptionForUmdExport() {
2202
+ return {
2203
+ code: MISSING_NAME_OPTION_FOR_IIFE_EXPORT,
2204
+ message: 'You must supply "output.name" for UMD bundles that have exports so that the exports are accessible in environments without a module loader.',
2205
+ url: 'https://rollupjs.org/guide/en/#outputname'
2206
+ };
2207
+ }
2208
+ function errMissingNodeBuiltins(externalBuiltins) {
2209
+ return {
2210
+ code: MISSING_NODE_BUILTINS,
2211
+ ids: externalBuiltins,
2212
+ message: `Creating a browser bundle that depends on Node.js built-in modules (${printQuotedStringList(externalBuiltins)}). You might need to include https://github.com/FredKSchott/rollup-plugin-polyfill-node`
2213
+ };
2214
+ }
2215
+ function errMissingFileOrDirOption() {
2216
+ return {
2217
+ code: MISSING_OPTION,
2218
+ message: 'You must specify "output.file" or "output.dir" for the build.',
2219
+ url: 'https://rollupjs.org/guide/en/#outputdir'
2220
+ };
2221
+ }
2127
2222
  function errMixedExport(facadeModuleId, name) {
2128
2223
  return {
2129
- code: Errors.MIXED_EXPORTS,
2224
+ code: MIXED_EXPORTS,
2130
2225
  id: facadeModuleId,
2131
- message: `Entry module "${relativeId(facadeModuleId)}" is using named and default exports together. Consumers of your bundle will have to use \`${name || 'chunk'}["default"]\` to access the default export, which may not be what you want. Use \`output.exports: "named"\` to disable this warning`,
2226
+ message: `Entry module "${relativeId(facadeModuleId)}" is using named and default exports together. Consumers of your bundle will have to use \`${name || 'chunk'}.default\` to access the default export, which may not be what you want. Use \`output.exports: "named"\` to disable this warning.`,
2132
2227
  url: `https://rollupjs.org/guide/en/#outputexports`
2133
2228
  };
2134
2229
  }
2135
- function errNamespaceConflict(name, reexportingModuleId, sources) {
2230
+ function errModuleLevelDirective(directive, id) {
2136
2231
  return {
2137
- code: Errors.NAMESPACE_CONFLICT,
2138
- message: `Conflicting namespaces: "${relativeId(reexportingModuleId)}" re-exports "${name}" from one of the modules ${printQuotedStringList(sources.map(moduleId => relativeId(moduleId)))} (will be ignored)`,
2139
- name,
2140
- reexporter: reexportingModuleId,
2141
- sources
2232
+ code: MODULE_LEVEL_DIRECTIVE,
2233
+ id,
2234
+ message: `Module level directives cause errors when bundled, "${directive}" in "${relativeId(id)}" was ignored.`
2142
2235
  };
2143
2236
  }
2144
- function errAmbiguousExternalNamespaces(name, reexportingModule, usedModule, sources) {
2237
+ function errNamespaceConflict(binding, reexportingModuleId, sources) {
2145
2238
  return {
2146
- code: Errors.AMBIGUOUS_EXTERNAL_NAMESPACES,
2147
- message: `Ambiguous external namespace resolution: "${relativeId(reexportingModule)}" re-exports "${name}" from one of the external modules ${printQuotedStringList(sources.map(module => relativeId(module)))}, guessing "${relativeId(usedModule)}".`,
2148
- name,
2149
- reexporter: reexportingModule,
2150
- sources
2239
+ binding,
2240
+ code: NAMESPACE_CONFLICT,
2241
+ ids: sources,
2242
+ message: `Conflicting namespaces: "${relativeId(reexportingModuleId)}" re-exports "${binding}" from one of the modules ${printQuotedStringList(sources.map(moduleId => relativeId(moduleId)))} (will be ignored).`,
2243
+ reexporter: reexportingModuleId
2151
2244
  };
2152
2245
  }
2153
2246
  function errNoTransformMapOrAstWithoutCode(pluginName) {
2154
2247
  return {
2155
- code: Errors.NO_TRANSFORM_MAP_OR_AST_WITHOUT_CODE,
2248
+ code: NO_TRANSFORM_MAP_OR_AST_WITHOUT_CODE,
2156
2249
  message: `The plugin "${pluginName}" returned a "map" or "ast" without returning ` +
2157
2250
  'a "code". This will be ignored.'
2158
2251
  };
2159
2252
  }
2253
+ function errParseError(error, moduleId) {
2254
+ let message = error.message.replace(/ \(\d+:\d+\)$/, '');
2255
+ if (moduleId.endsWith('.json')) {
2256
+ message += ' (Note that you need @rollup/plugin-json to import JSON files)';
2257
+ }
2258
+ else if (!moduleId.endsWith('.js')) {
2259
+ message += ' (Note that you need plugins to import files that are not JavaScript)';
2260
+ }
2261
+ return {
2262
+ cause: error,
2263
+ code: PARSE_ERROR,
2264
+ id: moduleId,
2265
+ message
2266
+ };
2267
+ }
2268
+ function errPluginError(error, plugin, { hook, id } = {}) {
2269
+ if (typeof error === 'string')
2270
+ error = { message: error };
2271
+ if (error.code && error.code !== PLUGIN_ERROR) {
2272
+ error.pluginCode = error.code;
2273
+ }
2274
+ error.code = PLUGIN_ERROR;
2275
+ error.plugin = plugin;
2276
+ if (hook) {
2277
+ error.hook = hook;
2278
+ }
2279
+ if (id) {
2280
+ error.id = id;
2281
+ }
2282
+ return error;
2283
+ }
2160
2284
  function errPreferNamedExports(facadeModuleId) {
2161
2285
  const file = relativeId(facadeModuleId);
2162
2286
  return {
2163
- code: Errors.PREFER_NAMED_EXPORTS,
2287
+ code: PREFER_NAMED_EXPORTS,
2164
2288
  id: facadeModuleId,
2165
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.`,
2166
2290
  url: `https://rollupjs.org/guide/en/#outputexports`
2167
2291
  };
2168
2292
  }
2169
- function errSyntheticNamedExportsNeedNamespaceExport(id, syntheticNamedExportsOption) {
2293
+ function errShimmedExport(id, binding) {
2294
+ return {
2295
+ binding,
2296
+ code: SHIMMED_EXPORT,
2297
+ exporter: id,
2298
+ message: `Missing export "${binding}" has been shimmed in module "${relativeId(id)}".`
2299
+ };
2300
+ }
2301
+ function errSourcemapBroken(plugin) {
2302
+ return {
2303
+ code: SOURCEMAP_BROKEN,
2304
+ message: `Sourcemap is likely to be incorrect: a plugin (${plugin}) was used to transform files, but didn't generate a sourcemap for the transformation. Consult the plugin documentation for help`,
2305
+ plugin,
2306
+ url: `https://rollupjs.org/guide/en/#warning-sourcemap-is-likely-to-be-incorrect`
2307
+ };
2308
+ }
2309
+ function errInvalidSourcemapForError(error, id, column, line, pos) {
2170
2310
  return {
2171
- code: Errors.SYNTHETIC_NAMED_EXPORTS_NEED_NAMESPACE_EXPORT,
2311
+ cause: error,
2312
+ code: SOURCEMAP_ERROR,
2172
2313
  id,
2173
- message: `Module "${relativeId(id)}" that is marked with 'syntheticNamedExports: ${JSON.stringify(syntheticNamedExportsOption)}' needs ${typeof syntheticNamedExportsOption === 'string' && syntheticNamedExportsOption !== 'default'
2314
+ loc: {
2315
+ column,
2316
+ file: id,
2317
+ line
2318
+ },
2319
+ message: `Error when using sourcemap for reporting an error: ${error.message}`,
2320
+ pos
2321
+ };
2322
+ }
2323
+ function errSyntheticNamedExportsNeedNamespaceExport(id, syntheticNamedExportsOption) {
2324
+ return {
2325
+ code: SYNTHETIC_NAMED_EXPORTS_NEED_NAMESPACE_EXPORT,
2326
+ exporter: id,
2327
+ message: `Module "${relativeId(id)}" that is marked with \`syntheticNamedExports: ${JSON.stringify(syntheticNamedExportsOption)}\` needs ${typeof syntheticNamedExportsOption === 'string' && syntheticNamedExportsOption !== 'default'
2174
2328
  ? `an explicit export named "${syntheticNamedExportsOption}"`
2175
2329
  : 'a default export'} that does not reexport an unresolved named export of the same module.`
2176
2330
  };
2177
2331
  }
2332
+ function errThisIsUndefined() {
2333
+ return {
2334
+ code: THIS_IS_UNDEFINED,
2335
+ message: `The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten`,
2336
+ url: `https://rollupjs.org/guide/en/#error-this-is-undefined`
2337
+ };
2338
+ }
2178
2339
  function errUnexpectedNamedImport(id, imported, isReexport) {
2179
2340
  const importType = isReexport ? 'reexport' : 'import';
2180
2341
  return {
2181
- code: Errors.UNEXPECTED_NAMED_IMPORT,
2182
- id,
2183
- message: `The named export "${imported}" was ${importType}ed from the external module ${relativeId(id)} even though its interop type is "defaultOnly". Either remove or change this ${importType} or change the value of the "output.interop" option.`,
2342
+ code: UNEXPECTED_NAMED_IMPORT,
2343
+ exporter: id,
2344
+ message: `The named export "${imported}" was ${importType}ed from the external module "${relativeId(id)}" even though its interop type is "defaultOnly". Either remove or change this ${importType} or change the value of the "output.interop" option.`,
2184
2345
  url: 'https://rollupjs.org/guide/en/#outputinterop'
2185
2346
  };
2186
2347
  }
2187
2348
  function errUnexpectedNamespaceReexport(id) {
2188
2349
  return {
2189
- code: Errors.UNEXPECTED_NAMED_IMPORT,
2190
- id,
2191
- message: `There was a namespace "*" reexport from the external module ${relativeId(id)} even though its interop type is "defaultOnly". This will be ignored as namespace reexports only reexport named exports. If this is not intended, either remove or change this reexport or change the value of the "output.interop" option.`,
2350
+ code: UNEXPECTED_NAMED_IMPORT,
2351
+ exporter: id,
2352
+ message: `There was a namespace "*" reexport from the external module "${relativeId(id)}" even though its interop type is "defaultOnly". This will be ignored as namespace reexports only reexport named exports. If this is not intended, either remove or change this reexport or change the value of the "output.interop" option.`,
2192
2353
  url: 'https://rollupjs.org/guide/en/#outputinterop'
2193
2354
  };
2194
2355
  }
2356
+ function errUnknownOption(optionType, unknownOptions, validOptions) {
2357
+ return {
2358
+ code: UNKNOWN_OPTION,
2359
+ message: `Unknown ${optionType}: ${unknownOptions.join(', ')}. Allowed options: ${validOptions.join(', ')}`
2360
+ };
2361
+ }
2195
2362
  function errEntryCannotBeExternal(unresolvedId) {
2196
2363
  return {
2197
- code: Errors.UNRESOLVED_ENTRY,
2198
- message: `Entry module cannot be external (${relativeId(unresolvedId)}).`
2364
+ code: UNRESOLVED_ENTRY,
2365
+ message: `Entry module "${relativeId(unresolvedId)}" cannot be external.`
2199
2366
  };
2200
2367
  }
2201
2368
  function errUnresolvedEntry(unresolvedId) {
2202
2369
  return {
2203
- code: Errors.UNRESOLVED_ENTRY,
2204
- message: `Could not resolve entry module (${relativeId(unresolvedId)}).`
2370
+ code: UNRESOLVED_ENTRY,
2371
+ message: `Could not resolve entry module "${relativeId(unresolvedId)}".`
2205
2372
  };
2206
2373
  }
2207
2374
  function errUnresolvedImport(source, importer) {
2208
2375
  return {
2209
- code: Errors.UNRESOLVED_IMPORT,
2210
- message: `Could not resolve '${source}' from ${relativeId(importer)}`
2376
+ code: UNRESOLVED_IMPORT,
2377
+ exporter: source,
2378
+ id: importer,
2379
+ message: `Could not resolve "${source}" from "${relativeId(importer)}"`
2211
2380
  };
2212
2381
  }
2213
2382
  function errUnresolvedImportTreatedAsExternal(source, importer) {
2214
2383
  return {
2215
- code: Errors.UNRESOLVED_IMPORT,
2216
- importer: relativeId(importer),
2217
- message: `'${source}' is imported by ${relativeId(importer)}, but could not be resolved – treating it as an external dependency`,
2218
- source,
2384
+ code: UNRESOLVED_IMPORT,
2385
+ exporter: source,
2386
+ id: importer,
2387
+ message: `"${source}" is imported by "${relativeId(importer)}", but could not be resolved – treating it as an external dependency.`,
2219
2388
  url: 'https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency'
2220
2389
  };
2221
2390
  }
2222
- function errExternalSyntheticExports(source, importer) {
2391
+ function errUnusedExternalImports(externalId, names, importers) {
2223
2392
  return {
2224
- code: Errors.EXTERNAL_SYNTHETIC_EXPORTS,
2225
- importer: relativeId(importer),
2226
- message: `External '${source}' can not have 'syntheticNamedExports' enabled.`,
2227
- source
2393
+ code: UNUSED_EXTERNAL_IMPORT,
2394
+ exporter: externalId,
2395
+ ids: importers,
2396
+ message: `${printQuotedStringList(names, [
2397
+ 'is',
2398
+ 'are'
2399
+ ])} imported from external module "${externalId}" but never used in ${printQuotedStringList(importers.map(importer => relativeId(importer)))}.`,
2400
+ names
2228
2401
  };
2229
2402
  }
2230
2403
  function errFailedValidation(message) {
2231
2404
  return {
2232
- code: Errors.VALIDATION_ERROR,
2405
+ code: VALIDATION_ERROR,
2233
2406
  message
2234
2407
  };
2235
2408
  }
2236
- function errAlreadyClosed() {
2237
- return {
2238
- code: Errors.ALREADY_CLOSED,
2239
- message: 'Bundle is already closed, no more calls to "generate" or "write" are allowed.'
2240
- };
2241
- }
2242
2409
  function warnDeprecation(deprecation, activeDeprecation, options) {
2243
2410
  warnDeprecationWithOptions(deprecation, activeDeprecation, options.onwarn, options.strictDeprecations);
2244
2411
  }
@@ -2400,13 +2567,7 @@ class ExternalModule {
2400
2567
  }
2401
2568
  }
2402
2569
  const importersArray = [...importersSet];
2403
- this.options.onwarn({
2404
- code: 'UNUSED_EXTERNAL_IMPORT',
2405
- message: `${printQuotedStringList(unused, ['is', 'are'])} imported from external module "${this.id}" but never used in ${printQuotedStringList(importersArray.map(importer => relativeId(importer)))}.`,
2406
- names: unused,
2407
- source: this.id,
2408
- sources: importersArray
2409
- });
2570
+ this.options.onwarn(errUnusedExternalImports(this.id, unused, importersArray));
2410
2571
  }
2411
2572
  }
2412
2573
 
@@ -7603,10 +7764,7 @@ class Identifier extends NodeBase {
7603
7764
  }
7604
7765
  }
7605
7766
  disallowImportReassignment() {
7606
- return this.context.error({
7607
- code: 'ILLEGAL_REASSIGNMENT',
7608
- message: `Illegal reassignment to import '${this.name}'`
7609
- }, this.start);
7767
+ return this.context.error(errIllegalImportReassignment(this.name, this.context.module.id), this.start);
7610
7768
  }
7611
7769
  getVariableRespectingTDZ() {
7612
7770
  if (this.isPossibleTDZ()) {
@@ -7802,10 +7960,7 @@ class ExpressionStatement extends NodeBase {
7802
7960
  this.parent.type === Program$1) {
7803
7961
  this.context.warn(
7804
7962
  // This is necessary, because either way (deleting or not) can lead to errors.
7805
- {
7806
- code: 'MODULE_LEVEL_DIRECTIVE',
7807
- message: `Module level directives cause errors when bundled, '${this.directive}' was ignored.`
7808
- }, this.start);
7963
+ errModuleLevelDirective(this.directive, this.context.module.id), this.start);
7809
7964
  }
7810
7965
  }
7811
7966
  render(code, options) {
@@ -8819,10 +8974,7 @@ class MemberExpression extends NodeBase {
8819
8974
  if (this.variable) {
8820
8975
  this.context.includeVariableInModule(this.variable);
8821
8976
  }
8822
- this.context.warn({
8823
- code: 'ILLEGAL_NAMESPACE_REASSIGNMENT',
8824
- message: `Illegal reassignment to import '${this.object.name}'`
8825
- }, this.start);
8977
+ this.context.warn(errIllegalImportReassignment(this.object.name, this.context.module.id), this.start);
8826
8978
  }
8827
8979
  }
8828
8980
  }
@@ -8862,14 +9014,7 @@ function resolveNamespaceVariables(baseVariable, path, astContext) {
8862
9014
  const variable = baseVariable.context.traceExport(exportName);
8863
9015
  if (!variable) {
8864
9016
  const fileName = baseVariable.context.fileName;
8865
- astContext.warn({
8866
- code: 'MISSING_EXPORT',
8867
- exporter: relativeId(fileName),
8868
- importer: relativeId(astContext.fileName),
8869
- message: `'${exportName}' is not exported by '${relativeId(fileName)}'`,
8870
- missing: exportName,
8871
- url: `https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module`
8872
- }, path[0].pos);
9017
+ astContext.warn(errMissingExport(exportName, astContext.module.id, fileName), path[0].pos);
8873
9018
  return 'undefined';
8874
9019
  }
8875
9020
  return resolveNamespaceVariables(variable, path.slice(1), astContext);
@@ -8959,17 +9104,10 @@ class CallExpression extends CallExpressionBase {
8959
9104
  if (this.callee instanceof Identifier) {
8960
9105
  const variable = this.scope.findVariable(this.callee.name);
8961
9106
  if (variable.isNamespace) {
8962
- this.context.warn({
8963
- code: 'CANNOT_CALL_NAMESPACE',
8964
- message: `Cannot call a namespace ('${this.callee.name}')`
8965
- }, this.start);
9107
+ this.context.warn(errCannotCallNamespace(this.callee.name), this.start);
8966
9108
  }
8967
9109
  if (this.callee.name === 'eval') {
8968
- this.context.warn({
8969
- code: 'EVAL',
8970
- message: `Use of eval is strongly discouraged, as it poses security risks and may cause issues with minification`,
8971
- url: 'https://rollupjs.org/guide/en/#avoiding-eval'
8972
- }, this.start);
9110
+ this.context.warn(errEval(this.context.module.id), this.start);
8973
9111
  }
8974
9112
  }
8975
9113
  this.interaction = {
@@ -10303,6 +10441,7 @@ class ImportExpression extends NodeBase {
10303
10441
  }
10304
10442
  setExternalResolution(exportMode, resolution, options, snippets, pluginDriver, accessedGlobalsByScope, resolutionString, namespaceExportName) {
10305
10443
  const { format } = options;
10444
+ this.inlineNamespace = null;
10306
10445
  this.resolution = resolution;
10307
10446
  this.resolutionString = resolutionString;
10308
10447
  this.namespaceExportName = namespaceExportName;
@@ -11213,10 +11352,7 @@ class TaggedTemplateExpression extends CallExpressionBase {
11213
11352
  const name = this.tag.name;
11214
11353
  const variable = this.scope.findVariable(name);
11215
11354
  if (variable.isNamespace) {
11216
- this.context.warn({
11217
- code: 'CANNOT_CALL_NAMESPACE',
11218
- message: `Cannot call a namespace ('${name}')`
11219
- }, this.start);
11355
+ this.context.warn(errCannotCallNamespace(name), this.start);
11220
11356
  }
11221
11357
  }
11222
11358
  }
@@ -11466,11 +11602,7 @@ class ThisExpression extends NodeBase {
11466
11602
  this.alias =
11467
11603
  this.scope.findLexicalBoundary() instanceof ModuleScope ? this.context.moduleContext : null;
11468
11604
  if (this.alias === 'undefined') {
11469
- this.context.warn({
11470
- code: 'THIS_IS_UNDEFINED',
11471
- message: `The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten`,
11472
- url: `https://rollupjs.org/guide/en/#error-this-is-undefined`
11473
- }, this.start);
11605
+ this.context.warn(errThisIsUndefined(), this.start);
11474
11606
  }
11475
11607
  }
11476
11608
  render(code) {
@@ -12805,18 +12937,7 @@ class Module {
12805
12937
  return this.graph.contextParse(this.info.code);
12806
12938
  }
12807
12939
  catch (err) {
12808
- let message = err.message.replace(/ \(\d+:\d+\)$/, '');
12809
- if (this.id.endsWith('.json')) {
12810
- message += ' (Note that you need @rollup/plugin-json to import JSON files)';
12811
- }
12812
- else if (!this.id.endsWith('.js')) {
12813
- message += ' (Note that you need plugins to import files that are not JavaScript)';
12814
- }
12815
- return this.error({
12816
- code: 'PARSE_ERROR',
12817
- message,
12818
- parserError: err
12819
- }, err.pos);
12940
+ return this.error(errParseError(err, this.id), err.pos);
12820
12941
  }
12821
12942
  }
12822
12943
  updateOptions({ meta, moduleSideEffects, syntheticNamedExports }) {
@@ -12942,17 +13063,7 @@ class Module {
12942
13063
  code = this.originalCode;
12943
13064
  }
12944
13065
  catch (err) {
12945
- this.options.onwarn({
12946
- code: 'SOURCEMAP_ERROR',
12947
- id: this.id,
12948
- loc: {
12949
- column,
12950
- file: this.id,
12951
- line
12952
- },
12953
- message: `Error when using sourcemap for reporting an error: ${err.message}`,
12954
- pos
12955
- });
13066
+ this.options.onwarn(errInvalidSourcemapForError(err, this.id, column, line, pos));
12956
13067
  }
12957
13068
  augmentCodeLocation(props, { column, line }, code, this.id);
12958
13069
  }
@@ -13090,12 +13201,7 @@ class Module {
13090
13201
  }
13091
13202
  }
13092
13203
  shimMissingExport(name) {
13093
- this.options.onwarn({
13094
- code: 'SHIMMED_EXPORT',
13095
- exporter: relativeId(this.id),
13096
- exportName: name,
13097
- message: `Missing export "${name}" has been shimmed in module ${relativeId(this.id)}.`
13098
- });
13204
+ this.options.onwarn(errShimmedExport(this.id, name));
13099
13205
  this.exports.set(name, MISSING_EXPORT_SHIM_DESCRIPTION);
13100
13206
  }
13101
13207
  }
@@ -13360,11 +13466,7 @@ function warnOnBuiltins(warn, dependencies) {
13360
13466
  .filter(importPath => importPath in builtins);
13361
13467
  if (!externalBuiltins.length)
13362
13468
  return;
13363
- warn({
13364
- code: 'MISSING_NODE_BUILTINS',
13365
- message: `Creating a browser bundle that depends on Node.js built-in modules (${printQuotedStringList(externalBuiltins)}). You might need to include https://github.com/FredKSchott/rollup-plugin-polyfill-node`,
13366
- modules: externalBuiltins
13367
- });
13469
+ warn(errMissingNodeBuiltins(externalBuiltins));
13368
13470
  }
13369
13471
 
13370
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 }) {
@@ -13602,24 +13704,18 @@ function trimEmptyImports(dependencies) {
13602
13704
  }
13603
13705
 
13604
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 }) {
13605
- const { _, cnst, getNonArrowFunctionIntro, getPropertyAccess, n } = snippets;
13707
+ const { _, getNonArrowFunctionIntro, getPropertyAccess, n } = snippets;
13606
13708
  const isNamespaced = name && name.includes('.');
13607
13709
  const useVariableAssignment = !extend && !isNamespaced;
13608
13710
  if (name && useVariableAssignment && !isLegal(name)) {
13609
- return error({
13610
- code: 'ILLEGAL_IDENTIFIER_AS_NAME',
13611
- message: `Given name "${name}" is not a legal JS identifier. If you need this, you can try "output.extend: true".`
13612
- });
13711
+ return error(errIllegalIdentifierAsName(name));
13613
13712
  }
13614
13713
  warnOnBuiltins(onwarn, dependencies);
13615
13714
  const external = trimEmptyImports(dependencies);
13616
13715
  const deps = external.map(dep => dep.globalName || 'null');
13617
13716
  const args = external.map(m => m.name);
13618
13717
  if (hasExports && !name) {
13619
- onwarn({
13620
- code: 'MISSING_NAME_OPTION_FOR_IIFE_EXPORT',
13621
- message: `If you do not supply "output.name", you may not be able to access the exports of an IIFE bundle.`
13622
- });
13718
+ onwarn(errMissingNameOptionForIifeExport());
13623
13719
  }
13624
13720
  if (namedExportsMode && hasExports) {
13625
13721
  if (extend) {
@@ -13641,7 +13737,7 @@ function iife(magicString, { accessedGlobals, dependencies, exports, hasExports,
13641
13737
  if (hasExports) {
13642
13738
  if (name && !(extend && namedExportsMode)) {
13643
13739
  wrapperIntro =
13644
- (useVariableAssignment ? `${cnst} ${name}` : `this${keypath(name, getPropertyAccess)}`) +
13740
+ (useVariableAssignment ? `var ${name}` : `this${keypath(name, getPropertyAccess)}`) +
13645
13741
  `${_}=${_}${wrapperIntro}`;
13646
13742
  }
13647
13743
  if (isNamespaced) {
@@ -13813,10 +13909,7 @@ function umd(magicString, { accessedGlobals, dependencies, exports, hasExports,
13813
13909
  const factoryVar = compact ? 'f' : 'factory';
13814
13910
  const globalVar = compact ? 'g' : 'global';
13815
13911
  if (hasExports && !name) {
13816
- return error({
13817
- code: 'MISSING_NAME_OPTION_FOR_IIFE_EXPORT',
13818
- message: 'You must supply "output.name" for UMD bundles that have exports so that the exports are accessible in environments without a module loader.'
13819
- });
13912
+ return error(errMissingNameOptionForUmdExport());
13820
13913
  }
13821
13914
  warnOnBuiltins(onwarn, dependencies);
13822
13915
  const amdDeps = dependencies.map(m => `'${removeExtensionFromRelativeAmdId(m.importPath)}'`);
@@ -14477,12 +14570,7 @@ function getGlobalName(chunk, globals, hasExports, warn) {
14477
14570
  return globalName;
14478
14571
  }
14479
14572
  if (hasExports) {
14480
- warn({
14481
- code: 'MISSING_GLOBAL_NAME',
14482
- guess: chunk.variableName,
14483
- message: `No name was provided for external module '${chunk.id}' in output.globals – guessing '${chunk.variableName}'`,
14484
- source: chunk.id
14485
- });
14573
+ warn(errMissingGlobalName(chunk.id, chunk.variableName));
14486
14574
  return chunk.variableName;
14487
14575
  }
14488
14576
  }
@@ -15280,12 +15368,7 @@ class Chunk {
15280
15368
  }
15281
15369
  const renderedSource = compact ? magicString : magicString.trim();
15282
15370
  if (isEmpty && this.getExportNames().length === 0 && dependencies.size === 0) {
15283
- const chunkName = this.getChunkName();
15284
- onwarn({
15285
- chunkName,
15286
- code: 'EMPTY_BUNDLE',
15287
- message: `Generated an empty chunk: "${chunkName}"`
15288
- });
15371
+ onwarn(errEmptyChunk(this.getChunkName()));
15289
15372
  }
15290
15373
  return { accessedGlobals, indent, magicString, renderedSource, usedModules, usesTopLevelAwait };
15291
15374
  }
@@ -15647,12 +15730,12 @@ function analyseModuleExecution(entryModules) {
15647
15730
  }
15648
15731
  function getCyclePath(module, parent, parents) {
15649
15732
  const cycleSymbol = Symbol(module.id);
15650
- const path = [relativeId(module.id)];
15733
+ const path = [module.id];
15651
15734
  let nextModule = parent;
15652
15735
  module.cycles.add(cycleSymbol);
15653
15736
  while (nextModule !== module) {
15654
15737
  nextModule.cycles.add(cycleSymbol);
15655
- path.push(relativeId(nextModule.id));
15738
+ path.push(nextModule.id);
15656
15739
  nextModule = parents.get(nextModule);
15657
15740
  }
15658
15741
  path.push(path[0]);
@@ -15824,14 +15907,7 @@ function getLinkMap(warn) {
15824
15907
  if (map.mappings) {
15825
15908
  return new Link(map, [source]);
15826
15909
  }
15827
- warn({
15828
- code: 'SOURCEMAP_BROKEN',
15829
- message: `Sourcemap is likely to be incorrect: a plugin (${map.plugin}) was used to transform ` +
15830
- "files, but didn't generate a sourcemap for the transformation. Consult the plugin " +
15831
- 'documentation for help',
15832
- plugin: map.plugin,
15833
- url: `https://rollupjs.org/guide/en/#warning-sourcemap-is-likely-to-be-incorrect`
15834
- });
15910
+ warn(errSourcemapBroken(map.plugin));
15835
15911
  return new Link({
15836
15912
  mappings: [],
15837
15913
  names: []
@@ -21846,22 +21922,6 @@ async function findFile(file, preserveSymlinks) {
21846
21922
 
21847
21923
  const ANONYMOUS_PLUGIN_PREFIX = 'at position ';
21848
21924
  const ANONYMOUS_OUTPUT_PLUGIN_PREFIX = 'at output position ';
21849
- function throwPluginError(err, plugin, { hook, id } = {}) {
21850
- if (typeof err === 'string')
21851
- err = { message: err };
21852
- if (err.code && err.code !== Errors.PLUGIN_ERROR) {
21853
- err.pluginCode = err.code;
21854
- }
21855
- err.code = Errors.PLUGIN_ERROR;
21856
- err.plugin = plugin;
21857
- if (hook) {
21858
- err.hook = hook;
21859
- }
21860
- if (id) {
21861
- err.id = id;
21862
- }
21863
- return error(err);
21864
- }
21865
21925
 
21866
21926
  function createPluginCache(cache) {
21867
21927
  return {
@@ -21922,15 +21982,9 @@ const NO_CACHE = {
21922
21982
  function uncacheablePluginError(pluginName) {
21923
21983
  if (pluginName.startsWith(ANONYMOUS_PLUGIN_PREFIX) ||
21924
21984
  pluginName.startsWith(ANONYMOUS_OUTPUT_PLUGIN_PREFIX)) {
21925
- return error({
21926
- code: 'ANONYMOUS_PLUGIN_CACHE',
21927
- message: 'A plugin is trying to use the Rollup cache but is not declaring a plugin name or cacheKey.'
21928
- });
21985
+ return error(errAnonymousPluginCache());
21929
21986
  }
21930
- return error({
21931
- code: 'DUPLICATE_PLUGIN_NAME',
21932
- message: `The plugin name ${pluginName} is being used twice in the same build. Plugin names must be distinct or provide a cacheKey (please post an issue to the plugin if you are a plugin user).`
21933
- });
21987
+ return error(errDuplicatePluginName(pluginName));
21934
21988
  }
21935
21989
  function getCacheForUncacheablePlugin(pluginName) {
21936
21990
  return {
@@ -22033,10 +22087,7 @@ async function transform(source, module, pluginDriver, warn) {
22033
22087
  });
22034
22088
  },
22035
22089
  setAssetSource() {
22036
- return this.error({
22037
- code: 'INVALID_SETASSETSOURCE',
22038
- message: `setAssetSource cannot be called in transform for caching reasons. Use emitFile with a source, or call setAssetSource in another hook.`
22039
- });
22090
+ return this.error(errInvalidSetAssetSourceCall());
22040
22091
  },
22041
22092
  warn(warning, pos) {
22042
22093
  if (typeof warning === 'string')
@@ -22051,7 +22102,7 @@ async function transform(source, module, pluginDriver, warn) {
22051
22102
  });
22052
22103
  }
22053
22104
  catch (err) {
22054
- throwPluginError(err, pluginName, { hook: 'transform', id });
22105
+ return error(errPluginError(err, pluginName, { hook: 'transform', id }));
22055
22106
  }
22056
22107
  if (!customTransformCache) {
22057
22108
  // files emitted by a transform hook need to be emitted again if the hook is skipped
@@ -22541,7 +22592,7 @@ function getPluginContext(plugin, pluginCache, graph, options, fileEmitter, exis
22541
22592
  cache: cacheInstance,
22542
22593
  emitFile: fileEmitter.emitFile.bind(fileEmitter),
22543
22594
  error(err) {
22544
- return throwPluginError(err, plugin.name);
22595
+ return error(errPluginError(err, plugin.name));
22545
22596
  },
22546
22597
  getFileName: fileEmitter.getFileName,
22547
22598
  getModuleIds: () => graph.modulesById.keys(),
@@ -22599,12 +22650,6 @@ const inputHookNames = {
22599
22650
  watchChange: 1
22600
22651
  };
22601
22652
  const inputHooks = Object.keys(inputHookNames);
22602
- function throwInvalidHookError(hookName, pluginName) {
22603
- return error({
22604
- code: 'INVALID_PLUGIN_HOOK',
22605
- message: `Error running plugin hook ${hookName} for ${pluginName}, expected a function hook.`
22606
- });
22607
- }
22608
22653
  class PluginDriver {
22609
22654
  constructor(graph, options, userPlugins, pluginCache, basePluginDriver) {
22610
22655
  this.graph = graph;
@@ -22741,7 +22786,7 @@ class PluginDriver {
22741
22786
  if (typeof hook !== 'function') {
22742
22787
  if (permitValues)
22743
22788
  return hook;
22744
- return throwInvalidHookError(hookName, plugin.name);
22789
+ return error(errInvalidPluginHook(hookName, plugin.name));
22745
22790
  }
22746
22791
  // eslint-disable-next-line @typescript-eslint/ban-types
22747
22792
  const hookResult = hook.apply(context, args);
@@ -22770,7 +22815,7 @@ class PluginDriver {
22770
22815
  // action considered to be fulfilled since error being handled
22771
22816
  this.unfulfilledActions.delete(action);
22772
22817
  }
22773
- return throwPluginError(err, plugin.name, { hook: hookName });
22818
+ return error(errPluginError(err, plugin.name, { hook: hookName }));
22774
22819
  });
22775
22820
  }
22776
22821
  /**
@@ -22791,13 +22836,13 @@ class PluginDriver {
22791
22836
  try {
22792
22837
  // permit values allows values to be returned instead of a functional hook
22793
22838
  if (typeof hook !== 'function') {
22794
- return throwInvalidHookError(hookName, plugin.name);
22839
+ return error(errInvalidPluginHook(hookName, plugin.name));
22795
22840
  }
22796
22841
  // eslint-disable-next-line @typescript-eslint/ban-types
22797
22842
  return hook.apply(context, args);
22798
22843
  }
22799
22844
  catch (err) {
22800
- return throwPluginError(err, plugin.name, { hook: hookName });
22845
+ return error(errPluginError(err, plugin.name, { hook: hookName }));
22801
22846
  }
22802
22847
  }
22803
22848
  }
@@ -23017,12 +23062,7 @@ class Graph {
23017
23062
  sortModules() {
23018
23063
  const { orderedModules, cyclePaths } = analyseModuleExecution(this.entryModules);
23019
23064
  for (const cyclePath of cyclePaths) {
23020
- this.options.onwarn({
23021
- code: 'CIRCULAR_DEPENDENCY',
23022
- cycle: cyclePath,
23023
- importer: cyclePath[0],
23024
- message: `Circular dependency: ${cyclePath.join(' -> ')}`
23025
- });
23065
+ this.options.onwarn(errCircularDependency(cyclePath));
23026
23066
  }
23027
23067
  this.modules = orderedModules;
23028
23068
  for (const module of this.modules) {
@@ -23035,12 +23075,7 @@ class Graph {
23035
23075
  for (const importDescription of module.importDescriptions.values()) {
23036
23076
  if (importDescription.name !== '*' &&
23037
23077
  !importDescription.module.getVariableForExportName(importDescription.name)[0]) {
23038
- module.warn({
23039
- code: 'NON_EXISTENT_EXPORT',
23040
- message: `Non-existent export '${importDescription.name}' is imported from ${relativeId(importDescription.module.id)}`,
23041
- name: importDescription.name,
23042
- source: importDescription.module.id
23043
- }, importDescription.start);
23078
+ module.warn(errMissingExport(importDescription.name, module.id, importDescription.module.id), importDescription.start);
23044
23079
  }
23045
23080
  }
23046
23081
  }
@@ -23100,14 +23135,7 @@ function warnUnknownOptions(passedOptions, validOptions, optionType, warn, ignor
23100
23135
  const validOptionSet = new Set(validOptions);
23101
23136
  const unknownOptions = Object.keys(passedOptions).filter(key => !(validOptionSet.has(key) || ignoredKeys.test(key)));
23102
23137
  if (unknownOptions.length > 0) {
23103
- warn({
23104
- code: 'UNKNOWN_OPTION',
23105
- message: `Unknown ${optionType}: ${unknownOptions.join(', ')}. Allowed options: ${[
23106
- ...validOptionSet
23107
- ]
23108
- .sort()
23109
- .join(', ')}`
23110
- });
23138
+ warn(errUnknownOption(optionType, unknownOptions, [...validOptionSet].sort()));
23111
23139
  }
23112
23140
  }
23113
23141
  const treeshakePresets = {
@@ -23754,10 +23782,7 @@ function handleGenerateWrite(isWrite, inputOptions, unsetInputOptions, rawOutput
23754
23782
  if (isWrite) {
23755
23783
  timeStart('WRITE', 1);
23756
23784
  if (!outputOptions.dir && !outputOptions.file) {
23757
- return error({
23758
- code: 'MISSING_OPTION',
23759
- message: 'You must specify "output.file" or "output.dir" for the build.'
23760
- });
23785
+ return error(errMissingFileOrDirOption());
23761
23786
  }
23762
23787
  await Promise.all(Object.values(generated).map(chunk => graph.fileOperationQueue.run(() => writeOutputFile(chunk, outputOptions))));
23763
23788
  await outputPluginDriver.hookParallel('writeBundle', [outputOptions, generated]);