Skip to content

Commit

Permalink
Update vFor.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 authored Jan 21, 2022
1 parent 7ee27ac commit 06aba4a
Showing 1 changed file with 18 additions and 24 deletions.
42 changes: 18 additions & 24 deletions packages/compiler-core/src/transforms/vFor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,8 @@ export const transformFor = createStructuralDirectiveTransform(
const renderExp = createCallExpression(helper(RENDER_LIST), [
forNode.source
]) as ForRenderListExpression
const isTemplate = isTemplateNode(node)
const memo = findDir(node, 'memo')

if (memo && isTemplateNode(node)) {
memo.exp = processExpression(
memo.exp! as SimpleExpressionNode,
context
)
}

const keyProp = findProp(node, `key`)
const keyExp =
keyProp &&
Expand All @@ -76,21 +69,23 @@ export const transformFor = createStructuralDirectiveTransform(
: keyProp.exp!)
const keyProperty = keyProp ? createObjectProperty(`key`, keyExp!) : null

if (
!__BROWSER__ &&
context.prefixIdentifiers &&
keyProperty &&
keyProp!.type !== NodeTypes.ATTRIBUTE
) {
// #2085 process :key expression needs to be processed in order for it
// to behave consistently for <template v-for> and <div v-for>.
// In the case of `<template v-for>`, the node is discarded and never
// traversed so its key expression won't be processed by the normal
// transforms.
keyProperty.value = processExpression(
keyProperty.value as SimpleExpressionNode,
context
)
if (!__BROWSER__ && isTemplate) {
// #2085 / #5288 process :key and v-memo expressions need to be
// processed on `<template v-for>`. In this case the node is discarded
// and never traversed so its binding expressions won't be processed
// by the normal transforms.
if (memo) {
memo.exp = processExpression(
memo.exp! as SimpleExpressionNode,
context
)
}
if (keyProperty && keyProp!.type !== NodeTypes.ATTRIBUTE) {
keyProperty.value = processExpression(
keyProperty.value as SimpleExpressionNode,
context
)
}
}

const isStableFragment =
Expand Down Expand Up @@ -120,7 +115,6 @@ export const transformFor = createStructuralDirectiveTransform(
return () => {
// finish the codegen now that all children have been traversed
let childBlock: BlockCodegenNode
const isTemplate = isTemplateNode(node)
const { children } = forNode

// check <template v-for> key placement
Expand Down

0 comments on commit 06aba4a

Please sign in to comment.