Archived
1
0

First commit

This commit is contained in:
Sean Edmunds
2021-12-13 17:00:40 -06:00
commit 0584430b5c
36617 changed files with 4676695 additions and 0 deletions

7
node_modules/rollup-plugin-babel/src/constants.js generated vendored Normal file
View File

@@ -0,0 +1,7 @@
export const INLINE = {};
export const RUNTIME = {};
export const EXTERNAL = {};
// NOTE: DO NOT REMOVE the null character `\0` as it may be used by other plugins
// e.g. https://github.com/rollup/rollup-plugin-node-resolve/blob/313a3e32f432f9eb18cc4c231cc7aac6df317a51/src/index.js#L74
export const HELPERS = '\0rollupPluginBabelHelpers.js';

21
node_modules/rollup-plugin-babel/src/helperPlugin.js generated vendored Normal file
View File

@@ -0,0 +1,21 @@
import { HELPERS } from './constants.js';
import { addNamed } from '@babel/helper-module-imports';
export default function importHelperPlugin() {
return {
pre(file) {
const cachedHelpers = {};
file.set('helperGenerator', name => {
if (!file.availableHelper(name)) {
return;
}
if (cachedHelpers[name]) {
return cachedHelpers[name];
}
return (cachedHelpers[name] = addNamed(file.path, name, HELPERS));
});
},
};
}

133
node_modules/rollup-plugin-babel/src/index.js generated vendored Normal file
View File

@@ -0,0 +1,133 @@
import * as babel from '@babel/core';
import { createFilter } from 'rollup-pluginutils';
import createPreflightCheck from './preflightCheck.js';
import helperPlugin from './helperPlugin.js';
import { addBabelPlugin, escapeRegExpCharacters, warnOnce } from './utils.js';
import { RUNTIME, EXTERNAL, HELPERS } from './constants.js';
const unpackOptions = ({
extensions = babel.DEFAULT_EXTENSIONS,
// rollup uses sourcemap, babel uses sourceMaps
// just normalize them here so people don't have to worry about it
sourcemap = true,
sourcemaps = true,
sourceMap = true,
sourceMaps = true,
...rest
} = {}) => ({
extensions,
plugins: [],
sourceMaps: sourcemap && sourcemaps && sourceMap && sourceMaps,
...rest,
caller: {
name: 'rollup-plugin-babel',
supportsStaticESM: true,
supportsDynamicImport: true,
...rest.caller,
},
});
const returnObject = () => ({});
function createBabelPluginFactory(customCallback = returnObject) {
const overrides = customCallback(babel);
return pluginOptions => {
let customOptions = null;
if (overrides.options) {
const overridden = overrides.options(pluginOptions);
if (typeof overridden.then === 'function') {
throw new Error(
".options hook can't be asynchronous. It should return `{ customOptions, pluginsOptions }` synchronously.",
);
}
({ customOptions = null, pluginOptions } = overridden);
}
const {
exclude,
extensions,
externalHelpers,
externalHelpersWhitelist,
include,
runtimeHelpers,
...babelOptions
} = unpackOptions(pluginOptions);
const extensionRegExp = new RegExp(`(${extensions.map(escapeRegExpCharacters).join('|')})$`);
const includeExcludeFilter = createFilter(include, exclude);
const filter = id => extensionRegExp.test(id) && includeExcludeFilter(id);
const preflightCheck = createPreflightCheck();
return {
name: 'babel',
resolveId(id) {
if (id === HELPERS) return id;
},
load(id) {
if (id !== HELPERS) {
return;
}
return babel.buildExternalHelpers(externalHelpersWhitelist, 'module');
},
transform(code, filename) {
if (!filter(filename)) return Promise.resolve(null);
if (filename === HELPERS) return Promise.resolve(null);
const config = babel.loadPartialConfig({ ...babelOptions, filename });
// file is ignored
if (!config) {
return Promise.resolve(null);
}
return Promise.resolve(
!overrides.config
? config.options
: overrides.config.call(this, config, {
code,
customOptions,
}),
).then(transformOptions => {
const helpers = preflightCheck(this, transformOptions);
if (helpers === EXTERNAL && !externalHelpers) {
warnOnce(
this,
'Using "external-helpers" plugin with rollup-plugin-babel is deprecated, as it now automatically deduplicates your Babel helpers.',
);
} else if (helpers === RUNTIME && !runtimeHelpers) {
this.error(
'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',
);
}
if (helpers !== RUNTIME && !externalHelpers) {
transformOptions = addBabelPlugin(transformOptions, helperPlugin);
}
const result = babel.transformSync(code, transformOptions);
return Promise.resolve(
!overrides.result
? result
: overrides.result.call(this, result, {
code,
customOptions,
config,
transformOptions,
}),
).then(({ code, map }) => ({ code, map }));
});
},
};
};
}
const babelPluginFactory = createBabelPluginFactory();
babelPluginFactory.custom = createBabelPluginFactory;
export default babelPluginFactory;

66
node_modules/rollup-plugin-babel/src/preflightCheck.js generated vendored Normal file
View File

@@ -0,0 +1,66 @@
import { transformSync } from '@babel/core';
import { INLINE, RUNTIME, EXTERNAL } from './constants.js';
import { addBabelPlugin } from './utils.js';
const MODULE_ERROR =
'Rollup requires that your Babel configuration keeps ES6 module syntax intact. ' +
'Unfortunately it looks like your configuration specifies a module transformer ' +
'to replace ES6 modules with another module format. To continue you have to disable it.' +
'\n\n' +
"Most commonly it's a CommonJS transform added by @babel/preset-env - " +
'in such case you should disable it by adding `modules: false` option to that preset ' +
'(described in more detail here - https://github.com/rollup/rollup-plugin-babel#modules ).';
const UNEXPECTED_ERROR =
'An unexpected situation arose. Please raise an issue at ' +
'https://github.com/rollup/rollup-plugin-babel/issues. Thanks!';
function fallbackClassTransform() {
return {
visitor: {
ClassDeclaration(path, state) {
path.replaceWith(state.file.addHelper('inherits'));
},
},
};
}
export default function createPreflightCheck() {
let preflightCheckResults = {};
return (ctx, options) => {
const key = options.filename;
if (preflightCheckResults[key] === undefined) {
let helpers;
const inputCode = 'class Foo extends Bar {};\nexport default Foo;';
const transformed = transformSync(inputCode, options);
let check = transformed.code;
if (~check.indexOf('class ')) {
check = transformSync(inputCode, addBabelPlugin(options, fallbackClassTransform)).code;
}
if (
!~check.indexOf('export default') &&
!~check.indexOf('export default Foo') &&
!~check.indexOf('export { Foo as default }')
) {
ctx.error(MODULE_ERROR);
}
if (check.match(/\/helpers\/(esm\/)?inherits/)) helpers = RUNTIME;
else if (~check.indexOf('function _inherits')) helpers = INLINE;
else if (~check.indexOf('babelHelpers')) helpers = EXTERNAL;
else {
ctx.error(UNEXPECTED_ERROR);
}
preflightCheckResults[key] = helpers;
}
return preflightCheckResults[key];
};
}

11
node_modules/rollup-plugin-babel/src/utils.js generated vendored Normal file
View File

@@ -0,0 +1,11 @@
export const addBabelPlugin = (options, plugin) => ({ ...options, plugins: options.plugins.concat(plugin) });
let warned = {};
export function warnOnce(ctx, msg) {
if (warned[msg]) return;
warned[msg] = true;
ctx.warn(msg);
}
const regExpCharactersRegExp = /[\\^$.*+?()[\]{}|]/g;
export const escapeRegExpCharacters = str => str.replace(regExpCharactersRegExp, '\\$&');