Skip to content

Commit e3a58cb

Browse files
committed
fix: skip polyfills for modern mode and fix tests
1 parent 9c0adab commit e3a58cb

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

packages/@vue/babel-preset-app/__tests__/babel-preset.spec.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ test('polyfill detection', () => {
1414
targets: { node: 'current' }
1515
}]]
1616
})
17-
// default includes
17+
// default i ncludes
1818
expect(code).not.toMatch(`import "core-js/modules/es6.promise"`)
1919
// usage-based detection
2020
expect(code).not.toMatch(`import "core-js/modules/es6.map"`)
@@ -32,7 +32,7 @@ test('polyfill detection', () => {
3232
// promise polyfill alone doesn't work in IE, needs this as well. fix: #1642
3333
expect(code).toMatch(`import "core-js/modules/es6.array.iterator"`)
3434
// usage-based detection
35-
expect(code).toMatch(`import "core-js/modules/es6.map"`)
35+
expect(code).toMatch(/import _Map from ".*@babel\/runtime-corejs2\/core-js\/map"/)
3636
})
3737

3838
test('modern mode always skips polyfills', () => {
@@ -49,7 +49,7 @@ test('modern mode always skips polyfills', () => {
4949
// default includes
5050
expect(code).not.toMatch(`import "core-js/modules/es6.promise"`)
5151
// usage-based detection
52-
expect(code).not.toMatch(`import "core-js/modules/es6.map"`)
52+
expect(code).not.toMatch(/import _Map from ".*@babel\/runtime-corejs2\/core-js\/map"/)
5353

5454
;({ code } = babel.transformSync(`
5555
const a = new Map()
@@ -63,7 +63,7 @@ test('modern mode always skips polyfills', () => {
6363
// default includes
6464
expect(code).not.toMatch(`import "core-js/modules/es6.promise"`)
6565
// usage-based detection
66-
expect(code).not.toMatch(`import "core-js/modules/es6.map"`)
66+
expect(code).not.toMatch(/import _Map from ".*@babel\/runtime-corejs2\/core-js\/map"/)
6767
delete process.env.VUE_CLI_MODERN_BUILD
6868
})
6969

@@ -92,7 +92,7 @@ test('async/await', () => {
9292
// should use regenerator runtime
9393
expect(code).toMatch(`import "regenerator-runtime/runtime"`)
9494
// should use required helper instead of inline
95-
expect(code).toMatch(/@babel.*runtime\/helpers\/.*asyncToGenerator/)
95+
expect(code).toMatch(/import _asyncToGenerator from ".*@babel\/runtime-corejs2\/helpers\/esm\/asyncToGenerator\"/)
9696
})
9797

9898
test('jsx', () => {

packages/@vue/babel-preset-app/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ module.exports = (context, options = {}) => {
144144
regenerator: useBuiltIns !== 'usage',
145145
// use @babel/runtime-corejs2 so that helpers that need polyfillable APIs will reference core-js instead.
146146
// if useBuiltIns is not set to 'usage', then it means users would take care of the polyfills on their own,
147-
// i.e., core-js 2 is no longer needed
148-
corejs: useBuiltIns === 'usage' ? 2 : false,
147+
// i.e., core-js 2 is no longer needed.
148+
corejs: (useBuiltIns === 'usage' && !process.env.VUE_CLI_MODERN_BUILD) ? 2 : false,
149149
helpers: useBuiltIns === 'usage',
150150
useESModules: !process.env.VUE_CLI_BABEL_TRANSPILE_MODULES,
151151
absoluteRuntime: path.dirname(require.resolve('@babel/runtime/package.json'))

0 commit comments

Comments
 (0)