Skip to content

Commit

Permalink
fix: use chrome support data when android is absent
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Dec 4, 2019
1 parent 0fd239c commit 83ea838
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
9 changes: 7 additions & 2 deletions packages/babel-preset-env/src/debug.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
// @flow
/*eslint quotes: ["error", "double", { "avoidEscape": true }]*/
import semver from "semver";
import { isUnreleasedVersion, prettifyVersion, semverify } from "./utils";
import {
isUnreleasedVersion,
prettifyVersion,
semverify,
getLowestImplementedVersion,
} from "./utils";

import type { Targets } from "./types";

Expand All @@ -19,7 +24,7 @@ export const logPluginOrPolyfill = (
const minVersions = list[item] || {};

const filteredList = Object.keys(targetVersions).reduce((result, env) => {
const minVersion = minVersions[env];
const minVersion = getLowestImplementedVersion(minVersions, env);
const targetVersion = targetVersions[env];

if (!minVersion) {
Expand Down
14 changes: 10 additions & 4 deletions packages/babel-preset-env/src/filter-items.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// @flow
import semver from "semver";
import { semverify, isUnreleasedVersion } from "./utils";
import {
semverify,
isUnreleasedVersion,
getLowestImplementedVersion,
} from "./utils";

import type { Targets } from "./types";

Expand All @@ -15,12 +19,14 @@ export function isPluginRequired(
}

const isRequiredForEnvironments = targetEnvironments.filter(environment => {
const lowestImplementedVersion = getLowestImplementedVersion(
plugin,
environment,
);
// Feature is not implemented in that environment
if (!plugin[environment]) {
if (!lowestImplementedVersion) {
return true;
}

const lowestImplementedVersion = plugin[environment];
const lowestTargetedVersion = supportedEnvironments[environment];

// If targets has unreleased value as a lowest version, then don't require a plugin.
Expand Down
9 changes: 9 additions & 0 deletions packages/babel-preset-env/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,15 @@ export function getLowestUnreleased(a: string, b: string, env: string): string {
return semverMin(a, b);
}

export function getLowestImplementedVersion(plugin, environment) {
const result = plugin[environment];
// When Android support data is absent, use Chrome data as fallback
if (!result && environment === "android") {
return plugin.chrome;
}
return result;
}

export function filterStageFromList(
list: { [feature: string]: Targets },
stageList: { [feature: string]: boolean },
Expand Down

0 comments on commit 83ea838

Please sign in to comment.