@babel/core
Advanced tools
Comparing version 7.14.3 to 7.22.5
@@ -6,46 +6,34 @@ "use strict"; | ||
}); | ||
exports.assertSimpleType = assertSimpleType; | ||
exports.makeStrongCache = makeStrongCache; | ||
exports.makeStrongCacheSync = makeStrongCacheSync; | ||
exports.makeWeakCache = makeWeakCache; | ||
exports.makeWeakCacheSync = makeWeakCacheSync; | ||
exports.makeStrongCache = makeStrongCache; | ||
exports.makeStrongCacheSync = makeStrongCacheSync; | ||
exports.assertSimpleType = assertSimpleType; | ||
function _gensync() { | ||
const data = require("gensync"); | ||
_gensync = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _async = require("../gensync-utils/async"); | ||
var _util = require("./util"); | ||
const synchronize = gen => { | ||
return _gensync()(gen).sync; | ||
}; | ||
function* genTrue() { | ||
return true; | ||
} | ||
function makeWeakCache(handler) { | ||
return makeCachedFunction(WeakMap, handler); | ||
} | ||
function makeWeakCacheSync(handler) { | ||
return synchronize(makeWeakCache(handler)); | ||
} | ||
function makeStrongCache(handler) { | ||
return makeCachedFunction(Map, handler); | ||
} | ||
function makeStrongCacheSync(handler) { | ||
return synchronize(makeStrongCache(handler)); | ||
} | ||
function makeCachedFunction(CallCache, handler) { | ||
@@ -64,6 +52,4 @@ const callCacheSync = new CallCache(); | ||
let value; | ||
if ((0, _util.isIterableIterator)(handlerResult)) { | ||
const gen = handlerResult; | ||
value = yield* (0, _async.onFirstPause)(gen, () => { | ||
value = yield* (0, _async.onFirstPause)(handlerResult, () => { | ||
finishLock = setupAsyncLocks(cache, futureCache, arg); | ||
@@ -74,5 +60,3 @@ }); | ||
} | ||
updateFunctionCache(callCache, cache, arg, value); | ||
if (finishLock) { | ||
@@ -82,10 +66,7 @@ futureCache.delete(arg); | ||
} | ||
return value; | ||
}; | ||
} | ||
function* getCachedValue(cache, arg, data) { | ||
const cachedValue = cache.get(arg); | ||
if (cachedValue) { | ||
@@ -102,3 +83,2 @@ for (const { | ||
} | ||
return { | ||
@@ -109,13 +89,9 @@ valid: false, | ||
} | ||
function* getCachedValueOrWait(asyncContext, callCache, futureCache, arg, data) { | ||
const cached = yield* getCachedValue(callCache, arg, data); | ||
if (cached.valid) { | ||
return cached; | ||
} | ||
if (asyncContext) { | ||
const cached = yield* getCachedValue(futureCache, arg, data); | ||
if (cached.valid) { | ||
@@ -129,3 +105,2 @@ const value = yield* (0, _async.waitFor)(cached.value.promise); | ||
} | ||
return { | ||
@@ -136,3 +111,2 @@ valid: false, | ||
} | ||
function setupAsyncLocks(config, futureCache, arg) { | ||
@@ -143,3 +117,2 @@ const finishLock = new Lock(); | ||
} | ||
function updateFunctionCache(cache, config, arg, value) { | ||
@@ -149,3 +122,2 @@ if (!config.configured()) config.forever(); | ||
config.deactivate(); | ||
switch (config.mode()) { | ||
@@ -159,3 +131,2 @@ case "forever": | ||
break; | ||
case "invalidate": | ||
@@ -168,3 +139,2 @@ cachedValue = [{ | ||
break; | ||
case "valid": | ||
@@ -183,6 +153,4 @@ if (cachedValue) { | ||
} | ||
} | ||
} | ||
class CacheConfigurator { | ||
@@ -199,7 +167,5 @@ constructor(data) { | ||
} | ||
simple() { | ||
return makeSimpleConfigurator(this); | ||
} | ||
mode() { | ||
@@ -211,3 +177,2 @@ if (this._never) return "never"; | ||
} | ||
forever() { | ||
@@ -217,11 +182,8 @@ if (!this._active) { | ||
} | ||
if (this._never) { | ||
throw new Error("Caching has already been configured with .never()"); | ||
} | ||
this._forever = true; | ||
this._configured = true; | ||
} | ||
never() { | ||
@@ -231,11 +193,8 @@ if (!this._active) { | ||
} | ||
if (this._forever) { | ||
throw new Error("Caching has already been configured with .forever()"); | ||
} | ||
this._never = true; | ||
this._configured = true; | ||
} | ||
using(handler) { | ||
@@ -245,24 +204,17 @@ if (!this._active) { | ||
} | ||
if (this._never || this._forever) { | ||
throw new Error("Caching has already been configured with .never or .forever()"); | ||
} | ||
this._configured = true; | ||
const key = handler(this._data); | ||
const fn = (0, _async.maybeAsync)(handler, `You appear to be using an async cache handler, but Babel has been called synchronously`); | ||
if ((0, _async.isThenable)(key)) { | ||
return key.then(key => { | ||
this._pairs.push([key, fn]); | ||
return key; | ||
}); | ||
} | ||
this._pairs.push([key, fn]); | ||
return key; | ||
} | ||
invalidate(handler) { | ||
@@ -272,3 +224,2 @@ this._invalidate = true; | ||
} | ||
validator() { | ||
@@ -280,17 +231,12 @@ const pairs = this._pairs; | ||
} | ||
return true; | ||
}; | ||
} | ||
deactivate() { | ||
this._active = false; | ||
} | ||
configured() { | ||
return this._configured; | ||
} | ||
} | ||
function makeSimpleConfigurator(cache) { | ||
@@ -302,17 +248,10 @@ function cacheFn(val) { | ||
} | ||
return cache.using(() => assertSimpleType(val())); | ||
} | ||
cacheFn.forever = () => cache.forever(); | ||
cacheFn.never = () => cache.never(); | ||
cacheFn.using = cb => cache.using(() => assertSimpleType(cb())); | ||
cacheFn.invalidate = cb => cache.invalidate(() => assertSimpleType(cb())); | ||
return cacheFn; | ||
} | ||
function assertSimpleType(value) { | ||
@@ -322,10 +261,7 @@ if ((0, _async.isThenable)(value)) { | ||
} | ||
if (value != null && typeof value !== "string" && typeof value !== "boolean" && typeof value !== "number") { | ||
throw new Error("Cache keys must be either string, boolean, number, null, or undefined."); | ||
} | ||
return value; | ||
} | ||
class Lock { | ||
@@ -340,9 +276,9 @@ constructor() { | ||
} | ||
release(value) { | ||
this.released = true; | ||
this._resolve(value); | ||
} | ||
} | ||
0 && 0; | ||
} | ||
//# sourceMappingURL=caching.js.map |
@@ -7,39 +7,27 @@ "use strict"; | ||
exports.buildPresetChain = buildPresetChain; | ||
exports.buildPresetChainWalker = void 0; | ||
exports.buildRootChain = buildRootChain; | ||
exports.buildPresetChainWalker = void 0; | ||
function _path() { | ||
const data = require("path"); | ||
_path = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _debug() { | ||
const data = require("debug"); | ||
_debug = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _options = require("./validation/options"); | ||
var _patternToRegex = require("./pattern-to-regex"); | ||
var _printer = require("./printer"); | ||
var _rewriteStackTrace = require("../errors/rewrite-stack-trace"); | ||
var _configError = require("../errors/config-error"); | ||
var _files = require("./files"); | ||
var _caching = require("./caching"); | ||
var _configDescriptors = require("./config-descriptors"); | ||
const debug = _debug()("babel:config:config-chain"); | ||
function* buildPresetChain(arg, context) { | ||
@@ -55,3 +43,2 @@ const chain = yield* buildPresetChainWalker(arg, context); | ||
} | ||
const buildPresetChainWalker = makeChainWalker({ | ||
@@ -69,3 +56,2 @@ root: preset => loadPresetDescriptors(preset), | ||
const loadPresetOverridesEnvDescriptors = (0, _caching.makeWeakCacheSync)(preset => (0, _caching.makeStrongCacheSync)(index => (0, _caching.makeStrongCacheSync)(envName => buildOverrideEnvDescriptors(preset, preset.alias, _configDescriptors.createUncachedDescriptors, index, envName)))); | ||
function* buildRootChain(opts, context) { | ||
@@ -81,3 +67,2 @@ let configReport, babelRcReport; | ||
let configFile; | ||
if (typeof opts.configFile === "string") { | ||
@@ -88,3 +73,2 @@ configFile = yield* (0, _files.loadConfig)(opts.configFile, context.cwd, context.envName, context.caller); | ||
} | ||
let { | ||
@@ -97,3 +81,2 @@ babelrc, | ||
const configFileLogger = new _printer.ConfigPrinter(); | ||
if (configFile) { | ||
@@ -104,7 +87,5 @@ const validatedFile = validateConfigFile(configFile); | ||
configReport = yield* configFileLogger.output(); | ||
if (babelrc === undefined) { | ||
babelrc = validatedFile.options.babelrc; | ||
} | ||
if (babelrcRoots === undefined) { | ||
@@ -114,13 +95,9 @@ babelrcRootsDirectory = validatedFile.dirname; | ||
} | ||
mergeChain(configFileChain, result); | ||
} | ||
let ignoreFile, babelrcFile; | ||
let isIgnored = false; | ||
const fileChain = emptyChain(); | ||
if ((babelrc === true || babelrc === undefined) && typeof context.filename === "string") { | ||
const pkgData = yield* (0, _files.findPackageData)(context.filename); | ||
if (pkgData && babelrcLoadEnabled(context, pkgData, babelrcRoots, babelrcRootsDirectory)) { | ||
@@ -131,11 +108,8 @@ ({ | ||
} = yield* (0, _files.findRelativeConfig)(pkgData, context.envName, context.caller)); | ||
if (ignoreFile) { | ||
fileChain.files.add(ignoreFile.filepath); | ||
} | ||
if (ignoreFile && shouldIgnore(context, ignoreFile.ignore, null, ignoreFile.dirname)) { | ||
isIgnored = true; | ||
} | ||
if (babelrcFile && !isIgnored) { | ||
@@ -145,3 +119,2 @@ const validatedFile = validateBabelrcFile(babelrcFile); | ||
const result = yield* loadFileChain(validatedFile, context, undefined, babelrcLogger); | ||
if (!result) { | ||
@@ -154,3 +127,2 @@ isIgnored = true; | ||
} | ||
if (babelrcFile && isIgnored) { | ||
@@ -161,7 +133,5 @@ fileChain.files.add(babelrcFile.filepath); | ||
} | ||
if (context.showConfig) { | ||
console.log(`Babel configs on "${context.filename}" (ascending priority):\n` + [configReport, babelRcReport, programmaticReport].filter(x => !!x).join("\n\n") + "\n-----End Babel configs-----"); | ||
} | ||
const chain = mergeChain(mergeChain(mergeChain(emptyChain(), configFileChain), fileChain), programmaticChain); | ||
@@ -179,25 +149,18 @@ return { | ||
} | ||
function babelrcLoadEnabled(context, pkgData, babelrcRoots, babelrcRootsDirectory) { | ||
if (typeof babelrcRoots === "boolean") return babelrcRoots; | ||
const absoluteRoot = context.root; | ||
if (babelrcRoots === undefined) { | ||
return pkgData.directories.indexOf(absoluteRoot) !== -1; | ||
} | ||
let babelrcPatterns = babelrcRoots; | ||
if (!Array.isArray(babelrcPatterns)) { | ||
babelrcPatterns = [babelrcPatterns]; | ||
} | ||
babelrcPatterns = babelrcPatterns.map(pat => { | ||
return typeof pat === "string" ? _path().resolve(babelrcRootsDirectory, pat) : pat; | ||
}); | ||
if (babelrcPatterns.length === 1 && babelrcPatterns[0] === absoluteRoot) { | ||
return pkgData.directories.indexOf(absoluteRoot) !== -1; | ||
} | ||
return babelrcPatterns.some(pat => { | ||
@@ -207,3 +170,2 @@ if (typeof pat === "string") { | ||
} | ||
return pkgData.directories.some(directory => { | ||
@@ -214,7 +176,6 @@ return matchPattern(pat, babelrcRootsDirectory, directory, context); | ||
} | ||
const validateConfigFile = (0, _caching.makeWeakCacheSync)(file => ({ | ||
filepath: file.filepath, | ||
dirname: file.dirname, | ||
options: (0, _options.validate)("configfile", file.options) | ||
options: (0, _options.validate)("configfile", file.options, file.filepath) | ||
})); | ||
@@ -224,3 +185,3 @@ const validateBabelrcFile = (0, _caching.makeWeakCacheSync)(file => ({ | ||
dirname: file.dirname, | ||
options: (0, _options.validate)("babelrcfile", file.options) | ||
options: (0, _options.validate)("babelrcfile", file.options, file.filepath) | ||
})); | ||
@@ -230,3 +191,3 @@ const validateExtendFile = (0, _caching.makeWeakCacheSync)(file => ({ | ||
dirname: file.dirname, | ||
options: (0, _options.validate)("extendsfile", file.options) | ||
options: (0, _options.validate)("extendsfile", file.options, file.filepath) | ||
})); | ||
@@ -247,13 +208,9 @@ const loadProgrammaticChain = makeChainWalker({ | ||
}); | ||
function* loadFileChain(input, context, files, baseLogger) { | ||
const chain = yield* loadFileChainWalker(input, context, files, baseLogger); | ||
if (chain) { | ||
chain.files.add(input.filepath); | ||
} | ||
return chain; | ||
} | ||
const loadFileDescriptors = (0, _caching.makeWeakCacheSync)(file => buildRootDescriptors(file, file.filepath, _configDescriptors.createUncachedDescriptors)); | ||
@@ -263,3 +220,2 @@ const loadFileEnvDescriptors = (0, _caching.makeWeakCacheSync)(file => (0, _caching.makeStrongCacheSync)(envName => buildEnvDescriptors(file, file.filepath, _configDescriptors.createUncachedDescriptors, envName))); | ||
const loadFileOverridesEnvDescriptors = (0, _caching.makeWeakCacheSync)(file => (0, _caching.makeStrongCacheSync)(index => (0, _caching.makeStrongCacheSync)(envName => buildOverrideEnvDescriptors(file, file.filepath, _configDescriptors.createUncachedDescriptors, index, envName)))); | ||
function buildFileLogger(filepath, context, baseLogger) { | ||
@@ -269,3 +225,2 @@ if (!baseLogger) { | ||
} | ||
return baseLogger.configure(context.showConfig, _printer.ChainFormatter.Config, { | ||
@@ -275,3 +230,2 @@ filepath | ||
} | ||
function buildRootDescriptors({ | ||
@@ -283,10 +237,7 @@ dirname, | ||
} | ||
function buildProgrammaticLogger(_, context, baseLogger) { | ||
var _context$caller; | ||
if (!baseLogger) { | ||
return () => {}; | ||
} | ||
return baseLogger.configure(context.showConfig, _printer.ChainFormatter.Programmatic, { | ||
@@ -296,3 +247,2 @@ callerName: (_context$caller = context.caller) == null ? void 0 : _context$caller.name | ||
} | ||
function buildEnvDescriptors({ | ||
@@ -305,3 +255,2 @@ dirname, | ||
} | ||
function buildOverrideDescriptors({ | ||
@@ -315,3 +264,2 @@ dirname, | ||
} | ||
function buildOverrideEnvDescriptors({ | ||
@@ -326,3 +274,2 @@ dirname, | ||
} | ||
function makeChainWalker({ | ||
@@ -335,3 +282,3 @@ root, | ||
}) { | ||
return function* (input, context, files = new Set(), baseLogger) { | ||
return function* chainWalker(input, context, files = new Set(), baseLogger) { | ||
const { | ||
@@ -342,4 +289,3 @@ dirname | ||
const rootOpts = root(input); | ||
if (configIsApplicable(rootOpts, dirname, context)) { | ||
if (configIsApplicable(rootOpts, dirname, context, input.filepath)) { | ||
flattenedConfigs.push({ | ||
@@ -351,4 +297,3 @@ config: rootOpts, | ||
const envOpts = env(input, context.envName); | ||
if (envOpts && configIsApplicable(envOpts, dirname, context)) { | ||
if (envOpts && configIsApplicable(envOpts, dirname, context, input.filepath)) { | ||
flattenedConfigs.push({ | ||
@@ -360,7 +305,5 @@ config: envOpts, | ||
} | ||
(rootOpts.options.overrides || []).forEach((_, index) => { | ||
const overrideOps = overrides(input, index); | ||
if (configIsApplicable(overrideOps, dirname, context)) { | ||
if (configIsApplicable(overrideOps, dirname, context, input.filepath)) { | ||
flattenedConfigs.push({ | ||
@@ -372,4 +315,3 @@ config: overrideOps, | ||
const overrideEnvOpts = overridesEnv(input, index, context.envName); | ||
if (overrideEnvOpts && configIsApplicable(overrideEnvOpts, dirname, context)) { | ||
if (overrideEnvOpts && configIsApplicable(overrideEnvOpts, dirname, context, input.filepath)) { | ||
flattenedConfigs.push({ | ||
@@ -384,3 +326,2 @@ config: overrideEnvOpts, | ||
} | ||
if (flattenedConfigs.some(({ | ||
@@ -396,6 +337,4 @@ config: { | ||
} | ||
const chain = emptyChain(); | ||
const logger = createLogger(input, context, baseLogger); | ||
for (const { | ||
@@ -409,19 +348,14 @@ config, | ||
} | ||
logger(config, index, envName); | ||
yield* mergeChainOpts(chain, config); | ||
} | ||
return chain; | ||
}; | ||
} | ||
function* mergeExtendsChain(chain, opts, dirname, context, files, baseLogger) { | ||
if (opts.extends === undefined) return true; | ||
const file = yield* (0, _files.loadConfig)(opts.extends, dirname, context.envName, context.caller); | ||
if (files.has(file)) { | ||
throw new Error(`Configuration cycle detected loading ${file.filepath}.\n` + `File already loaded following the config chain:\n` + Array.from(files, file => ` - ${file.filepath}`).join("\n")); | ||
} | ||
files.add(file); | ||
@@ -434,3 +368,2 @@ const fileChain = yield* loadFileChain(validateExtendFile(file), context, files, baseLogger); | ||
} | ||
function mergeChain(target, source) { | ||
@@ -440,10 +373,7 @@ target.options.push(...source.options); | ||
target.presets.push(...source.presets); | ||
for (const file of source.files) { | ||
target.files.add(file); | ||
} | ||
return target; | ||
} | ||
function* mergeChainOpts(target, { | ||
@@ -459,3 +389,2 @@ options, | ||
} | ||
function emptyChain() { | ||
@@ -469,3 +398,2 @@ return { | ||
} | ||
function normalizeOptions(opts) { | ||
@@ -484,3 +412,2 @@ const options = Object.assign({}, opts); | ||
delete options.exclude; | ||
if (Object.prototype.hasOwnProperty.call(options, "sourceMap")) { | ||
@@ -490,10 +417,7 @@ options.sourceMaps = options.sourceMap; | ||
} | ||
return options; | ||
} | ||
function dedupDescriptors(items) { | ||
const map = new Map(); | ||
const descriptors = []; | ||
for (const item of items) { | ||
@@ -503,3 +427,2 @@ if (typeof item.value === "function") { | ||
let nameMap = map.get(fnKey); | ||
if (!nameMap) { | ||
@@ -509,5 +432,3 @@ nameMap = new Map(); | ||
} | ||
let desc = nameMap.get(item.name); | ||
if (!desc) { | ||
@@ -528,3 +449,2 @@ desc = { | ||
} | ||
return descriptors.reduce((acc, desc) => { | ||
@@ -535,51 +455,44 @@ acc.push(desc.value); | ||
} | ||
function configIsApplicable({ | ||
options | ||
}, dirname, context) { | ||
return (options.test === undefined || configFieldIsApplicable(context, options.test, dirname)) && (options.include === undefined || configFieldIsApplicable(context, options.include, dirname)) && (options.exclude === undefined || !configFieldIsApplicable(context, options.exclude, dirname)); | ||
}, dirname, context, configName) { | ||
return (options.test === undefined || configFieldIsApplicable(context, options.test, dirname, configName)) && (options.include === undefined || configFieldIsApplicable(context, options.include, dirname, configName)) && (options.exclude === undefined || !configFieldIsApplicable(context, options.exclude, dirname, configName)); | ||
} | ||
function configFieldIsApplicable(context, test, dirname) { | ||
function configFieldIsApplicable(context, test, dirname, configName) { | ||
const patterns = Array.isArray(test) ? test : [test]; | ||
return matchesPatterns(context, patterns, dirname); | ||
return matchesPatterns(context, patterns, dirname, configName); | ||
} | ||
function ignoreListReplacer(_key, value) { | ||
if (value instanceof RegExp) { | ||
return String(value); | ||
} | ||
return value; | ||
} | ||
function shouldIgnore(context, ignore, only, dirname) { | ||
if (ignore && matchesPatterns(context, ignore, dirname)) { | ||
var _context$filename; | ||
const message = `No config is applied to "${(_context$filename = context.filename) != null ? _context$filename : "(unknown)"}" because it matches one of \`ignore: ${JSON.stringify(ignore)}\` from "${dirname}"`; | ||
const message = `No config is applied to "${(_context$filename = context.filename) != null ? _context$filename : "(unknown)"}" because it matches one of \`ignore: ${JSON.stringify(ignore, ignoreListReplacer)}\` from "${dirname}"`; | ||
debug(message); | ||
if (context.showConfig) { | ||
console.log(message); | ||
} | ||
return true; | ||
} | ||
if (only && !matchesPatterns(context, only, dirname)) { | ||
var _context$filename2; | ||
const message = `No config is applied to "${(_context$filename2 = context.filename) != null ? _context$filename2 : "(unknown)"}" because it fails to match one of \`only: ${JSON.stringify(only)}\` from "${dirname}"`; | ||
const message = `No config is applied to "${(_context$filename2 = context.filename) != null ? _context$filename2 : "(unknown)"}" because it fails to match one of \`only: ${JSON.stringify(only, ignoreListReplacer)}\` from "${dirname}"`; | ||
debug(message); | ||
if (context.showConfig) { | ||
console.log(message); | ||
} | ||
return true; | ||
} | ||
return false; | ||
} | ||
function matchesPatterns(context, patterns, dirname) { | ||
return patterns.some(pattern => matchPattern(pattern, dirname, context.filename, context)); | ||
function matchesPatterns(context, patterns, dirname, configName) { | ||
return patterns.some(pattern => matchPattern(pattern, dirname, context.filename, context, configName)); | ||
} | ||
function matchPattern(pattern, dirname, pathToTest, context) { | ||
function matchPattern(pattern, dirname, pathToTest, context, configName) { | ||
if (typeof pattern === "function") { | ||
return !!pattern(pathToTest, { | ||
return !!(0, _rewriteStackTrace.endHiddenCallStack)(pattern)(pathToTest, { | ||
dirname, | ||
@@ -590,12 +503,12 @@ envName: context.envName, | ||
} | ||
if (typeof pathToTest !== "string") { | ||
throw new Error(`Configuration contains string/RegExp pattern, but no filename was passed to Babel`); | ||
throw new _configError.default(`Configuration contains string/RegExp pattern, but no filename was passed to Babel`, configName); | ||
} | ||
if (typeof pattern === "string") { | ||
pattern = (0, _patternToRegex.default)(pattern, dirname); | ||
} | ||
return pattern.test(pathToTest); | ||
} | ||
0 && 0; | ||
return pattern.test(pathToTest); | ||
} | ||
//# sourceMappingURL=config-chain.js.map |
@@ -7,31 +7,22 @@ "use strict"; | ||
exports.createCachedDescriptors = createCachedDescriptors; | ||
exports.createDescriptor = createDescriptor; | ||
exports.createUncachedDescriptors = createUncachedDescriptors; | ||
exports.createDescriptor = createDescriptor; | ||
function _gensync() { | ||
const data = require("gensync"); | ||
_gensync = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _functional = require("../gensync-utils/functional"); | ||
var _files = require("./files"); | ||
var _item = require("./item"); | ||
var _caching = require("./caching"); | ||
var _resolveTargets = require("./resolve-targets"); | ||
function isEqualDescriptor(a, b) { | ||
return a.name === b.name && a.value === b.value && a.options === b.options && a.dirname === b.dirname && a.alias === b.alias && a.ownPass === b.ownPass && (a.file && a.file.request) === (b.file && b.file.request) && (a.file && a.file.resolved) === (b.file && b.file.resolved); | ||
} | ||
function* handlerOf(value) { | ||
return value; | ||
} | ||
function optionsWithResolvedBrowserslistConfigFile(options, dirname) { | ||
@@ -41,6 +32,4 @@ if (typeof options.browserslistConfigFile === "string") { | ||
} | ||
return options; | ||
} | ||
function createCachedDescriptors(dirname, options, alias) { | ||
@@ -58,28 +47,9 @@ const { | ||
} | ||
function createUncachedDescriptors(dirname, options, alias) { | ||
let plugins; | ||
let presets; | ||
return { | ||
options: optionsWithResolvedBrowserslistConfigFile(options, dirname), | ||
*plugins() { | ||
if (!plugins) { | ||
plugins = yield* createPluginDescriptors(options.plugins || [], dirname, alias); | ||
} | ||
return plugins; | ||
}, | ||
*presets() { | ||
if (!presets) { | ||
presets = yield* createPresetDescriptors(options.presets || [], dirname, alias, !!options.passPerPreset); | ||
} | ||
return presets; | ||
} | ||
plugins: (0, _functional.once)(() => createPluginDescriptors(options.plugins || [], dirname, alias)), | ||
presets: (0, _functional.once)(() => createPresetDescriptors(options.presets || [], dirname, alias, !!options.passPerPreset)) | ||
}; | ||
} | ||
const PRESET_DESCRIPTOR_CACHE = new WeakMap(); | ||
@@ -102,3 +72,2 @@ const createCachedPresetDescriptors = (0, _caching.makeWeakCacheSync)((items, cache) => { | ||
const DEFAULT_OPTIONS = {}; | ||
function loadCachedDescriptor(cache, desc) { | ||
@@ -111,3 +80,2 @@ const { | ||
let cacheByOptions = cache.get(value); | ||
if (!cacheByOptions) { | ||
@@ -117,5 +85,3 @@ cacheByOptions = new WeakMap(); | ||
} | ||
let possibilities = cacheByOptions.get(options); | ||
if (!possibilities) { | ||
@@ -125,24 +91,17 @@ possibilities = []; | ||
} | ||
if (possibilities.indexOf(desc) === -1) { | ||
const matches = possibilities.filter(possibility => isEqualDescriptor(possibility, desc)); | ||
if (matches.length > 0) { | ||
return matches[0]; | ||
} | ||
possibilities.push(desc); | ||
} | ||
return desc; | ||
} | ||
function* createPresetDescriptors(items, dirname, alias, passPerPreset) { | ||
return yield* createDescriptors("preset", items, dirname, alias, passPerPreset); | ||
} | ||
function* createPluginDescriptors(items, dirname, alias) { | ||
return yield* createDescriptors("plugin", items, dirname, alias); | ||
} | ||
function* createDescriptors(type, items, dirname, alias, ownPass) { | ||
@@ -157,3 +116,2 @@ const descriptors = yield* _gensync().all(items.map((item, index) => createDescriptor(item, dirname, { | ||
} | ||
function* createDescriptor(pair, dirname, { | ||
@@ -165,11 +123,8 @@ type, | ||
const desc = (0, _item.getItemDescriptor)(pair); | ||
if (desc) { | ||
return desc; | ||
} | ||
let name; | ||
let options; | ||
let value = pair; | ||
if (Array.isArray(value)) { | ||
@@ -182,6 +137,4 @@ if (value.length === 3) { | ||
} | ||
let file = undefined; | ||
let filepath = null; | ||
if (typeof value === "string") { | ||
@@ -191,3 +144,2 @@ if (typeof type !== "string") { | ||
} | ||
const resolver = type === "plugin" ? _files.loadPlugin : _files.loadPreset; | ||
@@ -204,7 +156,5 @@ const request = value; | ||
} | ||
if (!value) { | ||
throw new Error(`Unexpected falsy value: ${String(value)}`); | ||
} | ||
if (typeof value === "object" && value.__esModule) { | ||
@@ -217,11 +167,8 @@ if (value.default) { | ||
} | ||
if (typeof value !== "object" && typeof value !== "function") { | ||
throw new Error(`Unsupported format: ${typeof value}. Expected an object or a function.`); | ||
} | ||
if (filepath !== null && typeof value === "object" && value) { | ||
throw new Error(`Plugin/Preset files are not allowed to export objects, only functions. In ${filepath}`); | ||
} | ||
return { | ||
@@ -237,10 +184,7 @@ name, | ||
} | ||
function assertNoDuplicates(items) { | ||
const map = new Map(); | ||
for (const item of items) { | ||
if (typeof item.value !== "function") continue; | ||
let nameMap = map.get(item.value); | ||
if (!nameMap) { | ||
@@ -250,3 +194,2 @@ nameMap = new Set(); | ||
} | ||
if (nameMap.has(item.name)) { | ||
@@ -256,5 +199,7 @@ const conflicts = items.filter(i => i.value === item.value); | ||
} | ||
nameMap.add(item.name); | ||
} | ||
} | ||
} | ||
0 && 0; | ||
//# sourceMappingURL=config-descriptors.js.map |
@@ -6,2 +6,3 @@ "use strict"; | ||
}); | ||
exports.ROOT_CONFIG_FILENAMES = void 0; | ||
exports.findConfigUpwards = findConfigUpwards; | ||
@@ -12,187 +13,52 @@ exports.findRelativeConfig = findRelativeConfig; | ||
exports.resolveShowConfigPath = resolveShowConfigPath; | ||
exports.ROOT_CONFIG_FILENAMES = void 0; | ||
function _debug() { | ||
const data = require("debug"); | ||
_debug = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _fs() { | ||
const data = require("fs"); | ||
_fs = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _path() { | ||
const data = require("path"); | ||
_path = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _json() { | ||
const data = require("json5"); | ||
_json = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _gensync() { | ||
const data = require("gensync"); | ||
_gensync = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _caching = require("../caching"); | ||
var _configApi = require("../helpers/config-api"); | ||
var _utils = require("./utils"); | ||
var _moduleTypes = require("./module-types"); | ||
var _patternToRegex = require("../pattern-to-regex"); | ||
var _configError = require("../../errors/config-error"); | ||
var fs = require("../../gensync-utils/fs"); | ||
function _module() { | ||
const data = require("module"); | ||
_module = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _rewriteStackTrace = require("../../errors/rewrite-stack-trace"); | ||
const debug = _debug()("babel:config:loading:files:configuration"); | ||
const ROOT_CONFIG_FILENAMES = ["babel.config.js", "babel.config.cjs", "babel.config.mjs", "babel.config.json"]; | ||
const ROOT_CONFIG_FILENAMES = ["babel.config.js", "babel.config.cjs", "babel.config.mjs", "babel.config.json", "babel.config.cts"]; | ||
exports.ROOT_CONFIG_FILENAMES = ROOT_CONFIG_FILENAMES; | ||
const RELATIVE_CONFIG_FILENAMES = [".babelrc", ".babelrc.js", ".babelrc.cjs", ".babelrc.mjs", ".babelrc.json"]; | ||
const RELATIVE_CONFIG_FILENAMES = [".babelrc", ".babelrc.js", ".babelrc.cjs", ".babelrc.mjs", ".babelrc.json", ".babelrc.cts"]; | ||
const BABELIGNORE_FILENAME = ".babelignore"; | ||
function findConfigUpwards(rootDir) { | ||
let dirname = rootDir; | ||
for (;;) { | ||
for (const filename of ROOT_CONFIG_FILENAMES) { | ||
if (_fs().existsSync(_path().join(dirname, filename))) { | ||
return dirname; | ||
} | ||
} | ||
const nextDir = _path().dirname(dirname); | ||
if (dirname === nextDir) break; | ||
dirname = nextDir; | ||
} | ||
return null; | ||
} | ||
function* findRelativeConfig(packageData, envName, caller) { | ||
let config = null; | ||
let ignore = null; | ||
const dirname = _path().dirname(packageData.filepath); | ||
for (const loc of packageData.directories) { | ||
if (!config) { | ||
var _packageData$pkg; | ||
config = yield* loadOneConfig(RELATIVE_CONFIG_FILENAMES, loc, envName, caller, ((_packageData$pkg = packageData.pkg) == null ? void 0 : _packageData$pkg.dirname) === loc ? packageToBabelConfig(packageData.pkg) : null); | ||
} | ||
if (!ignore) { | ||
const ignoreLoc = _path().join(loc, BABELIGNORE_FILENAME); | ||
ignore = yield* readIgnoreConfig(ignoreLoc); | ||
if (ignore) { | ||
debug("Found ignore %o from %o.", ignore.filepath, dirname); | ||
} | ||
} | ||
} | ||
return { | ||
config, | ||
ignore | ||
}; | ||
} | ||
function findRootConfig(dirname, envName, caller) { | ||
return loadOneConfig(ROOT_CONFIG_FILENAMES, dirname, envName, caller); | ||
} | ||
function* loadOneConfig(names, dirname, envName, caller, previousConfig = null) { | ||
const configs = yield* _gensync().all(names.map(filename => readConfig(_path().join(dirname, filename), envName, caller))); | ||
const config = configs.reduce((previousConfig, config) => { | ||
if (config && previousConfig) { | ||
throw new Error(`Multiple configuration files found. Please remove one:\n` + ` - ${_path().basename(previousConfig.filepath)}\n` + ` - ${config.filepath}\n` + `from ${dirname}`); | ||
} | ||
return config || previousConfig; | ||
}, previousConfig); | ||
if (config) { | ||
debug("Found configuration %o from %o.", config.filepath, dirname); | ||
} | ||
return config; | ||
} | ||
function* loadConfig(name, dirname, envName, caller) { | ||
const filepath = (((v, w) => (v = v.split("."), w = w.split("."), +v[0] > +w[0] || v[0] == w[0] && +v[1] >= +w[1]))(process.versions.node, "8.9") ? require.resolve : (r, { | ||
paths: [b] | ||
}, M = require("module")) => { | ||
let f = M._findPath(r, M._nodeModulePaths(b).concat(b)); | ||
if (f) return f; | ||
f = new Error(`Cannot resolve module '${r}'`); | ||
f.code = "MODULE_NOT_FOUND"; | ||
throw f; | ||
})(name, { | ||
paths: [dirname] | ||
}); | ||
const conf = yield* readConfig(filepath, envName, caller); | ||
if (!conf) { | ||
throw new Error(`Config file ${filepath} contains no configuration data`); | ||
} | ||
debug("Loaded config %o from %o.", name, dirname); | ||
return conf; | ||
} | ||
function readConfig(filepath, envName, caller) { | ||
const ext = _path().extname(filepath); | ||
return ext === ".js" || ext === ".cjs" || ext === ".mjs" ? readConfigJS(filepath, { | ||
envName, | ||
caller | ||
}) : readConfigJSON5(filepath); | ||
} | ||
const LOADING_CONFIGS = new Set(); | ||
const readConfigJS = (0, _caching.makeStrongCache)(function* readConfigJS(filepath, cache) { | ||
const readConfigCode = (0, _caching.makeStrongCache)(function* readConfigCode(filepath, cache) { | ||
if (!_fs().existsSync(filepath)) { | ||
@@ -202,3 +68,2 @@ cache.never(); | ||
} | ||
if (LOADING_CONFIGS.has(filepath)) { | ||
@@ -213,32 +78,22 @@ cache.never(); | ||
} | ||
let options; | ||
try { | ||
LOADING_CONFIGS.add(filepath); | ||
options = yield* (0, _moduleTypes.default)(filepath, "You appear to be using a native ECMAScript module configuration " + "file, which is only supported when running Babel asynchronously."); | ||
} catch (err) { | ||
err.message = `${filepath}: Error while loading config - ${err.message}`; | ||
throw err; | ||
} finally { | ||
LOADING_CONFIGS.delete(filepath); | ||
} | ||
let assertCache = false; | ||
if (typeof options === "function") { | ||
yield* []; | ||
options = options((0, _configApi.makeConfigAPI)(cache)); | ||
options = (0, _rewriteStackTrace.endHiddenCallStack)(options)((0, _configApi.makeConfigAPI)(cache)); | ||
assertCache = true; | ||
} | ||
if (!options || typeof options !== "object" || Array.isArray(options)) { | ||
throw new Error(`${filepath}: Configuration should be an exported JavaScript object.`); | ||
throw new _configError.default(`Configuration should be an exported JavaScript object.`, filepath); | ||
} | ||
if (typeof options.then === "function") { | ||
throw new Error(`You appear to be using an async configuration, ` + `which your current version of Babel does not support. ` + `We may add support for this in the future, ` + `but if you're on the most recent version of @babel/core and still ` + `seeing this error, then you'll need to synchronously return your config.`); | ||
throw new _configError.default(`You appear to be using an async configuration, ` + `which your current version of Babel does not support. ` + `We may add support for this in the future, ` + `but if you're on the most recent version of @babel/core and still ` + `seeing this error, then you'll need to synchronously return your config.`, filepath); | ||
} | ||
if (assertCache && !cache.configured()) throwConfigError(); | ||
if (assertCache && !cache.configured()) throwConfigError(filepath); | ||
return { | ||
@@ -253,7 +108,5 @@ filepath, | ||
if (typeof babel === "undefined") return null; | ||
if (typeof babel !== "object" || Array.isArray(babel) || babel === null) { | ||
throw new Error(`${file.filepath}: .babel property must be an object`); | ||
throw new _configError.default(`.babel property must be an object`, file.filepath); | ||
} | ||
return { | ||
@@ -267,20 +120,15 @@ filepath: file.filepath, | ||
let options; | ||
try { | ||
options = _json().parse(content); | ||
} catch (err) { | ||
err.message = `${filepath}: Error while parsing config - ${err.message}`; | ||
throw err; | ||
throw new _configError.default(`Error while parsing config - ${err.message}`, filepath); | ||
} | ||
if (!options) throw new Error(`${filepath}: No config detected`); | ||
if (!options) throw new _configError.default(`No config detected`, filepath); | ||
if (typeof options !== "object") { | ||
throw new Error(`${filepath}: Config returned typeof ${typeof options}`); | ||
throw new _configError.default(`Config returned typeof ${typeof options}`, filepath); | ||
} | ||
if (Array.isArray(options)) { | ||
throw new Error(`${filepath}: Expected config object but found array`); | ||
throw new _configError.default(`Expected config object but found array`, filepath); | ||
} | ||
delete options["$schema"]; | ||
return { | ||
@@ -294,11 +142,8 @@ filepath, | ||
const ignoreDir = _path().dirname(filepath); | ||
const ignorePatterns = content.split("\n").map(line => line.replace(/#(.*?)$/, "").trim()).filter(line => !!line); | ||
for (const pattern of ignorePatterns) { | ||
if (pattern[0] === "!") { | ||
throw new Error(`Negation of file paths is not supported.`); | ||
throw new _configError.default(`Negation of file paths is not supported.`, filepath); | ||
} | ||
} | ||
return { | ||
@@ -310,23 +155,102 @@ filepath, | ||
}); | ||
function findConfigUpwards(rootDir) { | ||
let dirname = rootDir; | ||
for (;;) { | ||
for (const filename of ROOT_CONFIG_FILENAMES) { | ||
if (_fs().existsSync(_path().join(dirname, filename))) { | ||
return dirname; | ||
} | ||
} | ||
const nextDir = _path().dirname(dirname); | ||
if (dirname === nextDir) break; | ||
dirname = nextDir; | ||
} | ||
return null; | ||
} | ||
function* findRelativeConfig(packageData, envName, caller) { | ||
let config = null; | ||
let ignore = null; | ||
const dirname = _path().dirname(packageData.filepath); | ||
for (const loc of packageData.directories) { | ||
if (!config) { | ||
var _packageData$pkg; | ||
config = yield* loadOneConfig(RELATIVE_CONFIG_FILENAMES, loc, envName, caller, ((_packageData$pkg = packageData.pkg) == null ? void 0 : _packageData$pkg.dirname) === loc ? packageToBabelConfig(packageData.pkg) : null); | ||
} | ||
if (!ignore) { | ||
const ignoreLoc = _path().join(loc, BABELIGNORE_FILENAME); | ||
ignore = yield* readIgnoreConfig(ignoreLoc); | ||
if (ignore) { | ||
debug("Found ignore %o from %o.", ignore.filepath, dirname); | ||
} | ||
} | ||
} | ||
return { | ||
config, | ||
ignore | ||
}; | ||
} | ||
function findRootConfig(dirname, envName, caller) { | ||
return loadOneConfig(ROOT_CONFIG_FILENAMES, dirname, envName, caller); | ||
} | ||
function* loadOneConfig(names, dirname, envName, caller, previousConfig = null) { | ||
const configs = yield* _gensync().all(names.map(filename => readConfig(_path().join(dirname, filename), envName, caller))); | ||
const config = configs.reduce((previousConfig, config) => { | ||
if (config && previousConfig) { | ||
throw new _configError.default(`Multiple configuration files found. Please remove one:\n` + ` - ${_path().basename(previousConfig.filepath)}\n` + ` - ${config.filepath}\n` + `from ${dirname}`); | ||
} | ||
return config || previousConfig; | ||
}, previousConfig); | ||
if (config) { | ||
debug("Found configuration %o from %o.", config.filepath, dirname); | ||
} | ||
return config; | ||
} | ||
function* loadConfig(name, dirname, envName, caller) { | ||
const filepath = (((v, w) => (v = v.split("."), w = w.split("."), +v[0] > +w[0] || v[0] == w[0] && +v[1] >= +w[1]))(process.versions.node, "8.9") ? require.resolve : (r, { | ||
paths: [b] | ||
}, M = require("module")) => { | ||
let f = M._findPath(r, M._nodeModulePaths(b).concat(b)); | ||
if (f) return f; | ||
f = new Error(`Cannot resolve module '${r}'`); | ||
f.code = "MODULE_NOT_FOUND"; | ||
throw f; | ||
})(name, { | ||
paths: [dirname] | ||
}); | ||
const conf = yield* readConfig(filepath, envName, caller); | ||
if (!conf) { | ||
throw new _configError.default(`Config file contains no configuration data`, filepath); | ||
} | ||
debug("Loaded config %o from %o.", name, dirname); | ||
return conf; | ||
} | ||
function readConfig(filepath, envName, caller) { | ||
const ext = _path().extname(filepath); | ||
switch (ext) { | ||
case ".js": | ||
case ".cjs": | ||
case ".mjs": | ||
case ".cts": | ||
return readConfigCode(filepath, { | ||
envName, | ||
caller | ||
}); | ||
default: | ||
return readConfigJSON5(filepath); | ||
} | ||
} | ||
function* resolveShowConfigPath(dirname) { | ||
const targetPath = process.env.BABEL_SHOW_CONFIG_FOR; | ||
if (targetPath != null) { | ||
const absolutePath = _path().resolve(dirname, targetPath); | ||
const stats = yield* fs.stat(absolutePath); | ||
if (!stats.isFile()) { | ||
throw new Error(`${absolutePath}: BABEL_SHOW_CONFIG_FOR must refer to a regular file, directories are not supported.`); | ||
} | ||
return absolutePath; | ||
} | ||
return null; | ||
} | ||
function throwConfigError() { | ||
throw new Error(`\ | ||
function throwConfigError(filepath) { | ||
throw new _configError.default(`\ | ||
Caching was left unconfigured. Babel's plugins, presets, and .babelrc.js files can be configured | ||
@@ -364,3 +288,6 @@ for various types of caching, using the first param of their handler functions: | ||
return { }; | ||
};`); | ||
} | ||
};`, filepath); | ||
} | ||
0 && 0; | ||
//# sourceMappingURL=configuration.js.map |
@@ -6,2 +6,3 @@ "use strict"; | ||
}); | ||
exports.ROOT_CONFIG_FILENAMES = void 0; | ||
exports.findConfigUpwards = findConfigUpwards; | ||
@@ -12,13 +13,10 @@ exports.findPackageData = findPackageData; | ||
exports.loadConfig = loadConfig; | ||
exports.resolveShowConfigPath = resolveShowConfigPath; | ||
exports.loadPlugin = loadPlugin; | ||
exports.loadPreset = loadPreset; | ||
exports.resolvePlugin = resolvePlugin; | ||
exports.resolvePreset = resolvePreset; | ||
exports.loadPlugin = loadPlugin; | ||
exports.loadPreset = loadPreset; | ||
exports.ROOT_CONFIG_FILENAMES = void 0; | ||
exports.resolveShowConfigPath = resolveShowConfigPath; | ||
function findConfigUpwards(rootDir) { | ||
return null; | ||
} | ||
function* findPackageData(filepath) { | ||
@@ -32,3 +30,2 @@ return { | ||
} | ||
function* findRelativeConfig(pkgData, envName, caller) { | ||
@@ -40,32 +37,27 @@ return { | ||
} | ||
function* findRootConfig(dirname, envName, caller) { | ||
return null; | ||
} | ||
function* loadConfig(name, dirname, envName, caller) { | ||
throw new Error(`Cannot load ${name} relative to ${dirname} in a browser`); | ||
} | ||
function* resolveShowConfigPath(dirname) { | ||
return null; | ||
} | ||
const ROOT_CONFIG_FILENAMES = []; | ||
exports.ROOT_CONFIG_FILENAMES = ROOT_CONFIG_FILENAMES; | ||
function resolvePlugin(name, dirname) { | ||
return null; | ||
} | ||
function resolvePreset(name, dirname) { | ||
return null; | ||
} | ||
function loadPlugin(name, dirname) { | ||
throw new Error(`Cannot load plugin ${name} relative to ${dirname} in a browser`); | ||
} | ||
function loadPreset(name, dirname) { | ||
throw new Error(`Cannot load preset ${name} relative to ${dirname} in a browser`); | ||
} | ||
} | ||
0 && 0; | ||
//# sourceMappingURL=index-browser.js.map |
@@ -6,6 +6,6 @@ "use strict"; | ||
}); | ||
Object.defineProperty(exports, "findPackageData", { | ||
Object.defineProperty(exports, "ROOT_CONFIG_FILENAMES", { | ||
enumerable: true, | ||
get: function () { | ||
return _package.findPackageData; | ||
return _configuration.ROOT_CONFIG_FILENAMES; | ||
} | ||
@@ -19,2 +19,8 @@ }); | ||
}); | ||
Object.defineProperty(exports, "findPackageData", { | ||
enumerable: true, | ||
get: function () { | ||
return _package.findPackageData; | ||
} | ||
}); | ||
Object.defineProperty(exports, "findRelativeConfig", { | ||
@@ -38,12 +44,12 @@ enumerable: true, | ||
}); | ||
Object.defineProperty(exports, "resolveShowConfigPath", { | ||
Object.defineProperty(exports, "loadPlugin", { | ||
enumerable: true, | ||
get: function () { | ||
return _configuration.resolveShowConfigPath; | ||
return _plugins.loadPlugin; | ||
} | ||
}); | ||
Object.defineProperty(exports, "ROOT_CONFIG_FILENAMES", { | ||
Object.defineProperty(exports, "loadPreset", { | ||
enumerable: true, | ||
get: function () { | ||
return _configuration.ROOT_CONFIG_FILENAMES; | ||
return _plugins.loadPreset; | ||
} | ||
@@ -63,21 +69,14 @@ }); | ||
}); | ||
Object.defineProperty(exports, "loadPlugin", { | ||
Object.defineProperty(exports, "resolveShowConfigPath", { | ||
enumerable: true, | ||
get: function () { | ||
return _plugins.loadPlugin; | ||
return _configuration.resolveShowConfigPath; | ||
} | ||
}); | ||
Object.defineProperty(exports, "loadPreset", { | ||
enumerable: true, | ||
get: function () { | ||
return _plugins.loadPreset; | ||
} | ||
}); | ||
var _package = require("./package"); | ||
var _configuration = require("./configuration"); | ||
var _plugins = require("./plugins"); | ||
({}); | ||
0 && 0; | ||
({}); | ||
//# sourceMappingURL=index.js.map |
@@ -6,100 +6,151 @@ "use strict"; | ||
}); | ||
exports.default = loadCjsOrMjsDefault; | ||
exports.default = loadCodeDefault; | ||
exports.supportsESM = void 0; | ||
var _async = require("../../gensync-utils/async"); | ||
function _path() { | ||
const data = require("path"); | ||
_path = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _url() { | ||
const data = require("url"); | ||
_url = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _module() { | ||
const data = require("module"); | ||
_module = function () { | ||
function _semver() { | ||
const data = require("semver"); | ||
_semver = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _rewriteStackTrace = require("../../errors/rewrite-stack-trace"); | ||
var _configError = require("../../errors/config-error"); | ||
var _transformFile = require("../../transform-file"); | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } | ||
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } | ||
let import_; | ||
try { | ||
import_ = require("./import").default; | ||
import_ = require("./import.cjs"); | ||
} catch (_unused) {} | ||
function* loadCjsOrMjsDefault(filepath, asyncError, fallbackToTranspiledModule = false) { | ||
switch (guessJSModuleType(filepath)) { | ||
case "cjs": | ||
return loadCjsDefault(filepath, fallbackToTranspiledModule); | ||
case "unknown": | ||
const supportsESM = _semver().satisfies(process.versions.node, "^12.17 || >=13.2"); | ||
exports.supportsESM = supportsESM; | ||
function* loadCodeDefault(filepath, asyncError) { | ||
switch (_path().extname(filepath)) { | ||
case ".cjs": | ||
{ | ||
return loadCjsDefault(filepath, arguments[2]); | ||
} | ||
case ".mjs": | ||
break; | ||
case ".cts": | ||
return loadCtsDefault(filepath); | ||
default: | ||
try { | ||
return loadCjsDefault(filepath, fallbackToTranspiledModule); | ||
{ | ||
return loadCjsDefault(filepath, arguments[2]); | ||
} | ||
} catch (e) { | ||
if (e.code !== "ERR_REQUIRE_ESM") throw e; | ||
} | ||
case "mjs": | ||
if (yield* (0, _async.isAsync)()) { | ||
return yield* (0, _async.waitFor)(loadMjsDefault(filepath)); | ||
} | ||
if (yield* (0, _async.isAsync)()) { | ||
return yield* (0, _async.waitFor)(loadMjsDefault(filepath)); | ||
} | ||
throw new _configError.default(asyncError, filepath); | ||
} | ||
function loadCtsDefault(filepath) { | ||
const ext = ".cts"; | ||
const hasTsSupport = !!(require.extensions[".ts"] || require.extensions[".cts"] || require.extensions[".mts"]); | ||
let handler; | ||
if (!hasTsSupport) { | ||
const opts = { | ||
babelrc: false, | ||
configFile: false, | ||
sourceType: "unambiguous", | ||
sourceMaps: "inline", | ||
sourceFileName: _path().basename(filepath), | ||
presets: [[getTSPreset(filepath), Object.assign({ | ||
onlyRemoveTypeImports: true, | ||
optimizeConstEnums: true | ||
}, { | ||
allowDeclareFields: true | ||
})]] | ||
}; | ||
handler = function (m, filename) { | ||
if (handler && filename.endsWith(ext)) { | ||
try { | ||
return m._compile((0, _transformFile.transformFileSync)(filename, Object.assign({}, opts, { | ||
filename | ||
})).code, filename); | ||
} catch (error) { | ||
if (!hasTsSupport) { | ||
const packageJson = require("@babel/preset-typescript/package.json"); | ||
if (_semver().lt(packageJson.version, "7.21.4")) { | ||
console.error("`.cts` configuration file failed to load, please try to update `@babel/preset-typescript`."); | ||
} | ||
} | ||
throw error; | ||
} | ||
} | ||
throw new Error(asyncError); | ||
return require.extensions[".js"](m, filename); | ||
}; | ||
require.extensions[ext] = handler; | ||
} | ||
try { | ||
const module = (0, _rewriteStackTrace.endHiddenCallStack)(require)(filepath); | ||
return module != null && module.__esModule ? module.default : module; | ||
} finally { | ||
if (!hasTsSupport) { | ||
if (require.extensions[ext] === handler) delete require.extensions[ext]; | ||
handler = undefined; | ||
} | ||
} | ||
} | ||
function guessJSModuleType(filename) { | ||
switch (_path().extname(filename)) { | ||
case ".cjs": | ||
return "cjs"; | ||
case ".mjs": | ||
return "mjs"; | ||
default: | ||
return "unknown"; | ||
function loadCjsDefault(filepath) { | ||
const module = (0, _rewriteStackTrace.endHiddenCallStack)(require)(filepath); | ||
{ | ||
return module != null && module.__esModule ? module.default || (arguments[1] ? module : undefined) : module; | ||
} | ||
} | ||
function loadCjsDefault(filepath, fallbackToTranspiledModule) { | ||
const module = require(filepath); | ||
return module != null && module.__esModule ? module.default || (fallbackToTranspiledModule ? module : undefined) : module; | ||
} | ||
function loadMjsDefault(_x) { | ||
return _loadMjsDefault.apply(this, arguments); | ||
} | ||
function _loadMjsDefault() { | ||
_loadMjsDefault = _asyncToGenerator(function* (filepath) { | ||
if (!import_) { | ||
throw new Error("Internal error: Native ECMAScript modules aren't supported" + " by this platform.\n"); | ||
throw new _configError.default("Internal error: Native ECMAScript modules aren't supported by this platform.\n", filepath); | ||
} | ||
const module = yield import_((0, _url().pathToFileURL)(filepath)); | ||
const module = yield (0, _rewriteStackTrace.endHiddenCallStack)(import_)((0, _url().pathToFileURL)(filepath)); | ||
return module.default; | ||
}); | ||
return _loadMjsDefault.apply(this, arguments); | ||
} | ||
} | ||
function getTSPreset(filepath) { | ||
try { | ||
return require("@babel/preset-typescript"); | ||
} catch (error) { | ||
if (error.code !== "MODULE_NOT_FOUND") throw error; | ||
let message = "You appear to be using a .cts file as Babel configuration, but the `@babel/preset-typescript` package was not found: please install it!"; | ||
{ | ||
if (process.versions.pnp) { | ||
message += ` | ||
If you are using Yarn Plug'n'Play, you may also need to add the following configuration to your .yarnrc.yml file: | ||
packageExtensions: | ||
\t"@babel/core@*": | ||
\t\tpeerDependencies: | ||
\t\t\t"@babel/preset-typescript": "*" | ||
`; | ||
} | ||
} | ||
throw new _configError.default(message, filepath); | ||
} | ||
} | ||
0 && 0; | ||
//# sourceMappingURL=module-types.js.map |
@@ -7,17 +7,32 @@ "use strict"; | ||
exports.findPackageData = findPackageData; | ||
function _path() { | ||
const data = require("path"); | ||
_path = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _utils = require("./utils"); | ||
var _configError = require("../../errors/config-error"); | ||
const PACKAGE_FILENAME = "package.json"; | ||
const readConfigPackage = (0, _utils.makeStaticFileCache)((filepath, content) => { | ||
let options; | ||
try { | ||
options = JSON.parse(content); | ||
} catch (err) { | ||
throw new _configError.default(`Error while parsing JSON - ${err.message}`, filepath); | ||
} | ||
if (!options) throw new Error(`${filepath}: No config detected`); | ||
if (typeof options !== "object") { | ||
throw new _configError.default(`Config returned typeof ${typeof options}`, filepath); | ||
} | ||
if (Array.isArray(options)) { | ||
throw new _configError.default(`Expected config object but found array`, filepath); | ||
} | ||
return { | ||
filepath, | ||
dirname: _path().dirname(filepath), | ||
options | ||
}; | ||
}); | ||
function* findPackageData(filepath) { | ||
@@ -27,11 +42,7 @@ let pkg = null; | ||
let isPackage = true; | ||
let dirname = _path().dirname(filepath); | ||
while (!pkg && _path().basename(dirname) !== "node_modules") { | ||
directories.push(dirname); | ||
pkg = yield* readConfigPackage(_path().join(dirname, PACKAGE_FILENAME)); | ||
const nextLoc = _path().dirname(dirname); | ||
if (dirname === nextLoc) { | ||
@@ -41,6 +52,4 @@ isPackage = false; | ||
} | ||
dirname = nextLoc; | ||
} | ||
return { | ||
@@ -53,28 +62,4 @@ filepath, | ||
} | ||
0 && 0; | ||
const readConfigPackage = (0, _utils.makeStaticFileCache)((filepath, content) => { | ||
let options; | ||
try { | ||
options = JSON.parse(content); | ||
} catch (err) { | ||
err.message = `${filepath}: Error while parsing JSON - ${err.message}`; | ||
throw err; | ||
} | ||
if (!options) throw new Error(`${filepath}: No config detected`); | ||
if (typeof options !== "object") { | ||
throw new Error(`${filepath}: Config returned typeof ${typeof options}`); | ||
} | ||
if (Array.isArray(options)) { | ||
throw new Error(`${filepath}: Expected config object but found array`); | ||
} | ||
return { | ||
filepath, | ||
dirname: _path().dirname(filepath), | ||
options | ||
}; | ||
}); | ||
//# sourceMappingURL=package.js.map |
@@ -6,41 +6,30 @@ "use strict"; | ||
}); | ||
exports.resolvePlugin = resolvePlugin; | ||
exports.resolvePreset = resolvePreset; | ||
exports.loadPlugin = loadPlugin; | ||
exports.loadPreset = loadPreset; | ||
exports.resolvePreset = exports.resolvePlugin = void 0; | ||
function _debug() { | ||
const data = require("debug"); | ||
_debug = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _path() { | ||
const data = require("path"); | ||
_path = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _async = require("../../gensync-utils/async"); | ||
var _moduleTypes = require("./module-types"); | ||
function _module() { | ||
const data = require("module"); | ||
_module = function () { | ||
function _url() { | ||
const data = require("url"); | ||
_url = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _importMetaResolve = require("./import-meta-resolve"); | ||
const debug = _debug()("babel:config:loading:files:plugins"); | ||
const EXACT_RE = /^module:/; | ||
@@ -54,18 +43,8 @@ const BABEL_PLUGIN_PREFIX_RE = /^(?!@|module:|[^/]+\/|babel-plugin-)/; | ||
const OTHER_ORG_DEFAULT_RE = /^(@(?!babel$)[^/]+)$/; | ||
function resolvePlugin(name, dirname) { | ||
return resolveStandardizedName("plugin", name, dirname); | ||
} | ||
function resolvePreset(name, dirname) { | ||
return resolveStandardizedName("preset", name, dirname); | ||
} | ||
const resolvePlugin = resolveStandardizedName.bind(null, "plugin"); | ||
exports.resolvePlugin = resolvePlugin; | ||
const resolvePreset = resolveStandardizedName.bind(null, "preset"); | ||
exports.resolvePreset = resolvePreset; | ||
function* loadPlugin(name, dirname) { | ||
const filepath = resolvePlugin(name, dirname); | ||
if (!filepath) { | ||
throw new Error(`Plugin ${name} not found relative to ${dirname}`); | ||
} | ||
const filepath = resolvePlugin(name, dirname, yield* (0, _async.isAsync)()); | ||
const value = yield* requireModule("plugin", filepath); | ||
@@ -78,10 +57,4 @@ debug("Loaded plugin %o from %o.", name, dirname); | ||
} | ||
function* loadPreset(name, dirname) { | ||
const filepath = resolvePreset(name, dirname); | ||
if (!filepath) { | ||
throw new Error(`Preset ${name} not found relative to ${dirname}`); | ||
} | ||
const filepath = resolvePreset(name, dirname, yield* (0, _async.isAsync)()); | ||
const value = yield* requireModule("preset", filepath); | ||
@@ -94,3 +67,2 @@ debug("Loaded preset %o from %o.", name, dirname); | ||
} | ||
function standardizeName(type, name) { | ||
@@ -101,31 +73,45 @@ if (_path().isAbsolute(name)) return name; | ||
} | ||
function resolveStandardizedName(type, name, dirname = process.cwd()) { | ||
function* resolveAlternativesHelper(type, name) { | ||
const standardizedName = standardizeName(type, name); | ||
const { | ||
error, | ||
value | ||
} = yield standardizedName; | ||
if (!error) return value; | ||
if (error.code !== "MODULE_NOT_FOUND") throw error; | ||
if (standardizedName !== name && !(yield name).error) { | ||
error.message += `\n- If you want to resolve "${name}", use "module:${name}"`; | ||
} | ||
if (!(yield standardizeName(type, "@babel/" + name)).error) { | ||
error.message += `\n- Did you mean "@babel/${name}"?`; | ||
} | ||
const oppositeType = type === "preset" ? "plugin" : "preset"; | ||
if (!(yield standardizeName(oppositeType, name)).error) { | ||
error.message += `\n- Did you accidentally pass a ${oppositeType} as a ${type}?`; | ||
} | ||
if (type === "plugin") { | ||
const transformName = standardizedName.replace("-proposal-", "-transform-"); | ||
if (transformName !== standardizedName && !(yield transformName).error) { | ||
error.message += `\n- Did you mean "${transformName}"?`; | ||
} | ||
} | ||
error.message += `\n | ||
Make sure that all the Babel plugins and presets you are using | ||
are defined as dependencies or devDependencies in your package.json | ||
file. It's possible that the missing plugin is loaded by a preset | ||
you are using that forgot to add the plugin to its dependencies: you | ||
can workaround this problem by explicitly adding the missing package | ||
to your top-level package.json. | ||
`; | ||
throw error; | ||
} | ||
function tryRequireResolve(id, dirname) { | ||
try { | ||
return (((v, w) => (v = v.split("."), w = w.split("."), +v[0] > +w[0] || v[0] == w[0] && +v[1] >= +w[1]))(process.versions.node, "8.9") ? require.resolve : (r, { | ||
paths: [b] | ||
}, M = require("module")) => { | ||
let f = M._findPath(r, M._nodeModulePaths(b).concat(b)); | ||
if (f) return f; | ||
f = new Error(`Cannot resolve module '${r}'`); | ||
f.code = "MODULE_NOT_FOUND"; | ||
throw f; | ||
})(standardizedName, { | ||
paths: [dirname] | ||
}); | ||
} catch (e) { | ||
if (e.code !== "MODULE_NOT_FOUND") throw e; | ||
if (standardizedName !== name) { | ||
let resolvedOriginal = false; | ||
try { | ||
(((v, w) => (v = v.split("."), w = w.split("."), +v[0] > +w[0] || v[0] == w[0] && +v[1] >= +w[1]))(process.versions.node, "8.9") ? require.resolve : (r, { | ||
if (dirname) { | ||
return { | ||
error: null, | ||
value: (((v, w) => (v = v.split("."), w = w.split("."), +v[0] > +w[0] || v[0] == w[0] && +v[1] >= +w[1]))(process.versions.node, "8.9") ? require.resolve : (r, { | ||
paths: [b] | ||
}, M = require("module")) => { | ||
let f = M._findPath(r, M._nodeModulePaths(b).concat(b)); | ||
if (f) return f; | ||
@@ -135,72 +121,81 @@ f = new Error(`Cannot resolve module '${r}'`); | ||
throw f; | ||
})(name, { | ||
})(id, { | ||
paths: [dirname] | ||
}); | ||
resolvedOriginal = true; | ||
} catch (_unused) {} | ||
if (resolvedOriginal) { | ||
e.message += `\n- If you want to resolve "${name}", use "module:${name}"`; | ||
} | ||
}) | ||
}; | ||
} else { | ||
return { | ||
error: null, | ||
value: require.resolve(id) | ||
}; | ||
} | ||
let resolvedBabel = false; | ||
} catch (error) { | ||
return { | ||
error, | ||
value: null | ||
}; | ||
} | ||
} | ||
function tryImportMetaResolve(id, options) { | ||
try { | ||
return { | ||
error: null, | ||
value: (0, _importMetaResolve.default)(id, options) | ||
}; | ||
} catch (error) { | ||
return { | ||
error, | ||
value: null | ||
}; | ||
} | ||
} | ||
function resolveStandardizedNameForRequire(type, name, dirname) { | ||
const it = resolveAlternativesHelper(type, name); | ||
let res = it.next(); | ||
while (!res.done) { | ||
res = it.next(tryRequireResolve(res.value, dirname)); | ||
} | ||
return res.value; | ||
} | ||
function resolveStandardizedNameForImport(type, name, dirname) { | ||
const parentUrl = (0, _url().pathToFileURL)(_path().join(dirname, "./babel-virtual-resolve-base.js")).href; | ||
const it = resolveAlternativesHelper(type, name); | ||
let res = it.next(); | ||
while (!res.done) { | ||
res = it.next(tryImportMetaResolve(res.value, parentUrl)); | ||
} | ||
return (0, _url().fileURLToPath)(res.value); | ||
} | ||
function resolveStandardizedName(type, name, dirname, resolveESM) { | ||
if (!_moduleTypes.supportsESM || !resolveESM) { | ||
return resolveStandardizedNameForRequire(type, name, dirname); | ||
} | ||
try { | ||
return resolveStandardizedNameForImport(type, name, dirname); | ||
} catch (e) { | ||
try { | ||
(((v, w) => (v = v.split("."), w = w.split("."), +v[0] > +w[0] || v[0] == w[0] && +v[1] >= +w[1]))(process.versions.node, "8.9") ? require.resolve : (r, { | ||
paths: [b] | ||
}, M = require("module")) => { | ||
let f = M._findPath(r, M._nodeModulePaths(b).concat(b)); | ||
if (f) return f; | ||
f = new Error(`Cannot resolve module '${r}'`); | ||
f.code = "MODULE_NOT_FOUND"; | ||
throw f; | ||
})(standardizeName(type, "@babel/" + name), { | ||
paths: [dirname] | ||
}); | ||
resolvedBabel = true; | ||
} catch (_unused2) {} | ||
if (resolvedBabel) { | ||
e.message += `\n- Did you mean "@babel/${name}"?`; | ||
return resolveStandardizedNameForRequire(type, name, dirname); | ||
} catch (e2) { | ||
if (e.type === "MODULE_NOT_FOUND") throw e; | ||
if (e2.type === "MODULE_NOT_FOUND") throw e2; | ||
throw e; | ||
} | ||
let resolvedOppositeType = false; | ||
const oppositeType = type === "preset" ? "plugin" : "preset"; | ||
try { | ||
(((v, w) => (v = v.split("."), w = w.split("."), +v[0] > +w[0] || v[0] == w[0] && +v[1] >= +w[1]))(process.versions.node, "8.9") ? require.resolve : (r, { | ||
paths: [b] | ||
}, M = require("module")) => { | ||
let f = M._findPath(r, M._nodeModulePaths(b).concat(b)); | ||
if (f) return f; | ||
f = new Error(`Cannot resolve module '${r}'`); | ||
f.code = "MODULE_NOT_FOUND"; | ||
throw f; | ||
})(standardizeName(oppositeType, name), { | ||
paths: [dirname] | ||
}); | ||
resolvedOppositeType = true; | ||
} catch (_unused3) {} | ||
if (resolvedOppositeType) { | ||
e.message += `\n- Did you accidentally pass a ${oppositeType} as a ${type}?`; | ||
} | ||
throw e; | ||
} | ||
} | ||
const LOADING_MODULES = new Set(); | ||
{ | ||
var LOADING_MODULES = new Set(); | ||
} | ||
function* requireModule(type, name) { | ||
if (LOADING_MODULES.has(name)) { | ||
throw new Error(`Reentrant ${type} detected trying to load "${name}". This module is not ignored ` + "and is trying to load itself while compiling itself, leading to a dependency cycle. " + 'We recommend adding it to your "ignore" list in your babelrc, or to a .babelignore.'); | ||
{ | ||
if (!(yield* (0, _async.isAsync)()) && LOADING_MODULES.has(name)) { | ||
throw new Error(`Reentrant ${type} detected trying to load "${name}". This module is not ignored ` + "and is trying to load itself while compiling itself, leading to a dependency cycle. " + 'We recommend adding it to your "ignore" list in your babelrc, or to a .babelignore.'); | ||
} | ||
} | ||
try { | ||
LOADING_MODULES.add(name); | ||
return yield* (0, _moduleTypes.default)(name, `You appear to be using a native ECMAScript module ${type}, ` + "which is only supported when running Babel asynchronously.", true); | ||
{ | ||
LOADING_MODULES.add(name); | ||
} | ||
{ | ||
return yield* (0, _moduleTypes.default)(name, `You appear to be using a native ECMAScript module ${type}, ` + "which is only supported when running Babel asynchronously.", true); | ||
} | ||
} catch (err) { | ||
@@ -210,4 +205,9 @@ err.message = `[BABEL]: ${err.message} (While processing: ${name})`; | ||
} finally { | ||
LOADING_MODULES.delete(name); | ||
{ | ||
LOADING_MODULES.delete(name); | ||
} | ||
} | ||
} | ||
} | ||
0 && 0; | ||
//# sourceMappingURL=plugins.js.map |
@@ -7,32 +7,22 @@ "use strict"; | ||
exports.makeStaticFileCache = makeStaticFileCache; | ||
var _caching = require("../caching"); | ||
var fs = require("../../gensync-utils/fs"); | ||
function _fs2() { | ||
const data = require("fs"); | ||
_fs2 = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function makeStaticFileCache(fn) { | ||
return (0, _caching.makeStrongCache)(function* (filepath, cache) { | ||
const cached = cache.invalidate(() => fileMtime(filepath)); | ||
if (cached === null) { | ||
return null; | ||
} | ||
return fn(filepath, yield* fs.readFile(filepath, "utf8")); | ||
}); | ||
} | ||
function fileMtime(filepath) { | ||
if (!_fs2().existsSync(filepath)) return null; | ||
try { | ||
@@ -43,4 +33,6 @@ return +_fs2().statSync(filepath).mtime; | ||
} | ||
return null; | ||
} | ||
0 && 0; | ||
return null; | ||
} | ||
//# sourceMappingURL=utils.js.map |
@@ -7,56 +7,35 @@ "use strict"; | ||
exports.default = void 0; | ||
function _gensync() { | ||
const data = require("gensync"); | ||
_gensync = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _async = require("../gensync-utils/async"); | ||
var _util = require("./util"); | ||
var context = require("../index"); | ||
var _plugin = require("./plugin"); | ||
var _item = require("./item"); | ||
var _configChain = require("./config-chain"); | ||
var _deepArray = require("./helpers/deep-array"); | ||
function _traverse() { | ||
const data = require("@babel/traverse"); | ||
_traverse = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _caching = require("./caching"); | ||
var _options = require("./validation/options"); | ||
var _plugins = require("./validation/plugins"); | ||
var _configApi = require("./helpers/config-api"); | ||
var _partial = require("./partial"); | ||
var Context = require("./cache-contexts"); | ||
var _configError = require("../errors/config-error"); | ||
var _default = _gensync()(function* loadFullConfig(inputOpts) { | ||
var _opts$assumptions; | ||
const result = yield* (0, _partial.default)(inputOpts); | ||
if (!result) { | ||
return null; | ||
} | ||
const { | ||
@@ -67,7 +46,5 @@ options, | ||
} = result; | ||
if (fileHandling === "ignored") { | ||
return null; | ||
} | ||
const optionDefaults = {}; | ||
@@ -78,21 +55,15 @@ const { | ||
} = options; | ||
if (!plugins || !presets) { | ||
throw new Error("Assertion failure - plugins and presets exist"); | ||
} | ||
const presetContext = Object.assign({}, context, { | ||
targets: options.targets | ||
}); | ||
const toDescriptor = item => { | ||
const desc = (0, _item.getItemDescriptor)(item); | ||
if (!desc) { | ||
throw new Error("Assertion failure - must be config item"); | ||
} | ||
return desc; | ||
}; | ||
const presetsDescriptors = presets.map(toDescriptor); | ||
@@ -102,21 +73,10 @@ const initialPluginsDescriptors = plugins.map(toDescriptor); | ||
const passes = []; | ||
const externalDependencies = []; | ||
const ignored = yield* enhanceError(context, function* recursePresetDescriptors(rawPresets, pluginDescriptorsPass) { | ||
const presets = []; | ||
for (let i = 0; i < rawPresets.length; i++) { | ||
const descriptor = rawPresets[i]; | ||
if (descriptor.options !== false) { | ||
try { | ||
if (descriptor.ownPass) { | ||
presets.push({ | ||
preset: yield* loadPresetDescriptor(descriptor, presetContext), | ||
pass: [] | ||
}); | ||
} else { | ||
presets.unshift({ | ||
preset: yield* loadPresetDescriptor(descriptor, presetContext), | ||
pass: pluginDescriptorsPass | ||
}); | ||
} | ||
var preset = yield* loadPresetDescriptor(descriptor, presetContext); | ||
} catch (e) { | ||
@@ -126,11 +86,20 @@ if (e.code === "BABEL_UNKNOWN_OPTION") { | ||
} | ||
throw e; | ||
} | ||
externalDependencies.push(preset.externalDependencies); | ||
if (descriptor.ownPass) { | ||
presets.push({ | ||
preset: preset.chain, | ||
pass: [] | ||
}); | ||
} else { | ||
presets.unshift({ | ||
preset: preset.chain, | ||
pass: pluginDescriptorsPass | ||
}); | ||
} | ||
} | ||
} | ||
if (presets.length > 0) { | ||
pluginDescriptorsByPass.splice(1, 0, ...presets.map(o => o.pass).filter(p => p !== pluginDescriptorsPass)); | ||
for (const { | ||
@@ -158,13 +127,10 @@ preset, | ||
pluginDescriptorsByPass[0].unshift(...initialPluginsDescriptors); | ||
for (const descs of pluginDescriptorsByPass) { | ||
const pass = []; | ||
passes.push(pass); | ||
for (let i = 0; i < descs.length; i++) { | ||
const descriptor = descs[i]; | ||
if (descriptor.options !== false) { | ||
try { | ||
pass.push(yield* loadPluginDescriptor(descriptor, pluginContext)); | ||
var plugin = yield* loadPluginDescriptor(descriptor, pluginContext); | ||
} catch (e) { | ||
@@ -174,5 +140,6 @@ if (e.code === "BABEL_UNKNOWN_PLUGIN_PROPERTY") { | ||
} | ||
throw e; | ||
} | ||
pass.push(plugin); | ||
externalDependencies.push(plugin.externalDependencies); | ||
} | ||
@@ -189,8 +156,7 @@ } | ||
options: opts, | ||
passes: passes | ||
passes: passes, | ||
externalDependencies: (0, _deepArray.finalize)(externalDependencies) | ||
}; | ||
}); | ||
exports.default = _default; | ||
function enhanceError(context, fn) { | ||
@@ -202,5 +168,5 @@ return function* (arg1, arg2) { | ||
if (!/^\[BABEL\]/.test(e.message)) { | ||
e.message = `[BABEL] ${context.filename || "unknown"}: ${e.message}`; | ||
var _context$filename; | ||
e.message = `[BABEL] ${(_context$filename = context.filename) != null ? _context$filename : "unknown file"}: ${e.message}`; | ||
} | ||
throw e; | ||
@@ -210,3 +176,2 @@ } | ||
} | ||
const makeDescriptorLoader = apiFactory => (0, _caching.makeWeakCache)(function* ({ | ||
@@ -220,8 +185,7 @@ value, | ||
options = options || {}; | ||
const externalDependencies = []; | ||
let item = value; | ||
if (typeof value === "function") { | ||
const factory = (0, _async.maybeAsync)(value, `You appear to be using an async plugin/preset, but Babel has been called synchronously`); | ||
const api = Object.assign({}, context, apiFactory(cache)); | ||
const api = Object.assign({}, context, apiFactory(cache, externalDependencies)); | ||
try { | ||
@@ -233,11 +197,8 @@ item = yield* factory(api, options, dirname); | ||
} | ||
throw e; | ||
} | ||
} | ||
if (!item || typeof item !== "object") { | ||
throw new Error("Plugin/Preset did not return an object."); | ||
} | ||
if ((0, _async.isThenable)(item)) { | ||
@@ -247,3 +208,12 @@ yield* []; | ||
} | ||
if (externalDependencies.length > 0 && (!cache.configured() || cache.mode() === "forever")) { | ||
let error = `A plugin/preset has external untracked dependencies ` + `(${externalDependencies[0]}), but the cache `; | ||
if (!cache.configured()) { | ||
error += `has not been configured to be invalidated when the external dependencies change. `; | ||
} else { | ||
error += ` has been configured to never be invalidated. `; | ||
} | ||
error += `Plugins/presets should configure their cache to be invalidated when the external ` + `dependencies change, for example using \`api.cache.invalidate(() => ` + `statSync(filepath).mtimeMs)\` or \`api.cache.never()\`\n` + `(While processing: ${JSON.stringify(alias)})`; | ||
throw new Error(error); | ||
} | ||
return { | ||
@@ -253,21 +223,8 @@ value: item, | ||
dirname, | ||
alias | ||
alias, | ||
externalDependencies: (0, _deepArray.finalize)(externalDependencies) | ||
}; | ||
}); | ||
const pluginDescriptorLoader = makeDescriptorLoader(_configApi.makePluginAPI); | ||
const presetDescriptorLoader = makeDescriptorLoader(_configApi.makePresetAPI); | ||
function* loadPluginDescriptor(descriptor, context) { | ||
if (descriptor.value instanceof _plugin.default) { | ||
if (descriptor.options) { | ||
throw new Error("Passed options to an existing Plugin instance will not work."); | ||
} | ||
return descriptor.value; | ||
} | ||
return yield* instantiatePlugin(yield* pluginDescriptorLoader(descriptor, context), context); | ||
} | ||
const instantiatePlugin = (0, _caching.makeWeakCache)(function* ({ | ||
@@ -277,11 +234,10 @@ value, | ||
dirname, | ||
alias | ||
alias, | ||
externalDependencies | ||
}, cache) { | ||
const pluginObj = (0, _plugins.validatePluginObject)(value); | ||
const plugin = Object.assign({}, pluginObj); | ||
if (plugin.visitor) { | ||
plugin.visitor = _traverse().default.explode(Object.assign({}, plugin.visitor)); | ||
} | ||
if (plugin.inherits) { | ||
@@ -302,14 +258,28 @@ const inheritsDescriptor = { | ||
plugin.visitor = _traverse().default.visitors.merge([inherits.visitor || {}, plugin.visitor || {}]); | ||
if (inherits.externalDependencies.length > 0) { | ||
if (externalDependencies.length === 0) { | ||
externalDependencies = inherits.externalDependencies; | ||
} else { | ||
externalDependencies = (0, _deepArray.finalize)([externalDependencies, inherits.externalDependencies]); | ||
} | ||
} | ||
} | ||
return new _plugin.default(plugin, options, alias); | ||
return new _plugin.default(plugin, options, alias, externalDependencies); | ||
}); | ||
function* loadPluginDescriptor(descriptor, context) { | ||
if (descriptor.value instanceof _plugin.default) { | ||
if (descriptor.options) { | ||
throw new Error("Passed options to an existing Plugin instance will not work."); | ||
} | ||
return descriptor.value; | ||
} | ||
return yield* instantiatePlugin(yield* pluginDescriptorLoader(descriptor, context), context); | ||
} | ||
const needsFilename = val => val && typeof val !== "function"; | ||
const validateIfOptionNeedsFilename = (options, descriptor) => { | ||
if (options.test || options.include || options.exclude) { | ||
if (needsFilename(options.test) || needsFilename(options.include) || needsFilename(options.exclude)) { | ||
const formattedPresetName = descriptor.name ? `"${descriptor.name}"` : "/* your preset */"; | ||
throw new Error([`Preset ${formattedPresetName} requires a filename to be set when babel is called directly,`, `\`\`\``, `babel.transform(code, { filename: 'file.ts', presets: [${formattedPresetName}] });`, `\`\`\``, `See https://babeljs.io/docs/en/options#filename for more information.`].join("\n")); | ||
throw new _configError.default([`Preset ${formattedPresetName} requires a filename to be set when babel is called directly,`, `\`\`\``, `babel.transformSync(code, { filename: 'file.ts', presets: [${formattedPresetName}] });`, `\`\`\``, `See https://babeljs.io/docs/en/options#filename for more information.`].join("\n")); | ||
} | ||
}; | ||
const validatePreset = (preset, context, descriptor) => { | ||
@@ -321,3 +291,2 @@ if (!context.filename) { | ||
validateIfOptionNeedsFilename(options, descriptor); | ||
if (options.overrides) { | ||
@@ -328,13 +297,7 @@ options.overrides.forEach(overrideOptions => validateIfOptionNeedsFilename(overrideOptions, descriptor)); | ||
}; | ||
function* loadPresetDescriptor(descriptor, context) { | ||
const preset = instantiatePreset(yield* presetDescriptorLoader(descriptor, context)); | ||
validatePreset(preset, context, descriptor); | ||
return yield* (0, _configChain.buildPresetChain)(preset, context); | ||
} | ||
const instantiatePreset = (0, _caching.makeWeakCacheSync)(({ | ||
value, | ||
dirname, | ||
alias | ||
alias, | ||
externalDependencies | ||
}) => { | ||
@@ -344,6 +307,14 @@ return { | ||
alias, | ||
dirname | ||
dirname, | ||
externalDependencies | ||
}; | ||
}); | ||
function* loadPresetDescriptor(descriptor, context) { | ||
const preset = instantiatePreset(yield* presetDescriptorLoader(descriptor, context)); | ||
validatePreset(preset, context, descriptor); | ||
return { | ||
chain: yield* (0, _configChain.buildPresetChain)(preset, context), | ||
externalDependencies: preset.externalDependencies | ||
}; | ||
} | ||
function chain(a, b) { | ||
@@ -357,2 +328,5 @@ const fns = [a, b].filter(Boolean); | ||
}; | ||
} | ||
} | ||
0 && 0; | ||
//# sourceMappingURL=full.js.map |
@@ -7,41 +7,27 @@ "use strict"; | ||
exports.makeConfigAPI = makeConfigAPI; | ||
exports.makePluginAPI = makePluginAPI; | ||
exports.makePresetAPI = makePresetAPI; | ||
exports.makePluginAPI = makePluginAPI; | ||
function _semver() { | ||
const data = require("semver"); | ||
_semver = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _ = require("../../"); | ||
var _caching = require("../caching"); | ||
var Context = require("../cache-contexts"); | ||
function makeConfigAPI(cache) { | ||
const env = value => cache.using(data => { | ||
if (typeof value === "undefined") return data.envName; | ||
if (typeof value === "function") { | ||
return (0, _caching.assertSimpleType)(value(data.envName)); | ||
} | ||
if (!Array.isArray(value)) value = [value]; | ||
return value.some(entry => { | ||
return (Array.isArray(value) ? value : [value]).some(entry => { | ||
if (typeof entry !== "string") { | ||
throw new Error("Unexpected non-string value"); | ||
} | ||
return entry === data.envName; | ||
}); | ||
}); | ||
const caller = cb => cache.using(data => (0, _caching.assertSimpleType)(cb(data.caller))); | ||
return { | ||
@@ -56,19 +42,18 @@ version: _.version, | ||
} | ||
function makePresetAPI(cache) { | ||
function makePresetAPI(cache, externalDependencies) { | ||
const targets = () => JSON.parse(cache.using(data => JSON.stringify(data.targets))); | ||
const addExternalDependency = ref => { | ||
externalDependencies.push(ref); | ||
}; | ||
return Object.assign({}, makeConfigAPI(cache), { | ||
targets | ||
targets, | ||
addExternalDependency | ||
}); | ||
} | ||
function makePluginAPI(cache) { | ||
function makePluginAPI(cache, externalDependencies) { | ||
const assumption = name => cache.using(data => data.assumptions[name]); | ||
return Object.assign({}, makePresetAPI(cache), { | ||
return Object.assign({}, makePresetAPI(cache, externalDependencies), { | ||
assumption | ||
}); | ||
} | ||
function assertVersion(range) { | ||
@@ -79,23 +64,17 @@ if (typeof range === "number") { | ||
} | ||
range = `^${range}.0.0-0`; | ||
} | ||
if (typeof range !== "string") { | ||
throw new Error("Expected string or integer value."); | ||
} | ||
; | ||
if (_semver().satisfies(_.version, range)) return; | ||
const limit = Error.stackTraceLimit; | ||
if (typeof limit === "number" && limit < 25) { | ||
Error.stackTraceLimit = 25; | ||
} | ||
const err = new Error(`Requires Babel "${range}", but was loaded with "${_.version}". ` + `If you are sure you have a compatible version of @babel/core, ` + `it is likely that something in your build process is loading the ` + `wrong version. Inspect the stack trace of this error to look for ` + `the first entry that doesn't mention "@babel/core" or "babel-core" ` + `to see what is calling Babel.`); | ||
if (typeof limit === "number") { | ||
Error.stackTraceLimit = limit; | ||
} | ||
throw Object.assign(err, { | ||
@@ -106,2 +85,5 @@ code: "BABEL_VERSION_UNSUPPORTED", | ||
}); | ||
} | ||
} | ||
0 && 0; | ||
//# sourceMappingURL=config-api.js.map |
@@ -7,5 +7,7 @@ "use strict"; | ||
exports.getEnv = getEnv; | ||
function getEnv(defaultValue = "development") { | ||
return process.env.BABEL_ENV || process.env.NODE_ENV || defaultValue; | ||
} | ||
} | ||
0 && 0; | ||
//# sourceMappingURL=environment.js.map |
@@ -7,2 +7,3 @@ "use strict"; | ||
exports.createConfigItem = createConfigItem; | ||
exports.createConfigItemSync = exports.createConfigItemAsync = void 0; | ||
Object.defineProperty(exports, "default", { | ||
@@ -14,38 +15,34 @@ enumerable: true, | ||
}); | ||
exports.createConfigItemAsync = exports.createConfigItemSync = exports.loadOptionsAsync = exports.loadOptionsSync = exports.loadOptions = exports.loadPartialConfigAsync = exports.loadPartialConfigSync = exports.loadPartialConfig = void 0; | ||
exports.loadPartialConfigSync = exports.loadPartialConfigAsync = exports.loadPartialConfig = exports.loadOptionsSync = exports.loadOptionsAsync = exports.loadOptions = void 0; | ||
function _gensync() { | ||
const data = require("gensync"); | ||
_gensync = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _full = require("./full"); | ||
var _partial = require("./partial"); | ||
var _item = require("./item"); | ||
const loadOptionsRunner = _gensync()(function* (opts) { | ||
var _config$options; | ||
const config = yield* (0, _full.default)(opts); | ||
return (_config$options = config == null ? void 0 : config.options) != null ? _config$options : null; | ||
}); | ||
const createConfigItemRunner = _gensync()(_item.createConfigItem); | ||
const maybeErrback = runner => (opts, callback) => { | ||
if (callback === undefined && typeof opts === "function") { | ||
callback = opts; | ||
opts = undefined; | ||
const maybeErrback = runner => (argOrCallback, maybeCallback) => { | ||
let arg; | ||
let callback; | ||
if (maybeCallback === undefined && typeof argOrCallback === "function") { | ||
callback = argOrCallback; | ||
arg = undefined; | ||
} else { | ||
callback = maybeCallback; | ||
arg = argOrCallback; | ||
} | ||
return callback ? runner.errback(opts, callback) : runner.sync(opts); | ||
if (!callback) { | ||
return runner.sync(arg); | ||
} | ||
runner.errback(arg, callback); | ||
}; | ||
const loadPartialConfig = maybeErrback(_partial.loadPartialConfig); | ||
@@ -67,11 +64,13 @@ exports.loadPartialConfig = loadPartialConfig; | ||
exports.createConfigItemAsync = createConfigItemAsync; | ||
function createConfigItem(target, options, callback) { | ||
if (callback !== undefined) { | ||
return createConfigItemRunner.errback(target, options, callback); | ||
createConfigItemRunner.errback(target, options, callback); | ||
} else if (typeof options === "function") { | ||
return createConfigItemRunner.errback(target, undefined, callback); | ||
createConfigItemRunner.errback(target, undefined, callback); | ||
} else { | ||
return createConfigItemRunner.sync(target, options); | ||
} | ||
} | ||
} | ||
0 && 0; | ||
//# sourceMappingURL=index.js.map |
@@ -6,22 +6,16 @@ "use strict"; | ||
}); | ||
exports.createConfigItem = createConfigItem; | ||
exports.createItemFromDescriptor = createItemFromDescriptor; | ||
exports.createConfigItem = createConfigItem; | ||
exports.getItemDescriptor = getItemDescriptor; | ||
function _path() { | ||
const data = require("path"); | ||
_path = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _configDescriptors = require("./config-descriptors"); | ||
function createItemFromDescriptor(desc) { | ||
return new ConfigItem(desc); | ||
} | ||
function* createConfigItem(value, { | ||
@@ -37,3 +31,3 @@ dirname = ".", | ||
} | ||
const CONFIG_ITEM_BRAND = Symbol.for("@babel/core@7 - ConfigItem"); | ||
function getItemDescriptor(item) { | ||
@@ -43,8 +37,4 @@ if (item != null && item[CONFIG_ITEM_BRAND]) { | ||
} | ||
return undefined; | ||
} | ||
const CONFIG_ITEM_BRAND = Symbol.for("@babel/core@7 - ConfigItem"); | ||
class ConfigItem { | ||
@@ -76,5 +66,6 @@ constructor(descriptor) { | ||
} | ||
} | ||
Object.freeze(ConfigItem.prototype); | ||
0 && 0; | ||
Object.freeze(ConfigItem.prototype); | ||
//# sourceMappingURL=item.js.map |
@@ -8,41 +8,26 @@ "use strict"; | ||
exports.loadPartialConfig = void 0; | ||
function _path() { | ||
const data = require("path"); | ||
_path = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _gensync() { | ||
const data = require("gensync"); | ||
_gensync = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _plugin = require("./plugin"); | ||
var _util = require("./util"); | ||
var _item = require("./item"); | ||
var _configChain = require("./config-chain"); | ||
var _environment = require("./helpers/environment"); | ||
var _options = require("./validation/options"); | ||
var _files = require("./files"); | ||
var _resolveTargets = require("./resolve-targets"); | ||
const _excluded = ["showIgnoredFiles"]; | ||
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } | ||
function resolveRootMode(rootDir, rootMode) { | ||
@@ -52,3 +37,2 @@ switch (rootMode) { | ||
return rootDir; | ||
case "upward-optional": | ||
@@ -59,3 +43,2 @@ { | ||
} | ||
case "upward": | ||
@@ -70,3 +53,2 @@ { | ||
} | ||
default: | ||
@@ -76,3 +58,2 @@ throw new Error(`Assertion failure - unknown rootMode value.`); | ||
} | ||
function* loadPrivatePartialConfig(inputOpts) { | ||
@@ -82,3 +63,2 @@ if (inputOpts != null && (typeof inputOpts !== "object" || Array.isArray(inputOpts))) { | ||
} | ||
const args = inputOpts ? (0, _options.validate)("arguments", inputOpts) : {}; | ||
@@ -93,5 +73,3 @@ const { | ||
} = args; | ||
const absoluteCwd = _path().resolve(cwd); | ||
const absoluteRootDir = resolveRootMode(_path().resolve(absoluteCwd, rootDir), rootMode); | ||
@@ -141,6 +119,4 @@ const filename = typeof args.filename === "string" ? _path().resolve(cwd, args.filename) : undefined; | ||
} | ||
const loadPartialConfig = _gensync()(function* (opts) { | ||
let showIgnoredFiles = false; | ||
if (typeof opts === "object" && opts !== null && !Array.isArray(opts)) { | ||
@@ -151,6 +127,5 @@ var _opts = opts; | ||
} = _opts); | ||
opts = _objectWithoutPropertiesLoose(_opts, ["showIgnoredFiles"]); | ||
opts = _objectWithoutPropertiesLoose(_opts, _excluded); | ||
_opts; | ||
} | ||
const result = yield* loadPrivatePartialConfig(opts); | ||
@@ -166,7 +141,5 @@ if (!result) return null; | ||
} = result; | ||
if (fileHandling === "ignored" && !showIgnoredFiles) { | ||
return null; | ||
} | ||
(options.plugins || []).forEach(item => { | ||
@@ -179,5 +152,3 @@ if (item.value instanceof _plugin.default) { | ||
}); | ||
exports.loadPartialConfig = loadPartialConfig; | ||
class PartialConfig { | ||
@@ -199,9 +170,9 @@ constructor(options, babelrc, ignore, config, fileHandling, files) { | ||
} | ||
hasFilesystemConfig() { | ||
return this.babelrc !== undefined || this.config !== undefined; | ||
} | ||
} | ||
Object.freeze(PartialConfig.prototype); | ||
0 && 0; | ||
Object.freeze(PartialConfig.prototype); | ||
//# sourceMappingURL=partial.js.map |
@@ -7,13 +7,9 @@ "use strict"; | ||
exports.default = pathToPattern; | ||
function _path() { | ||
const data = require("path"); | ||
_path = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
const sep = `\\${_path().sep}`; | ||
@@ -26,10 +22,7 @@ const endSep = `(?:${sep}|$)`; | ||
const starStarPatLast = `${starPat}*?${starPatLast}?`; | ||
function escapeRegExp(string) { | ||
return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&"); | ||
} | ||
function pathToPattern(pattern, dirname) { | ||
const parts = _path().resolve(dirname, pattern).split(_path().sep); | ||
return new RegExp(["^", ...parts.map((part, i) => { | ||
@@ -39,9 +32,10 @@ const last = i === parts.length - 1; | ||
if (part === "*") return last ? starPatLast : starPat; | ||
if (part.indexOf("*.") === 0) { | ||
return substitution + escapeRegExp(part.slice(1)) + (last ? endSep : sep); | ||
} | ||
return escapeRegExp(part) + (last ? endSep : sep); | ||
})].join("")); | ||
} | ||
} | ||
0 && 0; | ||
//# sourceMappingURL=pattern-to-regex.js.map |
@@ -7,5 +7,5 @@ "use strict"; | ||
exports.default = void 0; | ||
var _deepArray = require("./helpers/deep-array"); | ||
class Plugin { | ||
constructor(plugin, options, key) { | ||
constructor(plugin, options, key, externalDependencies = (0, _deepArray.finalize)([])) { | ||
this.key = void 0; | ||
@@ -19,2 +19,3 @@ this.manipulateOptions = void 0; | ||
this.options = void 0; | ||
this.externalDependencies = void 0; | ||
this.key = plugin.name || key; | ||
@@ -28,6 +29,8 @@ this.manipulateOptions = plugin.manipulateOptions; | ||
this.options = options; | ||
this.externalDependencies = externalDependencies; | ||
} | ||
} | ||
exports.default = Plugin; | ||
0 && 0; | ||
exports.default = Plugin; | ||
//# sourceMappingURL=plugin.js.map |
@@ -7,13 +7,9 @@ "use strict"; | ||
exports.ConfigPrinter = exports.ChainFormatter = void 0; | ||
function _gensync() { | ||
const data = require("gensync"); | ||
_gensync = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
const ChainFormatter = { | ||
@@ -27,6 +23,4 @@ Programmatic: 0, | ||
let title = ""; | ||
if (type === ChainFormatter.Programmatic) { | ||
title = "programmatic options"; | ||
if (callerName) { | ||
@@ -38,20 +32,14 @@ title += " from " + callerName; | ||
} | ||
return title; | ||
}, | ||
loc(index, envName) { | ||
let loc = ""; | ||
if (index != null) { | ||
loc += `.overrides[${index}]`; | ||
} | ||
if (envName != null) { | ||
loc += `.env["${envName}"]`; | ||
} | ||
return loc; | ||
}, | ||
*optionsAndDescriptors(opt) { | ||
@@ -62,23 +50,15 @@ const content = Object.assign({}, opt.options); | ||
const pluginDescriptors = [...(yield* opt.plugins())]; | ||
if (pluginDescriptors.length) { | ||
content.plugins = pluginDescriptors.map(d => descriptorToConfig(d)); | ||
} | ||
const presetDescriptors = [...(yield* opt.presets())]; | ||
if (presetDescriptors.length) { | ||
content.presets = [...presetDescriptors].map(d => descriptorToConfig(d)); | ||
} | ||
return JSON.stringify(content, undefined, 2); | ||
} | ||
}; | ||
function descriptorToConfig(d) { | ||
var _d$file; | ||
let name = (_d$file = d.file) == null ? void 0 : _d$file.request; | ||
if (name == null) { | ||
@@ -88,10 +68,8 @@ if (typeof d.value === "object") { | ||
} else if (typeof d.value === "function") { | ||
name = `[Function: ${d.value.toString().substr(0, 50)} ... ]`; | ||
name = `[Function: ${d.value.toString().slice(0, 50)} ... ]`; | ||
} | ||
} | ||
if (name == null) { | ||
name = "[Unknown]"; | ||
} | ||
if (d.options === undefined) { | ||
@@ -105,3 +83,2 @@ return name; | ||
} | ||
class ConfigPrinter { | ||
@@ -111,3 +88,2 @@ constructor() { | ||
} | ||
configure(enabled, type, { | ||
@@ -129,3 +105,2 @@ callerName, | ||
} | ||
static *format(config) { | ||
@@ -138,3 +113,2 @@ let title = Formatter.title(config.type, config.callerName, config.filepath); | ||
} | ||
*output() { | ||
@@ -145,5 +119,6 @@ if (this._stack.length === 0) return ""; | ||
} | ||
} | ||
exports.ConfigPrinter = ConfigPrinter; | ||
0 && 0; | ||
exports.ConfigPrinter = ConfigPrinter; | ||
//# sourceMappingURL=printer.js.map |
@@ -8,32 +8,28 @@ "use strict"; | ||
exports.resolveTargets = resolveTargets; | ||
function _helperCompilationTargets() { | ||
const data = require("@babel/helper-compilation-targets"); | ||
_helperCompilationTargets = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function resolveBrowserslistConfigFile(browserslistConfigFile, configFilePath) { | ||
return undefined; | ||
} | ||
function resolveTargets(options, root) { | ||
let targets = options.targets; | ||
if (typeof targets === "string" || Array.isArray(targets)) { | ||
const optTargets = options.targets; | ||
let targets; | ||
if (typeof optTargets === "string" || Array.isArray(optTargets)) { | ||
targets = { | ||
browsers: targets | ||
browsers: optTargets | ||
}; | ||
} else if (optTargets) { | ||
if ("esmodules" in optTargets) { | ||
targets = Object.assign({}, optTargets, { | ||
esmodules: "intersect" | ||
}); | ||
} else { | ||
targets = optTargets; | ||
} | ||
} | ||
if (targets && targets.esmodules) { | ||
targets = Object.assign({}, targets, { | ||
esmodules: "intersect" | ||
}); | ||
} | ||
return (0, _helperCompilationTargets().default)(targets, { | ||
@@ -43,2 +39,5 @@ ignoreBrowserslistConfig: true, | ||
}); | ||
} | ||
} | ||
0 && 0; | ||
//# sourceMappingURL=resolve-targets-browser.js.map |
@@ -8,44 +8,36 @@ "use strict"; | ||
exports.resolveTargets = resolveTargets; | ||
function _path() { | ||
const data = require("path"); | ||
_path = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _helperCompilationTargets() { | ||
const data = require("@babel/helper-compilation-targets"); | ||
_helperCompilationTargets = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
({}); | ||
function resolveBrowserslistConfigFile(browserslistConfigFile, configFileDir) { | ||
return _path().resolve(configFileDir, browserslistConfigFile); | ||
} | ||
function resolveTargets(options, root) { | ||
let targets = options.targets; | ||
if (typeof targets === "string" || Array.isArray(targets)) { | ||
const optTargets = options.targets; | ||
let targets; | ||
if (typeof optTargets === "string" || Array.isArray(optTargets)) { | ||
targets = { | ||
browsers: targets | ||
browsers: optTargets | ||
}; | ||
} else if (optTargets) { | ||
if ("esmodules" in optTargets) { | ||
targets = Object.assign({}, optTargets, { | ||
esmodules: "intersect" | ||
}); | ||
} else { | ||
targets = optTargets; | ||
} | ||
} | ||
if (targets && targets.esmodules) { | ||
targets = Object.assign({}, targets, { | ||
esmodules: "intersect" | ||
}); | ||
} | ||
const { | ||
@@ -56,3 +48,2 @@ browserslistConfigFile | ||
let ignoreBrowserslistConfig = false; | ||
if (typeof browserslistConfigFile === "string") { | ||
@@ -63,3 +54,2 @@ configFile = browserslistConfigFile; | ||
} | ||
return (0, _helperCompilationTargets().default)(targets, { | ||
@@ -71,2 +61,5 @@ ignoreBrowserslistConfig, | ||
}); | ||
} | ||
} | ||
0 && 0; | ||
//# sourceMappingURL=resolve-targets.js.map |
@@ -6,5 +6,4 @@ "use strict"; | ||
}); | ||
exports.isIterableIterator = isIterableIterator; | ||
exports.mergeOptions = mergeOptions; | ||
exports.isIterableIterator = isIterableIterator; | ||
function mergeOptions(target, source) { | ||
@@ -22,3 +21,2 @@ for (const k of Object.keys(source)) { | ||
} | ||
function mergeDefaultFields(target, source) { | ||
@@ -30,5 +28,7 @@ for (const k of Object.keys(source)) { | ||
} | ||
function isIterableIterator(value) { | ||
return !!value && typeof value.next === "function" && typeof value[Symbol.iterator] === "function"; | ||
} | ||
} | ||
0 && 0; | ||
//# sourceMappingURL=util.js.map |
@@ -6,35 +6,30 @@ "use strict"; | ||
}); | ||
exports.msg = msg; | ||
exports.access = access; | ||
exports.assertArray = assertArray; | ||
exports.assertAssumptions = assertAssumptions; | ||
exports.assertBabelrcSearch = assertBabelrcSearch; | ||
exports.assertBoolean = assertBoolean; | ||
exports.assertCallerMetadata = assertCallerMetadata; | ||
exports.assertCompact = assertCompact; | ||
exports.assertConfigApplicableTest = assertConfigApplicableTest; | ||
exports.assertConfigFileSearch = assertConfigFileSearch; | ||
exports.assertFunction = assertFunction; | ||
exports.assertIgnoreList = assertIgnoreList; | ||
exports.assertInputSourceMap = assertInputSourceMap; | ||
exports.assertObject = assertObject; | ||
exports.assertPluginList = assertPluginList; | ||
exports.assertRootMode = assertRootMode; | ||
exports.assertSourceMaps = assertSourceMaps; | ||
exports.assertCompact = assertCompact; | ||
exports.assertSourceType = assertSourceType; | ||
exports.assertCallerMetadata = assertCallerMetadata; | ||
exports.assertInputSourceMap = assertInputSourceMap; | ||
exports.assertString = assertString; | ||
exports.assertFunction = assertFunction; | ||
exports.assertBoolean = assertBoolean; | ||
exports.assertObject = assertObject; | ||
exports.assertArray = assertArray; | ||
exports.assertIgnoreList = assertIgnoreList; | ||
exports.assertConfigApplicableTest = assertConfigApplicableTest; | ||
exports.assertConfigFileSearch = assertConfigFileSearch; | ||
exports.assertBabelrcSearch = assertBabelrcSearch; | ||
exports.assertPluginList = assertPluginList; | ||
exports.assertTargets = assertTargets; | ||
exports.assertAssumptions = assertAssumptions; | ||
exports.msg = msg; | ||
function _helperCompilationTargets() { | ||
const data = require("@babel/helper-compilation-targets"); | ||
_helperCompilationTargets = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _options = require("./options"); | ||
function msg(loc) { | ||
@@ -44,15 +39,10 @@ switch (loc.type) { | ||
return ``; | ||
case "env": | ||
return `${msg(loc.parent)}.env["${loc.name}"]`; | ||
case "overrides": | ||
return `${msg(loc.parent)}.overrides[${loc.index}]`; | ||
case "option": | ||
return `${msg(loc.parent)}.${loc.name}`; | ||
case "access": | ||
return `${msg(loc.parent)}[${JSON.stringify(loc.name)}]`; | ||
default: | ||
@@ -62,3 +52,2 @@ throw new Error(`Assertion failure: Unknown type ${loc.type}`); | ||
} | ||
function access(loc, name) { | ||
@@ -71,3 +60,2 @@ return { | ||
} | ||
function assertRootMode(loc, value) { | ||
@@ -77,6 +65,4 @@ if (value !== undefined && value !== "root" && value !== "upward" && value !== "upward-optional") { | ||
} | ||
return value; | ||
} | ||
function assertSourceMaps(loc, value) { | ||
@@ -86,6 +72,4 @@ if (value !== undefined && typeof value !== "boolean" && value !== "inline" && value !== "both") { | ||
} | ||
return value; | ||
} | ||
function assertCompact(loc, value) { | ||
@@ -95,6 +79,4 @@ if (value !== undefined && typeof value !== "boolean" && value !== "auto") { | ||
} | ||
return value; | ||
} | ||
function assertSourceType(loc, value) { | ||
@@ -104,9 +86,6 @@ if (value !== undefined && value !== "module" && value !== "script" && value !== "unambiguous") { | ||
} | ||
return value; | ||
} | ||
function assertCallerMetadata(loc, value) { | ||
const obj = assertObject(loc, value); | ||
if (obj) { | ||
@@ -116,7 +95,5 @@ if (typeof obj.name !== "string") { | ||
} | ||
for (const prop of Object.keys(obj)) { | ||
const propLoc = access(loc, prop); | ||
const value = obj[prop]; | ||
if (value != null && typeof value !== "boolean" && typeof value !== "string" && typeof value !== "number") { | ||
@@ -127,6 +104,4 @@ throw new Error(`${msg(propLoc)} must be null, undefined, a boolean, a string, or a number.`); | ||
} | ||
return value; | ||
} | ||
function assertInputSourceMap(loc, value) { | ||
@@ -136,6 +111,4 @@ if (value !== undefined && typeof value !== "boolean" && (typeof value !== "object" || !value)) { | ||
} | ||
return value; | ||
} | ||
function assertString(loc, value) { | ||
@@ -145,6 +118,4 @@ if (value !== undefined && typeof value !== "string") { | ||
} | ||
return value; | ||
} | ||
function assertFunction(loc, value) { | ||
@@ -154,6 +125,4 @@ if (value !== undefined && typeof value !== "function") { | ||
} | ||
return value; | ||
} | ||
function assertBoolean(loc, value) { | ||
@@ -163,6 +132,4 @@ if (value !== undefined && typeof value !== "boolean") { | ||
} | ||
return value; | ||
} | ||
function assertObject(loc, value) { | ||
@@ -172,6 +139,4 @@ if (value !== undefined && (typeof value !== "object" || Array.isArray(value) || !value)) { | ||
} | ||
return value; | ||
} | ||
function assertArray(loc, value) { | ||
@@ -181,16 +146,11 @@ if (value != null && !Array.isArray(value)) { | ||
} | ||
return value; | ||
} | ||
function assertIgnoreList(loc, value) { | ||
const arr = assertArray(loc, value); | ||
if (arr) { | ||
arr.forEach((item, i) => assertIgnoreItem(access(loc, i), item)); | ||
} | ||
return arr; | ||
} | ||
function assertIgnoreItem(loc, value) { | ||
@@ -200,9 +160,8 @@ if (typeof value !== "string" && typeof value !== "function" && !(value instanceof RegExp)) { | ||
} | ||
return value; | ||
} | ||
function assertConfigApplicableTest(loc, value) { | ||
if (value === undefined) return value; | ||
if (value === undefined) { | ||
return value; | ||
} | ||
if (Array.isArray(value)) { | ||
@@ -217,10 +176,7 @@ value.forEach((item, i) => { | ||
} | ||
return value; | ||
} | ||
function checkValidTest(value) { | ||
return typeof value === "string" || typeof value === "function" || value instanceof RegExp; | ||
} | ||
function assertConfigFileSearch(loc, value) { | ||
@@ -230,9 +186,8 @@ if (value !== undefined && typeof value !== "boolean" && typeof value !== "string") { | ||
} | ||
return value; | ||
} | ||
function assertBabelrcSearch(loc, value) { | ||
if (value === undefined || typeof value === "boolean") return value; | ||
if (value === undefined || typeof value === "boolean") { | ||
return value; | ||
} | ||
if (Array.isArray(value)) { | ||
@@ -247,16 +202,11 @@ value.forEach((item, i) => { | ||
} | ||
return value; | ||
} | ||
function assertPluginList(loc, value) { | ||
const arr = assertArray(loc, value); | ||
if (arr) { | ||
arr.forEach((item, i) => assertPluginItem(access(loc, i), item)); | ||
} | ||
return arr; | ||
} | ||
function assertPluginItem(loc, value) { | ||
@@ -267,12 +217,8 @@ if (Array.isArray(value)) { | ||
} | ||
if (value.length > 3) { | ||
throw new Error(`${msg(loc)} may only be a two-tuple or three-tuple`); | ||
} | ||
assertPluginTarget(access(loc, 0), value[0]); | ||
if (value.length > 1) { | ||
const opts = value[1]; | ||
if (opts !== undefined && opts !== false && (typeof opts !== "object" || Array.isArray(opts) || opts === null)) { | ||
@@ -282,6 +228,4 @@ throw new Error(`${msg(access(loc, 1))} must be an object, false, or undefined`); | ||
} | ||
if (value.length === 3) { | ||
const name = value[2]; | ||
if (name !== undefined && typeof name !== "string") { | ||
@@ -294,6 +238,4 @@ throw new Error(`${msg(access(loc, 2))} must be a string, or undefined`); | ||
} | ||
return value; | ||
} | ||
function assertPluginTarget(loc, value) { | ||
@@ -303,13 +245,9 @@ if ((typeof value !== "object" || !value) && typeof value !== "string" && typeof value !== "function") { | ||
} | ||
return value; | ||
} | ||
function assertTargets(loc, value) { | ||
if ((0, _helperCompilationTargets().isBrowsersQueryValid)(value)) return value; | ||
if (typeof value !== "object" || !value || Array.isArray(value)) { | ||
throw new Error(`${msg(loc)} must be a string, an array of strings or an object`); | ||
} | ||
const browsersLoc = access(loc, "browsers"); | ||
@@ -319,3 +257,2 @@ const esmodulesLoc = access(loc, "esmodules"); | ||
assertBoolean(esmodulesLoc, value.esmodules); | ||
for (const key of Object.keys(value)) { | ||
@@ -329,6 +266,4 @@ const val = value[key]; | ||
} | ||
return value; | ||
} | ||
function assertBrowsersList(loc, value) { | ||
@@ -339,3 +274,2 @@ if (value !== undefined && !(0, _helperCompilationTargets().isBrowsersQueryValid)(value)) { | ||
} | ||
function assertBrowserVersion(loc, value) { | ||
@@ -346,29 +280,20 @@ if (typeof value === "number" && Math.round(value) === value) return; | ||
} | ||
function assertAssumptions(loc, value) { | ||
if (value === undefined) return; | ||
if (typeof value !== "object" || value === null) { | ||
throw new Error(`${msg(loc)} must be an object or undefined.`); | ||
} | ||
let root = loc; | ||
do { | ||
root = root.parent; | ||
} while (root.type !== "root"); | ||
const inPreset = root.source === "preset"; | ||
for (const name of Object.keys(value)) { | ||
const subLoc = access(loc, name); | ||
if (!_options.assumptionsNames.has(name)) { | ||
throw new Error(`${msg(subLoc)} is not a supported assumption.`); | ||
} | ||
if (typeof value[name] !== "boolean") { | ||
throw new Error(`${msg(subLoc)} must be a boolean.`); | ||
} | ||
if (inPreset && value[name] === false) { | ||
@@ -378,4 +303,6 @@ throw new Error(`${msg(subLoc)} cannot be set to 'false' inside presets.`); | ||
} | ||
return value; | ||
} | ||
0 && 0; | ||
return value; | ||
} | ||
//# sourceMappingURL=option-assertions.js.map |
@@ -6,12 +6,8 @@ "use strict"; | ||
}); | ||
exports.assumptionsNames = void 0; | ||
exports.checkNoUnwrappedItemOptionPairs = checkNoUnwrappedItemOptionPairs; | ||
exports.validate = validate; | ||
exports.checkNoUnwrappedItemOptionPairs = checkNoUnwrappedItemOptionPairs; | ||
exports.assumptionsNames = void 0; | ||
var _plugin = require("../plugin"); | ||
var _removed = require("./removed"); | ||
var _optionAssertions = require("./option-assertions"); | ||
var _configError = require("../../errors/config-error"); | ||
const ROOT_VALIDATORS = { | ||
@@ -78,16 +74,20 @@ cwd: _optionAssertions.assertString, | ||
} | ||
const assumptionsNames = new Set(["arrayLikeIsIterable", "constantReexports", "constantSuper", "enumerableModuleMeta", "ignoreFunctionLength", "ignoreToPrimitiveHint", "iterableIsArray", "mutableTemplateObject", "noClassCalls", "noDocumentAll", "noNewArrows", "objectRestNoSymbols", "privateFieldsAsProperties", "pureGetters", "setClassMethods", "setComputedProperties", "setPublicClassFields", "setSpreadProperties", "skipForOfIteratorClosing", "superIsCallableConstructor"]); | ||
const knownAssumptions = ["arrayLikeIsIterable", "constantReexports", "constantSuper", "enumerableModuleMeta", "ignoreFunctionLength", "ignoreToPrimitiveHint", "iterableIsArray", "mutableTemplateObject", "noClassCalls", "noDocumentAll", "noIncompleteNsImportDetection", "noNewArrows", "objectRestNoSymbols", "privateFieldsAsSymbols", "privateFieldsAsProperties", "pureGetters", "setClassMethods", "setComputedProperties", "setPublicClassFields", "setSpreadProperties", "skipForOfIteratorClosing", "superIsCallableConstructor"]; | ||
const assumptionsNames = new Set(knownAssumptions); | ||
exports.assumptionsNames = assumptionsNames; | ||
function getSource(loc) { | ||
return loc.type === "root" ? loc.source : getSource(loc.parent); | ||
} | ||
function validate(type, opts) { | ||
return validateNested({ | ||
type: "root", | ||
source: type | ||
}, opts); | ||
function validate(type, opts, filename) { | ||
try { | ||
return validateNested({ | ||
type: "root", | ||
source: type | ||
}, opts); | ||
} catch (error) { | ||
const configError = new _configError.default(error.message, filename); | ||
if (error.code) configError.code = error.code; | ||
throw configError; | ||
} | ||
} | ||
function validateNested(loc, opts) { | ||
@@ -102,11 +102,8 @@ const type = getSource(loc); | ||
}; | ||
if (type === "preset" && NONPRESET_VALIDATORS[key]) { | ||
throw new Error(`${(0, _optionAssertions.msg)(optLoc)} is not allowed in preset options`); | ||
} | ||
if (type !== "arguments" && ROOT_VALIDATORS[key]) { | ||
throw new Error(`${(0, _optionAssertions.msg)(optLoc)} is only allowed in root programmatic options`); | ||
} | ||
if (type !== "arguments" && type !== "configfile" && BABELRC_VALIDATORS[key]) { | ||
@@ -116,6 +113,4 @@ if (type === "babelrcfile" || type === "extendsfile") { | ||
} | ||
throw new Error(`${(0, _optionAssertions.msg)(optLoc)} is only allowed in root programmatic options, or babel.config.js/config file options`); | ||
} | ||
const validator = COMMON_VALIDATORS[key] || NONPRESET_VALIDATORS[key] || BABELRC_VALIDATORS[key] || ROOT_VALIDATORS[key] || throwUnknownError; | ||
@@ -126,6 +121,4 @@ validator(optLoc, opts[key]); | ||
} | ||
function throwUnknownError(loc) { | ||
const key = loc.name; | ||
if (_removed.default[key]) { | ||
@@ -143,7 +136,5 @@ const { | ||
} | ||
function has(obj, key) { | ||
return Object.prototype.hasOwnProperty.call(obj, key); | ||
} | ||
function assertNoDuplicateSourcemap(opts) { | ||
@@ -154,3 +145,2 @@ if (has(opts, "sourceMap") && has(opts, "sourceMaps")) { | ||
} | ||
function assertEnvSet(loc, value) { | ||
@@ -160,6 +150,4 @@ if (loc.parent.type === "env") { | ||
} | ||
const parent = loc.parent; | ||
const obj = (0, _optionAssertions.assertObject)(loc, value); | ||
if (obj) { | ||
@@ -177,6 +165,4 @@ for (const envName of Object.keys(obj)) { | ||
} | ||
return obj; | ||
} | ||
function assertOverridesList(loc, value) { | ||
@@ -186,10 +172,7 @@ if (loc.parent.type === "env") { | ||
} | ||
if (loc.parent.type === "overrides") { | ||
throw new Error(`${(0, _optionAssertions.msg)(loc)} is not allowed inside an .overrides block`); | ||
} | ||
const parent = loc.parent; | ||
const arr = (0, _optionAssertions.assertArray)(loc, value); | ||
if (arr) { | ||
@@ -208,6 +191,4 @@ for (const [index, item] of arr.entries()) { | ||
} | ||
return arr; | ||
} | ||
function checkNoUnwrappedItemOptionPairs(items, index, type, e) { | ||
@@ -217,6 +198,8 @@ if (index === 0) return; | ||
const thisItem = items[index]; | ||
if (lastItem.file && lastItem.options === undefined && typeof thisItem.value === "object") { | ||
e.message += `\n- Maybe you meant to use\n` + `"${type}": [\n ["${lastItem.file.request}", ${JSON.stringify(thisItem.value, undefined, 2)}]\n]\n` + `To be a valid ${type}, its name and options should be wrapped in a pair of brackets`; | ||
e.message += `\n- Maybe you meant to use\n` + `"${type}s": [\n ["${lastItem.file.request}", ${JSON.stringify(thisItem.value, undefined, 2)}]\n]\n` + `To be a valid ${type}, its name and options should be wrapped in a pair of brackets`; | ||
} | ||
} | ||
} | ||
0 && 0; | ||
//# sourceMappingURL=options.js.map |
@@ -7,5 +7,3 @@ "use strict"; | ||
exports.validatePluginObject = validatePluginObject; | ||
var _optionAssertions = require("./option-assertions"); | ||
const VALIDATORS = { | ||
@@ -21,9 +19,6 @@ name: _optionAssertions.assertString, | ||
}; | ||
function assertVisitorMap(loc, value) { | ||
const obj = (0, _optionAssertions.assertObject)(loc, value); | ||
if (obj) { | ||
Object.keys(obj).forEach(prop => assertVisitorHandler(prop, obj[prop])); | ||
if (obj.enter || obj.exit) { | ||
@@ -33,6 +28,4 @@ throw new Error(`${(0, _optionAssertions.msg)(loc)} cannot contain catch-all "enter" or "exit" handlers. Please target individual nodes.`); | ||
} | ||
return obj; | ||
} | ||
function assertVisitorHandler(key, value) { | ||
@@ -48,6 +41,4 @@ if (value && typeof value === "object") { | ||
} | ||
return value; | ||
} | ||
function validatePluginObject(obj) { | ||
@@ -60,3 +51,2 @@ const rootPath = { | ||
const validator = VALIDATORS[key]; | ||
if (validator) { | ||
@@ -76,2 +66,5 @@ const optLoc = { | ||
return obj; | ||
} | ||
} | ||
0 && 0; | ||
//# sourceMappingURL=plugins.js.map |
@@ -66,2 +66,5 @@ "use strict"; | ||
}; | ||
exports.default = _default; | ||
exports.default = _default; | ||
0 && 0; | ||
//# sourceMappingURL=removed.js.map |
@@ -6,23 +6,19 @@ "use strict"; | ||
}); | ||
exports.maybeAsync = maybeAsync; | ||
exports.forwardAsync = forwardAsync; | ||
exports.isAsync = void 0; | ||
exports.isThenable = isThenable; | ||
exports.waitFor = exports.onFirstPause = exports.isAsync = void 0; | ||
exports.maybeAsync = maybeAsync; | ||
exports.waitFor = exports.onFirstPause = void 0; | ||
function _gensync() { | ||
const data = require("gensync"); | ||
_gensync = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
const id = x => x; | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } | ||
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } | ||
const runGenerator = _gensync()(function* (item) { | ||
return yield* item; | ||
}); | ||
const isAsync = _gensync()({ | ||
@@ -32,5 +28,3 @@ sync: () => false, | ||
}); | ||
exports.isAsync = isAsync; | ||
function maybeAsync(fn, message) { | ||
@@ -43,18 +37,20 @@ return _gensync()({ | ||
}, | ||
async(...args) { | ||
return Promise.resolve(fn.apply(this, args)); | ||
} | ||
}); | ||
} | ||
const withKind = _gensync()({ | ||
sync: cb => cb("sync"), | ||
async: cb => cb("async") | ||
async: function () { | ||
var _ref = _asyncToGenerator(function* (cb) { | ||
return cb("async"); | ||
}); | ||
return function async(_x) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}() | ||
}); | ||
function forwardAsync(action, cb) { | ||
const g = _gensync()(action); | ||
return withKind(kind => { | ||
@@ -65,3 +61,2 @@ const adapted = g[kind]; | ||
} | ||
const onFirstPause = _gensync()({ | ||
@@ -79,3 +74,2 @@ name: "onFirstPause", | ||
}); | ||
if (!completed) { | ||
@@ -86,14 +80,20 @@ firstPause(); | ||
}); | ||
exports.onFirstPause = onFirstPause; | ||
const waitFor = _gensync()({ | ||
sync: id, | ||
async: id | ||
sync: x => x, | ||
async: function () { | ||
var _ref2 = _asyncToGenerator(function* (x) { | ||
return x; | ||
}); | ||
return function async(_x2) { | ||
return _ref2.apply(this, arguments); | ||
}; | ||
}() | ||
}); | ||
exports.waitFor = waitFor; | ||
function isThenable(val) { | ||
return !!val && (typeof val === "object" || typeof val === "function") && !!val.then && typeof val.then === "function"; | ||
} | ||
} | ||
0 && 0; | ||
//# sourceMappingURL=async.js.map |
@@ -7,23 +7,16 @@ "use strict"; | ||
exports.stat = exports.readFile = void 0; | ||
function _fs() { | ||
const data = require("fs"); | ||
_fs = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _gensync() { | ||
const data = require("gensync"); | ||
_gensync = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
const readFile = _gensync()({ | ||
@@ -33,5 +26,3 @@ sync: _fs().readFileSync, | ||
}); | ||
exports.readFile = readFile; | ||
const stat = _gensync()({ | ||
@@ -41,3 +32,5 @@ sync: _fs().statSync, | ||
}); | ||
exports.stat = stat; | ||
0 && 0; | ||
exports.stat = stat; | ||
//# sourceMappingURL=fs.js.map |
151
lib/index.js
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.Plugin = Plugin; | ||
exports.DEFAULT_EXTENSIONS = void 0; | ||
Object.defineProperty(exports, "File", { | ||
@@ -20,14 +20,20 @@ enumerable: true, | ||
}); | ||
Object.defineProperty(exports, "resolvePlugin", { | ||
Object.defineProperty(exports, "createConfigItem", { | ||
enumerable: true, | ||
get: function () { | ||
return _files.resolvePlugin; | ||
return _config.createConfigItem; | ||
} | ||
}); | ||
Object.defineProperty(exports, "resolvePreset", { | ||
Object.defineProperty(exports, "createConfigItemAsync", { | ||
enumerable: true, | ||
get: function () { | ||
return _files.resolvePreset; | ||
return _config.createConfigItemAsync; | ||
} | ||
}); | ||
Object.defineProperty(exports, "createConfigItemSync", { | ||
enumerable: true, | ||
get: function () { | ||
return _config.createConfigItemSync; | ||
} | ||
}); | ||
Object.defineProperty(exports, "getEnv", { | ||
@@ -39,84 +45,84 @@ enumerable: true, | ||
}); | ||
Object.defineProperty(exports, "tokTypes", { | ||
Object.defineProperty(exports, "loadOptions", { | ||
enumerable: true, | ||
get: function () { | ||
return _parser().tokTypes; | ||
return _config.loadOptions; | ||
} | ||
}); | ||
Object.defineProperty(exports, "traverse", { | ||
Object.defineProperty(exports, "loadOptionsAsync", { | ||
enumerable: true, | ||
get: function () { | ||
return _traverse().default; | ||
return _config.loadOptionsAsync; | ||
} | ||
}); | ||
Object.defineProperty(exports, "template", { | ||
Object.defineProperty(exports, "loadOptionsSync", { | ||
enumerable: true, | ||
get: function () { | ||
return _template().default; | ||
return _config.loadOptionsSync; | ||
} | ||
}); | ||
Object.defineProperty(exports, "createConfigItem", { | ||
Object.defineProperty(exports, "loadPartialConfig", { | ||
enumerable: true, | ||
get: function () { | ||
return _config.createConfigItem; | ||
return _config.loadPartialConfig; | ||
} | ||
}); | ||
Object.defineProperty(exports, "createConfigItemSync", { | ||
Object.defineProperty(exports, "loadPartialConfigAsync", { | ||
enumerable: true, | ||
get: function () { | ||
return _config.createConfigItemSync; | ||
return _config.loadPartialConfigAsync; | ||
} | ||
}); | ||
Object.defineProperty(exports, "createConfigItemAsync", { | ||
Object.defineProperty(exports, "loadPartialConfigSync", { | ||
enumerable: true, | ||
get: function () { | ||
return _config.createConfigItemAsync; | ||
return _config.loadPartialConfigSync; | ||
} | ||
}); | ||
Object.defineProperty(exports, "loadPartialConfig", { | ||
Object.defineProperty(exports, "parse", { | ||
enumerable: true, | ||
get: function () { | ||
return _config.loadPartialConfig; | ||
return _parse.parse; | ||
} | ||
}); | ||
Object.defineProperty(exports, "loadPartialConfigSync", { | ||
Object.defineProperty(exports, "parseAsync", { | ||
enumerable: true, | ||
get: function () { | ||
return _config.loadPartialConfigSync; | ||
return _parse.parseAsync; | ||
} | ||
}); | ||
Object.defineProperty(exports, "loadPartialConfigAsync", { | ||
Object.defineProperty(exports, "parseSync", { | ||
enumerable: true, | ||
get: function () { | ||
return _config.loadPartialConfigAsync; | ||
return _parse.parseSync; | ||
} | ||
}); | ||
Object.defineProperty(exports, "loadOptions", { | ||
Object.defineProperty(exports, "resolvePlugin", { | ||
enumerable: true, | ||
get: function () { | ||
return _config.loadOptions; | ||
return _files.resolvePlugin; | ||
} | ||
}); | ||
Object.defineProperty(exports, "loadOptionsSync", { | ||
Object.defineProperty(exports, "resolvePreset", { | ||
enumerable: true, | ||
get: function () { | ||
return _config.loadOptionsSync; | ||
return _files.resolvePreset; | ||
} | ||
}); | ||
Object.defineProperty(exports, "loadOptionsAsync", { | ||
Object.defineProperty((0, exports), "template", { | ||
enumerable: true, | ||
get: function () { | ||
return _config.loadOptionsAsync; | ||
return _template().default; | ||
} | ||
}); | ||
Object.defineProperty(exports, "transform", { | ||
Object.defineProperty((0, exports), "tokTypes", { | ||
enumerable: true, | ||
get: function () { | ||
return _transform.transform; | ||
return _parser().tokTypes; | ||
} | ||
}); | ||
Object.defineProperty(exports, "transformSync", { | ||
Object.defineProperty(exports, "transform", { | ||
enumerable: true, | ||
get: function () { | ||
return _transform.transformSync; | ||
return _transform.transform; | ||
} | ||
@@ -136,12 +142,12 @@ }); | ||
}); | ||
Object.defineProperty(exports, "transformFileSync", { | ||
Object.defineProperty(exports, "transformFileAsync", { | ||
enumerable: true, | ||
get: function () { | ||
return _transformFile.transformFileSync; | ||
return _transformFile.transformFileAsync; | ||
} | ||
}); | ||
Object.defineProperty(exports, "transformFileAsync", { | ||
Object.defineProperty(exports, "transformFileSync", { | ||
enumerable: true, | ||
get: function () { | ||
return _transformFile.transformFileAsync; | ||
return _transformFile.transformFileSync; | ||
} | ||
@@ -155,8 +161,2 @@ }); | ||
}); | ||
Object.defineProperty(exports, "transformFromAstSync", { | ||
enumerable: true, | ||
get: function () { | ||
return _transformAst.transformFromAstSync; | ||
} | ||
}); | ||
Object.defineProperty(exports, "transformFromAstAsync", { | ||
@@ -168,41 +168,33 @@ enumerable: true, | ||
}); | ||
Object.defineProperty(exports, "parse", { | ||
Object.defineProperty(exports, "transformFromAstSync", { | ||
enumerable: true, | ||
get: function () { | ||
return _parse.parse; | ||
return _transformAst.transformFromAstSync; | ||
} | ||
}); | ||
Object.defineProperty(exports, "parseSync", { | ||
Object.defineProperty(exports, "transformSync", { | ||
enumerable: true, | ||
get: function () { | ||
return _parse.parseSync; | ||
return _transform.transformSync; | ||
} | ||
}); | ||
Object.defineProperty(exports, "parseAsync", { | ||
Object.defineProperty((0, exports), "traverse", { | ||
enumerable: true, | ||
get: function () { | ||
return _parse.parseAsync; | ||
return _traverse().default; | ||
} | ||
}); | ||
exports.types = exports.OptionManager = exports.DEFAULT_EXTENSIONS = exports.version = void 0; | ||
exports.version = exports.types = void 0; | ||
var _file = require("./transformation/file/file"); | ||
var _buildExternalHelpers = require("./tools/build-external-helpers"); | ||
var _files = require("./config/files"); | ||
var _environment = require("./config/helpers/environment"); | ||
function _types() { | ||
const data = require("@babel/types"); | ||
_types = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
Object.defineProperty(exports, "types", { | ||
Object.defineProperty((0, exports), "types", { | ||
enumerable: true, | ||
@@ -213,59 +205,48 @@ get: function () { | ||
}); | ||
function _parser() { | ||
const data = require("@babel/parser"); | ||
_parser = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _traverse() { | ||
const data = require("@babel/traverse"); | ||
_traverse = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _template() { | ||
const data = require("@babel/template"); | ||
_template = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _config = require("./config"); | ||
var _transform = require("./transform"); | ||
var _transformFile = require("./transform-file"); | ||
var _transformAst = require("./transform-ast"); | ||
var _parse = require("./parse"); | ||
const version = "7.14.3"; | ||
var thisFile = require("./index"); | ||
const version = "7.22.5"; | ||
exports.version = version; | ||
const DEFAULT_EXTENSIONS = Object.freeze([".js", ".jsx", ".es6", ".es", ".mjs", ".cjs"]); | ||
exports.DEFAULT_EXTENSIONS = DEFAULT_EXTENSIONS; | ||
class OptionManager { | ||
init(opts) { | ||
return (0, _config.loadOptions)(opts); | ||
; | ||
{ | ||
{ | ||
exports.OptionManager = class OptionManager { | ||
init(opts) { | ||
return (0, _config.loadOptionsSync)(opts); | ||
} | ||
}; | ||
exports.Plugin = function Plugin(alias) { | ||
throw new Error(`The (${alias}) Babel 5 plugin is being run with an unsupported Babel version.`); | ||
}; | ||
} | ||
} | ||
0 && (exports.types = exports.traverse = exports.tokTypes = exports.template = 0); | ||
exports.OptionManager = OptionManager; | ||
function Plugin(alias) { | ||
throw new Error(`The (${alias}) Babel 5 plugin is being run with an unsupported Babel version.`); | ||
} | ||
//# sourceMappingURL=index.js.map |
@@ -6,30 +6,23 @@ "use strict"; | ||
}); | ||
exports.parseAsync = exports.parseSync = exports.parse = void 0; | ||
exports.parse = void 0; | ||
exports.parseAsync = parseAsync; | ||
exports.parseSync = parseSync; | ||
function _gensync() { | ||
const data = require("gensync"); | ||
_gensync = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _config = require("./config"); | ||
var _parser = require("./parser"); | ||
var _normalizeOpts = require("./transformation/normalize-opts"); | ||
var _rewriteStackTrace = require("./errors/rewrite-stack-trace"); | ||
const parseRunner = _gensync()(function* parse(code, opts) { | ||
const config = yield* (0, _config.default)(opts); | ||
if (config === null) { | ||
return null; | ||
} | ||
return yield* (0, _parser.default)(config.passes, (0, _normalizeOpts.default)(config), code); | ||
}); | ||
const parse = function parse(code, opts, callback) { | ||
@@ -40,11 +33,18 @@ if (typeof opts === "function") { | ||
} | ||
if (callback === undefined) return parseRunner.sync(code, opts); | ||
parseRunner.errback(code, opts, callback); | ||
if (callback === undefined) { | ||
{ | ||
return (0, _rewriteStackTrace.beginHiddenCallStack)(parseRunner.sync)(code, opts); | ||
} | ||
} | ||
(0, _rewriteStackTrace.beginHiddenCallStack)(parseRunner.errback)(code, opts, callback); | ||
}; | ||
exports.parse = parse; | ||
function parseSync(...args) { | ||
return (0, _rewriteStackTrace.beginHiddenCallStack)(parseRunner.sync)(...args); | ||
} | ||
function parseAsync(...args) { | ||
return (0, _rewriteStackTrace.beginHiddenCallStack)(parseRunner.async)(...args); | ||
} | ||
0 && 0; | ||
exports.parse = parse; | ||
const parseSync = parseRunner.sync; | ||
exports.parseSync = parseSync; | ||
const parseAsync = parseRunner.async; | ||
exports.parseAsync = parseAsync; | ||
//# sourceMappingURL=parse.js.map |
@@ -7,25 +7,17 @@ "use strict"; | ||
exports.default = parser; | ||
function _parser() { | ||
const data = require("@babel/parser"); | ||
_parser = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _codeFrame() { | ||
const data = require("@babel/code-frame"); | ||
_codeFrame = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _missingPluginHelper = require("./util/missing-plugin-helper"); | ||
function* parser(pluginPasses, { | ||
@@ -38,3 +30,2 @@ parserOpts, | ||
const results = []; | ||
for (const plugins of pluginPasses) { | ||
@@ -45,3 +36,2 @@ for (const plugin of plugins) { | ||
} = plugin; | ||
if (parserOverride) { | ||
@@ -53,3 +43,2 @@ const ast = parserOverride(code, parserOpts, _parser().parse); | ||
} | ||
if (results.length === 0) { | ||
@@ -59,10 +48,7 @@ return (0, _parser().parse)(code, parserOpts); | ||
yield* []; | ||
if (typeof results[0].then === "function") { | ||
throw new Error(`You appear to be using an async parser plugin, ` + `which your current version of Babel does not support. ` + `If you're using a published plugin, you may need to upgrade ` + `your @babel/core version.`); | ||
} | ||
return results[0]; | ||
} | ||
throw new Error("More than one plugin attempted to override parsing."); | ||
@@ -73,3 +59,2 @@ } catch (err) { | ||
} | ||
const { | ||
@@ -79,3 +64,2 @@ loc, | ||
} = err; | ||
if (loc) { | ||
@@ -90,3 +74,2 @@ const codeFrame = (0, _codeFrame().codeFrameColumns)(code, { | ||
}); | ||
if (missingPlugin) { | ||
@@ -97,8 +80,9 @@ err.message = `${filename}: ` + (0, _missingPluginHelper.default)(missingPlugin[0], loc, codeFrame); | ||
} | ||
err.code = "BABEL_PARSE_ERROR"; | ||
} | ||
throw err; | ||
} | ||
} | ||
} | ||
0 && 0; | ||
//# sourceMappingURL=index.js.map |
@@ -11,49 +11,9 @@ "use strict"; | ||
name: "@babel/plugin-syntax-async-do-expressions", | ||
url: "https://git.io/JYer8" | ||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-async-do-expressions" | ||
} | ||
}, | ||
classProperties: { | ||
syntax: { | ||
name: "@babel/plugin-syntax-class-properties", | ||
url: "https://git.io/vb4yQ" | ||
}, | ||
transform: { | ||
name: "@babel/plugin-proposal-class-properties", | ||
url: "https://git.io/vb4SL" | ||
} | ||
}, | ||
classPrivateProperties: { | ||
syntax: { | ||
name: "@babel/plugin-syntax-class-properties", | ||
url: "https://git.io/vb4yQ" | ||
}, | ||
transform: { | ||
name: "@babel/plugin-proposal-class-properties", | ||
url: "https://git.io/vb4SL" | ||
} | ||
}, | ||
classPrivateMethods: { | ||
syntax: { | ||
name: "@babel/plugin-syntax-class-properties", | ||
url: "https://git.io/vb4yQ" | ||
}, | ||
transform: { | ||
name: "@babel/plugin-proposal-private-methods", | ||
url: "https://git.io/JvpRG" | ||
} | ||
}, | ||
classStaticBlock: { | ||
syntax: { | ||
name: "@babel/plugin-syntax-class-static-block", | ||
url: "https://git.io/JTLB6" | ||
}, | ||
transform: { | ||
name: "@babel/plugin-proposal-class-static-block", | ||
url: "https://git.io/JTLBP" | ||
} | ||
}, | ||
decimal: { | ||
syntax: { | ||
name: "@babel/plugin-syntax-decimal", | ||
url: "https://git.io/JfKOH" | ||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-decimal" | ||
} | ||
@@ -64,7 +24,7 @@ }, | ||
name: "@babel/plugin-syntax-decorators", | ||
url: "https://git.io/vb4y9" | ||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-decorators" | ||
}, | ||
transform: { | ||
name: "@babel/plugin-proposal-decorators", | ||
url: "https://git.io/vb4ST" | ||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-proposal-decorators" | ||
} | ||
@@ -75,43 +35,27 @@ }, | ||
name: "@babel/plugin-syntax-do-expressions", | ||
url: "https://git.io/vb4yh" | ||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-do-expressions" | ||
}, | ||
transform: { | ||
name: "@babel/plugin-proposal-do-expressions", | ||
url: "https://git.io/vb4S3" | ||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-proposal-do-expressions" | ||
} | ||
}, | ||
dynamicImport: { | ||
syntax: { | ||
name: "@babel/plugin-syntax-dynamic-import", | ||
url: "https://git.io/vb4Sv" | ||
} | ||
}, | ||
exportDefaultFrom: { | ||
syntax: { | ||
name: "@babel/plugin-syntax-export-default-from", | ||
url: "https://git.io/vb4SO" | ||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-export-default-from" | ||
}, | ||
transform: { | ||
name: "@babel/plugin-proposal-export-default-from", | ||
url: "https://git.io/vb4yH" | ||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-proposal-export-default-from" | ||
} | ||
}, | ||
exportNamespaceFrom: { | ||
syntax: { | ||
name: "@babel/plugin-syntax-export-namespace-from", | ||
url: "https://git.io/vb4Sf" | ||
}, | ||
transform: { | ||
name: "@babel/plugin-proposal-export-namespace-from", | ||
url: "https://git.io/vb4SG" | ||
} | ||
}, | ||
flow: { | ||
syntax: { | ||
name: "@babel/plugin-syntax-flow", | ||
url: "https://git.io/vb4yb" | ||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-flow" | ||
}, | ||
transform: { | ||
name: "@babel/preset-flow", | ||
url: "https://git.io/JfeDn" | ||
url: "https://github.com/babel/babel/tree/main/packages/babel-preset-flow" | ||
} | ||
@@ -122,7 +66,7 @@ }, | ||
name: "@babel/plugin-syntax-function-bind", | ||
url: "https://git.io/vb4y7" | ||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-function-bind" | ||
}, | ||
transform: { | ||
name: "@babel/plugin-proposal-function-bind", | ||
url: "https://git.io/vb4St" | ||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-proposal-function-bind" | ||
} | ||
@@ -133,81 +77,39 @@ }, | ||
name: "@babel/plugin-syntax-function-sent", | ||
url: "https://git.io/vb4yN" | ||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-function-sent" | ||
}, | ||
transform: { | ||
name: "@babel/plugin-proposal-function-sent", | ||
url: "https://git.io/vb4SZ" | ||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-proposal-function-sent" | ||
} | ||
}, | ||
importMeta: { | ||
syntax: { | ||
name: "@babel/plugin-syntax-import-meta", | ||
url: "https://git.io/vbKK6" | ||
} | ||
}, | ||
jsx: { | ||
syntax: { | ||
name: "@babel/plugin-syntax-jsx", | ||
url: "https://git.io/vb4yA" | ||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-jsx" | ||
}, | ||
transform: { | ||
name: "@babel/preset-react", | ||
url: "https://git.io/JfeDR" | ||
url: "https://github.com/babel/babel/tree/main/packages/babel-preset-react" | ||
} | ||
}, | ||
importAssertions: { | ||
importAttributes: { | ||
syntax: { | ||
name: "@babel/plugin-syntax-import-assertions", | ||
url: "https://git.io/JUbkv" | ||
name: "@babel/plugin-syntax-import-attributes", | ||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-import-attributes" | ||
} | ||
}, | ||
moduleStringNames: { | ||
syntax: { | ||
name: "@babel/plugin-syntax-module-string-names", | ||
url: "https://git.io/JTL8G" | ||
} | ||
}, | ||
numericSeparator: { | ||
syntax: { | ||
name: "@babel/plugin-syntax-numeric-separator", | ||
url: "https://git.io/vb4Sq" | ||
}, | ||
transform: { | ||
name: "@babel/plugin-proposal-numeric-separator", | ||
url: "https://git.io/vb4yS" | ||
} | ||
}, | ||
optionalChaining: { | ||
syntax: { | ||
name: "@babel/plugin-syntax-optional-chaining", | ||
url: "https://git.io/vb4Sc" | ||
}, | ||
transform: { | ||
name: "@babel/plugin-proposal-optional-chaining", | ||
url: "https://git.io/vb4Sk" | ||
} | ||
}, | ||
pipelineOperator: { | ||
syntax: { | ||
name: "@babel/plugin-syntax-pipeline-operator", | ||
url: "https://git.io/vb4yj" | ||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-pipeline-operator" | ||
}, | ||
transform: { | ||
name: "@babel/plugin-proposal-pipeline-operator", | ||
url: "https://git.io/vb4SU" | ||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-proposal-pipeline-operator" | ||
} | ||
}, | ||
privateIn: { | ||
syntax: { | ||
name: "@babel/plugin-syntax-private-property-in-object", | ||
url: "https://git.io/JfK3q" | ||
}, | ||
transform: { | ||
name: "@babel/plugin-proposal-private-property-in-object", | ||
url: "https://git.io/JfK3O" | ||
} | ||
}, | ||
recordAndTuple: { | ||
syntax: { | ||
name: "@babel/plugin-syntax-record-and-tuple", | ||
url: "https://git.io/JvKp3" | ||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-record-and-tuple" | ||
} | ||
@@ -218,7 +120,7 @@ }, | ||
name: "@babel/plugin-syntax-throw-expressions", | ||
url: "https://git.io/vb4SJ" | ||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-throw-expressions" | ||
}, | ||
transform: { | ||
name: "@babel/plugin-proposal-throw-expressions", | ||
url: "https://git.io/vb4yF" | ||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-proposal-throw-expressions" | ||
} | ||
@@ -229,62 +131,178 @@ }, | ||
name: "@babel/plugin-syntax-typescript", | ||
url: "https://git.io/vb4SC" | ||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-typescript" | ||
}, | ||
transform: { | ||
name: "@babel/preset-typescript", | ||
url: "https://git.io/JfeDz" | ||
url: "https://github.com/babel/babel/tree/main/packages/babel-preset-typescript" | ||
} | ||
}, | ||
asyncGenerators: { | ||
syntax: { | ||
name: "@babel/plugin-syntax-async-generators", | ||
url: "https://git.io/vb4SY" | ||
} | ||
}; | ||
{ | ||
Object.assign(pluginNameMap, { | ||
asyncGenerators: { | ||
syntax: { | ||
name: "@babel/plugin-syntax-async-generators", | ||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-async-generators" | ||
}, | ||
transform: { | ||
name: "@babel/plugin-transform-async-generator-functions", | ||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-transform-async-generator-functions" | ||
} | ||
}, | ||
transform: { | ||
name: "@babel/plugin-proposal-async-generator-functions", | ||
url: "https://git.io/vb4yp" | ||
} | ||
}, | ||
logicalAssignment: { | ||
syntax: { | ||
name: "@babel/plugin-syntax-logical-assignment-operators", | ||
url: "https://git.io/vAlBp" | ||
classProperties: { | ||
syntax: { | ||
name: "@babel/plugin-syntax-class-properties", | ||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-class-properties" | ||
}, | ||
transform: { | ||
name: "@babel/plugin-transform-class-properties", | ||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-transform-class-properties" | ||
} | ||
}, | ||
transform: { | ||
name: "@babel/plugin-proposal-logical-assignment-operators", | ||
url: "https://git.io/vAlRe" | ||
} | ||
}, | ||
nullishCoalescingOperator: { | ||
syntax: { | ||
name: "@babel/plugin-syntax-nullish-coalescing-operator", | ||
url: "https://git.io/vb4yx" | ||
classPrivateProperties: { | ||
syntax: { | ||
name: "@babel/plugin-syntax-class-properties", | ||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-class-properties" | ||
}, | ||
transform: { | ||
name: "@babel/plugin-transform-class-properties", | ||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-transform-class-properties" | ||
} | ||
}, | ||
transform: { | ||
name: "@babel/plugin-proposal-nullish-coalescing-operator", | ||
url: "https://git.io/vb4Se" | ||
} | ||
}, | ||
objectRestSpread: { | ||
syntax: { | ||
name: "@babel/plugin-syntax-object-rest-spread", | ||
url: "https://git.io/vb4y5" | ||
classPrivateMethods: { | ||
syntax: { | ||
name: "@babel/plugin-syntax-class-properties", | ||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-class-properties" | ||
}, | ||
transform: { | ||
name: "@babel/plugin-transform-private-methods", | ||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-transform-private-methods" | ||
} | ||
}, | ||
transform: { | ||
name: "@babel/plugin-proposal-object-rest-spread", | ||
url: "https://git.io/vb4Ss" | ||
} | ||
}, | ||
optionalCatchBinding: { | ||
syntax: { | ||
name: "@babel/plugin-syntax-optional-catch-binding", | ||
url: "https://git.io/vb4Sn" | ||
classStaticBlock: { | ||
syntax: { | ||
name: "@babel/plugin-syntax-class-static-block", | ||
url: "https://github.com/babel/babel/tree/HEAD/packages/babel-plugin-syntax-class-static-block" | ||
}, | ||
transform: { | ||
name: "@babel/plugin-transform-class-static-block", | ||
url: "https://github.com/babel/babel/tree/HEAD/packages/babel-plugin-transform-class-static-block" | ||
} | ||
}, | ||
transform: { | ||
name: "@babel/plugin-proposal-optional-catch-binding", | ||
url: "https://git.io/vb4SI" | ||
dynamicImport: { | ||
syntax: { | ||
name: "@babel/plugin-syntax-dynamic-import", | ||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-dynamic-import" | ||
} | ||
}, | ||
exportNamespaceFrom: { | ||
syntax: { | ||
name: "@babel/plugin-syntax-export-namespace-from", | ||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-export-namespace-from" | ||
}, | ||
transform: { | ||
name: "@babel/plugin-transform-export-namespace-from", | ||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-transform-export-namespace-from" | ||
} | ||
}, | ||
importAssertions: { | ||
syntax: { | ||
name: "@babel/plugin-syntax-import-assertions", | ||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-import-assertions" | ||
} | ||
}, | ||
importMeta: { | ||
syntax: { | ||
name: "@babel/plugin-syntax-import-meta", | ||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-import-meta" | ||
} | ||
}, | ||
logicalAssignment: { | ||
syntax: { | ||
name: "@babel/plugin-syntax-logical-assignment-operators", | ||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-logical-assignment-operators" | ||
}, | ||
transform: { | ||
name: "@babel/plugin-transform-logical-assignment-operators", | ||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-transform-logical-assignment-operators" | ||
} | ||
}, | ||
moduleStringNames: { | ||
syntax: { | ||
name: "@babel/plugin-syntax-module-string-names", | ||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-module-string-names" | ||
} | ||
}, | ||
numericSeparator: { | ||
syntax: { | ||
name: "@babel/plugin-syntax-numeric-separator", | ||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-numeric-separator" | ||
}, | ||
transform: { | ||
name: "@babel/plugin-transform-numeric-separator", | ||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-transform-numeric-separator" | ||
} | ||
}, | ||
nullishCoalescingOperator: { | ||
syntax: { | ||
name: "@babel/plugin-syntax-nullish-coalescing-operator", | ||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-nullish-coalescing-operator" | ||
}, | ||
transform: { | ||
name: "@babel/plugin-transform-nullish-coalescing-operator", | ||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-transform-nullish-coalescing-opearator" | ||
} | ||
}, | ||
objectRestSpread: { | ||
syntax: { | ||
name: "@babel/plugin-syntax-object-rest-spread", | ||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-object-rest-spread" | ||
}, | ||
transform: { | ||
name: "@babel/plugin-transform-object-rest-spread", | ||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-transform-object-rest-spread" | ||
} | ||
}, | ||
optionalCatchBinding: { | ||
syntax: { | ||
name: "@babel/plugin-syntax-optional-catch-binding", | ||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-optional-catch-binding" | ||
}, | ||
transform: { | ||
name: "@babel/plugin-transform-optional-catch-binding", | ||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-transform-optional-catch-binding" | ||
} | ||
}, | ||
optionalChaining: { | ||
syntax: { | ||
name: "@babel/plugin-syntax-optional-chaining", | ||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-optional-chaining" | ||
}, | ||
transform: { | ||
name: "@babel/plugin-transform-optional-chaining", | ||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-transform-optional-chaining" | ||
} | ||
}, | ||
privateIn: { | ||
syntax: { | ||
name: "@babel/plugin-syntax-private-property-in-object", | ||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-private-property-in-object" | ||
}, | ||
transform: { | ||
name: "@babel/plugin-transform-private-property-in-object", | ||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-transform-private-property-in-object" | ||
} | ||
}, | ||
regexpUnicodeSets: { | ||
syntax: { | ||
name: "@babel/plugin-syntax-unicode-sets-regex", | ||
url: "https://github.com/babel/babel/blob/main/packages/babel-plugin-syntax-unicode-sets-regex/README.md" | ||
}, | ||
transform: { | ||
name: "@babel/plugin-transform-unicode-sets-regex", | ||
url: "https://github.com/babel/babel/blob/main/packages/babel-plugin-proposalunicode-sets-regex/README.md" | ||
} | ||
} | ||
} | ||
}; | ||
pluginNameMap.privateIn.syntax = pluginNameMap.privateIn.transform; | ||
}); | ||
} | ||
const getNameURLCombination = ({ | ||
@@ -294,7 +312,5 @@ name, | ||
}) => `${name} (${url})`; | ||
function generateMissingPluginMessage(missingPluginName, loc, codeFrame) { | ||
let helpMessage = `Support for the experimental syntax '${missingPluginName}' isn't currently enabled ` + `(${loc.line}:${loc.column + 1}):\n\n` + codeFrame; | ||
const pluginInfo = pluginNameMap[missingPluginName]; | ||
if (pluginInfo) { | ||
@@ -305,6 +321,4 @@ const { | ||
} = pluginInfo; | ||
if (syntaxPlugin) { | ||
const syntaxPluginInfo = getNameURLCombination(syntaxPlugin); | ||
if (transformPlugin) { | ||
@@ -320,4 +334,6 @@ const transformPluginInfo = getNameURLCombination(transformPlugin); | ||
} | ||
return helpMessage; | ||
} | ||
0 && 0; | ||
return helpMessage; | ||
} | ||
//# sourceMappingURL=missing-plugin-helper.js.map |
@@ -7,46 +7,53 @@ "use strict"; | ||
exports.default = _default; | ||
function helpers() { | ||
const data = require("@babel/helpers"); | ||
helpers = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _generator() { | ||
const data = require("@babel/generator"); | ||
_generator = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _template() { | ||
const data = require("@babel/template"); | ||
_template = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function t() { | ||
function _t() { | ||
const data = require("@babel/types"); | ||
t = function () { | ||
_t = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _file = require("../transformation/file/file"); | ||
const buildUmdWrapper = replacements => (0, _template().default)` | ||
const { | ||
arrayExpression, | ||
assignmentExpression, | ||
binaryExpression, | ||
blockStatement, | ||
callExpression, | ||
cloneNode, | ||
conditionalExpression, | ||
exportNamedDeclaration, | ||
exportSpecifier, | ||
expressionStatement, | ||
functionExpression, | ||
identifier, | ||
memberExpression, | ||
objectExpression, | ||
program, | ||
stringLiteral, | ||
unaryExpression, | ||
variableDeclaration, | ||
variableDeclarator | ||
} = _t(); | ||
const buildUmdWrapper = replacements => _template().default.statement` | ||
(function (root, factory) { | ||
@@ -64,52 +71,46 @@ if (typeof define === "function" && define.amd) { | ||
`(replacements); | ||
function buildGlobal(allowlist) { | ||
const namespace = t().identifier("babelHelpers"); | ||
const namespace = identifier("babelHelpers"); | ||
const body = []; | ||
const container = t().functionExpression(null, [t().identifier("global")], t().blockStatement(body)); | ||
const tree = t().program([t().expressionStatement(t().callExpression(container, [t().conditionalExpression(t().binaryExpression("===", t().unaryExpression("typeof", t().identifier("global")), t().stringLiteral("undefined")), t().identifier("self"), t().identifier("global"))]))]); | ||
body.push(t().variableDeclaration("var", [t().variableDeclarator(namespace, t().assignmentExpression("=", t().memberExpression(t().identifier("global"), namespace), t().objectExpression([])))])); | ||
const container = functionExpression(null, [identifier("global")], blockStatement(body)); | ||
const tree = program([expressionStatement(callExpression(container, [conditionalExpression(binaryExpression("===", unaryExpression("typeof", identifier("global")), stringLiteral("undefined")), identifier("self"), identifier("global"))]))]); | ||
body.push(variableDeclaration("var", [variableDeclarator(namespace, assignmentExpression("=", memberExpression(identifier("global"), namespace), objectExpression([])))])); | ||
buildHelpers(body, namespace, allowlist); | ||
return tree; | ||
} | ||
function buildModule(allowlist) { | ||
const body = []; | ||
const refs = buildHelpers(body, null, allowlist); | ||
body.unshift(t().exportNamedDeclaration(null, Object.keys(refs).map(name => { | ||
return t().exportSpecifier(t().cloneNode(refs[name]), t().identifier(name)); | ||
body.unshift(exportNamedDeclaration(null, Object.keys(refs).map(name => { | ||
return exportSpecifier(cloneNode(refs[name]), identifier(name)); | ||
}))); | ||
return t().program(body, [], "module"); | ||
return program(body, [], "module"); | ||
} | ||
function buildUmd(allowlist) { | ||
const namespace = t().identifier("babelHelpers"); | ||
const namespace = identifier("babelHelpers"); | ||
const body = []; | ||
body.push(t().variableDeclaration("var", [t().variableDeclarator(namespace, t().identifier("global"))])); | ||
body.push(variableDeclaration("var", [variableDeclarator(namespace, identifier("global"))])); | ||
buildHelpers(body, namespace, allowlist); | ||
return t().program([buildUmdWrapper({ | ||
FACTORY_PARAMETERS: t().identifier("global"), | ||
BROWSER_ARGUMENTS: t().assignmentExpression("=", t().memberExpression(t().identifier("root"), namespace), t().objectExpression([])), | ||
COMMON_ARGUMENTS: t().identifier("exports"), | ||
AMD_ARGUMENTS: t().arrayExpression([t().stringLiteral("exports")]), | ||
return program([buildUmdWrapper({ | ||
FACTORY_PARAMETERS: identifier("global"), | ||
BROWSER_ARGUMENTS: assignmentExpression("=", memberExpression(identifier("root"), namespace), objectExpression([])), | ||
COMMON_ARGUMENTS: identifier("exports"), | ||
AMD_ARGUMENTS: arrayExpression([stringLiteral("exports")]), | ||
FACTORY_BODY: body, | ||
UMD_ROOT: t().identifier("this") | ||
UMD_ROOT: identifier("this") | ||
})]); | ||
} | ||
function buildVar(allowlist) { | ||
const namespace = t().identifier("babelHelpers"); | ||
const namespace = identifier("babelHelpers"); | ||
const body = []; | ||
body.push(t().variableDeclaration("var", [t().variableDeclarator(namespace, t().objectExpression([]))])); | ||
const tree = t().program(body); | ||
body.push(variableDeclaration("var", [variableDeclarator(namespace, objectExpression([]))])); | ||
const tree = program(body); | ||
buildHelpers(body, namespace, allowlist); | ||
body.push(t().expressionStatement(namespace)); | ||
body.push(expressionStatement(namespace)); | ||
return tree; | ||
} | ||
function buildHelpers(body, namespace, allowlist) { | ||
const getHelperReference = name => { | ||
return namespace ? t().memberExpression(namespace, t().identifier(name)) : t().identifier(`_${name}`); | ||
return namespace ? memberExpression(namespace, identifier(name)) : identifier(`_${name}`); | ||
}; | ||
const refs = {}; | ||
@@ -127,3 +128,2 @@ helpers().list.forEach(function (name) { | ||
} | ||
function _default(allowlist, outputType = "global") { | ||
@@ -137,3 +137,2 @@ let tree; | ||
}[outputType]; | ||
if (build) { | ||
@@ -144,4 +143,6 @@ tree = build(allowlist); | ||
} | ||
return (0, _generator().default)(tree).code; | ||
} | ||
0 && 0; | ||
return (0, _generator().default)(tree).code; | ||
} | ||
//# sourceMappingURL=build-external-helpers.js.map |
@@ -6,18 +6,15 @@ "use strict"; | ||
}); | ||
exports.transformFromAstAsync = exports.transformFromAstSync = exports.transformFromAst = void 0; | ||
exports.transformFromAst = void 0; | ||
exports.transformFromAstAsync = transformFromAstAsync; | ||
exports.transformFromAstSync = transformFromAstSync; | ||
function _gensync() { | ||
const data = require("gensync"); | ||
_gensync = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _config = require("./config"); | ||
var _transformation = require("./transformation"); | ||
var _rewriteStackTrace = require("./errors/rewrite-stack-trace"); | ||
const transformFromAstRunner = _gensync()(function* (ast, code, opts) { | ||
@@ -29,20 +26,28 @@ const config = yield* (0, _config.default)(opts); | ||
}); | ||
const transformFromAst = function transformFromAst(ast, code, opts, callback) { | ||
if (typeof opts === "function") { | ||
callback = opts; | ||
const transformFromAst = function transformFromAst(ast, code, optsOrCallback, maybeCallback) { | ||
let opts; | ||
let callback; | ||
if (typeof optsOrCallback === "function") { | ||
callback = optsOrCallback; | ||
opts = undefined; | ||
} else { | ||
opts = optsOrCallback; | ||
callback = maybeCallback; | ||
} | ||
if (callback === undefined) { | ||
return transformFromAstRunner.sync(ast, code, opts); | ||
{ | ||
return (0, _rewriteStackTrace.beginHiddenCallStack)(transformFromAstRunner.sync)(ast, code, opts); | ||
} | ||
} | ||
transformFromAstRunner.errback(ast, code, opts, callback); | ||
(0, _rewriteStackTrace.beginHiddenCallStack)(transformFromAstRunner.errback)(ast, code, opts, callback); | ||
}; | ||
exports.transformFromAst = transformFromAst; | ||
function transformFromAstSync(...args) { | ||
return (0, _rewriteStackTrace.beginHiddenCallStack)(transformFromAstRunner.sync)(...args); | ||
} | ||
function transformFromAstAsync(...args) { | ||
return (0, _rewriteStackTrace.beginHiddenCallStack)(transformFromAstRunner.async)(...args); | ||
} | ||
0 && 0; | ||
exports.transformFromAst = transformFromAst; | ||
const transformFromAstSync = transformFromAstRunner.sync; | ||
exports.transformFromAstSync = transformFromAstSync; | ||
const transformFromAstAsync = transformFromAstRunner.async; | ||
exports.transformFromAstAsync = transformFromAstAsync; | ||
//# sourceMappingURL=transform-ast.js.map |
@@ -6,6 +6,5 @@ "use strict"; | ||
}); | ||
exports.transformFile = void 0; | ||
exports.transformFileAsync = transformFileAsync; | ||
exports.transformFileSync = transformFileSync; | ||
exports.transformFileAsync = transformFileAsync; | ||
exports.transformFile = void 0; | ||
const transformFile = function transformFile(filename, opts, callback) { | ||
@@ -15,14 +14,13 @@ if (typeof opts === "function") { | ||
} | ||
callback(new Error("Transforming files is not supported in browsers"), null); | ||
}; | ||
exports.transformFile = transformFile; | ||
function transformFileSync() { | ||
throw new Error("Transforming files is not supported in browsers"); | ||
} | ||
function transformFileAsync() { | ||
return Promise.reject(new Error("Transforming files is not supported in browsers")); | ||
} | ||
} | ||
0 && 0; | ||
//# sourceMappingURL=transform-file-browser.js.map |
@@ -6,22 +6,16 @@ "use strict"; | ||
}); | ||
exports.transformFileAsync = exports.transformFileSync = exports.transformFile = void 0; | ||
exports.transformFile = transformFile; | ||
exports.transformFileAsync = transformFileAsync; | ||
exports.transformFileSync = transformFileSync; | ||
function _gensync() { | ||
const data = require("gensync"); | ||
_gensync = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _config = require("./config"); | ||
var _transformation = require("./transformation"); | ||
var fs = require("./gensync-utils/fs"); | ||
({}); | ||
const transformFileRunner = _gensync()(function* (filename, opts) { | ||
@@ -36,8 +30,13 @@ const options = Object.assign({}, opts, { | ||
}); | ||
function transformFile(...args) { | ||
transformFileRunner.errback(...args); | ||
} | ||
function transformFileSync(...args) { | ||
return transformFileRunner.sync(...args); | ||
} | ||
function transformFileAsync(...args) { | ||
return transformFileRunner.async(...args); | ||
} | ||
0 && 0; | ||
const transformFile = transformFileRunner.errback; | ||
exports.transformFile = transformFile; | ||
const transformFileSync = transformFileRunner.sync; | ||
exports.transformFileSync = transformFileSync; | ||
const transformFileAsync = transformFileRunner.async; | ||
exports.transformFileAsync = transformFileAsync; | ||
//# sourceMappingURL=transform-file.js.map |
@@ -6,18 +6,15 @@ "use strict"; | ||
}); | ||
exports.transformAsync = exports.transformSync = exports.transform = void 0; | ||
exports.transform = void 0; | ||
exports.transformAsync = transformAsync; | ||
exports.transformSync = transformSync; | ||
function _gensync() { | ||
const data = require("gensync"); | ||
_gensync = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _config = require("./config"); | ||
var _transformation = require("./transformation"); | ||
var _rewriteStackTrace = require("./errors/rewrite-stack-trace"); | ||
const transformRunner = _gensync()(function* transform(code, opts) { | ||
@@ -28,17 +25,28 @@ const config = yield* (0, _config.default)(opts); | ||
}); | ||
const transform = function transform(code, opts, callback) { | ||
if (typeof opts === "function") { | ||
callback = opts; | ||
const transform = function transform(code, optsOrCallback, maybeCallback) { | ||
let opts; | ||
let callback; | ||
if (typeof optsOrCallback === "function") { | ||
callback = optsOrCallback; | ||
opts = undefined; | ||
} else { | ||
opts = optsOrCallback; | ||
callback = maybeCallback; | ||
} | ||
if (callback === undefined) return transformRunner.sync(code, opts); | ||
transformRunner.errback(code, opts, callback); | ||
if (callback === undefined) { | ||
{ | ||
return (0, _rewriteStackTrace.beginHiddenCallStack)(transformRunner.sync)(code, opts); | ||
} | ||
} | ||
(0, _rewriteStackTrace.beginHiddenCallStack)(transformRunner.errback)(code, opts, callback); | ||
}; | ||
exports.transform = transform; | ||
function transformSync(...args) { | ||
return (0, _rewriteStackTrace.beginHiddenCallStack)(transformRunner.sync)(...args); | ||
} | ||
function transformAsync(...args) { | ||
return (0, _rewriteStackTrace.beginHiddenCallStack)(transformRunner.async)(...args); | ||
} | ||
0 && 0; | ||
exports.transform = transform; | ||
const transformSync = transformRunner.sync; | ||
exports.transformSync = transformSync; | ||
const transformAsync = transformRunner.async; | ||
exports.transformAsync = transformAsync; | ||
//# sourceMappingURL=transform.js.map |
@@ -7,17 +7,38 @@ "use strict"; | ||
exports.default = loadBlockHoistPlugin; | ||
function _traverse() { | ||
const data = require("@babel/traverse"); | ||
_traverse = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _plugin = require("../config/plugin"); | ||
let LOADED_PLUGIN; | ||
const blockHoistPlugin = { | ||
name: "internal.blockHoist", | ||
visitor: { | ||
Block: { | ||
exit({ | ||
node | ||
}) { | ||
const { | ||
body | ||
} = node; | ||
let max = Math.pow(2, 30) - 1; | ||
let hasChange = false; | ||
for (let i = 0; i < body.length; i++) { | ||
const n = body[i]; | ||
const p = priority(n); | ||
if (p > max) { | ||
hasChange = true; | ||
break; | ||
} | ||
max = p; | ||
} | ||
if (!hasChange) return; | ||
node.body = stableSort(body.slice()); | ||
} | ||
} | ||
} | ||
}; | ||
function loadBlockHoistPlugin() { | ||
@@ -29,6 +50,4 @@ if (!LOADED_PLUGIN) { | ||
} | ||
return LOADED_PLUGIN; | ||
} | ||
function priority(bodyNode) { | ||
@@ -40,6 +59,4 @@ const priority = bodyNode == null ? void 0 : bodyNode._blockHoist; | ||
} | ||
function stableSort(body) { | ||
const buckets = Object.create(null); | ||
for (let i = 0; i < body.length; i++) { | ||
@@ -51,9 +68,6 @@ const n = body[i]; | ||
} | ||
const keys = Object.keys(buckets).map(k => +k).sort((a, b) => b - a); | ||
let index = 0; | ||
for (const key of keys) { | ||
const bucket = buckets[key]; | ||
for (const n of bucket) { | ||
@@ -63,37 +77,6 @@ body[index++] = n; | ||
} | ||
return body; | ||
} | ||
0 && 0; | ||
const blockHoistPlugin = { | ||
name: "internal.blockHoist", | ||
visitor: { | ||
Block: { | ||
exit({ | ||
node | ||
}) { | ||
const { | ||
body | ||
} = node; | ||
let max = Math.pow(2, 30) - 1; | ||
let hasChange = false; | ||
for (let i = 0; i < body.length; i++) { | ||
const n = body[i]; | ||
const p = priority(n); | ||
if (p > max) { | ||
hasChange = true; | ||
break; | ||
} | ||
max = p; | ||
} | ||
if (!hasChange) return; | ||
node.body = stableSort(body.slice()); | ||
} | ||
} | ||
} | ||
}; | ||
//# sourceMappingURL=block-hoist-plugin.js.map |
@@ -7,67 +7,51 @@ "use strict"; | ||
exports.default = void 0; | ||
function helpers() { | ||
const data = require("@babel/helpers"); | ||
helpers = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _traverse() { | ||
const data = require("@babel/traverse"); | ||
_traverse = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _codeFrame() { | ||
const data = require("@babel/code-frame"); | ||
_codeFrame = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function t() { | ||
function _t() { | ||
const data = require("@babel/types"); | ||
t = function () { | ||
_t = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _helperModuleTransforms() { | ||
const data = require("@babel/helper-module-transforms"); | ||
_helperModuleTransforms = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _semver() { | ||
const data = require("semver"); | ||
_semver = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
const { | ||
cloneNode, | ||
interpreterDirective | ||
} = _t(); | ||
const errorVisitor = { | ||
enter(path, state) { | ||
const loc = path.node.loc; | ||
if (loc) { | ||
@@ -78,5 +62,3 @@ state.loc = loc; | ||
} | ||
}; | ||
class File { | ||
@@ -91,8 +73,8 @@ constructor(options, { | ||
this.declarations = {}; | ||
this.path = null; | ||
this.ast = {}; | ||
this.path = void 0; | ||
this.ast = void 0; | ||
this.scope = void 0; | ||
this.metadata = {}; | ||
this.code = ""; | ||
this.inputMap = null; | ||
this.inputMap = void 0; | ||
this.hub = { | ||
@@ -118,3 +100,2 @@ file: this, | ||
} | ||
get shebang() { | ||
@@ -126,6 +107,5 @@ const { | ||
} | ||
set shebang(value) { | ||
if (value) { | ||
this.path.get("interpreter").replaceWith(t().interpreterDirective(value)); | ||
this.path.get("interpreter").replaceWith(interpreterDirective(value)); | ||
} else { | ||
@@ -135,3 +115,2 @@ this.path.get("interpreter").remove(); | ||
} | ||
set(key, val) { | ||
@@ -141,25 +120,18 @@ if (key === "helpersNamespace") { | ||
} | ||
this._map.set(key, val); | ||
} | ||
get(key) { | ||
return this._map.get(key); | ||
} | ||
has(key) { | ||
return this._map.has(key); | ||
} | ||
getModuleName() { | ||
return (0, _helperModuleTransforms().getModuleName)(this.opts, this.opts); | ||
} | ||
addImport() { | ||
throw new Error("This API has been removed. If you're looking for this " + "functionality in Babel 7, you should import the " + "'@babel/helper-module-imports' module and use the functions exposed " + " from that module, such as 'addNamed' or 'addDefault'."); | ||
} | ||
availableHelper(name, versionRange) { | ||
let minVersion; | ||
try { | ||
@@ -171,3 +143,2 @@ minVersion = helpers().minVersion(name); | ||
} | ||
if (typeof versionRange !== "string") return true; | ||
@@ -177,8 +148,6 @@ if (_semver().valid(versionRange)) versionRange = `^${versionRange}`; | ||
} | ||
addHelper(name) { | ||
const declar = this.declarations[name]; | ||
if (declar) return t().cloneNode(declar); | ||
if (declar) return cloneNode(declar); | ||
const generator = this.get("helperGenerator"); | ||
if (generator) { | ||
@@ -188,11 +157,8 @@ const res = generator(name); | ||
} | ||
helpers().ensure(name, File); | ||
const uid = this.declarations[name] = this.scope.generateUidIdentifier(name); | ||
const dependencies = {}; | ||
for (const dep of helpers().getDependencies(name)) { | ||
dependencies[dep] = this.addHelper(dep); | ||
} | ||
const { | ||
@@ -217,10 +183,7 @@ nodes, | ||
} | ||
addTemplateObject() { | ||
throw new Error("This function has been moved into the template literal transform itself."); | ||
} | ||
buildCodeFrameError(node, msg, _Error = SyntaxError) { | ||
let loc = node && (node.loc || node._loc); | ||
if (!loc && node) { | ||
@@ -236,3 +199,2 @@ const state = { | ||
} | ||
if (loc) { | ||
@@ -255,8 +217,8 @@ const { | ||
} | ||
return new _Error(msg); | ||
} | ||
} | ||
exports.default = File; | ||
0 && 0; | ||
exports.default = File; | ||
//# sourceMappingURL=file.js.map |
@@ -7,25 +7,17 @@ "use strict"; | ||
exports.default = generateCode; | ||
function _convertSourceMap() { | ||
const data = require("convert-source-map"); | ||
_convertSourceMap = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _generator() { | ||
const data = require("@babel/generator"); | ||
_generator = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _mergeMap = require("./merge-map"); | ||
function generateCode(pluginPasses, file) { | ||
@@ -38,4 +30,7 @@ const { | ||
} = file; | ||
const { | ||
generatorOpts | ||
} = opts; | ||
generatorOpts.inputSourceMap = inputMap == null ? void 0 : inputMap.toObject(); | ||
const results = []; | ||
for (const plugins of pluginPasses) { | ||
@@ -46,5 +41,4 @@ for (const plugin of plugins) { | ||
} = plugin; | ||
if (generatorOverride) { | ||
const result = generatorOverride(ast, opts.generatorOpts, code, _generator().default); | ||
const result = generatorOverride(ast, generatorOpts, code, _generator().default); | ||
if (result !== undefined) results.push(result); | ||
@@ -54,10 +48,7 @@ } | ||
} | ||
let result; | ||
if (results.length === 0) { | ||
result = (0, _generator().default)(ast, opts.generatorOpts, code); | ||
result = (0, _generator().default)(ast, generatorOpts, code); | ||
} else if (results.length === 1) { | ||
result = results[0]; | ||
if (typeof result.then === "function") { | ||
@@ -69,20 +60,23 @@ throw new Error(`You appear to be using an async codegen plugin, ` + `which your current version of Babel does not support. ` + `If you're using a published plugin, ` + `you may need to upgrade your @babel/core version.`); | ||
} | ||
let { | ||
code: outputCode, | ||
map: outputMap | ||
decodedMap: outputMap = result.map | ||
} = result; | ||
if (outputMap && inputMap) { | ||
outputMap = (0, _mergeMap.default)(inputMap.toObject(), outputMap); | ||
if (result.__mergedMap) { | ||
outputMap = Object.assign({}, result.map); | ||
} else { | ||
if (outputMap) { | ||
if (inputMap) { | ||
outputMap = (0, _mergeMap.default)(inputMap.toObject(), outputMap, generatorOpts.sourceFileName); | ||
} else { | ||
outputMap = result.map; | ||
} | ||
} | ||
} | ||
if (opts.sourceMaps === "inline" || opts.sourceMaps === "both") { | ||
outputCode += "\n" + _convertSourceMap().fromObject(outputMap).toComment(); | ||
} | ||
if (opts.sourceMaps === "inline") { | ||
outputMap = null; | ||
} | ||
return { | ||
@@ -92,2 +86,5 @@ outputCode, | ||
}; | ||
} | ||
} | ||
0 && 0; | ||
//# sourceMappingURL=generate.js.map |
@@ -7,240 +7,32 @@ "use strict"; | ||
exports.default = mergeSourceMap; | ||
function _sourceMap() { | ||
const data = require("source-map"); | ||
_sourceMap = function () { | ||
function _remapping() { | ||
const data = require("@ampproject/remapping"); | ||
_remapping = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function mergeSourceMap(inputMap, map) { | ||
const input = buildMappingData(inputMap); | ||
const output = buildMappingData(map); | ||
const mergedGenerator = new (_sourceMap().SourceMapGenerator)(); | ||
for (const { | ||
source | ||
} of input.sources) { | ||
if (typeof source.content === "string") { | ||
mergedGenerator.setSourceContent(source.path, source.content); | ||
function mergeSourceMap(inputMap, map, sourceFileName) { | ||
const source = sourceFileName.replace(/\\/g, "/"); | ||
let found = false; | ||
const result = _remapping()(rootless(map), (s, ctx) => { | ||
if (s === source && !found) { | ||
found = true; | ||
ctx.source = ""; | ||
return rootless(inputMap); | ||
} | ||
} | ||
if (output.sources.length === 1) { | ||
const defaultSource = output.sources[0]; | ||
const insertedMappings = new Map(); | ||
eachInputGeneratedRange(input, (generated, original, source) => { | ||
eachOverlappingGeneratedOutputRange(defaultSource, generated, item => { | ||
const key = makeMappingKey(item); | ||
if (insertedMappings.has(key)) return; | ||
insertedMappings.set(key, item); | ||
mergedGenerator.addMapping({ | ||
source: source.path, | ||
original: { | ||
line: original.line, | ||
column: original.columnStart | ||
}, | ||
generated: { | ||
line: item.line, | ||
column: item.columnStart | ||
}, | ||
name: original.name | ||
}); | ||
}); | ||
}); | ||
for (const item of insertedMappings.values()) { | ||
if (item.columnEnd === Infinity) { | ||
continue; | ||
} | ||
const clearItem = { | ||
line: item.line, | ||
columnStart: item.columnEnd | ||
}; | ||
const key = makeMappingKey(clearItem); | ||
if (insertedMappings.has(key)) { | ||
continue; | ||
} | ||
mergedGenerator.addMapping({ | ||
generated: { | ||
line: clearItem.line, | ||
column: clearItem.columnStart | ||
} | ||
}); | ||
} | ||
} | ||
const result = mergedGenerator.toJSON(); | ||
if (typeof input.sourceRoot === "string") { | ||
result.sourceRoot = input.sourceRoot; | ||
} | ||
return result; | ||
} | ||
function makeMappingKey(item) { | ||
return `${item.line}/${item.columnStart}`; | ||
} | ||
function eachOverlappingGeneratedOutputRange(outputFile, inputGeneratedRange, callback) { | ||
const overlappingOriginal = filterApplicableOriginalRanges(outputFile, inputGeneratedRange); | ||
for (const { | ||
generated | ||
} of overlappingOriginal) { | ||
for (const item of generated) { | ||
callback(item); | ||
} | ||
} | ||
} | ||
function filterApplicableOriginalRanges({ | ||
mappings | ||
}, { | ||
line, | ||
columnStart, | ||
columnEnd | ||
}) { | ||
return filterSortedArray(mappings, ({ | ||
original: outOriginal | ||
}) => { | ||
if (line > outOriginal.line) return -1; | ||
if (line < outOriginal.line) return 1; | ||
if (columnStart >= outOriginal.columnEnd) return -1; | ||
if (columnEnd <= outOriginal.columnStart) return 1; | ||
return 0; | ||
return null; | ||
}); | ||
} | ||
function eachInputGeneratedRange(map, callback) { | ||
for (const { | ||
source, | ||
mappings | ||
} of map.sources) { | ||
for (const { | ||
original, | ||
generated | ||
} of mappings) { | ||
for (const item of generated) { | ||
callback(item, original, source); | ||
} | ||
} | ||
if (typeof inputMap.sourceRoot === "string") { | ||
result.sourceRoot = inputMap.sourceRoot; | ||
} | ||
return Object.assign({}, result); | ||
} | ||
function buildMappingData(map) { | ||
const consumer = new (_sourceMap().SourceMapConsumer)(Object.assign({}, map, { | ||
function rootless(map) { | ||
return Object.assign({}, map, { | ||
sourceRoot: null | ||
})); | ||
const sources = new Map(); | ||
const mappings = new Map(); | ||
let last = null; | ||
consumer.computeColumnSpans(); | ||
consumer.eachMapping(m => { | ||
if (m.originalLine === null) return; | ||
let source = sources.get(m.source); | ||
if (!source) { | ||
source = { | ||
path: m.source, | ||
content: consumer.sourceContentFor(m.source, true) | ||
}; | ||
sources.set(m.source, source); | ||
} | ||
let sourceData = mappings.get(source); | ||
if (!sourceData) { | ||
sourceData = { | ||
source, | ||
mappings: [] | ||
}; | ||
mappings.set(source, sourceData); | ||
} | ||
const obj = { | ||
line: m.originalLine, | ||
columnStart: m.originalColumn, | ||
columnEnd: Infinity, | ||
name: m.name | ||
}; | ||
if (last && last.source === source && last.mapping.line === m.originalLine) { | ||
last.mapping.columnEnd = m.originalColumn; | ||
} | ||
last = { | ||
source, | ||
mapping: obj | ||
}; | ||
sourceData.mappings.push({ | ||
original: obj, | ||
generated: consumer.allGeneratedPositionsFor({ | ||
source: m.source, | ||
line: m.originalLine, | ||
column: m.originalColumn | ||
}).map(item => ({ | ||
line: item.line, | ||
columnStart: item.column, | ||
columnEnd: item.lastColumn + 1 | ||
})) | ||
}); | ||
}, null, _sourceMap().SourceMapConsumer.ORIGINAL_ORDER); | ||
return { | ||
file: map.file, | ||
sourceRoot: map.sourceRoot, | ||
sources: Array.from(mappings.values()) | ||
}; | ||
}); | ||
} | ||
0 && 0; | ||
function findInsertionLocation(array, callback) { | ||
let left = 0; | ||
let right = array.length; | ||
while (left < right) { | ||
const mid = Math.floor((left + right) / 2); | ||
const item = array[mid]; | ||
const result = callback(item); | ||
if (result === 0) { | ||
left = mid; | ||
break; | ||
} | ||
if (result >= 0) { | ||
right = mid; | ||
} else { | ||
left = mid + 1; | ||
} | ||
} | ||
let i = left; | ||
if (i < array.length) { | ||
while (i >= 0 && callback(array[i]) >= 0) { | ||
i--; | ||
} | ||
return i + 1; | ||
} | ||
return i; | ||
} | ||
function filterSortedArray(array, callback) { | ||
const start = findInsertionLocation(array, callback); | ||
const results = []; | ||
for (let i = start; i < array.length && callback(array[i]) === 0; i++) { | ||
results.push(array[i]); | ||
} | ||
return results; | ||
} | ||
//# sourceMappingURL=merge-map.js.map |
@@ -7,27 +7,18 @@ "use strict"; | ||
exports.run = run; | ||
function _traverse() { | ||
const data = require("@babel/traverse"); | ||
_traverse = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _pluginPass = require("./plugin-pass"); | ||
var _blockHoistPlugin = require("./block-hoist-plugin"); | ||
var _normalizeOpts = require("./normalize-opts"); | ||
var _normalizeFile = require("./normalize-file"); | ||
var _generate = require("./file/generate"); | ||
var _deepArray = require("../config/helpers/deep-array"); | ||
function* run(config, code, ast) { | ||
const file = yield* (0, _normalizeFile.default)(config.passes, (0, _normalizeOpts.default)(config), code, ast); | ||
const opts = file.opts; | ||
try { | ||
@@ -37,14 +28,9 @@ yield* transformFile(file, config.passes); | ||
var _opts$filename; | ||
e.message = `${(_opts$filename = opts.filename) != null ? _opts$filename : "unknown"}: ${e.message}`; | ||
e.message = `${(_opts$filename = opts.filename) != null ? _opts$filename : "unknown file"}: ${e.message}`; | ||
if (!e.code) { | ||
e.code = "BABEL_TRANSFORM_ERROR"; | ||
} | ||
throw e; | ||
} | ||
let outputCode, outputMap; | ||
try { | ||
@@ -59,12 +45,8 @@ if (opts.code !== false) { | ||
var _opts$filename2; | ||
e.message = `${(_opts$filename2 = opts.filename) != null ? _opts$filename2 : "unknown"}: ${e.message}`; | ||
e.message = `${(_opts$filename2 = opts.filename) != null ? _opts$filename2 : "unknown file"}: ${e.message}`; | ||
if (!e.code) { | ||
e.code = "BABEL_GENERATE_ERROR"; | ||
} | ||
throw e; | ||
} | ||
return { | ||
@@ -76,6 +58,6 @@ metadata: file.metadata, | ||
map: outputMap === undefined ? null : outputMap, | ||
sourceType: file.ast.program.sourceType | ||
sourceType: file.ast.program.sourceType, | ||
externalDependencies: (0, _deepArray.flattenToSet)(config.externalDependencies) | ||
}; | ||
} | ||
function* transformFile(file, pluginPasses) { | ||
@@ -86,3 +68,2 @@ for (const pluginPairs of pluginPasses) { | ||
const visitors = []; | ||
for (const plugin of pluginPairs.concat([(0, _blockHoistPlugin.default)()])) { | ||
@@ -94,10 +75,7 @@ const pass = new _pluginPass.default(file, plugin.key, plugin.options); | ||
} | ||
for (const [plugin, pass] of passPairs) { | ||
const fn = plugin.pre; | ||
if (fn) { | ||
const result = fn.call(pass, file); | ||
yield* []; | ||
if (isThenable(result)) { | ||
@@ -108,14 +86,9 @@ throw new Error(`You appear to be using an plugin with an async .pre, ` + `which your current version of Babel does not support. ` + `If you're using a published plugin, you may need to upgrade ` + `your @babel/core version.`); | ||
} | ||
const visitor = _traverse().default.visitors.merge(visitors, passes, file.opts.wrapPluginVisitorMethod); | ||
(0, _traverse().default)(file.ast, visitor, file.scope); | ||
for (const [plugin, pass] of passPairs) { | ||
const fn = plugin.post; | ||
if (fn) { | ||
const result = fn.call(pass, file); | ||
yield* []; | ||
if (isThenable(result)) { | ||
@@ -128,5 +101,7 @@ throw new Error(`You appear to be using an plugin with an async .post, ` + `which your current version of Babel does not support. ` + `If you're using a published plugin, you may need to upgrade ` + `your @babel/core version.`); | ||
} | ||
function isThenable(val) { | ||
return !!val && (typeof val === "object" || typeof val === "function") && !!val.then && typeof val.then === "function"; | ||
} | ||
} | ||
0 && 0; | ||
//# sourceMappingURL=index.js.map |
@@ -7,73 +7,55 @@ "use strict"; | ||
exports.default = normalizeFile; | ||
function _fs() { | ||
const data = require("fs"); | ||
_fs = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _path() { | ||
const data = require("path"); | ||
_path = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _debug() { | ||
const data = require("debug"); | ||
_debug = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function t() { | ||
function _t() { | ||
const data = require("@babel/types"); | ||
t = function () { | ||
_t = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _convertSourceMap() { | ||
const data = require("convert-source-map"); | ||
_convertSourceMap = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _file = require("./file/file"); | ||
var _parser = require("../parser"); | ||
var _cloneDeep = require("./util/clone-deep"); | ||
const { | ||
file, | ||
traverseFast | ||
} = _t(); | ||
const debug = _debug()("babel:transform:file"); | ||
const LARGE_INPUT_SOURCEMAP_THRESHOLD = 1000000; | ||
const INLINE_SOURCEMAP_REGEX = /^[@#]\s+sourceMappingURL=data:(?:application|text)\/json;(?:charset[:=]\S+?;)?base64,(?:.*)$/; | ||
const EXTERNAL_SOURCEMAP_REGEX = /^[@#][ \t]+sourceMappingURL=([^\s'"`]+)[ \t]*$/; | ||
function* normalizeFile(pluginPasses, options, code, ast) { | ||
code = `${code || ""}`; | ||
if (ast) { | ||
if (ast.type === "Program") { | ||
ast = t().file(ast, [], []); | ||
ast = file(ast, [], []); | ||
} else if (ast.type !== "File") { | ||
throw new Error("AST root must be a Program or File node"); | ||
} | ||
if (options.cloneInputAst) { | ||
@@ -85,5 +67,3 @@ ast = (0, _cloneDeep.default)(ast); | ||
} | ||
let inputMap = null; | ||
if (options.inputSourceMap !== false) { | ||
@@ -93,6 +73,4 @@ if (typeof options.inputSourceMap === "object") { | ||
} | ||
if (!inputMap) { | ||
const lastComment = extractComments(INLINE_SOURCEMAP_REGEX, ast); | ||
if (lastComment) { | ||
@@ -106,17 +84,9 @@ try { | ||
} | ||
if (!inputMap) { | ||
const lastComment = extractComments(EXTERNAL_SOURCEMAP_REGEX, ast); | ||
if (typeof options.filename === "string" && lastComment) { | ||
try { | ||
const match = EXTERNAL_SOURCEMAP_REGEX.exec(lastComment); | ||
const inputMapContent = _fs().readFileSync(_path().resolve(_path().dirname(options.filename), match[1])); | ||
if (inputMapContent.length > LARGE_INPUT_SOURCEMAP_THRESHOLD) { | ||
debug("skip merging input map > 1 MB"); | ||
} else { | ||
inputMap = _convertSourceMap().fromJSON(inputMapContent); | ||
} | ||
const inputMapContent = _fs().readFileSync(_path().resolve(_path().dirname(options.filename), match[1]), "utf8"); | ||
inputMap = _convertSourceMap().fromJSON(inputMapContent); | ||
} catch (err) { | ||
@@ -130,13 +100,8 @@ debug("discarding unknown file input sourcemap", err); | ||
} | ||
return new _file.default(options, { | ||
code, | ||
ast, | ||
ast: ast, | ||
inputMap | ||
}); | ||
} | ||
const INLINE_SOURCEMAP_REGEX = /^[@#]\s+sourceMappingURL=data:(?:application|text)\/json;(?:charset[:=]\S+?;)?base64,(?:.*)$/; | ||
const EXTERNAL_SOURCEMAP_REGEX = /^[@#][ \t]+sourceMappingURL=([^\s'"`]+)[ \t]*$/; | ||
function extractCommentsFromList(regex, comments, lastComment) { | ||
@@ -151,13 +116,10 @@ if (comments) { | ||
} | ||
return true; | ||
}); | ||
} | ||
return [comments, lastComment]; | ||
} | ||
function extractComments(regex, ast) { | ||
let lastComment = null; | ||
t().traverseFast(ast, node => { | ||
traverseFast(ast, node => { | ||
[node.leadingComments, lastComment] = extractCommentsFromList(regex, node.leadingComments, lastComment); | ||
@@ -168,2 +130,5 @@ [node.innerComments, lastComment] = extractCommentsFromList(regex, node.innerComments, lastComment); | ||
return lastComment; | ||
} | ||
} | ||
0 && 0; | ||
//# sourceMappingURL=normalize-file.js.map |
@@ -7,13 +7,9 @@ "use strict"; | ||
exports.default = normalizeOptions; | ||
function _path() { | ||
const data = require("path"); | ||
_path = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function normalizeOptions(config) { | ||
@@ -53,3 +49,2 @@ const { | ||
}); | ||
for (const plugins of config.passes) { | ||
@@ -62,4 +57,6 @@ for (const plugin of plugins) { | ||
} | ||
return options; | ||
} | ||
0 && 0; | ||
return options; | ||
} | ||
//# sourceMappingURL=normalize-opts.js.map |
@@ -7,3 +7,2 @@ "use strict"; | ||
exports.default = void 0; | ||
class PluginPass { | ||
@@ -23,29 +22,18 @@ constructor(file, key, options) { | ||
} | ||
set(key, val) { | ||
this._map.set(key, val); | ||
} | ||
get(key) { | ||
return this._map.get(key); | ||
} | ||
availableHelper(name, versionRange) { | ||
return this.file.availableHelper(name, versionRange); | ||
} | ||
addHelper(name) { | ||
return this.file.addHelper(name); | ||
} | ||
addImport() { | ||
return this.file.addImport(); | ||
} | ||
buildCodeFrameError(node, msg, _Error) { | ||
return this.file.buildCodeFrameError(node, msg, _Error); | ||
} | ||
} | ||
exports.default = PluginPass; | ||
@@ -56,2 +44,8 @@ { | ||
}; | ||
} | ||
PluginPass.prototype.addImport = function addImport() { | ||
this.file.addImport(); | ||
}; | ||
} | ||
0 && 0; | ||
//# sourceMappingURL=plugin-pass.js.map |
@@ -7,21 +7,31 @@ "use strict"; | ||
exports.default = _default; | ||
function _v() { | ||
const data = require("v8"); | ||
_v = function () { | ||
return data; | ||
}; | ||
return data; | ||
function deepClone(value, cache) { | ||
if (value !== null) { | ||
if (cache.has(value)) return cache.get(value); | ||
let cloned; | ||
if (Array.isArray(value)) { | ||
cloned = new Array(value.length); | ||
cache.set(value, cloned); | ||
for (let i = 0; i < value.length; i++) { | ||
cloned[i] = typeof value[i] !== "object" ? value[i] : deepClone(value[i], cache); | ||
} | ||
} else { | ||
cloned = {}; | ||
cache.set(value, cloned); | ||
const keys = Object.keys(value); | ||
for (let i = 0; i < keys.length; i++) { | ||
const key = keys[i]; | ||
cloned[key] = typeof value[key] !== "object" ? value[key] : deepClone(value[key], cache); | ||
} | ||
} | ||
return cloned; | ||
} | ||
return value; | ||
} | ||
var _cloneDeepBrowser = require("./clone-deep-browser"); | ||
function _default(value) { | ||
if (_v().deserialize && _v().serialize) { | ||
return _v().deserialize(_v().serialize(value)); | ||
} | ||
if (typeof value !== "object") return value; | ||
return deepClone(value, new Map()); | ||
} | ||
0 && 0; | ||
return (0, _cloneDeepBrowser.default)(value); | ||
} | ||
//# sourceMappingURL=clone-deep.js.map |
{ | ||
"name": "@babel/core", | ||
"version": "7.14.3", | ||
"version": "7.22.5", | ||
"description": "Babel compiler core.", | ||
"main": "lib/index.js", | ||
"author": "Sebastian McKenzie <sebmck@gmail.com>", | ||
"main": "./lib/index.js", | ||
"author": "The Babel Team (https://babel.dev/team)", | ||
"license": "MIT", | ||
@@ -44,34 +44,40 @@ "publishConfig": { | ||
"./lib/transform-file.js": "./lib/transform-file-browser.js", | ||
"./lib/transformation/util/clone-deep.js": "./lib/transformation/util/clone-deep-browser.js", | ||
"./src/config/files/index.ts": "./src/config/files/index-browser.ts", | ||
"./src/config/resolve-targets.ts": "./src/config/resolve-targets-browser.ts", | ||
"./src/transform-file.ts": "./src/transform-file-browser.ts", | ||
"./src/transformation/util/clone-deep.ts": "./src/transformation/util/clone-deep-browser.ts" | ||
"./src/transform-file.ts": "./src/transform-file-browser.ts" | ||
}, | ||
"dependencies": { | ||
"@babel/code-frame": "^7.12.13", | ||
"@babel/generator": "^7.14.3", | ||
"@babel/helper-compilation-targets": "^7.13.16", | ||
"@babel/helper-module-transforms": "^7.14.2", | ||
"@babel/helpers": "^7.14.0", | ||
"@babel/parser": "^7.14.3", | ||
"@babel/template": "^7.12.13", | ||
"@babel/traverse": "^7.14.2", | ||
"@babel/types": "^7.14.2", | ||
"@ampproject/remapping": "^2.2.0", | ||
"@babel/code-frame": "^7.22.5", | ||
"@babel/generator": "^7.22.5", | ||
"@babel/helper-compilation-targets": "^7.22.5", | ||
"@babel/helper-module-transforms": "^7.22.5", | ||
"@babel/helpers": "^7.22.5", | ||
"@babel/parser": "^7.22.5", | ||
"@babel/template": "^7.22.5", | ||
"@babel/traverse": "^7.22.5", | ||
"@babel/types": "^7.22.5", | ||
"convert-source-map": "^1.7.0", | ||
"debug": "^4.1.0", | ||
"gensync": "^1.0.0-beta.2", | ||
"json5": "^2.1.2", | ||
"semver": "^6.3.0", | ||
"source-map": "^0.5.0" | ||
"json5": "^2.2.2", | ||
"semver": "^6.3.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/helper-transform-fixture-test-runner": "7.13.15", | ||
"@babel/plugin-transform-modules-commonjs": "7.14.0", | ||
"@babel/helper-transform-fixture-test-runner": "^7.22.5", | ||
"@babel/plugin-syntax-flow": "^7.22.5", | ||
"@babel/plugin-transform-flow-strip-types": "^7.22.5", | ||
"@babel/plugin-transform-modules-commonjs": "^7.22.5", | ||
"@babel/preset-env": "^7.22.5", | ||
"@babel/preset-typescript": "^7.22.5", | ||
"@jridgewell/trace-mapping": "^0.3.17", | ||
"@types/convert-source-map": "^1.5.1", | ||
"@types/debug": "^4.1.0", | ||
"@types/gensync": "^1.0.0", | ||
"@types/resolve": "^1.3.2", | ||
"@types/semver": "^5.4.0", | ||
"@types/source-map": "^0.5.0" | ||
} | ||
"rimraf": "^3.0.0", | ||
"ts-node": "^10.9.1" | ||
}, | ||
"type": "commonjs" | ||
} |
@@ -38,3 +38,3 @@ import type { Handler } from "gensync"; | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
caller: CallerMetadata | void, | ||
caller: CallerMetadata | undefined, | ||
): Handler<RelativeConfig> { | ||
@@ -51,3 +51,3 @@ return { config: null, ignore: null }; | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
caller: CallerMetadata | void, | ||
caller: CallerMetadata | undefined, | ||
): Handler<ConfigFile | null> { | ||
@@ -64,3 +64,3 @@ return null; | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
caller: CallerMetadata | void, | ||
caller: CallerMetadata | undefined, | ||
): Handler<ConfigFile> { | ||
@@ -78,3 +78,3 @@ throw new Error(`Cannot load ${name} relative to ${dirname} in a browser`); | ||
export const ROOT_CONFIG_FILENAMES = []; | ||
export const ROOT_CONFIG_FILENAMES: string[] = []; | ||
@@ -81,0 +81,0 @@ // eslint-disable-next-line @typescript-eslint/no-unused-vars |
@@ -6,3 +6,3 @@ type indexBrowserType = typeof import("./index-browser"); | ||
// exports of index-browser, since this file may be replaced at bundle time with index-browser. | ||
({} as any as indexBrowserType as indexType); | ||
({}) as any as indexBrowserType as indexType; | ||
@@ -26,6 +26,6 @@ export { findPackageData } from "./package"; | ||
export { | ||
loadPlugin, | ||
loadPreset, | ||
resolvePlugin, | ||
resolvePreset, | ||
loadPlugin, | ||
loadPreset, | ||
} from "./plugins"; |
import type { ValidatedOptions } from "./validation/options"; | ||
import getTargets from "@babel/helper-compilation-targets"; | ||
import getTargets, { | ||
type InputTargets, | ||
} from "@babel/helper-compilation-targets"; | ||
@@ -20,10 +22,15 @@ import type { Targets } from "@babel/helper-compilation-targets"; | ||
): Targets { | ||
// todo(flow->ts) remove any and refactor to not assign different types into same variable | ||
let targets: any = options.targets; | ||
if (typeof targets === "string" || Array.isArray(targets)) { | ||
targets = { browsers: targets }; | ||
const optTargets = options.targets; | ||
let targets: InputTargets; | ||
if (typeof optTargets === "string" || Array.isArray(optTargets)) { | ||
targets = { browsers: optTargets }; | ||
} else if (optTargets) { | ||
if ("esmodules" in optTargets) { | ||
targets = { ...optTargets, esmodules: "intersect" }; | ||
} else { | ||
// https://github.com/microsoft/TypeScript/issues/17002 | ||
targets = optTargets as InputTargets; | ||
} | ||
} | ||
if (targets && targets.esmodules) { | ||
targets = { ...targets, esmodules: "intersect" }; | ||
} | ||
@@ -30,0 +37,0 @@ return getTargets(targets, { |
@@ -6,7 +6,9 @@ type browserType = typeof import("./resolve-targets-browser"); | ||
// exports of index-browser, since this file may be replaced at bundle time with index-browser. | ||
({} as any as browserType as nodeType); | ||
({}) as any as browserType as nodeType; | ||
import type { ValidatedOptions } from "./validation/options"; | ||
import path from "path"; | ||
import getTargets from "@babel/helper-compilation-targets"; | ||
import getTargets, { | ||
type InputTargets, | ||
} from "@babel/helper-compilation-targets"; | ||
@@ -26,10 +28,15 @@ import type { Targets } from "@babel/helper-compilation-targets"; | ||
): Targets { | ||
// todo(flow->ts) remove any and refactor to not assign different types into same variable | ||
let targets: any = options.targets; | ||
if (typeof targets === "string" || Array.isArray(targets)) { | ||
targets = { browsers: targets }; | ||
const optTargets = options.targets; | ||
let targets: InputTargets; | ||
if (typeof optTargets === "string" || Array.isArray(optTargets)) { | ||
targets = { browsers: optTargets }; | ||
} else if (optTargets) { | ||
if ("esmodules" in optTargets) { | ||
targets = { ...optTargets, esmodules: "intersect" }; | ||
} else { | ||
// https://github.com/microsoft/TypeScript/issues/17002 | ||
targets = optTargets as InputTargets; | ||
} | ||
} | ||
if (targets && targets.esmodules) { | ||
targets = { ...targets, esmodules: "intersect" }; | ||
} | ||
@@ -36,0 +43,0 @@ const { browserslistConfigFile } = options; |
// duplicated from transform-file so we do not have to import anything here | ||
type TransformFile = { | ||
(filename: string, callback: Function): void; | ||
(filename: string, opts: any, callback: Function): void; | ||
(filename: string, callback: (error: Error, file: null) => void): void; | ||
( | ||
filename: string, | ||
opts: any, | ||
callback: (error: Error, file: null) => void, | ||
): void; | ||
}; | ||
@@ -10,3 +14,3 @@ | ||
opts, | ||
callback?, | ||
callback?: (error: Error, file: null) => void, | ||
) { | ||
@@ -13,0 +17,0 @@ if (typeof opts === "function") { |
@@ -1,2 +0,2 @@ | ||
import gensync from "gensync"; | ||
import gensync, { type Handler } from "gensync"; | ||
@@ -15,16 +15,8 @@ import loadConfig from "./config"; | ||
// transform-file-browser. | ||
({} as any as transformFileBrowserType as transformFileType); | ||
({}) as any as transformFileBrowserType as transformFileType; | ||
type TransformFile = { | ||
(filename: string, callback: FileResultCallback): void; | ||
( | ||
filename: string, | ||
opts: InputOptions | undefined | null, | ||
callback: FileResultCallback, | ||
): void; | ||
}; | ||
const transformFileRunner = gensync< | ||
(filename: string, opts?: InputOptions) => FileResult | null | ||
>(function* (filename, opts: InputOptions) { | ||
const transformFileRunner = gensync(function* ( | ||
filename: string, | ||
opts?: InputOptions, | ||
): Handler<FileResult | null> { | ||
const options = { ...opts, filename }; | ||
@@ -39,4 +31,27 @@ | ||
export const transformFile = transformFileRunner.errback as TransformFile; | ||
export const transformFileSync = transformFileRunner.sync; | ||
export const transformFileAsync = transformFileRunner.async; | ||
// @ts-expect-error TS doesn't detect that this signature is compatible | ||
export function transformFile( | ||
filename: string, | ||
callback: FileResultCallback, | ||
): void; | ||
export function transformFile( | ||
filename: string, | ||
opts: InputOptions | undefined | null, | ||
callback: FileResultCallback, | ||
): void; | ||
export function transformFile( | ||
...args: Parameters<typeof transformFileRunner.errback> | ||
) { | ||
transformFileRunner.errback(...args); | ||
} | ||
export function transformFileSync( | ||
...args: Parameters<typeof transformFileRunner.sync> | ||
) { | ||
return transformFileRunner.sync(...args); | ||
} | ||
export function transformFileAsync( | ||
...args: Parameters<typeof transformFileRunner.async> | ||
) { | ||
return transformFileRunner.async(...args); | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
768810
120
6791
11
14
+ Added@ampproject/remapping@^2.2.0
+ Added@ampproject/remapping@2.3.0(transitive)
+ Added@babel/code-frame@7.26.0(transitive)
+ Added@babel/compat-data@7.26.0(transitive)
+ Added@babel/generator@7.26.0(transitive)
+ Added@babel/parser@7.26.1(transitive)
+ Addedcaniuse-lite@1.0.30001674(transitive)
+ Addedelectron-to-chromium@1.5.49(transitive)
- Removedsource-map@^0.5.0
- Removed@babel/code-frame@7.26.2(transitive)
- Removed@babel/compat-data@7.26.2(transitive)
- Removed@babel/generator@7.26.2(transitive)
- Removed@babel/parser@7.26.2(transitive)
- Removedcaniuse-lite@1.0.30001677(transitive)
- Removedelectron-to-chromium@1.5.51(transitive)
- Removedsource-map@0.5.7(transitive)
Updated@babel/code-frame@^7.22.5
Updated@babel/generator@^7.22.5
Updated@babel/helpers@^7.22.5
Updated@babel/parser@^7.22.5
Updated@babel/template@^7.22.5
Updated@babel/traverse@^7.22.5
Updated@babel/types@^7.22.5
Updatedjson5@^2.2.2