fix(babel-preset-app): allow to specify corejs.version as string (#8085)

This commit is contained in:
Yihao Gao 2020-09-21 19:51:39 +09:30 committed by GitHub
parent 761d2abb7f
commit 4374e541ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -15,8 +15,16 @@ const coreJsMeta = {
}
}
function getMajorVersion (version) {
if (typeof version === 'number') {
return Math.floor(version)
} else {
return Number(version.split('.')[0])
}
}
function getDefaultPolyfills (corejs) {
const { prefixes: { es6, es7 } } = coreJsMeta[corejs.version]
const { prefixes: { es6, es7 } } = coreJsMeta[getMajorVersion(corejs.version)]
return [
// Promise polyfill alone doesn't work in IE,
// Needs this as well. see: #1642
@ -33,7 +41,7 @@ function getDefaultPolyfills (corejs) {
function getPolyfills (targets, includes, { ignoreBrowserslistConfig, configPath, corejs }) {
const { default: getTargets, isRequired } = require('@babel/helper-compilation-targets')
const builtInsList = require(coreJsMeta[corejs.version].builtIns)
const builtInsList = require(coreJsMeta[getMajorVersion(corejs.version)].builtIns)
const builtInTargets = getTargets(targets, {
ignoreBrowserslistConfig,
configPath