@babel/core
Advanced tools
Comparing version 7.0.0-rc.1 to 7.0.0-rc.2
@@ -8,2 +8,3 @@ "use strict"; | ||
exports.makeWeakCache = makeWeakCache; | ||
exports.assertSimpleType = assertSimpleType; | ||
@@ -179,3 +180,3 @@ function makeStrongCache(handler) { | ||
return cache.using(val); | ||
return cache.using(() => assertSimpleType(val())); | ||
} | ||
@@ -187,7 +188,15 @@ | ||
cacheFn.using = cb => cache.using(() => cb()); | ||
cacheFn.using = cb => cache.using(() => assertSimpleType(cb())); | ||
cacheFn.invalidate = cb => cache.invalidate(() => cb()); | ||
cacheFn.invalidate = cb => cache.invalidate(() => assertSimpleType(cb())); | ||
return cacheFn; | ||
} | ||
function assertSimpleType(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; | ||
} |
@@ -6,4 +6,5 @@ "use strict"; | ||
}); | ||
exports.buildPresetChain = buildPresetChain; | ||
exports.buildRootChain = buildRootChain; | ||
exports.buildPresetChain = void 0; | ||
exports.buildPresetChainWalker = void 0; | ||
@@ -43,3 +44,14 @@ function _path() { | ||
const debug = (0, _debug().default)("babel:config:config-chain"); | ||
const buildPresetChain = makeChainWalker({ | ||
function buildPresetChain(arg, context) { | ||
const chain = buildPresetChainWalker(arg, context); | ||
if (!chain) return null; | ||
return { | ||
plugins: dedupDescriptors(chain.plugins), | ||
presets: dedupDescriptors(chain.presets), | ||
options: chain.options | ||
}; | ||
} | ||
const buildPresetChainWalker = makeChainWalker({ | ||
init: arg => arg, | ||
@@ -51,3 +63,3 @@ root: preset => loadPresetDescriptors(preset), | ||
}); | ||
exports.buildPresetChain = buildPresetChain; | ||
exports.buildPresetChainWalker = buildPresetChainWalker; | ||
const loadPresetDescriptors = (0, _caching.makeWeakCache)(preset => buildRootDescriptors(preset, preset.alias, _configDescriptors.createUncachedDescriptors)); | ||
@@ -67,5 +79,5 @@ const loadPresetEnvDescriptors = (0, _caching.makeWeakCache)(preset => (0, _caching.makeStrongCache)(envName => buildEnvDescriptors(preset, preset.alias, _configDescriptors.createUncachedDescriptors, envName))); | ||
if (typeof opts.configFile === "string") { | ||
configFile = (0, _files.loadConfig)(opts.configFile, context.cwd, context.envName); | ||
configFile = (0, _files.loadConfig)(opts.configFile, context.cwd, context.envName, context.caller); | ||
} else if (opts.configFile !== false) { | ||
configFile = (0, _files.findRootConfig)(context.root, context.envName); | ||
configFile = (0, _files.findRootConfig)(context.root, context.envName, context.caller); | ||
} | ||
@@ -148,3 +160,3 @@ | ||
return pkgData.directories.some(directory => { | ||
return matchPattern(pat, context.cwd, directory); | ||
return matchPattern(pat, context.cwd, directory, context); | ||
}); | ||
@@ -280,3 +292,3 @@ }); | ||
if (opts.extends === undefined) return true; | ||
const file = (0, _files.loadConfig)(opts.extends, dirname, context.envName); | ||
const file = (0, _files.loadConfig)(opts.extends, dirname, context.envName, context.caller); | ||
@@ -361,10 +373,6 @@ if (files.has(file)) { | ||
desc = { | ||
value: null | ||
value: item | ||
}; | ||
descriptors.push(desc); | ||
if (!item.ownPass) nameMap.set(item.name, desc); | ||
} | ||
if (item.options === false) { | ||
desc.value = null; | ||
} else { | ||
@@ -381,3 +389,3 @@ desc.value = item; | ||
return descriptors.reduce((acc, desc) => { | ||
if (desc.value) acc.push(desc.value); | ||
acc.push(desc.value); | ||
return acc; | ||
@@ -413,7 +421,13 @@ }, []); | ||
function matchesPatterns(context, patterns, dirname) { | ||
return patterns.some(pattern => matchPattern(pattern, dirname, context.filename)); | ||
return patterns.some(pattern => matchPattern(pattern, dirname, context.filename, context)); | ||
} | ||
function matchPattern(pattern, dirname, pathToTest) { | ||
if (typeof pattern === "function") return !!pattern(pathToTest); | ||
function matchPattern(pattern, dirname, pathToTest, context) { | ||
if (typeof pattern === "function") { | ||
return !!pattern(pathToTest, { | ||
dirname, | ||
envName: context.envName, | ||
caller: context.caller | ||
}); | ||
} | ||
@@ -420,0 +434,0 @@ if (typeof pathToTest !== "string") { |
@@ -16,2 +16,6 @@ "use strict"; | ||
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 createCachedDescriptors(dirname, options, alias) { | ||
@@ -52,11 +56,47 @@ const { | ||
const PRESET_DESCRIPTOR_CACHE = new WeakMap(); | ||
const createCachedPresetDescriptors = (0, _caching.makeWeakCache)((items, cache) => { | ||
const dirname = cache.using(dir => dir); | ||
return (0, _caching.makeStrongCache)(alias => (0, _caching.makeStrongCache)(passPerPreset => createPresetDescriptors(items, dirname, alias, passPerPreset))); | ||
return (0, _caching.makeStrongCache)(alias => (0, _caching.makeStrongCache)(passPerPreset => createPresetDescriptors(items, dirname, alias, passPerPreset).map(desc => loadCachedDescriptor(PRESET_DESCRIPTOR_CACHE, desc)))); | ||
}); | ||
const PLUGIN_DESCRIPTOR_CACHE = new WeakMap(); | ||
const createCachedPluginDescriptors = (0, _caching.makeWeakCache)((items, cache) => { | ||
const dirname = cache.using(dir => dir); | ||
return (0, _caching.makeStrongCache)(alias => createPluginDescriptors(items, dirname, alias)); | ||
return (0, _caching.makeStrongCache)(alias => createPluginDescriptors(items, dirname, alias).map(desc => loadCachedDescriptor(PLUGIN_DESCRIPTOR_CACHE, desc))); | ||
}); | ||
const DEFAULT_OPTIONS = {}; | ||
function loadCachedDescriptor(cache, desc) { | ||
const { | ||
value, | ||
options = DEFAULT_OPTIONS | ||
} = desc; | ||
if (options === false) return desc; | ||
let cacheByOptions = cache.get(value); | ||
if (!cacheByOptions) { | ||
cacheByOptions = new WeakMap(); | ||
cache.set(value, cacheByOptions); | ||
} | ||
let possibilities = cacheByOptions.get(options); | ||
if (!possibilities) { | ||
possibilities = []; | ||
cacheByOptions.set(options, 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) { | ||
@@ -63,0 +103,0 @@ return createDescriptors("preset", items, dirname, alias, passPerPreset); |
@@ -76,3 +76,3 @@ "use strict"; | ||
function findRelativeConfig(packageData, envName) { | ||
function findRelativeConfig(packageData, envName, caller) { | ||
let config = null; | ||
@@ -88,3 +88,3 @@ let ignore = null; | ||
const config = readConfig(filepath, envName); | ||
const config = readConfig(filepath, envName, caller); | ||
@@ -129,6 +129,6 @@ if (config && previousConfig) { | ||
function findRootConfig(dirname, envName) { | ||
function findRootConfig(dirname, envName, caller) { | ||
const filepath = _path().default.resolve(dirname, BABEL_CONFIG_JS_FILENAME); | ||
const conf = readConfig(filepath, envName); | ||
const conf = readConfig(filepath, envName, caller); | ||
@@ -142,3 +142,3 @@ if (conf) { | ||
function loadConfig(name, dirname, envName) { | ||
function loadConfig(name, dirname, envName, caller) { | ||
const filepath = _resolve().default.sync(name, { | ||
@@ -148,3 +148,3 @@ basedir: dirname | ||
const conf = readConfig(filepath, envName); | ||
const conf = readConfig(filepath, envName, caller); | ||
@@ -159,5 +159,6 @@ if (!conf) { | ||
function readConfig(filepath, envName) { | ||
function readConfig(filepath, envName, caller) { | ||
return _path().default.extname(filepath) === ".js" ? readConfigJS(filepath, { | ||
envName | ||
envName, | ||
caller | ||
}) : readConfigJSON5(filepath); | ||
@@ -164,0 +165,0 @@ } |
@@ -24,3 +24,3 @@ "use strict"; | ||
function findRelativeConfig(pkgData, envName) { | ||
function findRelativeConfig(pkgData, envName, caller) { | ||
return { | ||
@@ -33,7 +33,7 @@ pkg: null, | ||
function findRootConfig(dirname, envName) { | ||
function findRootConfig(dirname, envName, caller) { | ||
return null; | ||
} | ||
function loadConfig(name, dirname, envName) { | ||
function loadConfig(name, dirname, envName, caller) { | ||
throw new Error(`Cannot load ${name} relative to ${dirname} in a browser`); | ||
@@ -40,0 +40,0 @@ } |
@@ -49,4 +49,4 @@ "use strict"; | ||
const BABEL_PRESET_ORG_RE = /^(@babel\/)(?!preset-|[^/]+\/)/; | ||
const OTHER_PLUGIN_ORG_RE = /^(@(?!babel\/)[^/]+\/)(?!babel-plugin(?:-|\/|$)|[^/]+\/)/; | ||
const OTHER_PRESET_ORG_RE = /^(@(?!babel\/)[^/]+\/)(?!babel-preset(?:-|\/|$)|[^/]+\/)/; | ||
const OTHER_PLUGIN_ORG_RE = /^(@(?!babel\/)[^/]+\/)(?![^/]*babel-plugin(?:-|\/|$)|[^/]+\/)/; | ||
const OTHER_PRESET_ORG_RE = /^(@(?!babel\/)[^/]+\/)(?![^/]*babel-preset(?:-|\/|$)|[^/]+\/)/; | ||
const OTHER_ORG_DEFAULT_RE = /^(@(?!babel$)[^/]+)$/; | ||
@@ -53,0 +53,0 @@ |
@@ -67,12 +67,20 @@ "use strict"; | ||
const ignored = function recurseDescriptors(config, pass) { | ||
const plugins = config.plugins.map(descriptor => { | ||
return loadPluginDescriptor(descriptor, context); | ||
}); | ||
const presets = config.presets.map(descriptor => { | ||
return { | ||
preset: loadPresetDescriptor(descriptor, context), | ||
pass: descriptor.ownPass ? [] : pass | ||
}; | ||
}); | ||
const plugins = config.plugins.reduce((acc, descriptor) => { | ||
if (descriptor.options !== false) { | ||
acc.push(loadPluginDescriptor(descriptor, context)); | ||
} | ||
return acc; | ||
}, []); | ||
const presets = config.presets.reduce((acc, descriptor) => { | ||
if (descriptor.options !== false) { | ||
acc.push({ | ||
preset: loadPresetDescriptor(descriptor, context), | ||
pass: descriptor.ownPass ? [] : pass | ||
}); | ||
} | ||
return acc; | ||
}, []); | ||
if (presets.length > 0) { | ||
@@ -79,0 +87,0 @@ passes.splice(1, 0, ...presets.map(o => o.pass).filter(p => p !== pass)); |
@@ -20,2 +20,4 @@ "use strict"; | ||
var _caching = require("../caching"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -26,3 +28,7 @@ | ||
if (typeof value === "undefined") return data.envName; | ||
if (typeof value === "function") return value(data.envName); | ||
if (typeof value === "function") { | ||
return (0, _caching.assertSimpleType)(value(data.envName)); | ||
} | ||
if (!Array.isArray(value)) value = [value]; | ||
@@ -38,2 +44,4 @@ return value.some(entry => { | ||
const caller = cb => cache.using(data => (0, _caching.assertSimpleType)(cb(data.caller))); | ||
return { | ||
@@ -44,2 +52,3 @@ version: _.version, | ||
async: () => false, | ||
caller, | ||
assertVersion | ||
@@ -46,0 +55,0 @@ }; |
@@ -53,7 +53,2 @@ "use strict"; | ||
}); | ||
if (this._descriptor.options === false) { | ||
throw new Error("Assertion failure - unexpected false options"); | ||
} | ||
this.value = this._descriptor.value; | ||
@@ -60,0 +55,0 @@ this.options = this._descriptor.options; |
@@ -42,3 +42,4 @@ "use strict"; | ||
cwd = ".", | ||
root: rootDir = "." | ||
root: rootDir = ".", | ||
caller | ||
} = args; | ||
@@ -54,3 +55,4 @@ | ||
root: absoluteRootDir, | ||
envName | ||
envName, | ||
caller | ||
}; | ||
@@ -57,0 +59,0 @@ const configChain = (0, _configChain.buildRootChain)(args, context); |
@@ -6,5 +6,8 @@ "use strict"; | ||
}); | ||
exports.msg = msg; | ||
exports.access = access; | ||
exports.assertSourceMaps = assertSourceMaps; | ||
exports.assertCompact = assertCompact; | ||
exports.assertSourceType = assertSourceType; | ||
exports.assertCallerMetadata = assertCallerMetadata; | ||
exports.assertInputSourceMap = assertInputSourceMap; | ||
@@ -22,5 +25,35 @@ exports.assertString = assertString; | ||
function assertSourceMaps(key, value) { | ||
function msg(loc) { | ||
switch (loc.type) { | ||
case "root": | ||
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: | ||
throw new Error(`Assertion failure: Unknown type ${loc.type}`); | ||
} | ||
} | ||
function access(loc, name) { | ||
return { | ||
type: "access", | ||
name, | ||
parent: loc | ||
}; | ||
} | ||
function assertSourceMaps(loc, value) { | ||
if (value !== undefined && typeof value !== "boolean" && value !== "inline" && value !== "both") { | ||
throw new Error(`.${key} must be a boolean, "inline", "both", or undefined`); | ||
throw new Error(`${msg(loc)} must be a boolean, "inline", "both", or undefined`); | ||
} | ||
@@ -31,5 +64,5 @@ | ||
function assertCompact(key, value) { | ||
function assertCompact(loc, value) { | ||
if (value !== undefined && typeof value !== "boolean" && value !== "auto") { | ||
throw new Error(`.${key} must be a boolean, "auto", or undefined`); | ||
throw new Error(`${msg(loc)} must be a boolean, "auto", or undefined`); | ||
} | ||
@@ -40,5 +73,5 @@ | ||
function assertSourceType(key, value) { | ||
function assertSourceType(loc, value) { | ||
if (value !== undefined && value !== "module" && value !== "script" && value !== "unambiguous") { | ||
throw new Error(`.${key} must be "module", "script", "unambiguous", or undefined`); | ||
throw new Error(`${msg(loc)} must be "module", "script", "unambiguous", or undefined`); | ||
} | ||
@@ -49,5 +82,26 @@ | ||
function assertInputSourceMap(key, value) { | ||
function assertCallerMetadata(loc, value) { | ||
const obj = assertObject(loc, value); | ||
if (obj) { | ||
if (typeof obj["name"] !== "string") { | ||
throw new Error(`${msg(loc)} set but does not contain "name" property 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") { | ||
throw new Error(`${msg(propLoc)} must be null, undefined, a boolean, a string, or a number.`); | ||
} | ||
} | ||
} | ||
return value; | ||
} | ||
function assertInputSourceMap(loc, value) { | ||
if (value !== undefined && typeof value !== "boolean" && (typeof value !== "object" || !value)) { | ||
throw new Error(".inputSourceMap must be a boolean, object, or undefined"); | ||
throw new Error(`${msg(loc)} must be a boolean, object, or undefined`); | ||
} | ||
@@ -58,5 +112,5 @@ | ||
function assertString(key, value) { | ||
function assertString(loc, value) { | ||
if (value !== undefined && typeof value !== "string") { | ||
throw new Error(`.${key} must be a string, or undefined`); | ||
throw new Error(`${msg(loc)} must be a string, or undefined`); | ||
} | ||
@@ -67,5 +121,5 @@ | ||
function assertFunction(key, value) { | ||
function assertFunction(loc, value) { | ||
if (value !== undefined && typeof value !== "function") { | ||
throw new Error(`.${key} must be a function, or undefined`); | ||
throw new Error(`${msg(loc)} must be a function, or undefined`); | ||
} | ||
@@ -76,5 +130,5 @@ | ||
function assertBoolean(key, value) { | ||
function assertBoolean(loc, value) { | ||
if (value !== undefined && typeof value !== "boolean") { | ||
throw new Error(`.${key} must be a boolean, or undefined`); | ||
throw new Error(`${msg(loc)} must be a boolean, or undefined`); | ||
} | ||
@@ -85,5 +139,5 @@ | ||
function assertObject(key, value) { | ||
function assertObject(loc, value) { | ||
if (value !== undefined && (typeof value !== "object" || Array.isArray(value) || !value)) { | ||
throw new Error(`.${key} must be an object, or undefined`); | ||
throw new Error(`${msg(loc)} must be an object, or undefined`); | ||
} | ||
@@ -94,5 +148,5 @@ | ||
function assertArray(key, value) { | ||
function assertArray(loc, value) { | ||
if (value != null && !Array.isArray(value)) { | ||
throw new Error(`.${key} must be an array, or undefined`); | ||
throw new Error(`${msg(loc)} must be an array, or undefined`); | ||
} | ||
@@ -103,7 +157,7 @@ | ||
function assertIgnoreList(key, value) { | ||
const arr = assertArray(key, value); | ||
function assertIgnoreList(loc, value) { | ||
const arr = assertArray(loc, value); | ||
if (arr) { | ||
arr.forEach((item, i) => assertIgnoreItem(key, i, item)); | ||
arr.forEach((item, i) => assertIgnoreItem(access(loc, i), item)); | ||
} | ||
@@ -114,5 +168,5 @@ | ||
function assertIgnoreItem(key, index, value) { | ||
function assertIgnoreItem(loc, value) { | ||
if (typeof value !== "string" && typeof value !== "function" && !(value instanceof RegExp)) { | ||
throw new Error(`.${key}[${index}] must be an array of string/Funtion/RegExp values, or undefined`); | ||
throw new Error(`${msg(loc)} must be an array of string/Funtion/RegExp values, or undefined`); | ||
} | ||
@@ -123,3 +177,3 @@ | ||
function assertConfigApplicableTest(key, value) { | ||
function assertConfigApplicableTest(loc, value) { | ||
if (value === undefined) return value; | ||
@@ -130,7 +184,7 @@ | ||
if (!checkValidTest(item)) { | ||
throw new Error(`.${key}[${i}] must be a string/Function/RegExp.`); | ||
throw new Error(`${msg(access(loc, i))} must be a string/Function/RegExp.`); | ||
} | ||
}); | ||
} else if (!checkValidTest(value)) { | ||
throw new Error(`.${key} must be a string/Function/RegExp, or an array of those`); | ||
throw new Error(`${msg(loc)} must be a string/Function/RegExp, or an array of those`); | ||
} | ||
@@ -145,5 +199,5 @@ | ||
function assertConfigFileSearch(key, value) { | ||
function assertConfigFileSearch(loc, value) { | ||
if (value !== undefined && typeof value !== "boolean" && typeof value !== "string") { | ||
throw new Error(`.${key} must be a undefined, a boolean, a string, ` + `got ${JSON.stringify(value)}`); | ||
throw new Error(`${msg(loc)} must be a undefined, a boolean, a string, ` + `got ${JSON.stringify(value)}`); | ||
} | ||
@@ -154,3 +208,3 @@ | ||
function assertBabelrcSearch(key, value) { | ||
function assertBabelrcSearch(loc, value) { | ||
if (value === undefined || typeof value === "boolean") return value; | ||
@@ -161,7 +215,7 @@ | ||
if (!checkValidTest(item)) { | ||
throw new Error(`.${key}[${i}] must be a string/Function/RegExp.`); | ||
throw new Error(`${msg(access(loc, i))} must be a string/Function/RegExp.`); | ||
} | ||
}); | ||
} else if (!checkValidTest(value)) { | ||
throw new Error(`.${key} must be a undefined, a boolean, a string/Function/RegExp ` + `or an array of those, got ${JSON.stringify(value)}`); | ||
throw new Error(`${msg(loc)} must be a undefined, a boolean, a string/Function/RegExp ` + `or an array of those, got ${JSON.stringify(value)}`); | ||
} | ||
@@ -172,7 +226,7 @@ | ||
function assertPluginList(key, value) { | ||
const arr = assertArray(key, value); | ||
function assertPluginList(loc, value) { | ||
const arr = assertArray(loc, value); | ||
if (arr) { | ||
arr.forEach((item, i) => assertPluginItem(key, i, item)); | ||
arr.forEach((item, i) => assertPluginItem(access(loc, i), item)); | ||
} | ||
@@ -183,13 +237,13 @@ | ||
function assertPluginItem(key, index, value) { | ||
function assertPluginItem(loc, value) { | ||
if (Array.isArray(value)) { | ||
if (value.length === 0) { | ||
throw new Error(`.${key}[${index}] must include an object`); | ||
throw new Error(`${msg(loc)} must include an object`); | ||
} | ||
if (value.length > 3) { | ||
throw new Error(`.${key}[${index}] may only be a two-tuple or three-tuple`); | ||
throw new Error(`${msg(loc)} may only be a two-tuple or three-tuple`); | ||
} | ||
assertPluginTarget(key, index, true, value[0]); | ||
assertPluginTarget(access(loc, 0), value[0]); | ||
@@ -200,3 +254,3 @@ if (value.length > 1) { | ||
if (opts !== undefined && opts !== false && (typeof opts !== "object" || Array.isArray(opts))) { | ||
throw new Error(`.${key}[${index}][1] must be an object, false, or undefined`); | ||
throw new Error(`${msg(access(loc, 1))} must be an object, false, or undefined`); | ||
} | ||
@@ -209,7 +263,7 @@ } | ||
if (name !== undefined && typeof name !== "string") { | ||
throw new Error(`.${key}[${index}][2] must be a string, or undefined`); | ||
throw new Error(`${msg(access(loc, 2))} must be a string, or undefined`); | ||
} | ||
} | ||
} else { | ||
assertPluginTarget(key, index, false, value); | ||
assertPluginTarget(loc, value); | ||
} | ||
@@ -220,5 +274,5 @@ | ||
function assertPluginTarget(key, index, inArray, value) { | ||
function assertPluginTarget(loc, value) { | ||
if ((typeof value !== "object" || !value) && typeof value !== "string" && typeof value !== "function") { | ||
throw new Error(`.${key}[${index}]${inArray ? `[0]` : ""} must be a string, object, function`); | ||
throw new Error(`${msg(loc)} must be a string, object, function`); | ||
} | ||
@@ -225,0 +279,0 @@ |
@@ -20,2 +20,3 @@ "use strict"; | ||
configFile: _optionAssertions.assertConfigFileSearch, | ||
caller: _optionAssertions.assertCallerMetadata, | ||
filename: _optionAssertions.assertString, | ||
@@ -68,11 +69,29 @@ filenameRelative: _optionAssertions.assertString, | ||
function getSource(loc) { | ||
return loc.type === "root" ? loc.source : getSource(loc.parent); | ||
} | ||
function validate(type, opts) { | ||
return validateNested({ | ||
type: "root", | ||
source: type | ||
}, opts); | ||
} | ||
function validateNested(loc, opts) { | ||
const type = getSource(loc); | ||
assertNoDuplicateSourcemap(opts); | ||
Object.keys(opts).forEach(key => { | ||
const optLoc = { | ||
type: "option", | ||
name: key, | ||
parent: loc | ||
}; | ||
if (type === "preset" && NONPRESET_VALIDATORS[key]) { | ||
throw new Error(`.${key} is not allowed in preset options`); | ||
throw new Error(`${(0, _optionAssertions.msg)(optLoc)} is not allowed in preset options`); | ||
} | ||
if (type !== "arguments" && ROOT_VALIDATORS[key]) { | ||
throw new Error(`.${key} is only allowed in root programmatic options`); | ||
throw new Error(`${(0, _optionAssertions.msg)(optLoc)} is only allowed in root programmatic options`); | ||
} | ||
@@ -82,22 +101,10 @@ | ||
if (type === "babelrcfile" || type === "extendsfile") { | ||
throw new Error(`.${key} is not allowed in .babelrc or "extend"ed files, only in root programmatic options, ` + `or babel.config.js/config file options`); | ||
throw new Error(`${(0, _optionAssertions.msg)(optLoc)} is not allowed in .babelrc or "extends"ed files, only in root programmatic options, ` + `or babel.config.js/config file options`); | ||
} | ||
throw new Error(`.${key} is only allowed in root programmatic options, or babel.config.js/config file options`); | ||
throw new Error(`${(0, _optionAssertions.msg)(optLoc)} is only allowed in root programmatic options, or babel.config.js/config file options`); | ||
} | ||
if (type === "env" && key === "env") { | ||
throw new Error(`.${key} is not allowed inside another env block`); | ||
} | ||
if (type === "env" && key === "overrides") { | ||
throw new Error(`.${key} is not allowed inside an env block`); | ||
} | ||
if (type === "override" && key === "overrides") { | ||
throw new Error(`.${key} is not allowed inside an overrides block`); | ||
} | ||
const validator = COMMON_VALIDATORS[key] || NONPRESET_VALIDATORS[key] || BABELRC_VALIDATORS[key] || ROOT_VALIDATORS[key]; | ||
if (validator) validator(key, opts[key]);else throw buildUnknownError(key); | ||
const validator = COMMON_VALIDATORS[key] || NONPRESET_VALIDATORS[key] || BABELRC_VALIDATORS[key] || ROOT_VALIDATORS[key] || throwUnknownError; | ||
validator(optLoc, opts[key]); | ||
}); | ||
@@ -107,3 +114,5 @@ return opts; | ||
function buildUnknownError(key) { | ||
function throwUnknownError(loc) { | ||
const key = loc.name; | ||
if (_removed.default[key]) { | ||
@@ -114,5 +123,5 @@ const { | ||
} = _removed.default[key]; | ||
throw new ReferenceError(`Using removed Babel ${version} option: .${key} - ${message}`); | ||
throw new ReferenceError(`Using removed Babel ${version} option: ${(0, _optionAssertions.msg)(loc)} - ${message}`); | ||
} else { | ||
const unknownOptErr = `Unknown option: .${key}. Check out http://babeljs.io/docs/usage/options/ for more information about options.`; | ||
const unknownOptErr = `Unknown option: ${(0, _optionAssertions.msg)(loc)}. Check out http://babeljs.io/docs/usage/options/ for more information about options.`; | ||
throw new ReferenceError(unknownOptErr); | ||
@@ -132,9 +141,20 @@ } | ||
function assertEnvSet(key, value) { | ||
const obj = (0, _optionAssertions.assertObject)(key, value); | ||
function assertEnvSet(loc, value) { | ||
if (loc.parent.type === "env") { | ||
throw new Error(`${(0, _optionAssertions.msg)(loc)} is not allowed inside of another .env block`); | ||
} | ||
const parent = loc.parent; | ||
const obj = (0, _optionAssertions.assertObject)(loc, value); | ||
if (obj) { | ||
for (const key of Object.keys(obj)) { | ||
const env = (0, _optionAssertions.assertObject)(key, obj[key]); | ||
if (env) validate("env", env); | ||
for (const envName of Object.keys(obj)) { | ||
const env = (0, _optionAssertions.assertObject)((0, _optionAssertions.access)(loc, envName), obj[envName]); | ||
if (!env) continue; | ||
const envLoc = { | ||
type: "env", | ||
name: envName, | ||
parent | ||
}; | ||
validateNested(envLoc, env); | ||
} | ||
@@ -146,10 +166,25 @@ } | ||
function assertOverridesList(key, value) { | ||
const arr = (0, _optionAssertions.assertArray)(key, value); | ||
function assertOverridesList(loc, value) { | ||
if (loc.parent.type === "env") { | ||
throw new Error(`${(0, _optionAssertions.msg)(loc)} is not allowed inside an .env block`); | ||
} | ||
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) { | ||
for (const [index, item] of arr.entries()) { | ||
const env = (0, _optionAssertions.assertObject)(`${index}`, item); | ||
if (!env) throw new Error(`.${key}[${index}] must be an object`); | ||
validate("override", env); | ||
const objLoc = (0, _optionAssertions.access)(loc, index); | ||
const env = (0, _optionAssertions.assertObject)(objLoc, item); | ||
if (!env) throw new Error(`${(0, _optionAssertions.msg)(objLoc)} must be an object`); | ||
const overridesLoc = { | ||
type: "overrides", | ||
index, | ||
parent | ||
}; | ||
validateNested(overridesLoc, env); | ||
} | ||
@@ -156,0 +191,0 @@ } |
@@ -85,5 +85,11 @@ "use strict"; | ||
this.metadata = {}; | ||
this.hub = new (_traverse().Hub)(this); | ||
this.code = ""; | ||
this.inputMap = null; | ||
this.hub = { | ||
file: this, | ||
getCode: () => this.code, | ||
getScope: () => this.scope, | ||
addHelper: this.addHelper.bind(this), | ||
buildError: this.buildCodeFrameError.bind(this) | ||
}; | ||
this.opts = options; | ||
@@ -167,6 +173,2 @@ this.code = code; | ||
resolveModuleSource(source) { | ||
return source; | ||
} | ||
addImport() { | ||
@@ -173,0 +175,0 @@ 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'."); |
@@ -236,3 +236,3 @@ "use strict"; | ||
if (i < array.length) { | ||
while (i > 0 && callback(array[i]) >= 0) { | ||
while (i >= 0 && callback(array[i]) >= 0) { | ||
i--; | ||
@@ -239,0 +239,0 @@ } |
{ | ||
"name": "@babel/core", | ||
"version": "7.0.0-rc.1", | ||
"version": "7.0.0-rc.2", | ||
"description": "Babel compiler core.", | ||
@@ -33,9 +33,9 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@babel/code-frame": "7.0.0-rc.1", | ||
"@babel/generator": "7.0.0-rc.1", | ||
"@babel/helpers": "7.0.0-rc.1", | ||
"@babel/parser": "7.0.0-rc.1", | ||
"@babel/template": "7.0.0-rc.1", | ||
"@babel/traverse": "7.0.0-rc.1", | ||
"@babel/types": "7.0.0-rc.1", | ||
"@babel/code-frame": "7.0.0-rc.2", | ||
"@babel/generator": "7.0.0-rc.2", | ||
"@babel/helpers": "7.0.0-rc.2", | ||
"@babel/parser": "7.0.0-rc.2", | ||
"@babel/template": "7.0.0-rc.2", | ||
"@babel/traverse": "7.0.0-rc.2", | ||
"@babel/types": "7.0.0-rc.2", | ||
"convert-source-map": "^1.1.0", | ||
@@ -50,5 +50,5 @@ "debug": "^3.1.0", | ||
"devDependencies": { | ||
"@babel/helper-transform-fixture-test-runner": "7.0.0-rc.1", | ||
"@babel/register": "7.0.0-rc.1" | ||
"@babel/helper-transform-fixture-test-runner": "7.0.0-rc.2", | ||
"@babel/register": "7.0.0-rc.2" | ||
} | ||
} |
129425
3865
+ Added@babel/code-frame@7.0.0-rc.2(transitive)
+ Added@babel/generator@7.0.0-rc.2(transitive)
+ Added@babel/helper-function-name@7.0.0-rc.2(transitive)
+ Added@babel/helper-get-function-arity@7.0.0-rc.2(transitive)
+ Added@babel/helper-split-export-declaration@7.0.0-rc.2(transitive)
+ Added@babel/helpers@7.0.0-rc.2(transitive)
+ Added@babel/highlight@7.0.0-rc.2(transitive)
+ Added@babel/parser@7.0.0-rc.2(transitive)
+ Added@babel/template@7.0.0-rc.2(transitive)
+ Added@babel/traverse@7.0.0-rc.2(transitive)
+ Added@babel/types@7.0.0-rc.2(transitive)
+ Addedjs-tokens@4.0.0(transitive)
- Removed@babel/code-frame@7.0.0-rc.1(transitive)
- Removed@babel/generator@7.0.0-rc.1(transitive)
- Removed@babel/helper-function-name@7.0.0-rc.1(transitive)
- Removed@babel/helper-get-function-arity@7.0.0-rc.1(transitive)
- Removed@babel/helper-split-export-declaration@7.0.0-rc.1(transitive)
- Removed@babel/helpers@7.0.0-rc.1(transitive)
- Removed@babel/highlight@7.0.0-rc.1(transitive)
- Removed@babel/parser@7.0.0-rc.1(transitive)
- Removed@babel/template@7.0.0-rc.1(transitive)
- Removed@babel/traverse@7.0.0-rc.1(transitive)
- Removed@babel/types@7.0.0-rc.1(transitive)
- Removedjs-tokens@3.0.2(transitive)
Updated@babel/code-frame@7.0.0-rc.2
Updated@babel/generator@7.0.0-rc.2
Updated@babel/helpers@7.0.0-rc.2
Updated@babel/parser@7.0.0-rc.2
Updated@babel/template@7.0.0-rc.2
Updated@babel/traverse@7.0.0-rc.2
Updated@babel/types@7.0.0-rc.2