@@ -59,15 +59,8 @@ export const transformFor = createStructuralDirectiveTransform(
59
59
const renderExp = createCallExpression ( helper ( RENDER_LIST ) , [
60
60
forNode . source
61
61
] ) as ForRenderListExpression
62
+ const isTemplate = isTemplateNode ( node )
62
63
const memo = findDir ( node , 'memo' )
63
-
64
- if ( memo && isTemplateNode ( node ) ) {
65
- memo . exp = processExpression (
66
- memo . exp ! as SimpleExpressionNode ,
67
- context
68
- )
69
- }
70
-
71
64
const keyProp = findProp ( node , `key` )
72
65
const keyExp =
73
66
keyProp &&
@@ -76,21 +69,23 @@ export const transformFor = createStructuralDirectiveTransform(
76
69
: keyProp . exp ! )
77
70
const keyProperty = keyProp ? createObjectProperty ( `key` , keyExp ! ) : null
78
71
79
- if (
80
- ! __BROWSER__ &&
81
- context . prefixIdentifiers &&
82
- keyProperty &&
83
- keyProp ! . type !== NodeTypes . ATTRIBUTE
84
- ) {
85
- // #2085 process :key expression needs to be processed in order for it
86
- // to behave consistently for <template v-for> and <div v-for>.
87
- // In the case of `<template v-for>`, the node is discarded and never
88
- // traversed so its key expression won't be processed by the normal
89
- // transforms.
90
- keyProperty . value = processExpression (
91
- keyProperty . value as SimpleExpressionNode ,
92
- context
93
- )
72
+ if ( ! __BROWSER__ && isTemplate ) {
73
+ // #2085 / #5288 process :key and v-memo expressions need to be
74
+ // processed on `<template v-for>`. In this case the node is discarded
75
+ // and never traversed so its binding expressions won't be processed
76
+ // by the normal transforms.
77
+ if ( memo ) {
78
+ memo . exp = processExpression (
79
+ memo . exp ! as SimpleExpressionNode ,
80
+ context
81
+ )
82
+ }
83
+ if ( keyProperty && keyProp ! . type !== NodeTypes . ATTRIBUTE ) {
84
+ keyProperty . value = processExpression (
85
+ keyProperty . value as SimpleExpressionNode ,
86
+ context
87
+ )
88
+ }
94
89
}
95
90
96
91
const isStableFragment =
@@ -120,7 +115,6 @@ export const transformFor = createStructuralDirectiveTransform(
120
115
return ( ) => {
121
116
// finish the codegen now that all children have been traversed
122
117
let childBlock : BlockCodegenNode
123
- const isTemplate = isTemplateNode ( node )
124
118
const { children } = forNode
125
119
126
120
// check <template v-for> key placement
0 commit comments