source: imaps-frontend/node_modules/@babel/helper-define-polyfill-provider/lib/normalize-options.js@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

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