wip(ssr): v-for

This commit is contained in:
Evan You
2020-02-03 18:30:56 -05:00
parent 2ad0eed5cd
commit 93c37b94f2
5 changed files with 39 additions and 14 deletions

View File

@@ -1,9 +1,18 @@
import {
createStructuralDirectiveTransform,
ForNode,
processForNode
processForNode,
createCallExpression,
createFunctionExpression,
createForLoopParams,
createBlockStatement
} from '@vue/compiler-dom'
import { SSRTransformContext } from '../ssrCodegenTransform'
import {
SSRTransformContext,
createChildContext,
processChildren
} from '../ssrCodegenTransform'
import { SSR_RENDER_LIST } from '../runtimeHelpers'
// Plugin for the first transform pass, which simply constructs the AST node
export const ssrTransformFor = createStructuralDirectiveTransform(
@@ -13,4 +22,17 @@ export const ssrTransformFor = createStructuralDirectiveTransform(
// This is called during the 2nd transform pass to construct the SSR-sepcific
// codegen nodes.
export function processFor(node: ForNode, context: SSRTransformContext) {}
export function processFor(node: ForNode, context: SSRTransformContext) {
const renderLoop = createFunctionExpression(
createForLoopParams(node.parseResult)
)
const childContext = createChildContext(context)
processChildren(node.children, childContext)
renderLoop.body = createBlockStatement(childContext.body)
context.pushStatement(
createCallExpression(context.helper(SSR_RENDER_LIST), [
node.source,
renderLoop
])
)
}