[runtime-corejs3] Only polyfill instance methods when it might be needed (#9754)

This commit is contained in:
Nicolò Ribaudo
2019-04-02 21:18:59 +02:00
committed by GitHub
parent 53e0622b54
commit e03eb17c08
9 changed files with 66 additions and 3 deletions

View File

@@ -1,4 +1,5 @@
import semver from "semver";
import { types as t } from "@babel/core";
export function hasMinVersion(minVersion, runtimeVersion) {
// If the range is unavailable, we're running the script during Babel's
@@ -30,3 +31,16 @@ export function hasMinVersion(minVersion, runtimeVersion) {
!semver.intersects(`>=8.0.0`, runtimeVersion)
);
}
// Note: We can't use NodePath#couldBeBaseType because it doesn't support arrays.
// Even if we added support for arrays, this package needs to be compatible with
// ^7.0.0 so we can't rely on it.
export function typeAnnotationToString(node) {
switch (node.type) {
case "GenericTypeAnnotation":
if (t.isIdentifier(node.id, { name: "Array" })) return "array";
break;
case "StringTypeAnnotation":
return "string";
}
}