wip(ssr): ssr helper codegen

This commit is contained in:
Evan You
2020-02-03 17:47:06 -05:00
parent d1d81cf1f9
commit b685805a26
18 changed files with 374 additions and 253 deletions

View File

@@ -1,3 +1,16 @@
import { NodeTransform } from '@vue/compiler-dom'
import {
createStructuralDirectiveTransform,
ForNode,
processForNode
} from '@vue/compiler-dom'
import { SSRTransformContext } from '../ssrCodegenTransform'
export const ssrTransformFor: NodeTransform = () => {}
// Plugin for the first transform pass, which simply constructs the AST node
export const ssrTransformFor = createStructuralDirectiveTransform(
'for',
processForNode
)
// This is called during the 2nd transform pass to construct the SSR-sepcific
// codegen nodes.
export function processFor(node: ForNode, context: SSRTransformContext) {}

View File

@@ -11,12 +11,11 @@ import {
} from '@vue/compiler-dom'
import {
SSRTransformContext,
createSSRTransformContext,
createChildContext,
processChildren
} from '../ssrCodegenTransform'
// This is the plugin for the first transform pass, which simply constructs the
// if node and its branches.
// Plugin for the first transform pass, which simply constructs the AST node
export const ssrTransformIf = createStructuralDirectiveTransform(
/^(if|else|else-if)$/,
processIfBranches
@@ -64,7 +63,7 @@ function processIfBranch(
// TODO optimize away nested fragments when the only child is a ForNode
const needFragmentWrapper =
children.length !== 1 || firstChild.type !== NodeTypes.ELEMENT
const childContext = createSSRTransformContext(context.options)
const childContext = createChildContext(context)
if (needFragmentWrapper) {
childContext.pushStringPart(`<!---->`)
}