Skip to content

Commit 646e694

Browse files
committed
chore: remove babelParserDefaultPlugins
The version of @babel/parser we are using now has these plugins enabled by default.
1 parent ed0071a commit 646e694

File tree

7 files changed

+10
-43
lines changed

7 files changed

+10
-43
lines changed

packages/compiler-core/src/transforms/transformExpression.ts

+2-8
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,7 @@ import {
2424
walkIdentifiers
2525
} from '../babelUtils'
2626
import { advancePositionWithClone, isSimpleIdentifier } from '../utils'
27-
import {
28-
isGloballyWhitelisted,
29-
makeMap,
30-
babelParserDefaultPlugins,
31-
hasOwn,
32-
isString
33-
} from '@vue/shared'
27+
import { isGloballyWhitelisted, makeMap, hasOwn, isString } from '@vue/shared'
3428
import { createCompilerError, ErrorCodes } from '../errors'
3529
import {
3630
Node,
@@ -244,7 +238,7 @@ export function processExpression(
244238
: `(${rawExp})${asParams ? `=>{}` : ``}`
245239
try {
246240
ast = parse(source, {
247-
plugins: [...context.expressionPlugins, ...babelParserDefaultPlugins]
241+
plugins: context.expressionPlugins
248242
}).program
249243
} catch (e: any) {
250244
context.onError(

packages/compiler-core/src/utils.ts

+2-9
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,7 @@ import {
4242
WITH_MEMO,
4343
OPEN_BLOCK
4444
} from './runtimeHelpers'
45-
import {
46-
isString,
47-
isObject,
48-
hyphenate,
49-
extend,
50-
babelParserDefaultPlugins,
51-
NOOP
52-
} from '@vue/shared'
45+
import { isString, isObject, hyphenate, extend, NOOP } from '@vue/shared'
5346
import { PropsExpression } from './transforms/transformElement'
5447
import { parseExpression } from '@babel/parser'
5548
import { Expression } from '@babel/types'
@@ -167,7 +160,7 @@ export const isMemberExpressionNode = __BROWSER__
167160
: (path: string, context: TransformContext): boolean => {
168161
try {
169162
let ret: Expression = parseExpression(path, {
170-
plugins: [...context.expressionPlugins, ...babelParserDefaultPlugins]
163+
plugins: context.expressionPlugins
171164
})
172165
if (ret.type === 'TSAsExpression' || ret.type === 'TSTypeAssertion') {
173166
ret = ret.expression

packages/compiler-sfc/__tests__/utils.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { parse, SFCScriptCompileOptions, compileScript } from '../src'
22
import { parse as babelParse } from '@babel/parser'
3-
import { babelParserDefaultPlugins } from '@vue/shared'
43

54
export const mockId = 'xxxxxxxx'
65

@@ -20,7 +19,7 @@ export function assertCode(code: string) {
2019
try {
2120
babelParse(code, {
2221
sourceType: 'module',
23-
plugins: [...babelParserDefaultPlugins, 'typescript']
22+
plugins: ['typescript']
2423
})
2524
} catch (e: any) {
2625
console.log(code)

packages/compiler-sfc/src/compileScript.ts

+2-8
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,7 @@ import {
1313
} from '@vue/compiler-dom'
1414
import { SFCDescriptor, SFCScriptBlock } from './parse'
1515
import { parse as _parse, ParserOptions, ParserPlugin } from '@babel/parser'
16-
import {
17-
babelParserDefaultPlugins,
18-
camelize,
19-
capitalize,
20-
generateCodeFrame,
21-
makeMap
22-
} from '@vue/shared'
16+
import { camelize, capitalize, generateCodeFrame, makeMap } from '@vue/shared'
2317
import {
2418
Node,
2519
Declaration,
@@ -161,7 +155,7 @@ export function compileScript(
161155
scriptLang === 'tsx' ||
162156
scriptSetupLang === 'ts' ||
163157
scriptSetupLang === 'tsx'
164-
const plugins: ParserPlugin[] = [...babelParserDefaultPlugins]
158+
const plugins: ParserPlugin[] = []
165159
if (!isTS || scriptLang === 'tsx' || scriptSetupLang === 'tsx') {
166160
plugins.push('jsx')
167161
}

packages/ref-transform/__tests__/refTransform.spec.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import { parse } from '@babel/parser'
2-
import { babelParserDefaultPlugins } from '@vue/shared'
32
import { transform } from '../src'
43

54
function assertCode(code: string) {
65
// parse the generated code to make sure it is valid
76
try {
87
parse(code, {
98
sourceType: 'module',
10-
plugins: [...babelParserDefaultPlugins, 'typescript']
9+
plugins: ['typescript']
1110
})
1211
} catch (e: any) {
1312
console.log(code)

packages/ref-transform/src/refTransform.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
walkFunctionParams
2121
} from '@vue/compiler-core'
2222
import { parse, ParserPlugin } from '@babel/parser'
23-
import { babelParserDefaultPlugins, hasOwn } from '@vue/shared'
23+
import { hasOwn } from '@vue/shared'
2424

2525
const TO_VAR_SYMBOL = '$'
2626
const TO_REF_SYMBOL = '$$'
@@ -68,7 +68,7 @@ export function transform(
6868

6969
const ast = parse(src, {
7070
sourceType: 'module',
71-
plugins: [...new Set([...babelParserDefaultPlugins, ...plugins])]
71+
plugins
7272
})
7373
const s = new MagicString(src)
7474
const res = transformAST(ast.program, s)

packages/shared/src/index.ts

-12
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,6 @@ export * from './escapeHtml'
1313
export * from './looseEqual'
1414
export * from './toDisplayString'
1515

16-
/**
17-
* List of @babel/parser plugins that are used for template expression
18-
* transforms and SFC script transforms. By default we enable proposals slated
19-
* for ES2020. This will need to be updated as the spec moves forward.
20-
* Full list at https://babeljs.io/docs/en/next/babel-parser#plugins
21-
*/
22-
export const babelParserDefaultPlugins = [
23-
'bigInt',
24-
'optionalChaining',
25-
'nullishCoalescingOperator'
26-
] as const
27-
2816
export const EMPTY_OBJ: { readonly [key: string]: any } = __DEV__
2917
? Object.freeze({})
3018
: {}

0 commit comments

Comments
 (0)