Skip to content

Commit

Permalink
Fix prerelease checks in .availableHelper and transform-runtime defin…
Browse files Browse the repository at this point in the history
…itions. (#8659)
  • Loading branch information
loganfsmyth committed Sep 11, 2018
1 parent 90fb82a commit 5aed3cc
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/babel-core/src/transformation/file/file.js
Expand Up @@ -166,6 +166,25 @@ export default class File {
return false;
}

// semver.intersects() has some surprising behavior with comparing ranges
// with preprelease versions. We add '^' to ensure that we are always
// comparing ranges with ranges, which sidesteps this logic.
// For example:
//
// semver.intersects(`<7.0.1`, "7.0.0-beta.0") // false - surprising
// semver.intersects(`<7.0.1`, "^7.0.0-beta.0") // true - expected
//
// This is because the first falls back to
//
// semver.satisfies("7.0.0-beta.0", `<7.0.1`) // false - surprising
//
// and this fails because a prerelease version can only satisfy a range
// if it is a prerelease within the same major/minor/patch range.
//
// Note: If this is found to have issues, please also revist the logic in
// transform-runtime's definitions.js file.
if (semver.valid(versionRange)) versionRange = `^${versionRange}`;

return (
typeof versionRange !== "string" ||
(!semver.intersects(`<${minVersion}`, versionRange) &&
Expand Down

0 comments on commit 5aed3cc

Please sign in to comment.