chore: remove babelParserDefaultPlugins

The version of @babel/parser we are using now has these plugins enabled by default.
This commit is contained in:
Evan You 2021-10-07 19:32:59 -04:00
parent ed0071ac1a
commit 646e694f0a
7 changed files with 10 additions and 43 deletions

View File

@ -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,
@ -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(

View File

@ -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'
@ -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

View File

@ -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'
@ -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)

View File

@ -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,
@ -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')
}

View File

@ -1,5 +1,4 @@
import { parse } from '@babel/parser'
import { babelParserDefaultPlugins } from '@vue/shared'
import { transform } from '../src'
function assertCode(code: string) {
@ -7,7 +6,7 @@ function assertCode(code: string) {
try {
parse(code, {
sourceType: 'module',
plugins: [...babelParserDefaultPlugins, 'typescript']
plugins: ['typescript']
})
} catch (e: any) {
console.log(code)

View File

@ -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 = '$$'
@ -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)

View File

@ -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({})
: {}