From 9f55e6fbb124a06d4e5c9d35ab60d6ec524feb18 Mon Sep 17 00:00:00 2001 From: edison Date: Fri, 21 Jan 2022 14:54:46 +0800 Subject: [PATCH] fix(compiler-core): handle v-memo in template v-for (#5291) fix #5288 --- .../__snapshots__/vMemo.spec.ts.snap | 2 +- packages/compiler-core/src/transforms/vFor.ts | 34 ++++++++++--------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/packages/compiler-core/__tests__/transforms/__snapshots__/vMemo.spec.ts.snap b/packages/compiler-core/__tests__/transforms/__snapshots__/vMemo.spec.ts.snap index 349eb97a..7627d8fd 100644 --- a/packages/compiler-core/__tests__/transforms/__snapshots__/vMemo.spec.ts.snap +++ b/packages/compiler-core/__tests__/transforms/__snapshots__/vMemo.spec.ts.snap @@ -36,7 +36,7 @@ exports[`compiler: v-memo transform on template v-for 1`] = ` export function render(_ctx, _cache) { return (_openBlock(), _createElementBlock(\\"div\\", null, [ (_openBlock(true), _createElementBlock(_Fragment, null, _renderList(_ctx.list, ({ x, y }, __, ___, _cached) => { - const _memo = ([x, y === z]) + const _memo = ([x, y === _ctx.z]) if (_cached && _cached.key === x && _isMemoSame(_cached, _memo)) return _cached const _item = (_openBlock(), _createElementBlock(\\"span\\", { key: x }, \\"foobar\\")) _item.memo = _memo diff --git a/packages/compiler-core/src/transforms/vFor.ts b/packages/compiler-core/src/transforms/vFor.ts index f1d739dc..e72c64c1 100644 --- a/packages/compiler-core/src/transforms/vFor.ts +++ b/packages/compiler-core/src/transforms/vFor.ts @@ -59,6 +59,7 @@ export const transformFor = createStructuralDirectiveTransform( const renderExp = createCallExpression(helper(RENDER_LIST), [ forNode.source ]) as ForRenderListExpression + const isTemplate = isTemplateNode(node) const memo = findDir(node, 'memo') const keyProp = findProp(node, `key`) const keyExp = @@ -68,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