Skip to content

revert: "fix: should not add polyfills from transform-runtime plugin (#3730)" #3742

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions packages/@vue/babel-preset-app/__tests__/babel-preset.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ test('polyfill detection', () => {
// promise polyfill alone doesn't work in IE, needs this as well. fix: #1642
expect(code).toMatch(genCoreJSImportRegExp('es6.array.iterator'))
// usage-based detection
expect(code).toMatch(/import "core-js\/modules\/es6.map"/)
expect(code).toMatch(/import _Map from ".*runtime-corejs2\/core-js\/map"/)
})

test('modern mode always skips polyfills', () => {
Expand All @@ -63,7 +63,7 @@ test('modern mode always skips polyfills', () => {
// default includes
expect(code).not.toMatch(genCoreJSImportRegExp('es6.promise'))
// usage-based detection
expect(code).not.toMatch(/import "core-js\/modules\/es6.map"/)
expect(code).not.toMatch(/import _Map from ".*runtime-corejs2\/core-js\/map"/)

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

Expand Down Expand Up @@ -107,7 +107,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(/import _asyncToGenerator from ".*runtime\/helpers\/esm\/asyncToGenerator\"/)
expect(code).toMatch(/import _asyncToGenerator from ".*runtime-corejs2\/helpers\/esm\/asyncToGenerator\"/)
})

test('jsx', () => {
Expand Down Expand Up @@ -152,6 +152,6 @@ test('disable absoluteRuntime', () => {
filename: 'test-entry-file.js'
})

expect(code).toMatch('import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray"')
expect(code).not.toMatch(genCoreJSImportRegExp('es6.promise'))
expect(code).toMatch('import _toConsumableArray from "@babel/runtime-corejs2/helpers/esm/toConsumableArray"')
// expect(code).not.toMatch(genCoreJSImportRegExp('es6.promise'))
})
8 changes: 4 additions & 4 deletions packages/@vue/babel-preset-app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ module.exports = (context, options = {}) => {
// transform runtime, but only for helpers
plugins.push([require('@babel/plugin-transform-runtime'), {
regenerator: useBuiltIns !== 'usage',

// polyfills are injected by preset-env & polyfillsPlugin, so no need to add them again
corejs: false,

// 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' && !process.env.VUE_CLI_MODERN_BUILD) ? 2 : false,
helpers: useBuiltIns === 'usage',
useESModules: !process.env.VUE_CLI_BABEL_TRANSPILE_MODULES,

Expand Down
1 change: 1 addition & 0 deletions packages/@vue/babel-preset-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"@babel/plugin-transform-runtime": "^7.4.0",
"@babel/preset-env": "^7.0.0 < 7.4.0",
"@babel/runtime": "^7.0.0",
"@babel/runtime-corejs2": "^7.2.0",
"@vue/babel-preset-jsx": "^1.0.0-beta.2",
"babel-plugin-dynamic-import-node": "^2.2.0",
"core-js": "^2.6.5"
Expand Down
5 changes: 0 additions & 5 deletions packages/@vue/cli-plugin-babel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ module.exports = (api, options) => {
if (transpileDepRegex && transpileDepRegex.test(filepath)) {
return false
}
// may need to add polyfills (by preset-env) for babel helpers
// https://github.com/babel/babel/issues/7597
if (/node_modules\/@babel\/runtime/.test(filepath)) {
return false
}
// Don't transpile node_modules
return /node_modules/.test(filepath)
})
Expand Down