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

Show error if target version is not a number #107

Merged
merged 1 commit into from
Jan 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ 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