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 b2b666b
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/babel-core/src/transformation/file/file.js
Expand Up @@ -166,6 +166,22 @@ 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.
if (semver.valid(versionRange)) versionRange = `^${versionRange}`;

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

0 comments on commit b2b666b

Please sign in to comment.