From 26105034da4fcce7ac883c899d781f016559310d Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 8 Nov 2018 00:38:48 +0800 Subject: switch to vuepress --- .../lib/config/validation/option-assertions.js | 205 +++++++++++++++++++++ .../@babel/core/lib/config/validation/options.js | 169 +++++++++++++++++ .../@babel/core/lib/config/validation/plugins.js | 55 ++++++ .../@babel/core/lib/config/validation/removed.js | 66 +++++++ 4 files changed, 495 insertions(+) create mode 100644 node_modules/@babel/core/lib/config/validation/option-assertions.js create mode 100644 node_modules/@babel/core/lib/config/validation/options.js create mode 100644 node_modules/@babel/core/lib/config/validation/plugins.js create mode 100644 node_modules/@babel/core/lib/config/validation/removed.js (limited to 'node_modules/@babel/core/lib/config/validation') diff --git a/node_modules/@babel/core/lib/config/validation/option-assertions.js b/node_modules/@babel/core/lib/config/validation/option-assertions.js new file mode 100644 index 00000000..4aa57c37 --- /dev/null +++ b/node_modules/@babel/core/lib/config/validation/option-assertions.js @@ -0,0 +1,205 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.assertSourceMaps = assertSourceMaps; +exports.assertCompact = assertCompact; +exports.assertSourceType = assertSourceType; +exports.assertInputSourceMap = assertInputSourceMap; +exports.assertString = assertString; +exports.assertFunction = assertFunction; +exports.assertBoolean = assertBoolean; +exports.assertObject = assertObject; +exports.assertArray = assertArray; +exports.assertIgnoreList = assertIgnoreList; +exports.assertConfigApplicableTest = assertConfigApplicableTest; +exports.assertConfigFileSearch = assertConfigFileSearch; +exports.assertBabelrcSearch = assertBabelrcSearch; +exports.assertPluginList = assertPluginList; + +function assertSourceMaps(key, value) { + if (value !== undefined && typeof value !== "boolean" && value !== "inline" && value !== "both") { + throw new Error(`.${key} must be a boolean, "inline", "both", or undefined`); + } + + return value; +} + +function assertCompact(key, value) { + if (value !== undefined && typeof value !== "boolean" && value !== "auto") { + throw new Error(`.${key} must be a boolean, "auto", or undefined`); + } + + return value; +} + +function assertSourceType(key, value) { + if (value !== undefined && value !== "module" && value !== "script" && value !== "unambiguous") { + throw new Error(`.${key} must be "module", "script", "unambiguous", or undefined`); + } + + return value; +} + +function assertInputSourceMap(key, value) { + if (value !== undefined && typeof value !== "boolean" && (typeof value !== "object" || !value)) { + throw new Error(".inputSourceMap must be a boolean, object, or undefined"); + } + + return value; +} + +function assertString(key, value) { + if (value !== undefined && typeof value !== "string") { + throw new Error(`.${key} must be a string, or undefined`); + } + + return value; +} + +function assertFunction(key, value) { + if (value !== undefined && typeof value !== "function") { + throw new Error(`.${key} must be a function, or undefined`); + } + + return value; +} + +function assertBoolean(key, value) { + if (value !== undefined && typeof value !== "boolean") { + throw new Error(`.${key} must be a boolean, or undefined`); + } + + return value; +} + +function assertObject(key, value) { + if (value !== undefined && (typeof value !== "object" || Array.isArray(value) || !value)) { + throw new Error(`.${key} must be an object, or undefined`); + } + + return value; +} + +function assertArray(key, value) { + if (value != null && !Array.isArray(value)) { + throw new Error(`.${key} must be an array, or undefined`); + } + + return value; +} + +function assertIgnoreList(key, value) { + const arr = assertArray(key, value); + + if (arr) { + arr.forEach((item, i) => assertIgnoreItem(key, i, item)); + } + + return arr; +} + +function assertIgnoreItem(key, index, 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`); + } + + return value; +} + +function assertConfigApplicableTest(key, value) { + if (value === undefined) return value; + + if (Array.isArray(value)) { + value.forEach((item, i) => { + if (!checkValidTest(item)) { + throw new Error(`.${key}[${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`); + } + + return value; +} + +function checkValidTest(value) { + return typeof value === "string" || typeof value === "function" || value instanceof RegExp; +} + +function assertConfigFileSearch(key, 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)}`); + } + + return value; +} + +function assertBabelrcSearch(key, value) { + if (value === undefined || typeof value === "boolean") return value; + + if (Array.isArray(value)) { + value.forEach((item, i) => { + if (typeof item !== "string") { + throw new Error(`.${key}[${i}] must be a string.`); + } + }); + } else if (typeof value !== "string") { + throw new Error(`.${key} must be a undefined, a boolean, a string, ` + `or an array of strings, got ${JSON.stringify(value)}`); + } + + return value; +} + +function assertPluginList(key, value) { + const arr = assertArray(key, value); + + if (arr) { + arr.forEach((item, i) => assertPluginItem(key, i, item)); + } + + return arr; +} + +function assertPluginItem(key, index, value) { + if (Array.isArray(value)) { + if (value.length === 0) { + throw new Error(`.${key}[${index}] must include an object`); + } + + if (value.length > 3) { + throw new Error(`.${key}[${index}] may only be a two-tuple or three-tuple`); + } + + assertPluginTarget(key, index, true, value[0]); + + if (value.length > 1) { + const opts = value[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`); + } + } + + if (value.length === 3) { + const name = value[2]; + + if (name !== undefined && typeof name !== "string") { + throw new Error(`.${key}[${index}][2] must be a string, or undefined`); + } + } + } else { + assertPluginTarget(key, index, false, value); + } + + return value; +} + +function assertPluginTarget(key, index, inArray, 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`); + } + + return value; +} \ No newline at end of file diff --git a/node_modules/@babel/core/lib/config/validation/options.js b/node_modules/@babel/core/lib/config/validation/options.js new file mode 100644 index 00000000..b427b693 --- /dev/null +++ b/node_modules/@babel/core/lib/config/validation/options.js @@ -0,0 +1,169 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.validate = validate; + +var _plugin = _interopRequireDefault(require("../plugin")); + +var _removed = _interopRequireDefault(require("./removed")); + +var _optionAssertions = require("./option-assertions"); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +const ROOT_VALIDATORS = { + cwd: _optionAssertions.assertString, + root: _optionAssertions.assertString, + configFile: _optionAssertions.assertConfigFileSearch, + filename: _optionAssertions.assertString, + filenameRelative: _optionAssertions.assertString, + code: _optionAssertions.assertBoolean, + ast: _optionAssertions.assertBoolean, + envName: _optionAssertions.assertString +}; +const BABELRC_VALIDATORS = { + babelrc: _optionAssertions.assertBoolean, + babelrcRoots: _optionAssertions.assertBabelrcSearch +}; +const NONPRESET_VALIDATORS = { + extends: _optionAssertions.assertString, + env: assertEnvSet, + ignore: _optionAssertions.assertIgnoreList, + only: _optionAssertions.assertIgnoreList, + overrides: assertOverridesList, + test: _optionAssertions.assertConfigApplicableTest, + include: _optionAssertions.assertConfigApplicableTest, + exclude: _optionAssertions.assertConfigApplicableTest +}; +const COMMON_VALIDATORS = { + inputSourceMap: _optionAssertions.assertInputSourceMap, + presets: _optionAssertions.assertPluginList, + plugins: _optionAssertions.assertPluginList, + passPerPreset: _optionAssertions.assertBoolean, + retainLines: _optionAssertions.assertBoolean, + comments: _optionAssertions.assertBoolean, + shouldPrintComment: _optionAssertions.assertFunction, + compact: _optionAssertions.assertCompact, + minified: _optionAssertions.assertBoolean, + auxiliaryCommentBefore: _optionAssertions.assertString, + auxiliaryCommentAfter: _optionAssertions.assertString, + sourceType: _optionAssertions.assertSourceType, + wrapPluginVisitorMethod: _optionAssertions.assertFunction, + highlightCode: _optionAssertions.assertBoolean, + sourceMaps: _optionAssertions.assertSourceMaps, + sourceMap: _optionAssertions.assertSourceMaps, + sourceFileName: _optionAssertions.assertString, + sourceRoot: _optionAssertions.assertString, + getModuleId: _optionAssertions.assertFunction, + moduleRoot: _optionAssertions.assertString, + moduleIds: _optionAssertions.assertBoolean, + moduleId: _optionAssertions.assertString, + parserOpts: _optionAssertions.assertObject, + generatorOpts: _optionAssertions.assertObject +}; + +function validate(type, opts) { + assertNoDuplicateSourcemap(opts); + Object.keys(opts).forEach(key => { + if (type === "preset" && NONPRESET_VALIDATORS[key]) { + throw new Error(`.${key} is not allowed in preset options`); + } + + if (type !== "arguments" && ROOT_VALIDATORS[key]) { + throw new Error(`.${key} is only allowed in root programmatic options`); + } + + if (type !== "arguments" && type !== "configfile" && BABELRC_VALIDATORS[key]) { + 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(`.${key} 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); + }); + return opts; +} + +function buildUnknownError(key) { + if (_removed.default[key]) { + const _removed$key = _removed.default[key], + message = _removed$key.message, + _removed$key$version = _removed$key.version, + version = _removed$key$version === void 0 ? 5 : _removed$key$version; + throw new ReferenceError(`Using removed Babel ${version} option: .${key} - ${message}`); + } else { + const unknownOptErr = `Unknown option: .${key}. Check out http://babeljs.io/docs/usage/options/ for more information about options.`; + throw new ReferenceError(unknownOptErr); + } +} + +function has(obj, key) { + return Object.prototype.hasOwnProperty.call(obj, key); +} + +function assertNoDuplicateSourcemap(opts) { + if (has(opts, "sourceMap") && has(opts, "sourceMaps")) { + throw new Error(".sourceMap is an alias for .sourceMaps, cannot use both"); + } +} + +function assertEnvSet(key, value) { + const obj = (0, _optionAssertions.assertObject)(key, value); + + if (obj) { + var _arr = Object.keys(obj); + + for (var _i = 0; _i < _arr.length; _i++) { + const key = _arr[_i]; + const env = (0, _optionAssertions.assertObject)(key, obj[key]); + if (env) validate("env", env); + } + } + + return obj; +} + +function assertOverridesList(key, value) { + const arr = (0, _optionAssertions.assertArray)(key, value); + + if (arr) { + for (var _iterator = arr.entries(), _isArray = Array.isArray(_iterator), _i2 = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { + var _ref; + + if (_isArray) { + if (_i2 >= _iterator.length) break; + _ref = _iterator[_i2++]; + } else { + _i2 = _iterator.next(); + if (_i2.done) break; + _ref = _i2.value; + } + + const _ref2 = _ref, + index = _ref2[0], + item = _ref2[1]; + const env = (0, _optionAssertions.assertObject)(`${index}`, item); + if (!env) throw new Error(`.${key}[${index}] must be an object`); + validate("override", env); + } + } + + return arr; +} \ No newline at end of file diff --git a/node_modules/@babel/core/lib/config/validation/plugins.js b/node_modules/@babel/core/lib/config/validation/plugins.js new file mode 100644 index 00000000..73b498cd --- /dev/null +++ b/node_modules/@babel/core/lib/config/validation/plugins.js @@ -0,0 +1,55 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.validatePluginObject = validatePluginObject; + +var _optionAssertions = require("./option-assertions"); + +const VALIDATORS = { + name: _optionAssertions.assertString, + manipulateOptions: _optionAssertions.assertFunction, + pre: _optionAssertions.assertFunction, + post: _optionAssertions.assertFunction, + inherits: _optionAssertions.assertFunction, + visitor: assertVisitorMap, + parserOverride: _optionAssertions.assertFunction, + generatorOverride: _optionAssertions.assertFunction +}; + +function assertVisitorMap(key, value) { + const obj = (0, _optionAssertions.assertObject)(key, value); + + if (obj) { + Object.keys(obj).forEach(prop => assertVisitorHandler(prop, obj[prop])); + + if (obj.enter || obj.exit) { + throw new Error(`.${key} cannot contain catch-all "enter" or "exit" handlers. Please target individual nodes.`); + } + } + + return obj; +} + +function assertVisitorHandler(key, value) { + if (value && typeof value === "object") { + Object.keys(value).forEach(handler => { + if (handler !== "enter" && handler !== "exit") { + throw new Error(`.visitor["${key}"] may only have .enter and/or .exit handlers.`); + } + }); + } else if (typeof value !== "function") { + throw new Error(`.visitor["${key}"] must be a function`); + } + + return value; +} + +function validatePluginObject(obj) { + Object.keys(obj).forEach(key => { + const validator = VALIDATORS[key]; + if (validator) validator(key, obj[key]);else throw new Error(`.${key} is not a valid Plugin property`); + }); + return obj; +} \ No newline at end of file diff --git a/node_modules/@babel/core/lib/config/validation/removed.js b/node_modules/@babel/core/lib/config/validation/removed.js new file mode 100644 index 00000000..f0fcd7de --- /dev/null +++ b/node_modules/@babel/core/lib/config/validation/removed.js @@ -0,0 +1,66 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = void 0; +var _default = { + auxiliaryComment: { + message: "Use `auxiliaryCommentBefore` or `auxiliaryCommentAfter`" + }, + blacklist: { + message: "Put the specific transforms you want in the `plugins` option" + }, + breakConfig: { + message: "This is not a necessary option in Babel 6" + }, + experimental: { + message: "Put the specific transforms you want in the `plugins` option" + }, + externalHelpers: { + message: "Use the `external-helpers` plugin instead. " + "Check out http://babeljs.io/docs/plugins/external-helpers/" + }, + extra: { + message: "" + }, + jsxPragma: { + message: "use the `pragma` option in the `react-jsx` plugin. " + "Check out http://babeljs.io/docs/plugins/transform-react-jsx/" + }, + loose: { + message: "Specify the `loose` option for the relevant plugin you are using " + "or use a preset that sets the option." + }, + metadataUsedHelpers: { + message: "Not required anymore as this is enabled by default" + }, + modules: { + message: "Use the corresponding module transform plugin in the `plugins` option. " + "Check out http://babeljs.io/docs/plugins/#modules" + }, + nonStandard: { + message: "Use the `react-jsx` and `flow-strip-types` plugins to support JSX and Flow. " + "Also check out the react preset http://babeljs.io/docs/plugins/preset-react/" + }, + optional: { + message: "Put the specific transforms you want in the `plugins` option" + }, + sourceMapName: { + message: "The `sourceMapName` option has been removed because it makes more sense for the " + "tooling that calls Babel to assign `map.file` themselves." + }, + stage: { + message: "Check out the corresponding stage-x presets http://babeljs.io/docs/plugins/#presets" + }, + whitelist: { + message: "Put the specific transforms you want in the `plugins` option" + }, + resolveModuleSource: { + version: 6, + message: "Use `babel-plugin-module-resolver@3`'s 'resolvePath' options" + }, + metadata: { + version: 6, + 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; \ No newline at end of file -- cgit v1.2.3