Skip to content

Commit 7228146

Browse files
authoredApr 1, 2019
revert: "fix: should not add polyfills from transform-runtime plugin (#3730)" (#3742)
This reverts commit b987969. closes #3741
1 parent cc2db63 commit 7228146

File tree

4 files changed

+11
-15
lines changed

4 files changed

+11
-15
lines changed
 

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ test('polyfill detection', () => {
4545
// promise polyfill alone doesn't work in IE, needs this as well. fix: #1642
4646
expect(code).toMatch(genCoreJSImportRegExp('es6.array.iterator'))
4747
// usage-based detection
48-
expect(code).toMatch(/import "core-js\/modules\/es6.map"/)
48+
expect(code).toMatch(/import _Map from ".*runtime-corejs2\/core-js\/map"/)
4949
})
5050

5151
test('modern mode always skips polyfills', () => {
@@ -63,7 +63,7 @@ test('modern mode always skips polyfills', () => {
6363
// default includes
6464
expect(code).not.toMatch(genCoreJSImportRegExp('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 ".*runtime-corejs2\/core-js\/map"/)
6767

6868
;({ code } = babel.transformSync(`
6969
const a = new Map()
@@ -78,7 +78,7 @@ test('modern mode always skips polyfills', () => {
7878
// default includes
7979
expect(code).not.toMatch(genCoreJSImportRegExp('es6.promise'))
8080
// usage-based detection
81-
expect(code).not.toMatch(/import "core-js\/modules\/es6.map"/)
81+
expect(code).not.toMatch(/import _Map from ".*runtime-corejs2\/core-js\/map"/)
8282
delete process.env.VUE_CLI_MODERN_BUILD
8383
})
8484

@@ -107,7 +107,7 @@ test('async/await', () => {
107107
// should use regenerator runtime
108108
expect(code).toMatch(`import "regenerator-runtime/runtime"`)
109109
// should use required helper instead of inline
110-
expect(code).toMatch(/import _asyncToGenerator from ".*runtime\/helpers\/esm\/asyncToGenerator\"/)
110+
expect(code).toMatch(/import _asyncToGenerator from ".*runtime-corejs2\/helpers\/esm\/asyncToGenerator\"/)
111111
})
112112

113113
test('jsx', () => {
@@ -152,6 +152,6 @@ test('disable absoluteRuntime', () => {
152152
filename: 'test-entry-file.js'
153153
})
154154

155-
expect(code).toMatch('import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray"')
156-
expect(code).not.toMatch(genCoreJSImportRegExp('es6.promise'))
155+
expect(code).toMatch('import _toConsumableArray from "@babel/runtime-corejs2/helpers/esm/toConsumableArray"')
156+
// expect(code).not.toMatch(genCoreJSImportRegExp('es6.promise'))
157157
})

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,10 @@ module.exports = (context, options = {}) => {
154154
// transform runtime, but only for helpers
155155
plugins.push([require('@babel/plugin-transform-runtime'), {
156156
regenerator: useBuiltIns !== 'usage',
157-
158-
// polyfills are injected by preset-env & polyfillsPlugin, so no need to add them again
159-
corejs: false,
160-
157+
// use @babel/runtime-corejs2 so that helpers that need polyfillable APIs will reference core-js instead.
158+
// if useBuiltIns is not set to 'usage', then it means users would take care of the polyfills on their own,
159+
// i.e., core-js 2 is no longer needed.
160+
corejs: (useBuiltIns === 'usage' && !process.env.VUE_CLI_MODERN_BUILD) ? 2 : false,
161161
helpers: useBuiltIns === 'usage',
162162
useESModules: !process.env.VUE_CLI_BABEL_TRANSPILE_MODULES,
163163

‎packages/@vue/babel-preset-app/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"@babel/plugin-transform-runtime": "^7.4.0",
3131
"@babel/preset-env": "^7.0.0 < 7.4.0",
3232
"@babel/runtime": "^7.0.0",
33+
"@babel/runtime-corejs2": "^7.2.0",
3334
"@vue/babel-preset-jsx": "^1.0.0-beta.2",
3435
"babel-plugin-dynamic-import-node": "^2.2.0",
3536
"core-js": "^2.6.5"

‎packages/@vue/cli-plugin-babel/index.js

-5
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,6 @@ module.exports = (api, options) => {
4040
if (transpileDepRegex && transpileDepRegex.test(filepath)) {
4141
return false
4242
}
43-
// may need to add polyfills (by preset-env) for babel helpers
44-
// https://github.com/babel/babel/issues/7597
45-
if (/node_modules\/@babel\/runtime/.test(filepath)) {
46-
return false
47-
}
4843
// Don't transpile node_modules
4944
return /node_modules/.test(filepath)
5045
})

0 commit comments

Comments
 (0)
Please sign in to comment.