@babel/core
Advanced tools
Comparing version 7.0.0-beta.40 to 7.0.0-beta.41
@@ -69,2 +69,3 @@ "use strict"; | ||
if (!programmaticChain) return null; | ||
var ignore, babelrc; | ||
var fileChain = emptyChain(); | ||
@@ -75,6 +76,7 @@ | ||
var _findRelativeConfig = (0, _files.findRelativeConfig)(_filename, context.envName), | ||
ignore = _findRelativeConfig.ignore, | ||
config = _findRelativeConfig.config; | ||
var _findRelativeConfig = (0, _files.findRelativeConfig)(_filename, context.envName); | ||
ignore = _findRelativeConfig.ignore; | ||
babelrc = _findRelativeConfig.config; | ||
if (ignore && shouldIgnore(context, ignore.ignore, null, ignore.dirname)) { | ||
@@ -84,4 +86,4 @@ return null; | ||
if (config) { | ||
var result = loadFileChain(config, context); | ||
if (babelrc) { | ||
var result = loadFileChain(babelrc, context); | ||
if (!result) return null; | ||
@@ -98,3 +100,5 @@ mergeChain(fileChain, result); | ||
return normalizeOptions(o); | ||
}) | ||
}), | ||
ignore: ignore || undefined, | ||
babelrc: babelrc || undefined | ||
}; | ||
@@ -101,0 +105,0 @@ } |
@@ -6,5 +6,8 @@ "use strict"; | ||
exports.createUncachedDescriptors = createUncachedDescriptors; | ||
exports.createDescriptor = createDescriptor; | ||
var _files = require("./files"); | ||
var _item2 = require("./item"); | ||
var _caching = require("./caching"); | ||
@@ -102,5 +105,5 @@ | ||
var descriptors = items.map(function (item, index) { | ||
return createDescriptor(item, type === "plugin" ? _files.loadPlugin : _files.loadPreset, dirname, { | ||
index: index, | ||
alias: alias, | ||
return createDescriptor(item, dirname, { | ||
type: type, | ||
alias: alias + "$" + index, | ||
ownPass: !!ownPass | ||
@@ -113,6 +116,12 @@ }); | ||
function createDescriptor(pair, resolver, dirname, _ref) { | ||
var index = _ref.index, | ||
function createDescriptor(pair, dirname, _ref) { | ||
var type = _ref.type, | ||
alias = _ref.alias, | ||
ownPass = _ref.ownPass; | ||
var desc = (0, _item2.getItemDescriptor)(pair); | ||
if (desc) { | ||
return desc; | ||
} | ||
var name; | ||
@@ -135,5 +144,13 @@ var options; | ||
var file = undefined; | ||
var filepath = null; | ||
if (typeof value === "string") { | ||
if (typeof type !== "string") { | ||
throw new Error("To resolve a string-based item, the type of item must be given"); | ||
} | ||
var resolver = type === "plugin" ? _files.loadPlugin : _files.loadPreset; | ||
var _request = value; | ||
var _resolver = resolver(value, dirname); | ||
@@ -143,2 +160,6 @@ | ||
value = _resolver.value; | ||
file = { | ||
request: _request, | ||
resolved: filepath | ||
}; | ||
} | ||
@@ -163,3 +184,3 @@ | ||
if (filepath !== null && typeof value === "object" && value) { | ||
throw new Error("Plugin/Preset files are not allowed to export objects, only functions."); | ||
throw new Error("Plugin/Preset files are not allowed to export objects, only functions. In " + filepath); | ||
} | ||
@@ -169,7 +190,8 @@ | ||
name: name, | ||
alias: filepath || alias + "$" + index, | ||
alias: filepath || alias, | ||
value: value, | ||
options: options, | ||
dirname: dirname, | ||
ownPass: ownPass | ||
ownPass: ownPass, | ||
file: file | ||
}; | ||
@@ -176,0 +198,0 @@ } |
@@ -19,2 +19,4 @@ "use strict"; | ||
var _configApi = _interopRequireDefault(require("../helpers/config-api")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -131,13 +133,3 @@ | ||
if (typeof options === "function") { | ||
options = options({ | ||
cache: cache.simple(), | ||
env: function env() { | ||
return cache.using(function (data) { | ||
return data.envName; | ||
}); | ||
}, | ||
async: function async() { | ||
return false; | ||
} | ||
}); | ||
options = options((0, _configApi.default)(cache)); | ||
if (!cache.configured()) throwConfigError(); | ||
@@ -144,0 +136,0 @@ } |
"use strict"; | ||
exports.__esModule = true; | ||
exports.default = loadConfig; | ||
exports.loadOptions = loadOptions; | ||
exports.OptionManager = exports.loadPartialConfig = void 0; | ||
var _path = _interopRequireDefault(require("path")); | ||
var _full = _interopRequireDefault(require("./full")); | ||
var context = _interopRequireWildcard(require("../index")); | ||
exports.default = _full.default; | ||
var _plugin = _interopRequireDefault(require("./plugin")); | ||
var _partial = require("./partial"); | ||
var _merge = _interopRequireDefault(require("lodash/merge")); | ||
exports.loadPartialConfig = _partial.loadPartialConfig; | ||
var _configChain = require("./config-chain"); | ||
var _traverse = _interopRequireDefault(require("@babel/traverse")); | ||
var _clone = _interopRequireDefault(require("lodash/clone")); | ||
var _caching = require("./caching"); | ||
var _environment = require("./helpers/environment"); | ||
var _options = require("./validation/options"); | ||
var _plugins = require("./validation/plugins"); | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function loadConfig(inputOpts) { | ||
if (inputOpts != null && (typeof inputOpts !== "object" || Array.isArray(inputOpts))) { | ||
throw new Error("Babel options must be an object, null, or undefined"); | ||
} | ||
var args = inputOpts ? (0, _options.validate)("arguments", inputOpts) : {}; | ||
var _args$envName = args.envName, | ||
envName = _args$envName === void 0 ? (0, _environment.getEnv)() : _args$envName, | ||
_args$cwd = args.cwd, | ||
cwd = _args$cwd === void 0 ? "." : _args$cwd; | ||
var absoluteCwd = _path.default.resolve(cwd); | ||
var context = { | ||
filename: args.filename ? _path.default.resolve(cwd, args.filename) : null, | ||
cwd: absoluteCwd, | ||
envName: envName | ||
}; | ||
var configChain = (0, _configChain.buildRootChain)(args, context); | ||
if (!configChain) return null; | ||
var optionDefaults = {}; | ||
var options = {}; | ||
var passes = [[]]; | ||
try { | ||
var ignored = function recurseDescriptors(config, pass) { | ||
var plugins = config.plugins.map(function (descriptor) { | ||
return loadPluginDescriptor(descriptor, context); | ||
}); | ||
var presets = config.presets.map(function (descriptor) { | ||
return { | ||
preset: loadPresetDescriptor(descriptor, context), | ||
pass: descriptor.ownPass ? [] : pass | ||
}; | ||
}); | ||
if (presets.length > 0) { | ||
passes.splice.apply(passes, [1, 0].concat(presets.map(function (o) { | ||
return o.pass; | ||
}).filter(function (p) { | ||
return p !== pass; | ||
}))); | ||
for (var _iterator = presets, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
var _ref2; | ||
if (_isArray) { | ||
if (_i >= _iterator.length) break; | ||
_ref2 = _iterator[_i++]; | ||
} else { | ||
_i = _iterator.next(); | ||
if (_i.done) break; | ||
_ref2 = _i.value; | ||
} | ||
var _ref3 = _ref2; | ||
var _preset = _ref3.preset, | ||
_pass2 = _ref3.pass; | ||
if (!_preset) return true; | ||
var _ignored2 = recurseDescriptors({ | ||
plugins: _preset.plugins, | ||
presets: _preset.presets | ||
}, _pass2); | ||
if (_ignored2) return true; | ||
_preset.options.forEach(function (opts) { | ||
(0, _merge.default)(optionDefaults, opts); | ||
}); | ||
} | ||
} | ||
if (plugins.length > 0) { | ||
pass.unshift.apply(pass, plugins); | ||
} | ||
}({ | ||
plugins: configChain.plugins, | ||
presets: configChain.presets | ||
}, passes[0]); | ||
if (ignored) return null; | ||
configChain.options.forEach(function (opts) { | ||
(0, _merge.default)(options, opts); | ||
}); | ||
} catch (e) { | ||
if (!/^\[BABEL\]/.test(e.message)) { | ||
e.message = "[BABEL] " + (args.filename || "unknown") + ": " + e.message; | ||
} | ||
throw e; | ||
} | ||
var opts = (0, _merge.default)(optionDefaults, options); | ||
opts.babelrc = false; | ||
opts.plugins = passes[0]; | ||
opts.presets = passes.slice(1).filter(function (plugins) { | ||
return plugins.length > 0; | ||
}).map(function (plugins) { | ||
return { | ||
plugins: plugins | ||
}; | ||
}); | ||
opts.passPerPreset = opts.presets.length > 0; | ||
opts.envName = envName; | ||
opts.cwd = absoluteCwd; | ||
return { | ||
options: opts, | ||
passes: passes | ||
}; | ||
function loadOptions(opts) { | ||
var config = (0, _full.default)(opts); | ||
return config ? config.options : null; | ||
} | ||
var loadDescriptor = (0, _caching.makeWeakCache)(function (_ref4, cache) { | ||
var value = _ref4.value, | ||
options = _ref4.options, | ||
dirname = _ref4.dirname, | ||
alias = _ref4.alias; | ||
if (options === false) throw new Error("Assertion failure"); | ||
options = options || {}; | ||
var item = value; | ||
var OptionManager = function () { | ||
function OptionManager() {} | ||
if (typeof value === "function") { | ||
var api = Object.assign(Object.create(context), { | ||
cache: cache.simple(), | ||
env: function env() { | ||
return cache.using(function (data) { | ||
return data.envName; | ||
}); | ||
}, | ||
async: function async() { | ||
return false; | ||
} | ||
}); | ||
var _proto = OptionManager.prototype; | ||
try { | ||
item = value(api, options, dirname); | ||
} catch (e) { | ||
if (alias) { | ||
e.message += " (While processing: " + JSON.stringify(alias) + ")"; | ||
} | ||
throw e; | ||
} | ||
} | ||
if (!item || typeof item !== "object") { | ||
throw new Error("Plugin/Preset did not return an object."); | ||
} | ||
if (typeof item.then === "function") { | ||
throw new Error("You appear to be using an async 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 { | ||
value: item, | ||
options: options, | ||
dirname: dirname, | ||
alias: alias | ||
_proto.init = function init(opts) { | ||
return loadOptions(opts); | ||
}; | ||
}); | ||
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 OptionManager; | ||
}(); | ||
return descriptor.value; | ||
} | ||
return instantiatePlugin(loadDescriptor(descriptor, context), context); | ||
} | ||
var instantiatePlugin = (0, _caching.makeWeakCache)(function (_ref5, cache) { | ||
var value = _ref5.value, | ||
options = _ref5.options, | ||
dirname = _ref5.dirname, | ||
alias = _ref5.alias; | ||
var pluginObj = (0, _plugins.validatePluginObject)(value); | ||
var plugin = Object.assign({}, pluginObj); | ||
if (plugin.visitor) { | ||
plugin.visitor = _traverse.default.explode((0, _clone.default)(plugin.visitor)); | ||
} | ||
if (plugin.inherits) { | ||
var inheritsDescriptor = { | ||
name: undefined, | ||
alias: alias + "$inherits", | ||
value: plugin.inherits, | ||
options: options, | ||
dirname: dirname | ||
}; | ||
var inherits = cache.invalidate(function (data) { | ||
return loadPluginDescriptor(inheritsDescriptor, data); | ||
}); | ||
plugin.pre = chain(inherits.pre, plugin.pre); | ||
plugin.post = chain(inherits.post, plugin.post); | ||
plugin.manipulateOptions = chain(inherits.manipulateOptions, plugin.manipulateOptions); | ||
plugin.visitor = _traverse.default.visitors.merge([inherits.visitor || {}, plugin.visitor || {}]); | ||
} | ||
return new _plugin.default(plugin, options, alias); | ||
}); | ||
var loadPresetDescriptor = function loadPresetDescriptor(descriptor, context) { | ||
return (0, _configChain.buildPresetChain)(instantiatePreset(loadDescriptor(descriptor, context)), context); | ||
}; | ||
var instantiatePreset = (0, _caching.makeWeakCache)(function (_ref6) { | ||
var value = _ref6.value, | ||
dirname = _ref6.dirname, | ||
alias = _ref6.alias; | ||
return { | ||
options: (0, _options.validate)("preset", value), | ||
alias: alias, | ||
dirname: dirname | ||
}; | ||
}); | ||
function chain(a, b) { | ||
var fns = [a, b].filter(Boolean); | ||
if (fns.length <= 1) return fns[0]; | ||
return function () { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
for (var _iterator2 = fns, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { | ||
var _ref7; | ||
if (_isArray2) { | ||
if (_i2 >= _iterator2.length) break; | ||
_ref7 = _iterator2[_i2++]; | ||
} else { | ||
_i2 = _iterator2.next(); | ||
if (_i2.done) break; | ||
_ref7 = _i2.value; | ||
} | ||
var _fn = _ref7; | ||
_fn.apply(this, args); | ||
} | ||
}; | ||
} | ||
exports.OptionManager = OptionManager; |
@@ -6,2 +6,4 @@ "use strict"; | ||
var _plugin = _interopRequireDefault(require("../plugin")); | ||
var _removed = _interopRequireDefault(require("./removed")); | ||
@@ -49,3 +51,2 @@ | ||
sourceMap: _optionAssertions.assertSourceMaps, | ||
sourceMapTarget: _optionAssertions.assertString, | ||
sourceFileName: _optionAssertions.assertString, | ||
@@ -52,0 +53,0 @@ sourceRoot: _optionAssertions.assertString, |
@@ -43,3 +43,3 @@ "use strict"; | ||
sourceMapName: { | ||
message: "Use the `sourceMapTarget` option" | ||
message: "The `sourceMapName` option has been removed because it makes more sense for the tooling that calls Babel to assign `map.file` themselves." | ||
}, | ||
@@ -59,4 +59,8 @@ stage: { | ||
message: "Generated plugin metadata is always included in the output result" | ||
}, | ||
sourceMapTarget: { | ||
version: 6, | ||
message: "The `sourceMapTarget` option has been removed because it makes more sense for the tooling that calls Babel to assign `map.file` themselves." | ||
} | ||
}; | ||
exports.default = _default; |
"use strict"; | ||
exports.__esModule = true; | ||
exports.loadOptions = loadOptions; | ||
exports.Plugin = Plugin; | ||
exports.types = exports.DEFAULT_EXTENSIONS = exports.OptionManager = exports.getEnv = exports.version = exports.resolvePreset = exports.resolvePlugin = exports.parse = exports.transformFromAstSync = exports.transformFromAst = exports.transformFileSync = exports.transformFile = exports.transformSync = exports.transform = exports.template = exports.traverse = exports.buildExternalHelpers = exports.File = void 0; | ||
exports.types = exports.DEFAULT_EXTENSIONS = exports.createConfigItem = exports.OptionManager = exports.loadOptions = exports.loadPartialConfig = exports.getEnv = exports.version = exports.resolvePreset = exports.resolvePlugin = exports.parse = exports.transformFromAstSync = exports.transformFromAst = exports.transformFileSync = exports.transformFile = exports.transformSync = exports.transform = exports.template = exports.traverse = exports.buildExternalHelpers = exports.File = void 0; | ||
@@ -41,4 +40,12 @@ var _file = _interopRequireDefault(require("./transformation/file/file")); | ||
var _config = _interopRequireDefault(require("./config")); | ||
var _config = require("./config"); | ||
exports.loadPartialConfig = _config.loadPartialConfig; | ||
exports.loadOptions = _config.loadOptions; | ||
exports.OptionManager = _config.OptionManager; | ||
var _item = require("./config/item"); | ||
exports.createConfigItem = _item.createConfigItem; | ||
var _transform = _interopRequireDefault(require("./transform")); | ||
@@ -76,21 +83,2 @@ | ||
function loadOptions(opts) { | ||
var config = (0, _config.default)(opts); | ||
return config ? config.options : null; | ||
} | ||
var OptionManager = function () { | ||
function OptionManager() {} | ||
var _proto = OptionManager.prototype; | ||
_proto.init = function init(opts) { | ||
return loadOptions(opts); | ||
}; | ||
return OptionManager; | ||
}(); | ||
exports.OptionManager = OptionManager; | ||
function Plugin(alias) { | ||
@@ -97,0 +85,0 @@ throw new Error("The (" + alias + ") Babel 5 plugin is being run with an unsupported Babel version."); |
@@ -14,2 +14,4 @@ "use strict"; | ||
var _templateObject = _taggedTemplateLiteralLoose(["\n (function (root, factory) {\n if (typeof define === \"function\" && define.amd) {\n define(AMD_ARGUMENTS, factory);\n } else if (typeof exports === \"object\") {\n factory(COMMON_ARGUMENTS);\n } else {\n factory(BROWSER_ARGUMENTS);\n }\n })(UMD_ROOT, function (FACTORY_PARAMETERS) {\n FACTORY_BODY\n });\n "], ["\n (function (root, factory) {\n if (typeof define === \"function\" && define.amd) {\n define(AMD_ARGUMENTS, factory);\n } else if (typeof exports === \"object\") {\n factory(COMMON_ARGUMENTS);\n } else {\n factory(BROWSER_ARGUMENTS);\n }\n })(UMD_ROOT, function (FACTORY_PARAMETERS) {\n FACTORY_BODY\n });\n "]); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -19,4 +21,8 @@ | ||
var buildUmdWrapper = (0, _template.default)("\n (function (root, factory) {\n if (typeof define === \"function\" && define.amd) {\n define(AMD_ARGUMENTS, factory);\n } else if (typeof exports === \"object\") {\n factory(COMMON_ARGUMENTS);\n } else {\n factory(BROWSER_ARGUMENTS);\n }\n })(UMD_ROOT, function (FACTORY_PARAMETERS) {\n FACTORY_BODY\n });\n"); | ||
function _taggedTemplateLiteralLoose(strings, raw) { strings.raw = raw; return strings; } | ||
var buildUmdWrapper = function buildUmdWrapper(replacements) { | ||
return (0, _template.default)(_templateObject)(replacements); | ||
}; | ||
function buildGlobal(whitelist) { | ||
@@ -23,0 +29,0 @@ var namespace = t.identifier("babelHelpers"); |
@@ -45,5 +45,6 @@ "use strict"; | ||
options: opts, | ||
ast: opts.ast !== false ? file.ast : null, | ||
ast: opts.ast === true ? file.ast : null, | ||
code: outputCode === undefined ? null : outputCode, | ||
map: outputMap === undefined ? null : outputMap | ||
map: outputMap === undefined ? null : outputMap, | ||
sourceType: file.ast.program.sourceType | ||
}; | ||
@@ -50,0 +51,0 @@ } |
@@ -117,2 +117,6 @@ "use strict"; | ||
} catch (err) { | ||
if (err.code === "BABEL_PARSER_SOURCETYPE_MODULE_REQUIRED") { | ||
err.message += "\nConsider renaming the file to '.mjs', or setting sourceType:module " + "or sourceType:unambiguous in your Babel config for this file."; | ||
} | ||
var loc = err.loc, | ||
@@ -119,0 +123,0 @@ missingPlugin = err.missingPlugin; |
@@ -25,4 +25,2 @@ "use strict"; | ||
sourceFileName = _config$options$sourc4 === void 0 ? filenameRelative : _config$options$sourc4, | ||
_config$options$sourc5 = _config$options.sourceMapTarget, | ||
sourceMapTarget = _config$options$sourc5 === void 0 ? filenameRelative : _config$options$sourc5, | ||
_config$options$comme = _config$options.comments, | ||
@@ -49,3 +47,2 @@ comments = _config$options$comme === void 0 ? true : _config$options$comme, | ||
sourceMaps: sourceMaps, | ||
sourceMapTarget: sourceMapTarget, | ||
sourceRoot: sourceRoot, | ||
@@ -52,0 +49,0 @@ sourceFileName: sourceFileName |
@@ -118,2 +118,12 @@ "use strict"; | ||
}, | ||
logicalAssignment: { | ||
syntax: { | ||
name: "@babel/plugin-syntax-logical-assignment-operators", | ||
url: "https://git.io/vAlBp" | ||
}, | ||
transform: { | ||
name: "@babel/plugin-proposal-logical-assignment-operators", | ||
url: "https://git.io/vAlRe" | ||
} | ||
}, | ||
nullishCoalescingOperator: { | ||
@@ -120,0 +130,0 @@ syntax: { |
{ | ||
"name": "@babel/core", | ||
"version": "7.0.0-beta.40", | ||
"version": "7.0.0-beta.41", | ||
"description": "Babel compiler core.", | ||
@@ -31,11 +31,11 @@ "main": "./lib/index.js", | ||
"dependencies": { | ||
"@babel/code-frame": "7.0.0-beta.40", | ||
"@babel/generator": "7.0.0-beta.40", | ||
"@babel/helpers": "7.0.0-beta.40", | ||
"@babel/template": "7.0.0-beta.40", | ||
"@babel/traverse": "7.0.0-beta.40", | ||
"@babel/types": "7.0.0-beta.40", | ||
"babylon": "7.0.0-beta.40", | ||
"@babel/code-frame": "7.0.0-beta.41", | ||
"@babel/generator": "7.0.0-beta.41", | ||
"@babel/helpers": "7.0.0-beta.41", | ||
"@babel/template": "7.0.0-beta.41", | ||
"@babel/traverse": "7.0.0-beta.41", | ||
"@babel/types": "7.0.0-beta.41", | ||
"babylon": "7.0.0-beta.41", | ||
"convert-source-map": "^1.1.0", | ||
"debug": "^3.0.1", | ||
"debug": "^3.1.0", | ||
"json5": "^0.5.0", | ||
@@ -45,8 +45,9 @@ "lodash": "^4.2.0", | ||
"resolve": "^1.3.2", | ||
"semver": "^5.4.1", | ||
"source-map": "^0.5.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/helper-transform-fixture-test-runner": "7.0.0-beta.40", | ||
"@babel/register": "7.0.0-beta.40" | ||
"@babel/helper-transform-fixture-test-runner": "7.0.0-beta.41", | ||
"@babel/register": "7.0.0-beta.41" | ||
} | ||
} |
@@ -96,3 +96,3 @@ # @babel/core | ||
## babel.transformFromAst(ast: Object, code?: string, [options?](#options): Object, callback: Function) | ||
## babel.transformFromAst(ast: Object, code?: string, [options?](#options): Object, callback: Function): FileNode | null | ||
@@ -127,3 +127,76 @@ Given an [AST](https://astexplorer.net/), transform it. | ||
## babel.parse(code: string, [options?](#options): Object) | ||
Given some code, parse it using Babel's standard behavior. Referenced presets and | ||
plugins will be loaded such that optional syntax plugins are automatically | ||
enabled. | ||
## Advanced APIs | ||
Many systems that wrap Babel like to automatically inject plugins and presets, | ||
or override options. To accomplish this goal, Babel exposes several functions | ||
that aid in loading the configuration part-way without transforming. | ||
### babel.loadOptions([options?](#options): Object) | ||
Resolve Babel's options fully, resulting in an options object where: | ||
* `opts.plugins` is a full list of `Plugin` instances. | ||
* `opts.presets` is empty and all presets are flattened into `opts`. | ||
* It can be safely passed back to Babel. Fields like `babelrc` have been set to | ||
false so that later calls to Babel will not make a second attempt to load | ||
config files. | ||
`Plugin` instances aren't meant to be manipulated directly, but often | ||
callers will serialize this `opts` to JSON to use it as a cache key representing | ||
the options Babel has received. Caching on this isn't 100% guaranteed to | ||
invalidate properly, but it is the best we have at the moment. | ||
### babel.loadPartialConfig([options?](#options): Object): PartialConfig | ||
To allow systems to easily manipulate and validate a user's config, this function | ||
resolves the plugins and presets and proceeds no further. The expectation is | ||
that callers will take the config's `.options`, manipulate it as then see fit | ||
and pass it back to Babel again. | ||
* `babelrc: string | void` - The path of the `.babelrc` file, if there was one. | ||
* `babelignore: string | void` - The path of the `.babelignore` file, if there was one. | ||
* `options: ValidatedOptions` - The partially resolved options, which can be manipulated and passed back to Babel again. | ||
* `plugins: Array<ConfigItem>` - See below. | ||
* `presets: Array<ConfigItem>` - See below. | ||
* It can be safely passed back to Babel. Fields like `babelrc` have been set | ||
to false so that later calls to Babel will not make a second attempt to | ||
load config files. | ||
* `hasFilesystemConfig(): boolean` - Check if the resolved config loaded any settings from the filesystem. | ||
[`ConfigItem`](#configitem-type) instances expose properties to introspect the values, but each | ||
item should be treated as immutable. If changes are desired, the item should be | ||
removed from the list and replaced with either a normal Babel config value, or | ||
with a replacement item created by `babel.createConfigItem`. See that | ||
function for information about `ConfigItem` fields. | ||
### babel.createConfigItem(value: string | {} | Function | [string | {} | Function, {} | void], { dirname?: string, type?: "preset" | "plugin" }): ConfigItem | ||
Allows build tooling to create and cache config items up front. If this function | ||
is called multiple times for a given plugin, Babel will call the plugin's function itself | ||
multiple times. If you have a clear set of expected plugins and presets to | ||
inject, pre-constructing the config items would be recommended. | ||
### `ConfigItem` type | ||
Each `ConfigItem` exposes all of the information Babel knows. The fields are: | ||
* `value: {} | Function` - The resolved value of the plugin. | ||
* `options: {} | void` - The options object passed to the plugin. | ||
* `dirname: string` - The path that the options are relative to. | ||
* `name: string | void` - The name that the user gave the plugin instance, e.g. `plugins: [ ['env', {}, 'my-env'] ]` | ||
* `file: Object | void` - Information about the plugin's file, if Babel knows it. | ||
* `request: string` - The file that the user requested, e.g. `"@babel/env"` | ||
* `resolved: string` - The full path of the resolved file, e.g. `"/tmp/node_modules/@babel/preset-env/lib/index.js"` | ||
## Options | ||
@@ -174,5 +247,4 @@ | ||
| `sourceMaps` | `false` | If truthy, adds a `map` property to returned output. If set to `"inline"`, a comment with a sourceMappingURL directive is added to the bottom of the returned code. If set to `"both"` then a `map` property is returned as well as a source map comment appended. **This does not emit sourcemap files by itself!** To have sourcemaps emitted using the CLI, you must pass it the `--source-maps` option | | ||
| `sourceMapTarget` | `(filenameRelative)` | Set `file` on returned source map | | ||
| `sourceRoot` | `(moduleRoot)` | The root from which all sources are relative | | ||
| `sourceType` | `"module"` | Indicate the mode the code should be parsed in. Can be one of "script", "module", or "unambiguous". `"unambiguous"` will make Babel attempt to _guess_, based on the presence of ES6 `import` or `export` statements. Files with ES6 `import`s and `export`s are considered `"module"` and are otherwise `"script"`. | | ||
| `wrapPluginVisitorMethod`| `null` | An optional callback that can be used to wrap visitor methods. **NOTE:** This is useful for things like introspection, and not really needed for implementing anything. Called as `wrapPluginVisitorMethod(pluginAlias, visitorType, callback)`. |
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
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
129656
40
3091
248
15
0
+ Addedsemver@^5.4.1
+ Added@babel/code-frame@7.0.0-beta.41(transitive)
+ Added@babel/generator@7.0.0-beta.41(transitive)
+ Added@babel/helper-function-name@7.0.0-beta.41(transitive)
+ Added@babel/helper-get-function-arity@7.0.0-beta.41(transitive)
+ Added@babel/helper-split-export-declaration@7.0.0-beta.41(transitive)
+ Added@babel/helpers@7.0.0-beta.41(transitive)
+ Added@babel/highlight@7.0.0-beta.41(transitive)
+ Added@babel/template@7.0.0-beta.41(transitive)
+ Added@babel/traverse@7.0.0-beta.41(transitive)
+ Added@babel/types@7.0.0-beta.41(transitive)
+ Addedbabylon@7.0.0-beta.41(transitive)
+ Addedsemver@5.7.2(transitive)
- Removed@babel/code-frame@7.0.0-beta.40(transitive)
- Removed@babel/generator@7.0.0-beta.40(transitive)
- Removed@babel/helper-function-name@7.0.0-beta.40(transitive)
- Removed@babel/helper-get-function-arity@7.0.0-beta.40(transitive)
- Removed@babel/helpers@7.0.0-beta.40(transitive)
- Removed@babel/highlight@7.0.0-beta.40(transitive)
- Removed@babel/template@7.0.0-beta.40(transitive)
- Removed@babel/traverse@7.0.0-beta.40(transitive)
- Removed@babel/types@7.0.0-beta.40(transitive)
- Removedbabylon@7.0.0-beta.40(transitive)
Updated@babel/helpers@7.0.0-beta.41
Updated@babel/types@7.0.0-beta.41
Updatedbabylon@7.0.0-beta.41
Updateddebug@^3.1.0