Procházet zdrojové kódy

refactor(compiler): move `expressionPlugins` to shared options

三咲智子 Kevin Deng před 2 roky
rodič
revize
bf5f7c389b

+ 4 - 1
packages/compiler-core/src/codegen.ts

@@ -89,7 +89,10 @@ export enum NewlineType {
 export interface CodegenContext
   extends Omit<
     Required<CodegenOptions>,
-    'bindingMetadata' | 'inline' | 'vaporRuntimeModuleName'
+    | 'bindingMetadata'
+    | 'inline'
+    | 'vaporRuntimeModuleName'
+    | 'expressionPlugins'
   > {
   source: string
   code: string

+ 6 - 6
packages/compiler-core/src/options.ts

@@ -168,6 +168,12 @@ interface SharedTransformCodegenOptions {
    * @default mode === 'module'
    */
   prefixIdentifiers?: boolean
+  /**
+   * A list of parser plugins to enable for `@babel/parser`, which is used to
+   * parse expressions in bindings and interpolations.
+   * https://babeljs.io/docs/en/next/babel-parser#plugins
+   */
+  expressionPlugins?: ParserPlugin[]
   /**
    * Control whether generate SSR-optimized render functions instead.
    * The resulting function must be attached to the component via the
@@ -257,12 +263,6 @@ export interface TransformOptions
    * @default false
    */
   cacheHandlers?: boolean
-  /**
-   * A list of parser plugins to enable for `@babel/parser`, which is used to
-   * parse expressions in bindings and interpolations.
-   * https://babeljs.io/docs/en/next/babel-parser#plugins
-   */
-  expressionPlugins?: ParserPlugin[]
   /**
    * SFC scoped styles ID
    */

+ 2 - 6
packages/compiler-vapor/src/generate.ts

@@ -5,7 +5,6 @@ import type {
 import type { IREffect, RootIRNode, VaporHelper } from './ir'
 import { SourceMapGenerator } from 'source-map-js'
 import { extend, remove } from '@vue/shared'
-import type { ParserPlugin } from '@babel/parser'
 import { genBlockFunctionContent } from './generators/block'
 import { genTemplates } from './generators/template'
 import {
@@ -20,9 +19,7 @@ import {
 
 export * from './generators/utils'
 
-export interface CodegenOptions extends BaseCodegenOptions {
-  expressionPlugins?: ParserPlugin[]
-}
+export type CodegenOptions = Omit<BaseCodegenOptions, 'optimizeImports'>
 
 export class CodegenContext {
   options: Required<CodegenOptions>
@@ -64,12 +61,11 @@ export class CodegenContext {
     options: CodegenOptions,
   ) {
     const defaultOptions: Required<CodegenOptions> = {
-      mode: 'function',
+      mode: 'function', // TODO
       prefixIdentifiers: options.mode === 'module',
       sourceMap: false,
       filename: `template.vue.html`,
       scopeId: null,
-      optimizeImports: false,
       runtimeGlobalName: `Vue`,
       runtimeModuleName: `vue`,
       vaporRuntimeModuleName: 'vue/vapor',