fix: skip polyfills for modern mode and fix tests

This commit is contained in:
Haoqun Jiang
2018-12-26 14:56:07 +08:00
parent 9c0adab85b
commit e3a58cb29e
2 changed files with 7 additions and 7 deletions
@@ -14,7 +14,7 @@ test('polyfill detection', () => {
targets: { node: 'current' }
}]]
})
// default includes
// default i ncludes
expect(code).not.toMatch(`import "core-js/modules/es6.promise"`)
// usage-based detection
expect(code).not.toMatch(`import "core-js/modules/es6.map"`)
@@ -32,7 +32,7 @@ test('polyfill detection', () => {
// promise polyfill alone doesn't work in IE, needs this as well. fix: #1642
expect(code).toMatch(`import "core-js/modules/es6.array.iterator"`)
// usage-based detection
expect(code).toMatch(`import "core-js/modules/es6.map"`)
expect(code).toMatch(/import _Map from ".*@babel\/runtime-corejs2\/core-js\/map"/)
})
test('modern mode always skips polyfills', () => {
@@ -49,7 +49,7 @@ test('modern mode always skips polyfills', () => {
// default includes
expect(code).not.toMatch(`import "core-js/modules/es6.promise"`)
// usage-based detection
expect(code).not.toMatch(`import "core-js/modules/es6.map"`)
expect(code).not.toMatch(/import _Map from ".*@babel\/runtime-corejs2\/core-js\/map"/)
;({ code } = babel.transformSync(`
const a = new Map()
@@ -63,7 +63,7 @@ test('modern mode always skips polyfills', () => {
// default includes
expect(code).not.toMatch(`import "core-js/modules/es6.promise"`)
// usage-based detection
expect(code).not.toMatch(`import "core-js/modules/es6.map"`)
expect(code).not.toMatch(/import _Map from ".*@babel\/runtime-corejs2\/core-js\/map"/)
delete process.env.VUE_CLI_MODERN_BUILD
})
@@ -92,7 +92,7 @@ test('async/await', () => {
// should use regenerator runtime
expect(code).toMatch(`import "regenerator-runtime/runtime"`)
// should use required helper instead of inline
expect(code).toMatch(/@babel.*runtime\/helpers\/.*asyncToGenerator/)
expect(code).toMatch(/import _asyncToGenerator from ".*@babel\/runtime-corejs2\/helpers\/esm\/asyncToGenerator\"/)
})
test('jsx', () => {
+2 -2
View File
@@ -144,8 +144,8 @@ module.exports = (context, options = {}) => {
regenerator: useBuiltIns !== 'usage',
// use @babel/runtime-corejs2 so that helpers that need polyfillable APIs will reference core-js instead.
// if useBuiltIns is not set to 'usage', then it means users would take care of the polyfills on their own,
// i.e., core-js 2 is no longer needed
corejs: useBuiltIns === 'usage' ? 2 : false,
// i.e., core-js 2 is no longer needed.
corejs: (useBuiltIns === 'usage' && !process.env.VUE_CLI_MODERN_BUILD) ? 2 : false,
helpers: useBuiltIns === 'usage',
useESModules: !process.env.VUE_CLI_BABEL_TRANSPILE_MODULES,
absoluteRuntime: path.dirname(require.resolve('@babel/runtime/package.json'))