Skip to content
This repository has been archived by the owner on May 11, 2018. It is now read-only.

Commit

Permalink
Show error if target version is not a number
Browse files Browse the repository at this point in the history
  • Loading branch information
existentialism committed Dec 22, 2016
1 parent 259d203 commit 8444a2f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ export const isPluginRequired = (supportedEnvironments, plugin) => {
const lowestImplementedVersion = plugin[environment];
const lowestTargetedVersion = supportedEnvironments[environment];

if (lowestTargetedVersion < lowestImplementedVersion) {
return true;
if (typeof lowestTargetedVersion === "string") {
throw new Error(`Target version must be a number, '${lowestTargetedVersion}' was given for '${environment}'`);
}

return false;
return lowestTargetedVersion < lowestImplementedVersion;
});

return isRequiredForEnvironments.length > 0 ? true : false;
Expand Down
14 changes: 14 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,20 @@ describe("babel-preset-env", () => {
babelPresetEnv.isPluginRequired(targets, plugin);
}, Error);
});

it("will throw if target version is not a number", () => {
const plugin = {
"node": 6,
};

const targets = {
"node": "6.5",
};

assert.throws(() => {
babelPresetEnv.isPluginRequired(targets, plugin);
}, Error);
});
});

describe("validateLooseOption", () => {
Expand Down

0 comments on commit 8444a2f

Please sign in to comment.