Socket
Socket
Sign inDemoInstall

@rollup/plugin-babel

Package Overview
Dependencies
Maintainers
4
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rollup/plugin-babel - npm Package Compare versions

Comparing version 6.0.0 to 6.0.1

80

dist/cjs/index.js

@@ -31,5 +31,6 @@ 'use strict';

const RUNTIME = 'runtime';
const EXTERNAL = 'external'; // NOTE: DO NOT REMOVE the null character `\0` as it may be used by other plugins
const EXTERNAL = '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
const HELPERS = '\0rollupPluginBabelHelpers.js';

@@ -47,11 +48,8 @@

}
if (cachedHelpers[name]) {
return t.cloneNode(cachedHelpers[name]);
}
return cachedHelpers[name] = helperModuleImports.addNamed(file.path, name, HELPERS);
});
}
};

@@ -61,3 +59,4 @@ }

const addBabelPlugin = (options, plugin) => {
return { ...options,
return {
...options,
plugins: options.plugins.concat(plugin)

@@ -89,3 +88,2 @@ };

const PREFLIGHT_INPUT = `export default "${PREFLIGHT_TEST_STRING}";`;
function helpersTestTransform() {

@@ -99,19 +97,17 @@ return {

}
}
};
}
const mismatchError = (actual, expected, filename) => `You have declared using "${expected}" babelHelpers, but transforming ${filename} resulted in "${actual}". Please check your configuration.`;
const mismatchError = (actual, expected, filename) => `You have declared using "${expected}" babelHelpers, but transforming ${filename} resulted in "${actual}". Please check your configuration.`; // Revert to /\/helpers\/(esm\/)?inherits/ when Babel 8 gets released, this was fixed in https://github.com/babel/babel/issues/14185
// Revert to /\/helpers\/(esm\/)?inherits/ when Babel 8 gets released, this was fixed in https://github.com/babel/babel/issues/14185
const inheritsHelperRe = /[\\/]+helpers[\\/]+(esm[\\/]+)?inherits/;
async function preflightCheck(ctx, babelHelpers, transformOptions) {
const finalOptions = addBabelPlugin(transformOptions, helpersTestTransform);
const check = (await babel__namespace.transformAsync(PREFLIGHT_INPUT, finalOptions)).code; // Babel sometimes splits ExportDefaultDeclaration into 2 statements, so we also check for ExportNamedDeclaration
const check = (await babel__namespace.transformAsync(PREFLIGHT_INPUT, finalOptions)).code;
// Babel sometimes splits ExportDefaultDeclaration into 2 statements, so we also check for ExportNamedDeclaration
if (!/export (d|{)/.test(check)) {
ctx.error(MODULE_ERROR);
}
if (inheritsHelperRe.test(check)) {

@@ -121,6 +117,4 @@ if (babelHelpers === RUNTIME) {

}
ctx.error(mismatchError(RUNTIME, babelHelpers, transformOptions.filename));
}
if (check.includes('babelHelpers.inherits')) {

@@ -130,7 +124,6 @@ if (babelHelpers === EXTERNAL) {

}
ctx.error(mismatchError(EXTERNAL, babelHelpers, transformOptions.filename));
} // test unminifiable string content
}
// test unminifiable string content
if (check.includes('Super expression must either be null or a function')) {

@@ -140,10 +133,7 @@ if (babelHelpers === INLINE || babelHelpers === BUNDLED) {

}
if (babelHelpers === RUNTIME && !transformOptions.plugins.length) {
ctx.error(`You must use the \`@babel/plugin-transform-runtime\` plugin when \`babelHelpers\` is "${RUNTIME}".\n`);
}
ctx.error(mismatchError(INLINE, babelHelpers, transformOptions.filename));
}
ctx.error(UNEXPECTED_ERROR);

@@ -154,8 +144,8 @@ }

// loadPartialConfigAsync has become available in @babel/core@7.8.0
const config = await (babel__namespace.loadPartialConfigAsync || babel__namespace.loadPartialConfig)(babelOptions); // file is ignored by babel
const config = await (babel__namespace.loadPartialConfigAsync || babel__namespace.loadPartialConfig)(babelOptions);
// file is ignored by babel
if (!config) {
return null;
}
let transformOptions = !overrides.config ? config.options : await overrides.config.call(ctx, config, {

@@ -165,7 +155,5 @@ code: inputCode,

});
if (finalizeOptions) {
transformOptions = await finalizeOptions(transformOptions);
}
if (!overrides.result) {

@@ -181,3 +169,2 @@ const {

}
const result = await babel__namespace.transformAsync(inputCode, transformOptions);

@@ -220,3 +207,2 @@ const {

};
const warnAboutDeprecatedHelpersOption = ({

@@ -229,3 +215,2 @@ deprecatedOption,

};
const unpackInputPluginOptions = ({

@@ -249,4 +234,4 @@ skipPreflightCheck = false,

}
return unpackOptions({ ...rest,
return unpackOptions({
...rest,
skipPreflightCheck,

@@ -264,3 +249,2 @@ babelHelpers: rest.babelHelpers || BUNDLED,

};
const unpackOutputPluginOptions = (options, {

@@ -277,3 +261,2 @@ format

});
function getOptionsWithOverrides(pluginOptions = {}, overrides = {}) {

@@ -285,7 +268,5 @@ if (!overrides.options) return {

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.");
}
return {

@@ -296,7 +277,5 @@ customOptions: overridden.customOptions || null,

}
const returnObject = () => {
return {};
};
function createBabelInputPluginFactory(customCallback = returnObject) {

@@ -315,3 +294,2 @@ const overrides = customCallback(babel__namespace);

name: 'babel',
options() {

@@ -333,14 +311,9 @@ // todo: remove options hook and hoist declarations when version checks are removed

const extensionRegExp = new RegExp(`(${extensions.map(escapeRegExpCharacters).join('|')})$`);
if (customFilter && (include || exclude)) {
throw new Error('Could not handle include or exclude with custom filter together');
}
const userDefinedFilter = typeof customFilter === 'function' ? customFilter : pluginutils.createFilter(include, exclude);
filter = id => extensionRegExp.test(stripQuery(id).bareId) && userDefinedFilter(id);
return null;
},
resolveId(id) {

@@ -350,6 +323,4 @@ if (id !== HELPERS) {

}
return id;
},
load(id) {

@@ -359,10 +330,9 @@ if (id !== HELPERS) {

}
return babel__namespace.buildExternalHelpers(null, 'module');
},
transform(code, filename) {
if (!filter(filename)) return null;
if (filename === HELPERS) return null;
return transformCode(code, { ...babelOptions,
return transformCode(code, {
...babelOptions,
filename

@@ -373,11 +343,8 @@ }, overrides, customOptions, this, async transformOptions => {

}
return babelHelpers === BUNDLED ? addBabelPlugin(transformOptions, importHelperPlugin) : transformOptions;
});
}
};
};
}
function getRecommendedFormat(rollupFormat) {

@@ -387,10 +354,7 @@ switch (rollupFormat) {

return 'amd';
case 'iife':
case 'umd':
return 'umd';
case 'system':
return 'systemjs';
default:

@@ -400,3 +364,2 @@ return '<module format>';

}
function createBabelOutputPluginFactory(customCallback = returnObject) {

@@ -411,3 +374,2 @@ const overrides = customCallback(babel__namespace);

name: 'babel',
renderStart(outputOptions) {

@@ -420,7 +382,5 @@ const {

} = pluginOptionsWithOverrides;
if (extensions || include || exclude) {
warnOnce(this, 'The "include", "exclude" and "extensions" options are ignored when transforming the output.');
}
if (!allowAllFormats && outputOptions.format !== 'es' && outputOptions.format !== 'cjs') {

@@ -430,3 +390,2 @@ this.error(`Using Babel on the generated chunks is strongly discouraged for formats other than "esm" or "cjs" as it can easily break wrapper code and lead to accidentally created global variables. Instead, you should set "output.format" to "esm" and use Babel to transform to another format, e.g. by adding "presets: [['@babel/env', { modules: '${getRecommendedFormat(outputOptions.format)}' }]]" to your Babel options. If you still want to proceed, add "allowAllFormats: true" to your plugin options.`);

},
renderChunk(code, chunk, outputOptions) {

@@ -448,8 +407,7 @@ /* eslint-disable no-unused-vars */

}
};
};
} // export this for symmetry with output-related exports
}
// export this for symmetry with output-related exports
const getBabelInputPlugin = createBabelInputPluginFactory();

@@ -456,0 +414,0 @@ const getBabelOutputPlugin = createBabelOutputPluginFactory();

@@ -8,5 +8,6 @@ import * as babel from '@babel/core';

const RUNTIME = 'runtime';
const EXTERNAL = 'external'; // NOTE: DO NOT REMOVE the null character `\0` as it may be used by other plugins
const EXTERNAL = '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
const HELPERS = '\0rollupPluginBabelHelpers.js';

@@ -24,11 +25,8 @@

}
if (cachedHelpers[name]) {
return t.cloneNode(cachedHelpers[name]);
}
return cachedHelpers[name] = addNamed(file.path, name, HELPERS);
});
}
};

@@ -38,3 +36,4 @@ }

const addBabelPlugin = (options, plugin) => {
return { ...options,
return {
...options,
plugins: options.plugins.concat(plugin)

@@ -66,3 +65,2 @@ };

const PREFLIGHT_INPUT = `export default "${PREFLIGHT_TEST_STRING}";`;
function helpersTestTransform() {

@@ -76,19 +74,17 @@ return {

}
}
};
}
const mismatchError = (actual, expected, filename) => `You have declared using "${expected}" babelHelpers, but transforming ${filename} resulted in "${actual}". Please check your configuration.`;
const mismatchError = (actual, expected, filename) => `You have declared using "${expected}" babelHelpers, but transforming ${filename} resulted in "${actual}". Please check your configuration.`; // Revert to /\/helpers\/(esm\/)?inherits/ when Babel 8 gets released, this was fixed in https://github.com/babel/babel/issues/14185
// Revert to /\/helpers\/(esm\/)?inherits/ when Babel 8 gets released, this was fixed in https://github.com/babel/babel/issues/14185
const inheritsHelperRe = /[\\/]+helpers[\\/]+(esm[\\/]+)?inherits/;
async function preflightCheck(ctx, babelHelpers, transformOptions) {
const finalOptions = addBabelPlugin(transformOptions, helpersTestTransform);
const check = (await babel.transformAsync(PREFLIGHT_INPUT, finalOptions)).code; // Babel sometimes splits ExportDefaultDeclaration into 2 statements, so we also check for ExportNamedDeclaration
const check = (await babel.transformAsync(PREFLIGHT_INPUT, finalOptions)).code;
// Babel sometimes splits ExportDefaultDeclaration into 2 statements, so we also check for ExportNamedDeclaration
if (!/export (d|{)/.test(check)) {
ctx.error(MODULE_ERROR);
}
if (inheritsHelperRe.test(check)) {

@@ -98,6 +94,4 @@ if (babelHelpers === RUNTIME) {

}
ctx.error(mismatchError(RUNTIME, babelHelpers, transformOptions.filename));
}
if (check.includes('babelHelpers.inherits')) {

@@ -107,7 +101,6 @@ if (babelHelpers === EXTERNAL) {

}
ctx.error(mismatchError(EXTERNAL, babelHelpers, transformOptions.filename));
} // test unminifiable string content
}
// test unminifiable string content
if (check.includes('Super expression must either be null or a function')) {

@@ -117,10 +110,7 @@ if (babelHelpers === INLINE || babelHelpers === BUNDLED) {

}
if (babelHelpers === RUNTIME && !transformOptions.plugins.length) {
ctx.error(`You must use the \`@babel/plugin-transform-runtime\` plugin when \`babelHelpers\` is "${RUNTIME}".\n`);
}
ctx.error(mismatchError(INLINE, babelHelpers, transformOptions.filename));
}
ctx.error(UNEXPECTED_ERROR);

@@ -131,8 +121,8 @@ }

// loadPartialConfigAsync has become available in @babel/core@7.8.0
const config = await (babel.loadPartialConfigAsync || babel.loadPartialConfig)(babelOptions); // file is ignored by babel
const config = await (babel.loadPartialConfigAsync || babel.loadPartialConfig)(babelOptions);
// file is ignored by babel
if (!config) {
return null;
}
let transformOptions = !overrides.config ? config.options : await overrides.config.call(ctx, config, {

@@ -142,7 +132,5 @@ code: inputCode,

});
if (finalizeOptions) {
transformOptions = await finalizeOptions(transformOptions);
}
if (!overrides.result) {

@@ -158,3 +146,2 @@ const {

}
const result = await babel.transformAsync(inputCode, transformOptions);

@@ -197,3 +184,2 @@ const {

};
const warnAboutDeprecatedHelpersOption = ({

@@ -206,3 +192,2 @@ deprecatedOption,

};
const unpackInputPluginOptions = ({

@@ -226,4 +211,4 @@ skipPreflightCheck = false,

}
return unpackOptions({ ...rest,
return unpackOptions({
...rest,
skipPreflightCheck,

@@ -241,3 +226,2 @@ babelHelpers: rest.babelHelpers || BUNDLED,

};
const unpackOutputPluginOptions = (options, {

@@ -254,3 +238,2 @@ format

});
function getOptionsWithOverrides(pluginOptions = {}, overrides = {}) {

@@ -262,7 +245,5 @@ if (!overrides.options) return {

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.");
}
return {

@@ -273,7 +254,5 @@ customOptions: overridden.customOptions || null,

}
const returnObject = () => {
return {};
};
function createBabelInputPluginFactory(customCallback = returnObject) {

@@ -292,3 +271,2 @@ const overrides = customCallback(babel);

name: 'babel',
options() {

@@ -310,14 +288,9 @@ // todo: remove options hook and hoist declarations when version checks are removed

const extensionRegExp = new RegExp(`(${extensions.map(escapeRegExpCharacters).join('|')})$`);
if (customFilter && (include || exclude)) {
throw new Error('Could not handle include or exclude with custom filter together');
}
const userDefinedFilter = typeof customFilter === 'function' ? customFilter : createFilter(include, exclude);
filter = id => extensionRegExp.test(stripQuery(id).bareId) && userDefinedFilter(id);
return null;
},
resolveId(id) {

@@ -327,6 +300,4 @@ if (id !== HELPERS) {

}
return id;
},
load(id) {

@@ -336,10 +307,9 @@ if (id !== HELPERS) {

}
return babel.buildExternalHelpers(null, 'module');
},
transform(code, filename) {
if (!filter(filename)) return null;
if (filename === HELPERS) return null;
return transformCode(code, { ...babelOptions,
return transformCode(code, {
...babelOptions,
filename

@@ -350,11 +320,8 @@ }, overrides, customOptions, this, async transformOptions => {

}
return babelHelpers === BUNDLED ? addBabelPlugin(transformOptions, importHelperPlugin) : transformOptions;
});
}
};
};
}
function getRecommendedFormat(rollupFormat) {

@@ -364,10 +331,7 @@ switch (rollupFormat) {

return 'amd';
case 'iife':
case 'umd':
return 'umd';
case 'system':
return 'systemjs';
default:

@@ -377,3 +341,2 @@ return '<module format>';

}
function createBabelOutputPluginFactory(customCallback = returnObject) {

@@ -388,3 +351,2 @@ const overrides = customCallback(babel);

name: 'babel',
renderStart(outputOptions) {

@@ -397,7 +359,5 @@ const {

} = pluginOptionsWithOverrides;
if (extensions || include || exclude) {
warnOnce(this, 'The "include", "exclude" and "extensions" options are ignored when transforming the output.');
}
if (!allowAllFormats && outputOptions.format !== 'es' && outputOptions.format !== 'cjs') {

@@ -407,3 +367,2 @@ this.error(`Using Babel on the generated chunks is strongly discouraged for formats other than "esm" or "cjs" as it can easily break wrapper code and lead to accidentally created global variables. Instead, you should set "output.format" to "esm" and use Babel to transform to another format, e.g. by adding "presets: [['@babel/env', { modules: '${getRecommendedFormat(outputOptions.format)}' }]]" to your Babel options. If you still want to proceed, add "allowAllFormats: true" to your plugin options.`);

},
renderChunk(code, chunk, outputOptions) {

@@ -425,8 +384,7 @@ /* eslint-disable no-unused-vars */

}
};
};
} // export this for symmetry with output-related exports
}
// export this for symmetry with output-related exports
const getBabelInputPlugin = createBabelInputPluginFactory();

@@ -433,0 +391,0 @@ const getBabelOutputPlugin = createBabelOutputPluginFactory();

{
"name": "@rollup/plugin-babel",
"version": "6.0.0",
"version": "6.0.1",
"publishConfig": {

@@ -69,3 +69,3 @@ "access": "public"

"@babel/helper-module-imports": "^7.18.6",
"@rollup/pluginutils": "^4.2.1"
"@rollup/pluginutils": "^5.0.1"
},

@@ -79,6 +79,6 @@ "devDependencies": {

"@babel/preset-env": "^7.19.1",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^14.1.0",
"@rollup/plugin-json": "^5.0.0",
"@rollup/plugin-node-resolve": "^15.0.0",
"@types/babel__core": "^7.1.9",
"rollup": "^3.0.0-7",
"rollup": "^3.2.3",
"source-map": "^0.7.4"

@@ -85,0 +85,0 @@ },

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with âšĄïž by Socket Inc