Skip to content

Commit c7fa1cf

Browse files
committed
fix: always transpile syntaxes introduced in ES2020 or later
To fix compatibility issues with webpack 4 and ESLint 6. Browserslist doesn't support ES version queries, so we approximate it as Chrome 79.0.0 and Node.js 12 Fixes #7209
1 parent 5b57792 commit c7fa1cf

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,21 @@ module.exports = (context, options = {}) => {
176176

177177
// resolve targets for preset-env
178178
let targets = getTargets(rawTargets, { ignoreBrowserslistConfig, configPath })
179+
180+
// Webpack 4 uses acorn 6 underlyingly;
181+
// The highest ESLint version that Vue CLI v4 supports is 6.x;
182+
// Both can only parse ES2019 syntax + BigInt at most.
183+
// Thus, newer syntaxes such as optional chaining and nullish coalescing won't
184+
// be accept by webpack / ESLint, and must be processed by Babel first.
185+
// Chrome 79 is the last Chrome version that doesn't support these syntaxes.
186+
// So the targets set by the user cannot be higher than Chrome 79.
187+
if (!targets.chrome || semver.gt(targets.chrome, '79.0.0')) {
188+
targets.chrome = '79.0.0'
189+
}
190+
179191
if (process.env.VUE_CLI_BABEL_TARGET_NODE) {
180192
// running tests in Node.js
181-
targets = { node: 'current' }
193+
targets = { node: '12' }
182194
} else if (process.env.VUE_CLI_BUILD_TARGET === 'wc' || process.env.VUE_CLI_BUILD_TARGET === 'wc-async') {
183195
// targeting browsers that at least support ES2015 classes
184196
targets = getWCTargets(targets)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy