From 646e694f0aa942616a142bd5b20c6762b48d580d Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 7 Oct 2021 19:32:59 -0400 Subject: [PATCH] chore: remove babelParserDefaultPlugins The version of @babel/parser we are using now has these plugins enabled by default. --- .../src/transforms/transformExpression.ts | 10 ++-------- packages/compiler-core/src/utils.ts | 11 ++--------- packages/compiler-sfc/__tests__/utils.ts | 3 +-- packages/compiler-sfc/src/compileScript.ts | 10 ++-------- .../ref-transform/__tests__/refTransform.spec.ts | 3 +-- packages/ref-transform/src/refTransform.ts | 4 ++-- packages/shared/src/index.ts | 12 ------------ 7 files changed, 10 insertions(+), 43 deletions(-) diff --git a/packages/compiler-core/src/transforms/transformExpression.ts b/packages/compiler-core/src/transforms/transformExpression.ts index bf4d568e..7a5e699e 100644 --- a/packages/compiler-core/src/transforms/transformExpression.ts +++ b/packages/compiler-core/src/transforms/transformExpression.ts @@ -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( diff --git a/packages/compiler-core/src/utils.ts b/packages/compiler-core/src/utils.ts index 374f0a87..ab5dd80b 100644 --- a/packages/compiler-core/src/utils.ts +++ b/packages/compiler-core/src/utils.ts @@ -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 diff --git a/packages/compiler-sfc/__tests__/utils.ts b/packages/compiler-sfc/__tests__/utils.ts index 1ae9ee15..206ff368 100644 --- a/packages/compiler-sfc/__tests__/utils.ts +++ b/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' @@ -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) diff --git a/packages/compiler-sfc/src/compileScript.ts b/packages/compiler-sfc/src/compileScript.ts index 94d13f64..1f1336fd 100644 --- a/packages/compiler-sfc/src/compileScript.ts +++ b/packages/compiler-sfc/src/compileScript.ts @@ -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') } diff --git a/packages/ref-transform/__tests__/refTransform.spec.ts b/packages/ref-transform/__tests__/refTransform.spec.ts index 37f55bb6..ec8e841d 100644 --- a/packages/ref-transform/__tests__/refTransform.spec.ts +++ b/packages/ref-transform/__tests__/refTransform.spec.ts @@ -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) diff --git a/packages/ref-transform/src/refTransform.ts b/packages/ref-transform/src/refTransform.ts index 4822a4e0..8dcf14e9 100644 --- a/packages/ref-transform/src/refTransform.ts +++ b/packages/ref-transform/src/refTransform.ts @@ -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) diff --git a/packages/shared/src/index.ts b/packages/shared/src/index.ts index 8c98b3b6..97750a81 100644 --- a/packages/shared/src/index.ts +++ b/packages/shared/src/index.ts @@ -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({}) : {}