Socket
Socket
Sign inDemoInstall

@babel/core

Package Overview
Dependencies
76
Maintainers
4
Versions
187
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 7.0.0-beta.32 to 7.0.0-beta.33

31

lib/config/build-config-chain.js

@@ -6,4 +6,2 @@ "use strict";

var _environment = require("./helpers/environment");
var _path = _interopRequireDefault(require("path"));

@@ -27,13 +25,12 @@

function buildConfigChain(opts) {
var filename = opts.filename ? _path.default.resolve(opts.filename) : null;
function buildConfigChain(cwd, opts, envName) {
var filename = opts.filename ? _path.default.resolve(cwd, opts.filename) : null;
var builder = new ConfigChainBuilder(filename ? new LoadedFile(filename) : null);
var envKey = (0, _environment.getEnv)();
try {
builder.mergeConfigArguments(opts, process.cwd(), envKey);
builder.mergeConfigArguments(opts, cwd, envName);
if (opts.babelrc !== false && filename) {
(0, _files.findConfigs)(_path.default.dirname(filename)).forEach(function (configFile) {
return builder.mergeConfigFile(configFile, envKey);
(0, _files.findConfigs)(_path.default.dirname(filename), envName).forEach(function (configFile) {
return builder.mergeConfigFile(configFile, envName);
});

@@ -67,3 +64,3 @@ }

_proto.mergeConfigFile = function mergeConfigFile(file, envKey) {
_proto.mergeConfigFile = function mergeConfigFile(file, envName) {
var _this2 = this;

@@ -75,6 +72,6 @@

var parts = flattenFileOptionsParts(file)(envKey);
var parts = flattenFileOptionsParts(file)(envName);
this.seenFiles.add(file);
parts.forEach(function (part) {
return _this2._processConfigPart(part, envKey);
return _this2._processConfigPart(part, envName);
});

@@ -84,3 +81,3 @@ this.seenFiles.delete(file);

_proto._processConfigPart = function _processConfigPart(part, envKey) {
_proto._processConfigPart = function _processConfigPart(part, envName) {
if (part.part === "config") {

@@ -98,3 +95,3 @@ var _ignore = part.ignore,

} else {
this.mergeConfigFile((0, _files.loadConfig)(part.path, part.dirname), envKey);
this.mergeConfigFile((0, _files.loadConfig)(part.path, part.dirname, envName), envName);
}

@@ -106,3 +103,3 @@ };

function flattenArgumentsOptionsParts(opts, dirname, envKey) {
function flattenArgumentsOptionsParts(opts, dirname, envName) {
var env = opts.env,

@@ -118,3 +115,3 @@ plugins = opts.plugins,

if (env) {
raw.push.apply(raw, flattenArgumentsEnvOptionsParts(env)(dirname)(envKey));
raw.push.apply(raw, flattenArgumentsEnvOptionsParts(env)(dirname)(envName));
}

@@ -226,4 +223,4 @@

return function (envKey) {
return lookup.get(envKey) || def;
return function (envName) {
return lookup.get(envName) || def;
};

@@ -230,0 +227,0 @@ }

@@ -7,16 +7,12 @@ "use strict";

function makeStrongCache(handler, autoPermacache) {
return makeCachedFunction(new Map(), handler, autoPermacache);
function makeStrongCache(handler) {
return makeCachedFunction(new Map(), handler);
}
function makeWeakCache(handler, autoPermacache) {
return makeCachedFunction(new WeakMap(), handler, autoPermacache);
function makeWeakCache(handler) {
return makeCachedFunction(new WeakMap(), handler);
}
function makeCachedFunction(callCache, handler, autoPermacache) {
if (autoPermacache === void 0) {
autoPermacache = true;
}
return function cachedFunction(arg) {
function makeCachedFunction(callCache, handler) {
return function cachedFunction(arg, data) {
var cachedValue = callCache.get(arg);

@@ -40,32 +36,32 @@

var _valid = _ref3[1];
if (_valid()) return _value2;
if (_valid(data)) return _value2;
}
}
var _makeCacheConfig = makeCacheConfig(),
cache = _makeCacheConfig.cache,
result = _makeCacheConfig.result,
deactivate = _makeCacheConfig.deactivate;
var cache = new CacheConfigurator(data);
var value = handler(arg, cache);
if (autoPermacache && !result.configured) cache.forever();
deactivate();
if (!cache.configured()) cache.forever();
cache.deactivate();
if (!result.configured) {
throw new Error(["Caching was left unconfigured. Babel's plugins, presets, and .babelrc.js files can be configured", "for various types of caching, using the first param of their handler functions:", "", "module.exports = function(api) {", " // The API exposes the following:", "", " // Cache the returned value forever and don't call this function again.", " api.cache(true);", "", " // Don't cache at all. Not recommended because it will be very slow.", " api.cache(false);", "", " // Cached based on the value of some function. If this function returns a value different from", " // a previously-encountered value, the plugins will re-evaluate.", " var env = api.cache(() => process.env.NODE_ENV);", "", " // If testing for a specific env, we recommend specifics to avoid instantiating a plugin for", " // any possible NODE_ENV value that might come up during plugin execution.", ' var isProd = api.cache(() => process.env.NODE_ENV === "production");', "", " // .cache(fn) will perform a linear search though instances to find the matching plugin based", " // based on previous instantiated plugins. If you want to recreate the plugin and discard the", " // previous instance whenever something changes, you may use:", ' var isProd = api.cache.invalidate(() => process.env.NODE_ENV === "production");', "", " // Note, we also expose the following more-verbose versions of the above examples:", " api.cache.forever(); // api.cache(true)", " api.cache.never(); // api.cache(false)", " api.cache.using(fn); // api.cache(fn)", "", " // Return the value that will be cached.", " return { };", "};"].join("\n"));
}
if (!result.never) {
if (result.forever) {
switch (cache.mode()) {
case "forever":
cachedValue = [[value, function () {
return true;
}]];
} else if (result.invalidate) {
cachedValue = [[value, result.valid]];
} else {
cachedValue = cachedValue || [];
cachedValue.push([value, result.valid]);
}
callCache.set(arg, cachedValue);
break;
callCache.set(arg, cachedValue);
case "invalidate":
cachedValue = [[value, cache.validator()]];
callCache.set(arg, cachedValue);
break;
case "valid":
if (cachedValue) {
cachedValue.push([value, cache.validator()]);
} else {
cachedValue = [[value, cache.validator()]];
callCache.set(arg, cachedValue);
}
}

@@ -77,24 +73,112 @@

function makeCacheConfig() {
var pairs = [];
var result = {
configured: false,
never: false,
forever: false,
invalidate: false,
valid: function valid() {
var CacheConfigurator = function () {
function CacheConfigurator(data) {
this._active = true;
this._never = false;
this._forever = false;
this._invalidate = false;
this._configured = false;
this._pairs = [];
this._data = void 0;
this._data = data;
}
var _proto = CacheConfigurator.prototype;
_proto.simple = function simple() {
return makeSimpleConfigurator(this);
};
_proto.mode = function mode() {
if (this._never) return "never";
if (this._forever) return "forever";
if (this._invalidate) return "invalidate";
return "valid";
};
_proto.forever = function forever() {
if (!this._active) {
throw new Error("Cannot change caching after evaluation has completed.");
}
if (this._never) {
throw new Error("Caching has already been configured with .never()");
}
this._forever = true;
this._configured = true;
};
_proto.never = function never() {
if (!this._active) {
throw new Error("Cannot change caching after evaluation has completed.");
}
if (this._forever) {
throw new Error("Caching has already been configured with .forever()");
}
this._never = true;
this._configured = true;
};
_proto.using = function using(handler) {
if (!this._active) {
throw new Error("Cannot change caching after evaluation has completed.");
}
if (this._never || this._forever) {
throw new Error("Caching has already been configured with .never or .forever()");
}
this._configured = true;
var key = handler(this._data);
this._pairs.push([key, handler]);
return key;
};
_proto.invalidate = function invalidate(handler) {
if (!this._active) {
throw new Error("Cannot change caching after evaluation has completed.");
}
if (this._never || this._forever) {
throw new Error("Caching has already been configured with .never or .forever()");
}
this._invalidate = true;
this._configured = true;
var key = handler(this._data);
this._pairs.push([key, handler]);
return key;
};
_proto.validator = function validator() {
var pairs = this._pairs;
return function (data) {
return pairs.every(function (_ref4) {
var key = _ref4[0],
fn = _ref4[1];
return key === fn();
return key === fn(data);
});
}
};
};
var active = true;
var deactivate = function deactivate() {
active = false;
_proto.deactivate = function deactivate() {
this._active = false;
};
var cache = Object.assign(function cacheFn(val) {
_proto.configured = function configured() {
return this._configured;
};
return CacheConfigurator;
}();
function makeSimpleConfigurator(cache) {
function cacheFn(val) {
if (typeof val === "boolean") {

@@ -106,62 +190,25 @@ if (val) cache.forever();else cache.never();

return cache.using(val);
}, {
forever: function forever() {
if (!active) {
throw new Error("Cannot change caching after evaluation has completed.");
}
}
if (result.never) {
throw new Error("Caching has already been configured with .never()");
}
cacheFn.forever = function () {
return cache.forever();
};
result.forever = true;
result.configured = true;
},
never: function never() {
if (!active) {
throw new Error("Cannot change caching after evaluation has completed.");
}
cacheFn.never = function () {
return cache.never();
};
if (result.forever) {
throw new Error("Caching has already been configured with .forever()");
}
cacheFn.using = function (cb) {
return cache.using(function () {
return cb();
});
};
result.never = true;
result.configured = true;
},
using: function using(handler) {
if (!active) {
throw new Error("Cannot change caching after evaluation has completed.");
}
cacheFn.invalidate = function (cb) {
return cache.invalidate(function () {
return cb();
});
};
if (result.never || result.forever) {
throw new Error("Caching has already been configured with .never or .forever()");
}
result.configured = true;
var key = handler();
pairs.push([key, handler]);
return key;
},
invalidate: function invalidate(handler) {
if (!active) {
throw new Error("Cannot change caching after evaluation has completed.");
}
if (result.never || result.forever) {
throw new Error("Caching has already been configured with .never or .forever()");
}
result.invalidate = true;
result.configured = true;
var key = handler();
pairs.push([key, handler]);
return key;
}
});
return {
cache: cache,
result: result,
deactivate: deactivate
};
return cacheFn;
}

@@ -17,4 +17,2 @@ "use strict";

var _environment = require("../../helpers/environment");
var _caching = require("../../caching");

@@ -30,3 +28,3 @@

function findConfigs(dirname) {
function findConfigs(dirname, envName) {
var foundConfig = false;

@@ -54,3 +52,3 @@ var foundIgnore = false;

var config = readConfig(filepath);
var config = readConfig(filepath, envName);

@@ -79,3 +77,3 @@ if (config && previousConfig) {

function loadConfig(name, dirname) {
function loadConfig(name, dirname, envName) {
var filepath = _resolve.default.sync(name, {

@@ -85,3 +83,3 @@ basedir: dirname

var conf = readConfig(filepath);
var conf = readConfig(filepath, envName);

@@ -96,4 +94,6 @@ if (!conf) {

function readConfig(filepath) {
return _path.default.extname(filepath) === ".js" ? readConfigJS(filepath) : readConfigFile(filepath);
function readConfig(filepath, envName) {
return _path.default.extname(filepath) === ".js" ? readConfigJS(filepath, {
envName: envName
}) : readConfigFile(filepath);
}

@@ -135,11 +135,13 @@

options = options({
cache: cache,
cache: cache.simple(),
env: function env() {
return cache.using(function () {
return (0, _environment.getEnv)();
return cache.using(function (data) {
return data.envName;
});
},
async: function async() {
return false;
}
});
} else {
cache.forever();
if (!cache.configured()) throwConfigError();
}

@@ -151,2 +153,6 @@

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

@@ -157,3 +163,3 @@ filepath: filepath,

};
}, false);
});
var readConfigFile = makeStaticFileCache(function (filepath, content) {

@@ -232,2 +238,6 @@ var options;

return null;
}
function throwConfigError() {
throw new Error("Caching was left unconfigured. Babel's plugins, presets, and .babelrc.js files can be configured\nfor various types of caching, using the first param of their handler functions:\n\nmodule.exports = function(api) {\n // The API exposes the following:\n\n // Cache the returned value forever and don't call this function again.\n api.cache(true);\n\n // Don't cache at all. Not recommended because it will be very slow.\n api.cache(false);\n\n // Cached based on the value of some function. If this function returns a value different from\n // a previously-encountered value, the plugins will re-evaluate.\n var env = api.cache(() => process.env.NODE_ENV);\n\n // If testing for a specific env, we recommend specifics to avoid instantiating a plugin for\n // any possible NODE_ENV value that might come up during plugin execution.\n var isProd = api.cache(() => process.env.NODE_ENV === \"production\");\n\n // .cache(fn) will perform a linear search though instances to find the matching plugin based\n // based on previous instantiated plugins. If you want to recreate the plugin and discard the\n // previous instance whenever something changes, you may use:\n var isProd = api.cache.invalidate(() => process.env.NODE_ENV === \"production\");\n\n // Note, we also expose the following more-verbose versions of the above examples:\n api.cache.forever(); // api.cache(true)\n api.cache.never(); // api.cache(false)\n api.cache.using(fn); // api.cache(fn)\n\n // Return the value that will be cached.\n return { };\n};");
}

@@ -117,4 +117,4 @@ "use strict";

if (value.length > 2) {
throw new Error("." + key + "[" + index + "] may only be a two-tuple");
if (value.length > 3) {
throw new Error("." + key + "[" + index + "] may only be a two-tuple or three-tuple");
}

@@ -124,9 +124,17 @@

if (value.length === 2) {
if (value.length > 1) {
var opts = value[1];
if (opts != null && (typeof opts !== "object" || Array.isArray(opts))) {
throw new Error("." + key + "[" + index + "][1] must be an object, or undefined");
if (opts !== undefined && opts !== false && (typeof opts !== "object" || Array.isArray(opts))) {
throw new Error("." + key + "[" + index + "][1] must be an object, false, or undefined");
}
}
if (value.length === 3) {
var name = value[2];
if (name !== undefined && typeof name !== "string") {
throw new Error("." + key + "[" + index + "][2] must be a string, or undefined");
}
}
} else {

@@ -133,0 +141,0 @@ assertPluginTarget(key, index, false, value);

@@ -6,2 +6,4 @@ "use strict";

var _path = _interopRequireDefault(require("path"));
var context = _interopRequireWildcard(require("../index"));

@@ -27,6 +29,6 @@

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)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function manageOptions(opts) {

@@ -38,4 +40,3 @@ return new OptionManager().init(opts);

function OptionManager() {
this.options = void 0;
this.passes = void 0;
this.optionDefaults = {};
this.options = {};

@@ -47,30 +48,35 @@ this.passes = [[]];

_proto.mergeOptions = function mergeOptions(config, pass) {
_proto.mergeOptions = function mergeOptions(config, pass, envName) {
var _this = this;
var result = loadConfig(config);
var plugins = result.plugins.map(function (descriptor) {
return loadPluginDescriptor(descriptor);
var plugins = config.plugins.map(function (descriptor) {
return loadPluginDescriptor(descriptor, envName);
});
var presets = result.presets.map(function (descriptor) {
return loadPresetDescriptor(descriptor);
var presets = config.presets.map(function (descriptor) {
return {
preset: loadPresetDescriptor(descriptor, envName),
pass: descriptor.ownPass ? [] : pass
};
});
var passPerPreset = config.options.passPerPreset;
pass = pass || this.passes[0];
if (presets.length > 0) {
var presetPasses = null;
var _passes;
if (passPerPreset) {
var _passes;
(_passes = this.passes).splice.apply(_passes, [1, 0].concat(presets.map(function (o) {
return o.pass;
}).filter(function (p) {
return p !== pass;
})));
presetPasses = presets.map(function () {
return [];
});
presets.forEach(function (_ref) {
var preset = _ref.preset,
pass = _ref.pass;
var loadedConfig = loadConfig(preset);
(_passes = this.passes).splice.apply(_passes, [1, 0].concat(presetPasses));
}
_this.mergeOptions({
plugins: dedupDescriptors(loadedConfig.plugins),
presets: dedupDescriptors(loadedConfig.presets)
}, pass, envName);
presets.forEach(function (presetConfig, i) {
_this.mergeOptions(presetConfig, presetPasses ? presetPasses[i] : pass);
(0, _merge.default)(_this.optionDefaults, normalizeOptions(loadedConfig.options));
});

@@ -80,20 +86,19 @@ }

if (plugins.length > 0) {
var _pass;
(_pass = pass).unshift.apply(_pass, plugins);
pass.unshift.apply(pass, plugins);
}
};
var options = Object.assign({}, result.options);
delete options.extends;
delete options.env;
delete options.plugins;
delete options.presets;
delete options.passPerPreset;
_proto.mergeConfigChain = function mergeConfigChain(chain, envName) {
var _this2 = this;
if (options.sourceMap) {
options.sourceMaps = options.sourceMap;
delete options.sourceMap;
}
(0, _merge.default)(this.options, options);
var config = dedupLoadedConfigs(chain.map(function (config) {
return loadConfig(config);
}));
this.mergeOptions({
plugins: config.plugins,
presets: config.presets
}, this.passes[0], envName);
config.options.forEach(function (opts) {
(0, _merge.default)(_this2.options, normalizeOptions(opts));
});
};

@@ -103,21 +108,14 @@

var args = (0, _options.validate)("arguments", inputOpts);
var configChain = (0, _buildConfigChain.default)(args);
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 configChain = (0, _buildConfigChain.default)(absoluteCwd, args, envName);
if (!configChain) return null;
try {
for (var _iterator = configChain, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
var _ref;
if (_isArray) {
if (_i >= _iterator.length) break;
_ref = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref = _i.value;
}
var _config = _ref;
this.mergeOptions(_config);
}
this.mergeConfigChain(configChain, envName);
} catch (e) {

@@ -131,3 +129,3 @@ if (!/^\[BABEL\]/.test(e.message)) {

var opts = this.options;
var opts = (0, _merge.default)(this.optionDefaults, this.options);
opts.babelrc = false;

@@ -143,2 +141,4 @@ opts.plugins = this.passes[0];

opts.passPerPreset = opts.presets.length > 0;
opts.envName = envName;
opts.cwd = absoluteCwd;
return {

@@ -153,2 +153,20 @@ options: opts,

function normalizeOptions(opts) {
var options = Object.assign({}, opts);
delete options.extends;
delete options.env;
delete options.plugins;
delete options.presets;
delete options.passPerPreset;
delete options.ignore;
delete options.only;
if (options.sourceMap) {
options.sourceMaps = options.sourceMap;
delete options.sourceMap;
}
return options;
}
var loadConfig = (0, _caching.makeWeakCache)(function (config) {

@@ -162,8 +180,11 @@ var options = config.options;

});
assertNoDuplicates(plugins);
var presets = (config.options.presets || []).map(function (preset, index) {
return createDescriptor(preset, _files.loadPreset, config.dirname, {
index: index,
alias: config.alias
alias: config.alias,
ownPass: options.passPerPreset
});
});
assertNoDuplicates(presets);
return {

@@ -175,8 +196,127 @@ options: options,

});
var loadDescriptor = (0, _caching.makeWeakCache)(function (_ref2, cache) {
var value = _ref2.value,
_ref2$options = _ref2.options,
options = _ref2$options === void 0 ? {} : _ref2$options,
dirname = _ref2.dirname,
alias = _ref2.alias;
function assertNoDuplicates(items) {
var map = new Map();
for (var _iterator = items, _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 _item = _ref2;
if (typeof _item.value !== "function") continue;
var nameMap = map.get(_item.value);
if (!nameMap) {
nameMap = new Set();
map.set(_item.value, nameMap);
}
if (nameMap.has(_item.name)) {
throw new Error(["Duplicate plugin/preset detected.", "If you'd like to use two separate instances of a plugin,", "they neen separate names, e.g.", "", " plugins: [", " ['some-plugin', {}],", " ['some-plugin', {}, 'some unique name'],", " ]"].join("\n"));
}
nameMap.add(_item.name);
}
}
function dedupLoadedConfigs(items) {
var options = [];
var plugins = [];
var presets = [];
for (var _iterator2 = items, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
var _ref3;
if (_isArray2) {
if (_i2 >= _iterator2.length) break;
_ref3 = _iterator2[_i2++];
} else {
_i2 = _iterator2.next();
if (_i2.done) break;
_ref3 = _i2.value;
}
var _item2 = _ref3;
plugins.push.apply(plugins, _item2.plugins);
presets.push.apply(presets, _item2.presets);
options.push(_item2.options);
}
return {
options: options,
plugins: dedupDescriptors(plugins),
presets: dedupDescriptors(presets)
};
}
function dedupDescriptors(items) {
var map = new Map();
var descriptors = [];
for (var _iterator3 = items, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) {
var _ref4;
if (_isArray3) {
if (_i3 >= _iterator3.length) break;
_ref4 = _iterator3[_i3++];
} else {
_i3 = _iterator3.next();
if (_i3.done) break;
_ref4 = _i3.value;
}
var _item3 = _ref4;
if (typeof _item3.value === "function") {
var fnKey = _item3.value;
var nameMap = map.get(fnKey);
if (!nameMap) {
nameMap = new Map();
map.set(fnKey, nameMap);
}
var desc = nameMap.get(_item3.name);
if (!desc) {
desc = {
value: null
};
descriptors.push(desc);
if (!_item3.ownPass) nameMap.set(_item3.name, desc);
}
if (_item3.options === false) {
desc.value = null;
} else {
desc.value = _item3;
}
} else {
descriptors.push({
value: _item3
});
}
}
return descriptors.reduce(function (acc, desc) {
if (desc.value) acc.push(desc.value);
return acc;
}, []);
}
var loadDescriptor = (0, _caching.makeWeakCache)(function (_ref5, cache) {
var value = _ref5.value,
options = _ref5.options,
dirname = _ref5.dirname,
alias = _ref5.alias;
if (options === false) throw new Error("Assertion failure");
options = options || {};
var item = value;

@@ -186,7 +326,10 @@

var api = Object.assign(Object.create(context), {
cache: cache,
cache: cache.simple(),
env: function env() {
return cache.using(function () {
return (0, _environment.getEnv)();
return cache.using(function (data) {
return data.envName;
});
},
async: function async() {
return false;
}

@@ -210,2 +353,6 @@ });

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 {

@@ -219,3 +366,3 @@ value: item,

function loadPluginDescriptor(descriptor) {
function loadPluginDescriptor(descriptor, envName) {
if (descriptor.value instanceof _plugin.default) {

@@ -229,10 +376,14 @@ if (descriptor.options) {

return instantiatePlugin(loadDescriptor(descriptor));
return instantiatePlugin(loadDescriptor(descriptor, {
envName: envName
}), {
envName: envName
});
}
var instantiatePlugin = (0, _caching.makeWeakCache)(function (_ref3, cache) {
var value = _ref3.value,
options = _ref3.options,
dirname = _ref3.dirname,
alias = _ref3.alias;
var instantiatePlugin = (0, _caching.makeWeakCache)(function (_ref6, cache) {
var value = _ref6.value,
options = _ref6.options,
dirname = _ref6.dirname,
alias = _ref6.alias;
var pluginObj = (0, _plugin.validatePluginObject)(value);

@@ -247,2 +398,3 @@ var plugin = Object.assign({}, pluginObj);

var inheritsDescriptor = {
name: undefined,
alias: alias + "$inherits",

@@ -253,4 +405,4 @@ value: plugin.inherits,

};
var inherits = cache.invalidate(function () {
return loadPluginDescriptor(inheritsDescriptor);
var inherits = cache.invalidate(function (data) {
return loadPluginDescriptor(inheritsDescriptor, data.envName);
});

@@ -266,10 +418,12 @@ plugin.pre = chain(inherits.pre, plugin.pre);

var loadPresetDescriptor = function loadPresetDescriptor(descriptor) {
return instantiatePreset(loadDescriptor(descriptor));
var loadPresetDescriptor = function loadPresetDescriptor(descriptor, envName) {
return instantiatePreset(loadDescriptor(descriptor, {
envName: envName
}));
};
var instantiatePreset = (0, _caching.makeWeakCache)(function (_ref4) {
var value = _ref4.value,
dirname = _ref4.dirname,
alias = _ref4.alias;
var instantiatePreset = (0, _caching.makeWeakCache)(function (_ref7) {
var value = _ref7.value,
dirname = _ref7.dirname,
alias = _ref7.alias;
return {

@@ -283,5 +437,7 @@ type: "preset",

function createDescriptor(pair, resolver, dirname, _ref5) {
var index = _ref5.index,
alias = _ref5.alias;
function createDescriptor(pair, resolver, dirname, _ref8) {
var index = _ref8.index,
alias = _ref8.alias,
ownPass = _ref8.ownPass;
var name;
var options;

@@ -291,5 +447,12 @@ var value = pair;

if (Array.isArray(value)) {
var _value = value;
value = _value[0];
options = _value[1];
if (value.length === 3) {
var _value = value;
value = _value[0];
options = _value[1];
name = _value[2];
} else {
var _value2 = value;
value = _value2[0];
options = _value2[1];
}
}

@@ -326,12 +489,9 @@

if (options != null && typeof options !== "object") {
throw new Error("Plugin/Preset options must be an object, null, or undefined");
}
options = options || undefined;
return {
name: name,
alias: filepath || alias + "$" + index,
value: value,
options: options,
dirname: dirname
dirname: dirname,
ownPass: ownPass
};

@@ -348,15 +508,15 @@ }

for (var _iterator2 = fns, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
var _ref6;
for (var _iterator4 = fns, _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) {
var _ref9;
if (_isArray2) {
if (_i2 >= _iterator2.length) break;
_ref6 = _iterator2[_i2++];
if (_isArray4) {
if (_i4 >= _iterator4.length) break;
_ref9 = _iterator4[_i4++];
} else {
_i2 = _iterator2.next();
if (_i2.done) break;
_ref6 = _i2.value;
_i4 = _iterator4.next();
if (_i4.done) break;
_ref9 = _i4.value;
}
var _fn = _ref6;
var _fn = _ref9;

@@ -363,0 +523,0 @@ _fn.apply(this, args);

@@ -13,2 +13,3 @@ "use strict";

var ROOT_VALIDATORS = {
cwd: _optionAssertions.assertString,
filename: _optionAssertions.assertString,

@@ -18,3 +19,4 @@ filenameRelative: _optionAssertions.assertString,

code: _optionAssertions.assertBoolean,
ast: _optionAssertions.assertBoolean
ast: _optionAssertions.assertBoolean,
envName: _optionAssertions.assertString
};

@@ -66,2 +68,6 @@ var NONPRESET_VALIDATORS = {

if (type === "env" && key === "env") {
throw new Error("." + key + " is not allowed inside another env block");
}
var validator = COMMON_VALIDATORS[key] || NONPRESET_VALIDATORS[key] || ROOT_VALIDATORS[key];

@@ -68,0 +74,0 @@ if (validator) validator(key, opts[key]);else throw buildUnknownError(key);

@@ -15,8 +15,10 @@ "use strict";

function transformFileSync(filename, opts) {
var options;
if (opts == null) {
opts = {
options = {
filename: filename
};
} else if (opts && typeof opts === "object") {
opts = Object.assign(opts, {
options = Object.assign({}, opts, {
filename: filename

@@ -26,5 +28,5 @@ });

var config = (0, _config.default)(opts);
var config = (0, _config.default)(options);
if (config === null) return null;
return (0, _transformation.runSync)(config, _fs.default.readFileSync(filename, "utf8"));
}

@@ -15,2 +15,4 @@ "use strict";

var _default = function transformFile(filename, opts, callback) {
var options;
if (typeof opts === "function") {

@@ -22,7 +24,7 @@ callback = opts;

if (opts == null) {
opts = {
options = {
filename: filename
};
} else if (opts && typeof opts === "object") {
opts = Object.assign(opts, {
options = Object.assign({}, opts, {
filename: filename

@@ -36,3 +38,3 @@ });

try {
cfg = (0, _config.default)(opts);
cfg = (0, _config.default)(options);
if (cfg === null) return callback(null, null);

@@ -39,0 +41,0 @@ } catch (err) {

@@ -65,2 +65,6 @@ "use strict";

result = results[0];
if (typeof result.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.");
}
} else {

@@ -67,0 +71,0 @@ throw new Error("More than one plugin attempted to override codegen.");

@@ -95,3 +95,10 @@ "use strict";

var fn = _plugin.pre;
if (fn) fn.call(pass, file);
if (fn) {
var result = fn.call(pass, file);
if (isThenable(result)) {
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.");
}
}
}

@@ -108,5 +115,16 @@

var fn = _plugin2.post;
if (fn) fn.call(_pass, file);
if (fn) {
var _result = fn.call(_pass, file);
if (isThenable(_result)) {
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") && typeof val.then === "function";
}

@@ -106,2 +106,6 @@ "use strict";

} else if (results.length === 1) {
if (typeof results[0].then === "function") {
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.");
}
return results[0];

@@ -108,0 +112,0 @@ }

@@ -44,5 +44,5 @@ "use strict";

comments: comments,
shouldPrintComment: opts.shouldPrintComment,
compact: compact,
minified: opts.minified,
concise: opts.concise,
sourceMaps: sourceMaps,

@@ -49,0 +49,0 @@ sourceMapTarget: sourceMapTarget,

{
"name": "@babel/core",
"version": "7.0.0-beta.32",
"version": "7.0.0-beta.33",
"description": "Babel compiler core.",

@@ -31,9 +31,9 @@ "main": "./lib/index.js",

"dependencies": {
"@babel/code-frame": "7.0.0-beta.32",
"@babel/generator": "7.0.0-beta.32",
"@babel/helpers": "7.0.0-beta.32",
"@babel/template": "7.0.0-beta.32",
"@babel/traverse": "7.0.0-beta.32",
"@babel/types": "7.0.0-beta.32",
"babylon": "7.0.0-beta.32",
"@babel/code-frame": "7.0.0-beta.33",
"@babel/generator": "7.0.0-beta.33",
"@babel/helpers": "7.0.0-beta.33",
"@babel/template": "7.0.0-beta.33",
"@babel/traverse": "7.0.0-beta.33",
"@babel/types": "7.0.0-beta.33",
"babylon": "7.0.0-beta.33",
"convert-source-map": "^1.1.0",

@@ -48,5 +48,5 @@ "debug": "^3.0.1",

"devDependencies": {
"@babel/helper-transform-fixture-test-runner": "7.0.0-beta.32",
"@babel/register": "7.0.0-beta.32"
"@babel/helper-transform-fixture-test-runner": "7.0.0-beta.33",
"@babel/register": "7.0.0-beta.33"
}
}

@@ -147,6 +147,7 @@ # @babel/core

| `babelrc` | `true` | Specify whether or not to use .babelrc and .babelignore files. Not available when using the CLI, [use `--no-babelrc` instead](https://babeljs.io/docs/usage/cli/#babel-ignoring-babelrc) |
| `envName` | env vars | Defaults to environment variable `BABEL_ENV` if set, or else `NODE_ENV` if set, or else it defaults to `"development"` |
| `code` | `true` | Enable code generation |
| `comments` | `true` | Output comments in generated output |
| `compact` | `"auto"` | Do not include superfluous whitespace characters and line terminators. When set to `"auto"` compact is set to `true` on input sizes of >500KB |
| `env` | `{}` | This is an object of keys that represent different environments. For example, you may have: `{ env: { production: { /* specific options */ } } }` which will use those options when the environment variable `BABEL_ENV` is set to `"production"`. If `BABEL_ENV` isn't set then `NODE_ENV` will be used, if it's not set then it defaults to `"development"` |
| `env` | `{}` | This is an object of keys that represent different environments. For example, you may have: `{ env: { production: { /* specific options */ } } }` which will use those options when the `envName` is `production` |
| `extends` | `null` | A path to a `.babelrc` file to extend |

@@ -153,0 +154,0 @@ | `filename` | `"unknown"` | Filename for use in errors etc |

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc