aboutsummaryrefslogtreecommitdiff
path: root/node_modules/@babel/helper-compilation-targets/lib
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/@babel/helper-compilation-targets/lib')
-rw-r--r--node_modules/@babel/helper-compilation-targets/lib/debug.js33
-rw-r--r--node_modules/@babel/helper-compilation-targets/lib/filter-items.js88
-rw-r--r--node_modules/@babel/helper-compilation-targets/lib/index.js255
-rw-r--r--node_modules/@babel/helper-compilation-targets/lib/options.js21
-rw-r--r--node_modules/@babel/helper-compilation-targets/lib/pretty.js47
-rw-r--r--node_modules/@babel/helper-compilation-targets/lib/targets.js27
-rw-r--r--node_modules/@babel/helper-compilation-targets/lib/types.js0
-rw-r--r--node_modules/@babel/helper-compilation-targets/lib/utils.js69
8 files changed, 540 insertions, 0 deletions
diff --git a/node_modules/@babel/helper-compilation-targets/lib/debug.js b/node_modules/@babel/helper-compilation-targets/lib/debug.js
new file mode 100644
index 0000000..4e05fdd
--- /dev/null
+++ b/node_modules/@babel/helper-compilation-targets/lib/debug.js
@@ -0,0 +1,33 @@
+"use strict";
+
+Object.defineProperty(exports, "__esModule", {
+ value: true
+});
+exports.getInclusionReasons = getInclusionReasons;
+
+var _semver = require("semver");
+
+var _pretty = require("./pretty");
+
+var _utils = require("./utils");
+
+function getInclusionReasons(item, targetVersions, list) {
+ const minVersions = list[item] || {};
+ return Object.keys(targetVersions).reduce((result, env) => {
+ const minVersion = (0, _utils.getLowestImplementedVersion)(minVersions, env);
+ const targetVersion = targetVersions[env];
+
+ if (!minVersion) {
+ result[env] = (0, _pretty.prettifyVersion)(targetVersion);
+ } else {
+ const minIsUnreleased = (0, _utils.isUnreleasedVersion)(minVersion, env);
+ const targetIsUnreleased = (0, _utils.isUnreleasedVersion)(targetVersion, env);
+
+ if (!targetIsUnreleased && (minIsUnreleased || _semver.lt(targetVersion.toString(), (0, _utils.semverify)(minVersion)))) {
+ result[env] = (0, _pretty.prettifyVersion)(targetVersion);
+ }
+ }
+
+ return result;
+ }, {});
+} \ No newline at end of file
diff --git a/node_modules/@babel/helper-compilation-targets/lib/filter-items.js b/node_modules/@babel/helper-compilation-targets/lib/filter-items.js
new file mode 100644
index 0000000..f47f605
--- /dev/null
+++ b/node_modules/@babel/helper-compilation-targets/lib/filter-items.js
@@ -0,0 +1,88 @@
+"use strict";
+
+Object.defineProperty(exports, "__esModule", {
+ value: true
+});
+exports.default = filterItems;
+exports.isRequired = isRequired;
+exports.targetsSupported = targetsSupported;
+
+var _semver = require("semver");
+
+var _plugins = require("@babel/compat-data/plugins");
+
+var _utils = require("./utils");
+
+function targetsSupported(target, support) {
+ const targetEnvironments = Object.keys(target);
+
+ if (targetEnvironments.length === 0) {
+ return false;
+ }
+
+ const unsupportedEnvironments = targetEnvironments.filter(environment => {
+ const lowestImplementedVersion = (0, _utils.getLowestImplementedVersion)(support, environment);
+
+ if (!lowestImplementedVersion) {
+ return true;
+ }
+
+ const lowestTargetedVersion = target[environment];
+
+ if ((0, _utils.isUnreleasedVersion)(lowestTargetedVersion, environment)) {
+ return false;
+ }
+
+ if ((0, _utils.isUnreleasedVersion)(lowestImplementedVersion, environment)) {
+ return true;
+ }
+
+ if (!_semver.valid(lowestTargetedVersion.toString())) {
+ throw new Error(`Invalid version passed for target "${environment}": "${lowestTargetedVersion}". ` + "Versions must be in semver format (major.minor.patch)");
+ }
+
+ return _semver.gt((0, _utils.semverify)(lowestImplementedVersion), lowestTargetedVersion.toString());
+ });
+ return unsupportedEnvironments.length === 0;
+}
+
+function isRequired(name, targets, {
+ compatData = _plugins,
+ includes,
+ excludes
+} = {}) {
+ if (excludes != null && excludes.has(name)) return false;
+ if (includes != null && includes.has(name)) return true;
+ return !targetsSupported(targets, compatData[name]);
+}
+
+function filterItems(list, includes, excludes, targets, defaultIncludes, defaultExcludes, pluginSyntaxMap) {
+ const result = new Set();
+ const options = {
+ compatData: list,
+ includes,
+ excludes
+ };
+
+ for (const item in list) {
+ if (isRequired(item, targets, options)) {
+ result.add(item);
+ } else if (pluginSyntaxMap) {
+ const shippedProposalsSyntax = pluginSyntaxMap.get(item);
+
+ if (shippedProposalsSyntax) {
+ result.add(shippedProposalsSyntax);
+ }
+ }
+ }
+
+ if (defaultIncludes) {
+ defaultIncludes.forEach(item => !excludes.has(item) && result.add(item));
+ }
+
+ if (defaultExcludes) {
+ defaultExcludes.forEach(item => !includes.has(item) && result.delete(item));
+ }
+
+ return result;
+} \ No newline at end of file
diff --git a/node_modules/@babel/helper-compilation-targets/lib/index.js b/node_modules/@babel/helper-compilation-targets/lib/index.js
new file mode 100644
index 0000000..c186599
--- /dev/null
+++ b/node_modules/@babel/helper-compilation-targets/lib/index.js
@@ -0,0 +1,255 @@
+"use strict";
+
+Object.defineProperty(exports, "__esModule", {
+ value: true
+});
+Object.defineProperty(exports, "TargetNames", {
+ enumerable: true,
+ get: function () {
+ return _options.TargetNames;
+ }
+});
+exports.default = getTargets;
+Object.defineProperty(exports, "filterItems", {
+ enumerable: true,
+ get: function () {
+ return _filterItems.default;
+ }
+});
+Object.defineProperty(exports, "getInclusionReasons", {
+ enumerable: true,
+ get: function () {
+ return _debug.getInclusionReasons;
+ }
+});
+exports.isBrowsersQueryValid = isBrowsersQueryValid;
+Object.defineProperty(exports, "isRequired", {
+ enumerable: true,
+ get: function () {
+ return _filterItems.isRequired;
+ }
+});
+Object.defineProperty(exports, "prettifyTargets", {
+ enumerable: true,
+ get: function () {
+ return _pretty.prettifyTargets;
+ }
+});
+Object.defineProperty(exports, "unreleasedLabels", {
+ enumerable: true,
+ get: function () {
+ return _targets.unreleasedLabels;
+ }
+});
+
+var _browserslist = require("browserslist");
+
+var _helperValidatorOption = require("@babel/helper-validator-option");
+
+var _nativeModules = require("@babel/compat-data/native-modules");
+
+var _utils = require("./utils");
+
+var _targets = require("./targets");
+
+var _options = require("./options");
+
+var _pretty = require("./pretty");
+
+var _debug = require("./debug");
+
+var _filterItems = require("./filter-items");
+
+const ESM_SUPPORT = _nativeModules["es6.module"];
+const v = new _helperValidatorOption.OptionValidator("@babel/helper-compilation-targets");
+
+function validateTargetNames(targets) {
+ const validTargets = Object.keys(_options.TargetNames);
+
+ for (const target of Object.keys(targets)) {
+ if (!(target in _options.TargetNames)) {
+ throw new Error(v.formatMessage(`'${target}' is not a valid target
+- Did you mean '${(0, _helperValidatorOption.findSuggestion)(target, validTargets)}'?`));
+ }
+ }
+
+ return targets;
+}
+
+function isBrowsersQueryValid(browsers) {
+ return typeof browsers === "string" || Array.isArray(browsers) && browsers.every(b => typeof b === "string");
+}
+
+function validateBrowsers(browsers) {
+ v.invariant(browsers === undefined || isBrowsersQueryValid(browsers), `'${String(browsers)}' is not a valid browserslist query`);
+ return browsers;
+}
+
+function getLowestVersions(browsers) {
+ return browsers.reduce((all, browser) => {
+ const [browserName, browserVersion] = browser.split(" ");
+ const normalizedBrowserName = _targets.browserNameMap[browserName];
+
+ if (!normalizedBrowserName) {
+ return all;
+ }
+
+ try {
+ const splitVersion = browserVersion.split("-")[0].toLowerCase();
+ const isSplitUnreleased = (0, _utils.isUnreleasedVersion)(splitVersion, browserName);
+
+ if (!all[normalizedBrowserName]) {
+ all[normalizedBrowserName] = isSplitUnreleased ? splitVersion : (0, _utils.semverify)(splitVersion);
+ return all;
+ }
+
+ const version = all[normalizedBrowserName];
+ const isUnreleased = (0, _utils.isUnreleasedVersion)(version, browserName);
+
+ if (isUnreleased && isSplitUnreleased) {
+ all[normalizedBrowserName] = (0, _utils.getLowestUnreleased)(version, splitVersion, browserName);
+ } else if (isUnreleased) {
+ all[normalizedBrowserName] = (0, _utils.semverify)(splitVersion);
+ } else if (!isUnreleased && !isSplitUnreleased) {
+ const parsedBrowserVersion = (0, _utils.semverify)(splitVersion);
+ all[normalizedBrowserName] = (0, _utils.semverMin)(version, parsedBrowserVersion);
+ }
+ } catch (e) {}
+
+ return all;
+ }, {});
+}
+
+function outputDecimalWarning(decimalTargets) {
+ if (!decimalTargets.length) {
+ return;
+ }
+
+ console.warn("Warning, the following targets are using a decimal version:\n");
+ decimalTargets.forEach(({
+ target,
+ value
+ }) => console.warn(` ${target}: ${value}`));
+ console.warn(`
+We recommend using a string for minor/patch versions to avoid numbers like 6.10
+getting parsed as 6.1, which can lead to unexpected behavior.
+`);
+}
+
+function semverifyTarget(target, value) {
+ try {
+ return (0, _utils.semverify)(value);
+ } catch (error) {
+ throw new Error(v.formatMessage(`'${value}' is not a valid value for 'targets.${target}'.`));
+ }
+}
+
+const targetParserMap = {
+ __default(target, value) {
+ const version = (0, _utils.isUnreleasedVersion)(value, target) ? value.toLowerCase() : semverifyTarget(target, value);
+ return [target, version];
+ },
+
+ node(target, value) {
+ const parsed = value === true || value === "current" ? process.versions.node : semverifyTarget(target, value);
+ return [target, parsed];
+ }
+
+};
+
+function generateTargets(inputTargets) {
+ const input = Object.assign({}, inputTargets);
+ delete input.esmodules;
+ delete input.browsers;
+ return input;
+}
+
+function resolveTargets(queries, env) {
+ const resolved = _browserslist(queries, {
+ mobileToDesktop: true,
+ env
+ });
+
+ return getLowestVersions(resolved);
+}
+
+function getTargets(inputTargets = {}, options = {}) {
+ var _browsers;
+
+ let {
+ browsers,
+ esmodules
+ } = inputTargets;
+ const {
+ configPath = "."
+ } = options;
+ validateBrowsers(browsers);
+ const input = generateTargets(inputTargets);
+ let targets = validateTargetNames(input);
+ const shouldParseBrowsers = !!browsers;
+ const hasTargets = shouldParseBrowsers || Object.keys(targets).length > 0;
+ const shouldSearchForConfig = !options.ignoreBrowserslistConfig && !hasTargets;
+
+ if (!browsers && shouldSearchForConfig) {
+ browsers = _browserslist.loadConfig({
+ config: options.configFile,
+ path: configPath,
+ env: options.browserslistEnv
+ });
+
+ if (browsers == null) {
+ {
+ browsers = [];
+ }
+ }
+ }
+
+ if (esmodules && (esmodules !== "intersect" || !((_browsers = browsers) != null && _browsers.length))) {
+ browsers = Object.keys(ESM_SUPPORT).map(browser => `${browser} >= ${ESM_SUPPORT[browser]}`).join(", ");
+ esmodules = false;
+ }
+
+ if (browsers) {
+ const queryBrowsers = resolveTargets(browsers, options.browserslistEnv);
+
+ if (esmodules === "intersect") {
+ for (const browser of Object.keys(queryBrowsers)) {
+ const version = queryBrowsers[browser];
+
+ if (ESM_SUPPORT[browser]) {
+ queryBrowsers[browser] = (0, _utils.getHighestUnreleased)(version, (0, _utils.semverify)(ESM_SUPPORT[browser]), browser);
+ } else {
+ delete queryBrowsers[browser];
+ }
+ }
+ }
+
+ targets = Object.assign(queryBrowsers, targets);
+ }
+
+ const result = {};
+ const decimalWarnings = [];
+
+ for (const target of Object.keys(targets).sort()) {
+ var _targetParserMap$targ;
+
+ const value = targets[target];
+
+ if (typeof value === "number" && value % 1 !== 0) {
+ decimalWarnings.push({
+ target,
+ value
+ });
+ }
+
+ const parser = (_targetParserMap$targ = targetParserMap[target]) != null ? _targetParserMap$targ : targetParserMap.__default;
+ const [parsedTarget, parsedValue] = parser(target, value);
+
+ if (parsedValue) {
+ result[parsedTarget] = parsedValue;
+ }
+ }
+
+ outputDecimalWarning(decimalWarnings);
+ return result;
+} \ No newline at end of file
diff --git a/node_modules/@babel/helper-compilation-targets/lib/options.js b/node_modules/@babel/helper-compilation-targets/lib/options.js
new file mode 100644
index 0000000..cbf4de0
--- /dev/null
+++ b/node_modules/@babel/helper-compilation-targets/lib/options.js
@@ -0,0 +1,21 @@
+"use strict";
+
+Object.defineProperty(exports, "__esModule", {
+ value: true
+});
+exports.TargetNames = void 0;
+const TargetNames = {
+ node: "node",
+ chrome: "chrome",
+ opera: "opera",
+ edge: "edge",
+ firefox: "firefox",
+ safari: "safari",
+ ie: "ie",
+ ios: "ios",
+ android: "android",
+ electron: "electron",
+ samsung: "samsung",
+ rhino: "rhino"
+};
+exports.TargetNames = TargetNames; \ No newline at end of file
diff --git a/node_modules/@babel/helper-compilation-targets/lib/pretty.js b/node_modules/@babel/helper-compilation-targets/lib/pretty.js
new file mode 100644
index 0000000..88df640
--- /dev/null
+++ b/node_modules/@babel/helper-compilation-targets/lib/pretty.js
@@ -0,0 +1,47 @@
+"use strict";
+
+Object.defineProperty(exports, "__esModule", {
+ value: true
+});
+exports.prettifyTargets = prettifyTargets;
+exports.prettifyVersion = prettifyVersion;
+
+var _semver = require("semver");
+
+var _targets = require("./targets");
+
+function prettifyVersion(version) {
+ if (typeof version !== "string") {
+ return version;
+ }
+
+ const parts = [_semver.major(version)];
+
+ const minor = _semver.minor(version);
+
+ const patch = _semver.patch(version);
+
+ if (minor || patch) {
+ parts.push(minor);
+ }
+
+ if (patch) {
+ parts.push(patch);
+ }
+
+ return parts.join(".");
+}
+
+function prettifyTargets(targets) {
+ return Object.keys(targets).reduce((results, target) => {
+ let value = targets[target];
+ const unreleasedLabel = _targets.unreleasedLabels[target];
+
+ if (typeof value === "string" && unreleasedLabel !== value) {
+ value = prettifyVersion(value);
+ }
+
+ results[target] = value;
+ return results;
+ }, {});
+} \ No newline at end of file
diff --git a/node_modules/@babel/helper-compilation-targets/lib/targets.js b/node_modules/@babel/helper-compilation-targets/lib/targets.js
new file mode 100644
index 0000000..3cbaeac
--- /dev/null
+++ b/node_modules/@babel/helper-compilation-targets/lib/targets.js
@@ -0,0 +1,27 @@
+"use strict";
+
+Object.defineProperty(exports, "__esModule", {
+ value: true
+});
+exports.unreleasedLabels = exports.browserNameMap = void 0;
+const unreleasedLabels = {
+ safari: "tp"
+};
+exports.unreleasedLabels = unreleasedLabels;
+const browserNameMap = {
+ and_chr: "chrome",
+ and_ff: "firefox",
+ android: "android",
+ chrome: "chrome",
+ edge: "edge",
+ firefox: "firefox",
+ ie: "ie",
+ ie_mob: "ie",
+ ios_saf: "ios",
+ node: "node",
+ op_mob: "opera",
+ opera: "opera",
+ safari: "safari",
+ samsung: "samsung"
+};
+exports.browserNameMap = browserNameMap; \ No newline at end of file
diff --git a/node_modules/@babel/helper-compilation-targets/lib/types.js b/node_modules/@babel/helper-compilation-targets/lib/types.js
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/node_modules/@babel/helper-compilation-targets/lib/types.js
diff --git a/node_modules/@babel/helper-compilation-targets/lib/utils.js b/node_modules/@babel/helper-compilation-targets/lib/utils.js
new file mode 100644
index 0000000..711a84f
--- /dev/null
+++ b/node_modules/@babel/helper-compilation-targets/lib/utils.js
@@ -0,0 +1,69 @@
+"use strict";
+
+Object.defineProperty(exports, "__esModule", {
+ value: true
+});
+exports.getHighestUnreleased = getHighestUnreleased;
+exports.getLowestImplementedVersion = getLowestImplementedVersion;
+exports.getLowestUnreleased = getLowestUnreleased;
+exports.isUnreleasedVersion = isUnreleasedVersion;
+exports.semverMin = semverMin;
+exports.semverify = semverify;
+
+var _semver = require("semver");
+
+var _helperValidatorOption = require("@babel/helper-validator-option");
+
+var _targets = require("./targets");
+
+const versionRegExp = /^(\d+|\d+.\d+)$/;
+const v = new _helperValidatorOption.OptionValidator("@babel/helper-compilation-targets");
+
+function semverMin(first, second) {
+ return first && _semver.lt(first, second) ? first : second;
+}
+
+function semverify(version) {
+ if (typeof version === "string" && _semver.valid(version)) {
+ return version;
+ }
+
+ v.invariant(typeof version === "number" || typeof version === "string" && versionRegExp.test(version), `'${version}' is not a valid version`);
+ const split = version.toString().split(".");
+
+ while (split.length < 3) {
+ split.push("0");
+ }
+
+ return split.join(".");
+}
+
+function isUnreleasedVersion(version, env) {
+ const unreleasedLabel = _targets.unreleasedLabels[env];
+ return !!unreleasedLabel && unreleasedLabel === version.toString().toLowerCase();
+}
+
+function getLowestUnreleased(a, b, env) {
+ const unreleasedLabel = _targets.unreleasedLabels[env];
+ const hasUnreleased = [a, b].some(item => item === unreleasedLabel);
+
+ if (hasUnreleased) {
+ return a === hasUnreleased ? b : a || b;
+ }
+
+ return semverMin(a, b);
+}
+
+function getHighestUnreleased(a, b, env) {
+ return getLowestUnreleased(a, b, env) === a ? b : a;
+}
+
+function getLowestImplementedVersion(plugin, environment) {
+ const result = plugin[environment];
+
+ if (!result && environment === "android") {
+ return plugin.chrome;
+ }
+
+ return result;
+} \ No newline at end of file