rollup-plugin-babel.esm.js.map
13 KB
{"version":3,"file":"rollup-plugin-babel.esm.js","sources":["../src/constants.js","../src/utils.js","../src/preflightCheck.js","../src/helperPlugin.js","../src/index.js"],"sourcesContent":["export const INLINE = {};\nexport const RUNTIME = {};\nexport const EXTERNAL = {};\n\n// NOTE: DO NOT REMOVE the null character `\\0` as it may be used by other plugins\n// e.g. https://github.com/rollup/rollup-plugin-node-resolve/blob/313a3e32f432f9eb18cc4c231cc7aac6df317a51/src/index.js#L74\nexport const HELPERS = '\\0rollupPluginBabelHelpers.js';\n","export const addBabelPlugin = (options, plugin) => ({ ...options, plugins: options.plugins.concat(plugin) });\n\nlet warned = {};\nexport function warnOnce(ctx, msg) {\n\tif (warned[msg]) return;\n\twarned[msg] = true;\n\tctx.warn(msg);\n}\n\nconst regExpCharactersRegExp = /[\\\\^$.*+?()[\\]{}|]/g;\nexport const escapeRegExpCharacters = str => str.replace(regExpCharactersRegExp, '\\\\$&');\n","import { transformSync } from '@babel/core';\nimport { INLINE, RUNTIME, EXTERNAL } from './constants.js';\nimport { addBabelPlugin } from './utils.js';\n\nconst MODULE_ERROR =\n\t'Rollup requires that your Babel configuration keeps ES6 module syntax intact. ' +\n\t'Unfortunately it looks like your configuration specifies a module transformer ' +\n\t'to replace ES6 modules with another module format. To continue you have to disable it.' +\n\t'\\n\\n' +\n\t\"Most commonly it's a CommonJS transform added by @babel/preset-env - \" +\n\t'in such case you should disable it by adding `modules: false` option to that preset ' +\n\t'(described in more detail here - https://github.com/rollup/rollup-plugin-babel#modules ).';\n\nconst UNEXPECTED_ERROR =\n\t'An unexpected situation arose. Please raise an issue at ' +\n\t'https://github.com/rollup/rollup-plugin-babel/issues. Thanks!';\n\nfunction fallbackClassTransform() {\n\treturn {\n\t\tvisitor: {\n\t\t\tClassDeclaration(path, state) {\n\t\t\t\tpath.replaceWith(state.file.addHelper('inherits'));\n\t\t\t},\n\t\t},\n\t};\n}\n\nexport default function createPreflightCheck() {\n\tlet preflightCheckResults = {};\n\n\treturn (ctx, options) => {\n\t\tconst key = options.filename;\n\n\t\tif (preflightCheckResults[key] === undefined) {\n\t\t\tlet helpers;\n\n\t\t\tconst inputCode = 'class Foo extends Bar {};\\nexport default Foo;';\n\t\t\tconst transformed = transformSync(inputCode, options);\n\n\t\t\tlet check = transformed.code;\n\n\t\t\tif (~check.indexOf('class ')) {\n\t\t\t\tcheck = transformSync(inputCode, addBabelPlugin(options, fallbackClassTransform)).code;\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\t!~check.indexOf('export default') &&\n\t\t\t\t!~check.indexOf('export default Foo') &&\n\t\t\t\t!~check.indexOf('export { Foo as default }')\n\t\t\t) {\n\t\t\t\tctx.error(MODULE_ERROR);\n\t\t\t}\n\n\t\t\tif (check.match(/\\/helpers\\/(esm\\/)?inherits/)) helpers = RUNTIME;\n\t\t\telse if (~check.indexOf('function _inherits')) helpers = INLINE;\n\t\t\telse if (~check.indexOf('babelHelpers')) helpers = EXTERNAL;\n\t\t\telse {\n\t\t\t\tctx.error(UNEXPECTED_ERROR);\n\t\t\t}\n\n\t\t\tpreflightCheckResults[key] = helpers;\n\t\t}\n\n\t\treturn preflightCheckResults[key];\n\t};\n}\n","import { HELPERS } from './constants.js';\nimport { addNamed } from '@babel/helper-module-imports';\n\nexport default function importHelperPlugin() {\n\treturn {\n\t\tpre(file) {\n\t\t\tconst cachedHelpers = {};\n\t\t\tfile.set('helperGenerator', name => {\n\t\t\t\tif (!file.availableHelper(name)) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif (cachedHelpers[name]) {\n\t\t\t\t\treturn cachedHelpers[name];\n\t\t\t\t}\n\n\t\t\t\treturn (cachedHelpers[name] = addNamed(file.path, name, HELPERS));\n\t\t\t});\n\t\t},\n\t};\n}\n","import * as babel from '@babel/core';\nimport { createFilter } from 'rollup-pluginutils';\nimport createPreflightCheck from './preflightCheck.js';\nimport helperPlugin from './helperPlugin.js';\nimport { addBabelPlugin, escapeRegExpCharacters, warnOnce } from './utils.js';\nimport { RUNTIME, EXTERNAL, HELPERS } from './constants.js';\n\nconst unpackOptions = ({\n\textensions = babel.DEFAULT_EXTENSIONS,\n\t// rollup uses sourcemap, babel uses sourceMaps\n\t// just normalize them here so people don't have to worry about it\n\tsourcemap = true,\n\tsourcemaps = true,\n\tsourceMap = true,\n\tsourceMaps = true,\n\t...rest\n} = {}) => ({\n\textensions,\n\tplugins: [],\n\tsourceMaps: sourcemap && sourcemaps && sourceMap && sourceMaps,\n\t...rest,\n\tcaller: {\n\t\tname: 'rollup-plugin-babel',\n\t\tsupportsStaticESM: true,\n\t\tsupportsDynamicImport: true,\n\t\t...rest.caller,\n\t},\n});\n\nconst returnObject = () => ({});\n\nfunction createBabelPluginFactory(customCallback = returnObject) {\n\tconst overrides = customCallback(babel);\n\n\treturn pluginOptions => {\n\t\tlet customOptions = null;\n\n\t\tif (overrides.options) {\n\t\t\tconst overridden = overrides.options(pluginOptions);\n\n\t\t\tif (typeof overridden.then === 'function') {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\".options hook can't be asynchronous. It should return `{ customOptions, pluginsOptions }` synchronously.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\t({ customOptions = null, pluginOptions } = overridden);\n\t\t}\n\n\t\tconst {\n\t\t\texclude,\n\t\t\textensions,\n\t\t\texternalHelpers,\n\t\t\texternalHelpersWhitelist,\n\t\t\tinclude,\n\t\t\truntimeHelpers,\n\t\t\t...babelOptions\n\t\t} = unpackOptions(pluginOptions);\n\n\t\tconst extensionRegExp = new RegExp(`(${extensions.map(escapeRegExpCharacters).join('|')})$`);\n\t\tconst includeExcludeFilter = createFilter(include, exclude);\n\t\tconst filter = id => extensionRegExp.test(id) && includeExcludeFilter(id);\n\t\tconst preflightCheck = createPreflightCheck();\n\n\t\treturn {\n\t\t\tname: 'babel',\n\t\t\tresolveId(id) {\n\t\t\t\tif (id === HELPERS) return id;\n\t\t\t},\n\t\t\tload(id) {\n\t\t\t\tif (id !== HELPERS) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\treturn babel.buildExternalHelpers(externalHelpersWhitelist, 'module');\n\t\t\t},\n\t\t\ttransform(code, filename) {\n\t\t\t\tif (!filter(filename)) return Promise.resolve(null);\n\t\t\t\tif (filename === HELPERS) return Promise.resolve(null);\n\n\t\t\t\tconst config = babel.loadPartialConfig({ ...babelOptions, filename });\n\n\t\t\t\t// file is ignored\n\t\t\t\tif (!config) {\n\t\t\t\t\treturn Promise.resolve(null);\n\t\t\t\t}\n\n\t\t\t\treturn Promise.resolve(\n\t\t\t\t\t!overrides.config\n\t\t\t\t\t\t? config.options\n\t\t\t\t\t\t: overrides.config.call(this, config, {\n\t\t\t\t\t\t\t\tcode,\n\t\t\t\t\t\t\t\tcustomOptions,\n\t\t\t\t\t\t }),\n\t\t\t\t).then(transformOptions => {\n\t\t\t\t\tconst helpers = preflightCheck(this, transformOptions);\n\n\t\t\t\t\tif (helpers === EXTERNAL && !externalHelpers) {\n\t\t\t\t\t\twarnOnce(\n\t\t\t\t\t\t\tthis,\n\t\t\t\t\t\t\t'Using \"external-helpers\" plugin with rollup-plugin-babel is deprecated, as it now automatically deduplicates your Babel helpers.',\n\t\t\t\t\t\t);\n\t\t\t\t\t} else if (helpers === RUNTIME && !runtimeHelpers) {\n\t\t\t\t\t\tthis.error(\n\t\t\t\t\t\t\t'Runtime helpers are not enabled. Either exclude the transform-runtime Babel plugin or pass the `runtimeHelpers: true` option. See https://github.com/rollup/rollup-plugin-babel#configuring-babel for more information',\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tif (helpers !== RUNTIME && !externalHelpers) {\n\t\t\t\t\t\ttransformOptions = addBabelPlugin(transformOptions, helperPlugin);\n\t\t\t\t\t}\n\n\t\t\t\t\tconst result = babel.transformSync(code, transformOptions);\n\n\t\t\t\t\treturn Promise.resolve(\n\t\t\t\t\t\t!overrides.result\n\t\t\t\t\t\t\t? result\n\t\t\t\t\t\t\t: overrides.result.call(this, result, {\n\t\t\t\t\t\t\t\t\tcode,\n\t\t\t\t\t\t\t\t\tcustomOptions,\n\t\t\t\t\t\t\t\t\tconfig,\n\t\t\t\t\t\t\t\t\ttransformOptions,\n\t\t\t\t\t\t\t }),\n\t\t\t\t\t).then(({ code, map }) => ({ code, map }));\n\t\t\t\t});\n\t\t\t},\n\t\t};\n\t};\n}\n\nconst babelPluginFactory = createBabelPluginFactory();\nbabelPluginFactory.custom = createBabelPluginFactory;\n\nexport default babelPluginFactory;\n"],"names":["const","let","babel.DEFAULT_EXTENSIONS","babel.buildExternalHelpers","babel.loadPartialConfig","this","helperPlugin","babel.transformSync"],"mappings":";;;;;AAAOA,IAAM,MAAM,GAAG,EAAE,CAAC;AAClBA,IAAM,OAAO,GAAG,EAAE,CAAC;AACnBA,IAAM,QAAQ,GAAG,EAAE,CAAC;;;;AAIpBA,IAAM,OAAO,GAAG,+BAA+B;;ACN/CA,IAAM,cAAc,aAAI,OAAO,EAAE,MAAM,EAAE,UAAI,kBAAK,OAAO,GAAE,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAC,CAAE,IAAC,CAAC;;AAE7GC,IAAI,MAAM,GAAG,EAAE,CAAC;AACT,SAAS,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE;CAClC,IAAI,MAAM,CAAC,GAAG,CAAC,IAAE,SAAO;CACxB,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;CACnB,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;CACd;;AAEDD,IAAM,sBAAsB,GAAG,qBAAqB,CAAC;AAC9CA,IAAM,sBAAsB,aAAG,KAAI,SAAG,GAAG,CAAC,OAAO,CAAC,sBAAsB,EAAE,MAAM,IAAC;;ACNxFA,IAAM,YAAY;CACjB,gFAAgF;CAChF,gFAAgF;CAChF,wFAAwF;CACxF,MAAM;CACN,uEAAuE;CACvE,sFAAsF;CACtF,2FAA2F,CAAC;;AAE7FA,IA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