Skip to content

Commit

Permalink
fix(compiler-dom): fix duplicated transforms
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Feb 7, 2020
1 parent a51e710 commit 9e51297
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 31 deletions.
45 changes: 16 additions & 29 deletions packages/compiler-dom/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
ParserOptions,
RootNode,
noopDirectiveTransform,
TransformPreset,
getBaseTransformPreset
NodeTransform,
DirectiveTransform
} from '@vue/compiler-core'
import { parserOptionsMinimal } from './parserOptionsMinimal'
import { parserOptionsStandard } from './parserOptionsStandard'
Expand All @@ -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<string, DirectiveTransform> = {
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 || {})
}
})
Expand Down
11 changes: 9 additions & 2 deletions packages/compiler-ssr/src/transforms/ssrTransformComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import {
TRANSITION_GROUP,
createIfStatement,
createSimpleExpression,
getDOMTransformPreset,
getBaseTransformPreset,
DOMNodeTransforms,
DOMDirectiveTransforms,
createReturnStatement,
ReturnStatement,
Namespaces,
Expand Down Expand Up @@ -165,9 +167,14 @@ export function ssrProcessComponent(

export const rawOptionsMap = new WeakMap<RootNode, CompilerOptions>()

const [vnodeNodeTransforms, vnodeDirectiveTransforms] = getDOMTransformPreset(
const [baseNodeTransforms, baseDirectiveTransforms] = getBaseTransformPreset(
true
)
const vnodeNodeTransforms = [...baseNodeTransforms, ...DOMNodeTransforms]
const vnodeDirectiveTransforms = {
...baseDirectiveTransforms,
...DOMDirectiveTransforms
}

function createVNodeSlotBranch(
props: ExpressionNode | undefined,
Expand Down

0 comments on commit 9e51297

Please sign in to comment.