Fix prerelease checks in .availableHelper and transform-runtime definitions. (#8659)
This commit is contained in:
@@ -1,14 +1,40 @@
|
||||
import semver from "semver";
|
||||
|
||||
function hasMinVersion(minVersion, runtimeVersion) {
|
||||
// If the range is unavailable, we're running the script during Babel's
|
||||
// build process, and we want to assume that all versions are satisfied so
|
||||
// that the built output will include all definitions.
|
||||
if (!runtimeVersion) return true;
|
||||
|
||||
// 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
|
||||
// babel-core's availableHelper() API.
|
||||
if (semver.valid(runtimeVersion)) runtimeVersion = `^${runtimeVersion}`;
|
||||
|
||||
return (
|
||||
!semver.intersects(`<${minVersion}`, runtimeVersion) &&
|
||||
!semver.intersects(`>=8.0.0`, runtimeVersion)
|
||||
);
|
||||
}
|
||||
|
||||
export default runtimeVersion => {
|
||||
let includeMathModule = true;
|
||||
if (runtimeVersion) {
|
||||
// reason for conditionally including this module:
|
||||
// https://github.com/babel/babel/pull/8616#issuecomment-418154753
|
||||
includeMathModule =
|
||||
!semver.intersects(`<=7.0.0`, runtimeVersion) &&
|
||||
!semver.intersects(`>=8.0.0`, runtimeVersion);
|
||||
}
|
||||
// Conditionally include 'Math' because it was not included in the 7.0.0
|
||||
// release of '@babel/runtime'. See issue https://github.com/babel/babel/pull/8616.
|
||||
const includeMathModule = hasMinVersion("7.0.1", runtimeVersion);
|
||||
|
||||
return {
|
||||
builtins: {
|
||||
|
||||
@@ -1,51 +1,17 @@
|
||||
var _Math$trunc = require("@babel/runtime-corejs2/core-js/math/trunc");
|
||||
|
||||
var _Math$tanh = require("@babel/runtime-corejs2/core-js/math/tanh");
|
||||
|
||||
var _Math$sinh = require("@babel/runtime-corejs2/core-js/math/sinh");
|
||||
|
||||
var _Math$sign = require("@babel/runtime-corejs2/core-js/math/sign");
|
||||
|
||||
var _Math$log2 = require("@babel/runtime-corejs2/core-js/math/log2");
|
||||
|
||||
var _Math$log1p = require("@babel/runtime-corejs2/core-js/math/log1p");
|
||||
|
||||
var _Math$log = require("@babel/runtime-corejs2/core-js/math/log10");
|
||||
|
||||
var _Math$imul = require("@babel/runtime-corejs2/core-js/math/imul");
|
||||
|
||||
var _Math$hypot = require("@babel/runtime-corejs2/core-js/math/hypot");
|
||||
|
||||
var _Math$fround = require("@babel/runtime-corejs2/core-js/math/fround");
|
||||
|
||||
var _Math$expm = require("@babel/runtime-corejs2/core-js/math/expm1");
|
||||
|
||||
var _Math$cosh = require("@babel/runtime-corejs2/core-js/math/cosh");
|
||||
|
||||
var _Math$clz = require("@babel/runtime-corejs2/core-js/math/clz32");
|
||||
|
||||
var _Math$cbrt = require("@babel/runtime-corejs2/core-js/math/cbrt");
|
||||
|
||||
var _Math$atanh = require("@babel/runtime-corejs2/core-js/math/atanh");
|
||||
|
||||
var _Math$asinh = require("@babel/runtime-corejs2/core-js/math/asinh");
|
||||
|
||||
var _Math$acosh = require("@babel/runtime-corejs2/core-js/math/acosh");
|
||||
|
||||
_Math$acosh;
|
||||
_Math$asinh;
|
||||
_Math$atanh;
|
||||
_Math$cbrt;
|
||||
_Math$clz;
|
||||
_Math$cosh;
|
||||
_Math$expm;
|
||||
_Math$fround;
|
||||
_Math$hypot;
|
||||
_Math$imul;
|
||||
_Math$log;
|
||||
_Math$log1p;
|
||||
_Math$log2;
|
||||
_Math$sign;
|
||||
_Math$sinh;
|
||||
_Math$tanh;
|
||||
_Math$trunc;
|
||||
Math.acosh;
|
||||
Math.asinh;
|
||||
Math.atanh;
|
||||
Math.cbrt;
|
||||
Math.clz32;
|
||||
Math.cosh;
|
||||
Math.expm1;
|
||||
Math.fround;
|
||||
Math.hypot;
|
||||
Math.imul;
|
||||
Math.log10;
|
||||
Math.log1p;
|
||||
Math.log2;
|
||||
Math.sign;
|
||||
Math.sinh;
|
||||
Math.tanh;
|
||||
Math.trunc;
|
||||
|
||||
Reference in New Issue
Block a user