Skip to content

Commit

Permalink
chore: remove babelParserDefaultPlugins
Browse files Browse the repository at this point in the history
The version of @babel/parser we are using now has these plugins enabled by default.
  • Loading branch information
yyx990803 committed Oct 7, 2021
1 parent ed0071a commit 646e694
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 43 deletions.
10 changes: 2 additions & 8 deletions packages/compiler-core/src/transforms/transformExpression.ts
Expand Up @@ -24,13 +24,7 @@ import {
walkIdentifiers
} from '../babelUtils'
import { advancePositionWithClone, isSimpleIdentifier } from '../utils'
import {
isGloballyWhitelisted,
makeMap,
babelParserDefaultPlugins,
hasOwn,
isString
} from '@vue/shared'
import { isGloballyWhitelisted, makeMap, hasOwn, isString } from '@vue/shared'
import { createCompilerError, ErrorCodes } from '../errors'
import {
Node,
Expand Down Expand Up @@ -244,7 +238,7 @@ export function processExpression(
: `(${rawExp})${asParams ? `=>{}` : ``}`
try {
ast = parse(source, {
plugins: [...context.expressionPlugins, ...babelParserDefaultPlugins]
plugins: context.expressionPlugins
}).program
} catch (e: any) {
context.onError(
Expand Down
11 changes: 2 additions & 9 deletions packages/compiler-core/src/utils.ts
Expand Up @@ -42,14 +42,7 @@ import {
WITH_MEMO,
OPEN_BLOCK
} from './runtimeHelpers'
import {
isString,
isObject,
hyphenate,
extend,
babelParserDefaultPlugins,
NOOP
} from '@vue/shared'
import { isString, isObject, hyphenate, extend, NOOP } from '@vue/shared'
import { PropsExpression } from './transforms/transformElement'
import { parseExpression } from '@babel/parser'
import { Expression } from '@babel/types'
Expand Down Expand Up @@ -167,7 +160,7 @@ export const isMemberExpressionNode = __BROWSER__
: (path: string, context: TransformContext): boolean => {
try {
let ret: Expression = parseExpression(path, {
plugins: [...context.expressionPlugins, ...babelParserDefaultPlugins]
plugins: context.expressionPlugins
})
if (ret.type === 'TSAsExpression' || ret.type === 'TSTypeAssertion') {
ret = ret.expression
Expand Down
3 changes: 1 addition & 2 deletions packages/compiler-sfc/__tests__/utils.ts
@@ -1,6 +1,5 @@
import { parse, SFCScriptCompileOptions, compileScript } from '../src'
import { parse as babelParse } from '@babel/parser'
import { babelParserDefaultPlugins } from '@vue/shared'

export const mockId = 'xxxxxxxx'

Expand All @@ -20,7 +19,7 @@ export function assertCode(code: string) {
try {
babelParse(code, {
sourceType: 'module',
plugins: [...babelParserDefaultPlugins, 'typescript']
plugins: ['typescript']
})
} catch (e: any) {
console.log(code)
Expand Down
10 changes: 2 additions & 8 deletions packages/compiler-sfc/src/compileScript.ts
Expand Up @@ -13,13 +13,7 @@ import {
} from '@vue/compiler-dom'
import { SFCDescriptor, SFCScriptBlock } from './parse'
import { parse as _parse, ParserOptions, ParserPlugin } from '@babel/parser'
import {
babelParserDefaultPlugins,
camelize,
capitalize,
generateCodeFrame,
makeMap
} from '@vue/shared'
import { camelize, capitalize, generateCodeFrame, makeMap } from '@vue/shared'
import {
Node,
Declaration,
Expand Down Expand Up @@ -161,7 +155,7 @@ export function compileScript(
scriptLang === 'tsx' ||
scriptSetupLang === 'ts' ||
scriptSetupLang === 'tsx'
const plugins: ParserPlugin[] = [...babelParserDefaultPlugins]
const plugins: ParserPlugin[] = []
if (!isTS || scriptLang === 'tsx' || scriptSetupLang === 'tsx') {
plugins.push('jsx')
}
Expand Down
3 changes: 1 addition & 2 deletions packages/ref-transform/__tests__/refTransform.spec.ts
@@ -1,13 +1,12 @@
import { parse } from '@babel/parser'
import { babelParserDefaultPlugins } from '@vue/shared'
import { transform } from '../src'

function assertCode(code: string) {
// parse the generated code to make sure it is valid
try {
parse(code, {
sourceType: 'module',
plugins: [...babelParserDefaultPlugins, 'typescript']
plugins: ['typescript']
})
} catch (e: any) {
console.log(code)
Expand Down
4 changes: 2 additions & 2 deletions packages/ref-transform/src/refTransform.ts
Expand Up @@ -20,7 +20,7 @@ import {
walkFunctionParams
} from '@vue/compiler-core'
import { parse, ParserPlugin } from '@babel/parser'
import { babelParserDefaultPlugins, hasOwn } from '@vue/shared'
import { hasOwn } from '@vue/shared'

const TO_VAR_SYMBOL = '$'
const TO_REF_SYMBOL = '$$'
Expand Down Expand Up @@ -68,7 +68,7 @@ export function transform(

const ast = parse(src, {
sourceType: 'module',
plugins: [...new Set([...babelParserDefaultPlugins, ...plugins])]
plugins
})
const s = new MagicString(src)
const res = transformAST(ast.program, s)
Expand Down
12 changes: 0 additions & 12 deletions packages/shared/src/index.ts
Expand Up @@ -13,18 +13,6 @@ export * from './escapeHtml'
export * from './looseEqual'
export * from './toDisplayString'

/**
* List of @babel/parser plugins that are used for template expression
* transforms and SFC script transforms. By default we enable proposals slated
* for ES2020. This will need to be updated as the spec moves forward.
* Full list at https://babeljs.io/docs/en/next/babel-parser#plugins
*/
export const babelParserDefaultPlugins = [
'bigInt',
'optionalChaining',
'nullishCoalescingOperator'
] as const

export const EMPTY_OBJ: { readonly [key: string]: any } = __DEV__
? Object.freeze({})
: {}
Expand Down

0 comments on commit 646e694

Please sign in to comment.