diff --git a/packages/compiler-dom/src/index.ts b/packages/compiler-dom/src/index.ts index 273d1f08..07f427e5 100644 --- a/packages/compiler-dom/src/index.ts +++ b/packages/compiler-dom/src/index.ts @@ -6,8 +6,8 @@ import { ParserOptions, RootNode, noopDirectiveTransform, - TransformPreset, - getBaseTransformPreset + NodeTransform, + DirectiveTransform } from '@vue/compiler-core' import { parserOptionsMinimal } from './parserOptionsMinimal' import { parserOptionsStandard } from './parserOptionsStandard' @@ -23,43 +23,30 @@ export const parserOptions = __BROWSER__ ? parserOptionsMinimal : parserOptionsStandard -export function getDOMTransformPreset( - prefixIdentifiers?: boolean -): TransformPreset { - const [nodeTransforms, directiveTransforms] = getBaseTransformPreset( - prefixIdentifiers - ) - return [ - [ - ...nodeTransforms, - transformStyle, - ...(__DEV__ ? [warnTransitionChildren] : []) - ], - { - ...directiveTransforms, - cloak: noopDirectiveTransform, - html: transformVHtml, - text: transformVText, - model: transformModel, // override compiler-core - on: transformOn, // override compiler-core - show: transformShow - } - ] +export const DOMNodeTransforms: NodeTransform[] = [ + transformStyle, + ...(__DEV__ ? [warnTransitionChildren] : []) +] + +export const DOMDirectiveTransforms: Record = { + cloak: noopDirectiveTransform, + html: transformVHtml, + text: transformVText, + model: transformModel, // override compiler-core + on: transformOn, // override compiler-core + show: transformShow } export function compile( template: string, options: CompilerOptions = {} ): CodegenResult { - const [nodeTransforms, directiveTransforms] = getDOMTransformPreset( - options.prefixIdentifiers - ) return baseCompile(template, { ...parserOptions, ...options, - nodeTransforms: [...nodeTransforms, ...(options.nodeTransforms || [])], + nodeTransforms: [...DOMNodeTransforms, ...(options.nodeTransforms || [])], directiveTransforms: { - ...directiveTransforms, + ...DOMDirectiveTransforms, ...(options.directiveTransforms || {}) } }) diff --git a/packages/compiler-ssr/src/transforms/ssrTransformComponent.ts b/packages/compiler-ssr/src/transforms/ssrTransformComponent.ts index 500e4ee8..a9c38c70 100644 --- a/packages/compiler-ssr/src/transforms/ssrTransformComponent.ts +++ b/packages/compiler-ssr/src/transforms/ssrTransformComponent.ts @@ -16,7 +16,9 @@ import { TRANSITION_GROUP, createIfStatement, createSimpleExpression, - getDOMTransformPreset, + getBaseTransformPreset, + DOMNodeTransforms, + DOMDirectiveTransforms, createReturnStatement, ReturnStatement, Namespaces, @@ -165,9 +167,14 @@ export function ssrProcessComponent( export const rawOptionsMap = new WeakMap() -const [vnodeNodeTransforms, vnodeDirectiveTransforms] = getDOMTransformPreset( +const [baseNodeTransforms, baseDirectiveTransforms] = getBaseTransformPreset( true ) +const vnodeNodeTransforms = [...baseNodeTransforms, ...DOMNodeTransforms] +const vnodeDirectiveTransforms = { + ...baseDirectiveTransforms, + ...DOMDirectiveTransforms +} function createVNodeSlotBranch( props: ExpressionNode | undefined,