[6a3a178] | 1 | "use strict";
|
---|
| 2 |
|
---|
| 3 | exports.__esModule = true;
|
---|
| 4 | exports.validateIncludeExclude = validateIncludeExclude;
|
---|
| 5 | exports.applyMissingDependenciesDefaults = applyMissingDependenciesDefaults;
|
---|
| 6 |
|
---|
| 7 | var _utils = require("./utils");
|
---|
| 8 |
|
---|
| 9 | function patternToRegExp(pattern) {
|
---|
| 10 | if (pattern instanceof RegExp) return pattern;
|
---|
| 11 |
|
---|
| 12 | try {
|
---|
| 13 | return new RegExp(`^${pattern}$`);
|
---|
| 14 | } catch (_unused) {
|
---|
| 15 | return null;
|
---|
| 16 | }
|
---|
| 17 | }
|
---|
| 18 |
|
---|
| 19 | function buildUnusedError(label, unused) {
|
---|
| 20 | if (!unused.length) return "";
|
---|
| 21 | return ` - The following "${label}" patterns didn't match any polyfill:\n` + unused.map(original => ` ${String(original)}\n`).join("");
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | function buldDuplicatesError(duplicates) {
|
---|
| 25 | if (!duplicates.size) return "";
|
---|
| 26 | return ` - The following polyfills were matched both by "include" and "exclude" patterns:\n` + Array.from(duplicates, name => ` ${name}\n`).join("");
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | function validateIncludeExclude(provider, polyfills, includePatterns, excludePatterns) {
|
---|
| 30 | let current;
|
---|
| 31 |
|
---|
| 32 | const filter = pattern => {
|
---|
| 33 | const regexp = patternToRegExp(pattern);
|
---|
| 34 | if (!regexp) return false;
|
---|
| 35 | let matched = false;
|
---|
| 36 |
|
---|
| 37 | for (const polyfill of polyfills) {
|
---|
| 38 | if (regexp.test(polyfill)) {
|
---|
| 39 | matched = true;
|
---|
| 40 | current.add(polyfill);
|
---|
| 41 | }
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | return !matched;
|
---|
| 45 | }; // prettier-ignore
|
---|
| 46 |
|
---|
| 47 |
|
---|
| 48 | const include = current = new Set();
|
---|
| 49 | const unusedInclude = Array.from(includePatterns).filter(filter); // prettier-ignore
|
---|
| 50 |
|
---|
| 51 | const exclude = current = new Set();
|
---|
| 52 | const unusedExclude = Array.from(excludePatterns).filter(filter);
|
---|
| 53 | const duplicates = (0, _utils.intersection)(include, exclude);
|
---|
| 54 |
|
---|
| 55 | if (duplicates.size > 0 || unusedInclude.length > 0 || unusedExclude.length > 0) {
|
---|
| 56 | throw new Error(`Error while validating the "${provider}" provider options:\n` + buildUnusedError("include", unusedInclude) + buildUnusedError("exclude", unusedExclude) + buldDuplicatesError(duplicates));
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | return {
|
---|
| 60 | include,
|
---|
| 61 | exclude
|
---|
| 62 | };
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | function applyMissingDependenciesDefaults(options, babelApi) {
|
---|
| 66 | const {
|
---|
| 67 | missingDependencies = {}
|
---|
| 68 | } = options;
|
---|
| 69 | if (missingDependencies === false) return false;
|
---|
| 70 | const caller = babelApi.caller(caller => caller == null ? void 0 : caller.name);
|
---|
| 71 | const {
|
---|
| 72 | log = "deferred",
|
---|
| 73 | inject = caller === "rollup-plugin-babel" ? "throw" : "import",
|
---|
| 74 | all = false
|
---|
| 75 | } = missingDependencies;
|
---|
| 76 | return {
|
---|
| 77 | log,
|
---|
| 78 | inject,
|
---|
| 79 | all
|
---|
| 80 | };
|
---|
| 81 | } |
---|