Преглед изворни кода

chore: remove babelParserDefaultPlugins

The version of @babel/parser we are using now has these plugins enabled by default.
Evan You пре 4 година
родитељ
комит
646e694f0a

+ 2 - 8
packages/compiler-core/src/transforms/transformExpression.ts

@@ -24,13 +24,7 @@ import {
   walkIdentifiers
   walkIdentifiers
 } from '../babelUtils'
 } from '../babelUtils'
 import { advancePositionWithClone, isSimpleIdentifier } from '../utils'
 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 { createCompilerError, ErrorCodes } from '../errors'
 import {
 import {
   Node,
   Node,
@@ -244,7 +238,7 @@ export function processExpression(
     : `(${rawExp})${asParams ? `=>{}` : ``}`
     : `(${rawExp})${asParams ? `=>{}` : ``}`
   try {
   try {
     ast = parse(source, {
     ast = parse(source, {
-      plugins: [...context.expressionPlugins, ...babelParserDefaultPlugins]
+      plugins: context.expressionPlugins
     }).program
     }).program
   } catch (e: any) {
   } catch (e: any) {
     context.onError(
     context.onError(

+ 2 - 9
packages/compiler-core/src/utils.ts

@@ -42,14 +42,7 @@ import {
   WITH_MEMO,
   WITH_MEMO,
   OPEN_BLOCK
   OPEN_BLOCK
 } from './runtimeHelpers'
 } 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 { PropsExpression } from './transforms/transformElement'
 import { parseExpression } from '@babel/parser'
 import { parseExpression } from '@babel/parser'
 import { Expression } from '@babel/types'
 import { Expression } from '@babel/types'
@@ -167,7 +160,7 @@ export const isMemberExpressionNode = __BROWSER__
   : (path: string, context: TransformContext): boolean => {
   : (path: string, context: TransformContext): boolean => {
       try {
       try {
         let ret: Expression = parseExpression(path, {
         let ret: Expression = parseExpression(path, {
-          plugins: [...context.expressionPlugins, ...babelParserDefaultPlugins]
+          plugins: context.expressionPlugins
         })
         })
         if (ret.type === 'TSAsExpression' || ret.type === 'TSTypeAssertion') {
         if (ret.type === 'TSAsExpression' || ret.type === 'TSTypeAssertion') {
           ret = ret.expression
           ret = ret.expression

+ 1 - 2
packages/compiler-sfc/__tests__/utils.ts

@@ -1,6 +1,5 @@
 import { parse, SFCScriptCompileOptions, compileScript } from '../src'
 import { parse, SFCScriptCompileOptions, compileScript } from '../src'
 import { parse as babelParse } from '@babel/parser'
 import { parse as babelParse } from '@babel/parser'
-import { babelParserDefaultPlugins } from '@vue/shared'
 
 
 export const mockId = 'xxxxxxxx'
 export const mockId = 'xxxxxxxx'
 
 
@@ -20,7 +19,7 @@ export function assertCode(code: string) {
   try {
   try {
     babelParse(code, {
     babelParse(code, {
       sourceType: 'module',
       sourceType: 'module',
-      plugins: [...babelParserDefaultPlugins, 'typescript']
+      plugins: ['typescript']
     })
     })
   } catch (e: any) {
   } catch (e: any) {
     console.log(code)
     console.log(code)

+ 2 - 8
packages/compiler-sfc/src/compileScript.ts

@@ -13,13 +13,7 @@ import {
 } from '@vue/compiler-dom'
 } from '@vue/compiler-dom'
 import { SFCDescriptor, SFCScriptBlock } from './parse'
 import { SFCDescriptor, SFCScriptBlock } from './parse'
 import { parse as _parse, ParserOptions, ParserPlugin } from '@babel/parser'
 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 {
 import {
   Node,
   Node,
   Declaration,
   Declaration,
@@ -161,7 +155,7 @@ export function compileScript(
     scriptLang === 'tsx' ||
     scriptLang === 'tsx' ||
     scriptSetupLang === 'ts' ||
     scriptSetupLang === 'ts' ||
     scriptSetupLang === 'tsx'
     scriptSetupLang === 'tsx'
-  const plugins: ParserPlugin[] = [...babelParserDefaultPlugins]
+  const plugins: ParserPlugin[] = []
   if (!isTS || scriptLang === 'tsx' || scriptSetupLang === 'tsx') {
   if (!isTS || scriptLang === 'tsx' || scriptSetupLang === 'tsx') {
     plugins.push('jsx')
     plugins.push('jsx')
   }
   }

+ 1 - 2
packages/ref-transform/__tests__/refTransform.spec.ts

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

+ 2 - 2
packages/ref-transform/src/refTransform.ts

@@ -20,7 +20,7 @@ import {
   walkFunctionParams
   walkFunctionParams
 } from '@vue/compiler-core'
 } from '@vue/compiler-core'
 import { parse, ParserPlugin } from '@babel/parser'
 import { parse, ParserPlugin } from '@babel/parser'
-import { babelParserDefaultPlugins, hasOwn } from '@vue/shared'
+import { hasOwn } from '@vue/shared'
 
 
 const TO_VAR_SYMBOL = '$'
 const TO_VAR_SYMBOL = '$'
 const TO_REF_SYMBOL = '$$'
 const TO_REF_SYMBOL = '$$'
@@ -68,7 +68,7 @@ export function transform(
 
 
   const ast = parse(src, {
   const ast = parse(src, {
     sourceType: 'module',
     sourceType: 'module',
-    plugins: [...new Set([...babelParserDefaultPlugins, ...plugins])]
+    plugins
   })
   })
   const s = new MagicString(src)
   const s = new MagicString(src)
   const res = transformAST(ast.program, s)
   const res = transformAST(ast.program, s)

+ 0 - 12
packages/shared/src/index.ts

@@ -13,18 +13,6 @@ export * from './escapeHtml'
 export * from './looseEqual'
 export * from './looseEqual'
 export * from './toDisplayString'
 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__
 export const EMPTY_OBJ: { readonly [key: string]: any } = __DEV__
   ? Object.freeze({})
   ? Object.freeze({})
   : {}
   : {}