wip: pass all compiler-ssr tests

This commit is contained in:
Evan You 2023-11-20 15:33:03 +08:00
parent 5a44b84cde
commit dda4fd526e
3 changed files with 31 additions and 31 deletions

View File

@ -353,6 +353,13 @@ export function finalizeForParseResult(
true true
) )
} }
if (result.value) {
validateBrowserExpression(
result.value as SimpleExpressionNode,
context,
true
)
}
} }
result.finalized = true result.finalized = true
} }

View File

@ -97,7 +97,7 @@ export const trackVForSlotScopes: NodeTransform = (node, context) => {
export type SlotFnBuilder = ( export type SlotFnBuilder = (
slotProps: ExpressionNode | undefined, slotProps: ExpressionNode | undefined,
vForExp: ExpressionNode | undefined, vFor: DirectiveNode | undefined,
slotChildren: TemplateChildNode[], slotChildren: TemplateChildNode[],
loc: SourceLocation loc: SourceLocation
) => FunctionExpression ) => FunctionExpression
@ -200,12 +200,7 @@ export function buildSlots(
} }
const vFor = findDir(slotElement, 'for') const vFor = findDir(slotElement, 'for')
const slotFunction = buildSlotFn( const slotFunction = buildSlotFn(slotProps, vFor, slotChildren, slotLoc)
slotProps,
vFor?.exp,
slotChildren,
slotLoc
)
// check if this slot is conditional (v-if/v-for) // check if this slot is conditional (v-if/v-for)
let vIf: DirectiveNode | undefined let vIf: DirectiveNode | undefined

View File

@ -37,7 +37,8 @@ import {
JSChildNode, JSChildNode,
RESOLVE_DYNAMIC_COMPONENT, RESOLVE_DYNAMIC_COMPONENT,
TRANSITION, TRANSITION,
stringifyExpression stringifyExpression,
DirectiveNode
} from '@vue/compiler-dom' } from '@vue/compiler-dom'
import { SSR_RENDER_COMPONENT, SSR_RENDER_VNODE } from '../runtimeHelpers' import { SSR_RENDER_COMPONENT, SSR_RENDER_VNODE } from '../runtimeHelpers'
import { import {
@ -54,7 +55,7 @@ import {
ssrProcessTransitionGroup, ssrProcessTransitionGroup,
ssrTransformTransitionGroup ssrTransformTransitionGroup
} from './ssrTransformTransitionGroup' } from './ssrTransformTransitionGroup'
import { isSymbol, isObject, isArray } from '@vue/shared' import { isSymbol, isObject, isArray, extend } from '@vue/shared'
import { buildSSRProps } from './ssrTransformElement' import { buildSSRProps } from './ssrTransformElement'
import { import {
ssrProcessTransition, ssrProcessTransition,
@ -278,8 +279,8 @@ const vnodeDirectiveTransforms = {
} }
function createVNodeSlotBranch( function createVNodeSlotBranch(
props: ExpressionNode | undefined, slotProps: ExpressionNode | undefined,
vForExp: ExpressionNode | undefined, vFor: DirectiveNode | undefined,
children: TemplateChildNode[], children: TemplateChildNode[],
parentContext: TransformContext parentContext: TransformContext
): ReturnStatement { ): ReturnStatement {
@ -300,32 +301,29 @@ function createVNodeSlotBranch(
} }
// wrap the children with a wrapper template for proper children treatment. // wrap the children with a wrapper template for proper children treatment.
// important: provide v-slot="props" and v-for="exp" on the wrapper for
// proper scope analysis
const wrapperProps: TemplateNode['props'] = []
if (slotProps) {
wrapperProps.push({
type: NodeTypes.DIRECTIVE,
name: 'slot',
exp: slotProps,
arg: undefined,
modifiers: [],
loc: locStub
})
}
if (vFor) {
wrapperProps.push(extend({}, vFor))
}
const wrapperNode: TemplateNode = { const wrapperNode: TemplateNode = {
type: NodeTypes.ELEMENT, type: NodeTypes.ELEMENT,
ns: Namespaces.HTML, ns: Namespaces.HTML,
tag: 'template', tag: 'template',
tagType: ElementTypes.TEMPLATE, tagType: ElementTypes.TEMPLATE,
isSelfClosing: false, isSelfClosing: false,
// important: provide v-slot="props" and v-for="exp" on the wrapper for props: wrapperProps,
// proper scope analysis
props: [
{
type: NodeTypes.DIRECTIVE,
name: 'slot',
exp: props,
arg: undefined,
modifiers: [],
loc: locStub
},
{
type: NodeTypes.DIRECTIVE,
name: 'for',
exp: vForExp,
arg: undefined,
modifiers: [],
loc: locStub
}
],
children, children,
loc: locStub, loc: locStub,
codegenNode: undefined codegenNode: undefined