diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2023-10-14 15:31:11 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2023-10-14 15:31:11 +0800 |
| commit | aa773172311dcada759dfbaac485f4bc6e00bc21 (patch) | |
| tree | ca6d9a5eff3ab8f689f9acb4f0df791d9486813d /node_modules/@babel/helper-define-polyfill-provider/lib/normalize-options.js | |
| parent | c5a5384e846f242e901e859fe600d695d8990a9a (diff) | |
added babel
Diffstat (limited to 'node_modules/@babel/helper-define-polyfill-provider/lib/normalize-options.js')
| -rw-r--r-- | node_modules/@babel/helper-define-polyfill-provider/lib/normalize-options.js | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/node_modules/@babel/helper-define-polyfill-provider/lib/normalize-options.js b/node_modules/@babel/helper-define-polyfill-provider/lib/normalize-options.js new file mode 100644 index 00000000..62937764 --- /dev/null +++ b/node_modules/@babel/helper-define-polyfill-provider/lib/normalize-options.js @@ -0,0 +1,70 @@ +"use strict"; + +exports.__esModule = true; +exports.applyMissingDependenciesDefaults = applyMissingDependenciesDefaults; +exports.validateIncludeExclude = validateIncludeExclude; +var _utils = require("./utils"); +function patternToRegExp(pattern) { + if (pattern instanceof RegExp) return pattern; + try { + return new RegExp(`^${pattern}$`); + } catch (_unused) { + return null; + } +} +function buildUnusedError(label, unused) { + if (!unused.length) return ""; + return ` - The following "${label}" patterns didn't match any polyfill:\n` + unused.map(original => ` ${String(original)}\n`).join(""); +} +function buldDuplicatesError(duplicates) { + if (!duplicates.size) return ""; + return ` - The following polyfills were matched both by "include" and "exclude" patterns:\n` + Array.from(duplicates, name => ` ${name}\n`).join(""); +} +function validateIncludeExclude(provider, polyfills, includePatterns, excludePatterns) { + let current; + const filter = pattern => { + const regexp = patternToRegExp(pattern); + if (!regexp) return false; + let matched = false; + for (const polyfill of polyfills) { + if (regexp.test(polyfill)) { + matched = true; + current.add(polyfill); + } + } + return !matched; + }; + + // prettier-ignore + const include = current = new Set(); + const unusedInclude = Array.from(includePatterns).filter(filter); + + // prettier-ignore + const exclude = current = new Set(); + const unusedExclude = Array.from(excludePatterns).filter(filter); + const duplicates = (0, _utils.intersection)(include, exclude); + if (duplicates.size > 0 || unusedInclude.length > 0 || unusedExclude.length > 0) { + throw new Error(`Error while validating the "${provider}" provider options:\n` + buildUnusedError("include", unusedInclude) + buildUnusedError("exclude", unusedExclude) + buldDuplicatesError(duplicates)); + } + return { + include, + exclude + }; +} +function applyMissingDependenciesDefaults(options, babelApi) { + const { + missingDependencies = {} + } = options; + if (missingDependencies === false) return false; + const caller = babelApi.caller(caller => caller == null ? void 0 : caller.name); + const { + log = "deferred", + inject = caller === "rollup-plugin-babel" ? "throw" : "import", + all = false + } = missingDependencies; + return { + log, + inject, + all + }; +}
\ No newline at end of file |
