]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
wip: pass all compiler-ssr tests
authorEvan You <yyx990803@gmail.com>
Mon, 20 Nov 2023 07:33:03 +0000 (15:33 +0800)
committerEvan You <yyx990803@gmail.com>
Sat, 25 Nov 2023 08:18:29 +0000 (16:18 +0800)
packages/compiler-core/src/transforms/vFor.ts
packages/compiler-core/src/transforms/vSlot.ts
packages/compiler-ssr/src/transforms/ssrTransformComponent.ts

index 51962b2faa1c47cd9ad1132e5f9248f5dcf33ffc..e23b39e1fabdc7922b4a136fa0daa9d2ab3f4ddd 100644 (file)
@@ -353,6 +353,13 @@ export function finalizeForParseResult(
         true
       )
     }
+    if (result.value) {
+      validateBrowserExpression(
+        result.value as SimpleExpressionNode,
+        context,
+        true
+      )
+    }
   }
   result.finalized = true
 }
index fac861b20b26ef91ae39bd895984548ef9db3a40..b270797cc756585320a0f5222fafddcce37aa8af 100644 (file)
@@ -97,7 +97,7 @@ export const trackVForSlotScopes: NodeTransform = (node, context) => {
 
 export type SlotFnBuilder = (
   slotProps: ExpressionNode | undefined,
-  vForExp: ExpressionNode | undefined,
+  vFor: DirectiveNode | undefined,
   slotChildren: TemplateChildNode[],
   loc: SourceLocation
 ) => FunctionExpression
@@ -200,12 +200,7 @@ export function buildSlots(
     }
 
     const vFor = findDir(slotElement, 'for')
-    const slotFunction = buildSlotFn(
-      slotProps,
-      vFor?.exp,
-      slotChildren,
-      slotLoc
-    )
+    const slotFunction = buildSlotFn(slotProps, vFor, slotChildren, slotLoc)
 
     // check if this slot is conditional (v-if/v-for)
     let vIf: DirectiveNode | undefined
index 7a12cb29009d00a2bf108fb696b5f00873337bd8..e59eee745f0d980a1f0d35589dcaadcf049b0151 100644 (file)
@@ -37,7 +37,8 @@ import {
   JSChildNode,
   RESOLVE_DYNAMIC_COMPONENT,
   TRANSITION,
-  stringifyExpression
+  stringifyExpression,
+  DirectiveNode
 } from '@vue/compiler-dom'
 import { SSR_RENDER_COMPONENT, SSR_RENDER_VNODE } from '../runtimeHelpers'
 import {
@@ -54,7 +55,7 @@ import {
   ssrProcessTransitionGroup,
   ssrTransformTransitionGroup
 } from './ssrTransformTransitionGroup'
-import { isSymbol, isObject, isArray } from '@vue/shared'
+import { isSymbol, isObject, isArray, extend } from '@vue/shared'
 import { buildSSRProps } from './ssrTransformElement'
 import {
   ssrProcessTransition,
@@ -278,8 +279,8 @@ const vnodeDirectiveTransforms = {
 }
 
 function createVNodeSlotBranch(
-  props: ExpressionNode | undefined,
-  vForExp: ExpressionNode | undefined,
+  slotProps: ExpressionNode | undefined,
+  vFor: DirectiveNode | undefined,
   children: TemplateChildNode[],
   parentContext: TransformContext
 ): ReturnStatement {
@@ -300,32 +301,29 @@ function createVNodeSlotBranch(
   }
 
   // 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 = {
     type: NodeTypes.ELEMENT,
     ns: Namespaces.HTML,
     tag: 'template',
     tagType: ElementTypes.TEMPLATE,
     isSelfClosing: false,
-    // important: provide v-slot="props" and v-for="exp" on the wrapper for
-    // 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
-      }
-    ],
+    props: wrapperProps,
     children,
     loc: locStub,
     codegenNode: undefined