Skip to content

Commit

Permalink
chore: update
Browse files Browse the repository at this point in the history
  • Loading branch information
linzhe141 committed Dec 18, 2024
1 parent 77bec58 commit 9917dd7
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,26 +135,6 @@ return function render(_ctx, _cache) {
}"
`;

exports[`compiler: v-for > codegen > template w/ v-for + custom directive should not be STABLE_FRAGMENT 1`] = `
"const _Vue = Vue
return function render(_ctx, _cache) {
with (_ctx) {
const { renderList: _renderList, Fragment: _Fragment, openBlock: _openBlock, createElementBlock: _createElementBlock, resolveDirective: _resolveDirective, withDirectives: _withDirectives, createCommentVNode: _createCommentVNode } = _Vue
const _directive_focus = _resolveDirective("focus")
return show
? (_openBlock(true), _createElementBlock(_Fragment, { key: 0 }, _renderList(arr, (i) => {
return _withDirectives((_openBlock(), _createElementBlock("h1", { key: i })), [
[_directive_focus]
])
}), 128 /* KEYED_FRAGMENT */))
: _createCommentVNode("v-if", true)
}
}"
`;

exports[`compiler: v-for > codegen > v-for on <slot/> 1`] = `
"const _Vue = Vue
Expand Down
7 changes: 0 additions & 7 deletions packages/compiler-core/__tests__/transforms/vFor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1073,12 +1073,5 @@ describe('compiler: v-for', () => {
},
})
})

test('template w/ v-for + custom directive should not be STABLE_FRAGMENT', () => {
const { root } = parseWithForTransform(
'<template v-if="show"><h1 v-for="i in arr" :key="i" v-focus></h1></template>',
)
expect(generate(root).code).toMatchSnapshot()
})
})
})
10 changes: 2 additions & 8 deletions packages/compiler-core/src/transforms/vFor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,10 @@ export const transformFor: NodeTransform = createStructuralDirectiveTransform(
)
}
}
const maybeRuntimeDir = findDir(
node,
/^(?!if$|else$|else-if$|bind$|for$|memo$|on$|once$|slot$|model$|show$|html$|text$|model$).*$/,
true,
)

const isStableFragment =
forNode.source.type === NodeTypes.SIMPLE_EXPRESSION &&
forNode.source.constType > ConstantTypes.NOT_CONSTANT &&
!maybeRuntimeDir

forNode.source.constType > ConstantTypes.NOT_CONSTANT
const fragmentFlag = isStableFragment
? PatchFlags.STABLE_FRAGMENT
: keyProp
Expand Down
3 changes: 2 additions & 1 deletion packages/runtime-core/src/directives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ return withDirectives(h(comp), [
])
*/

import type { VNode } from './vnode'
import { type VNode, currentBlock } from './vnode'
import { EMPTY_OBJ, isBuiltInDirective, isFunction } from '@vue/shared'
import { warn } from './warning'
import {
Expand Down Expand Up @@ -143,6 +143,7 @@ export function withDirectives<T extends VNode>(
for (let i = 0; i < directives.length; i++) {
let [dir, value, arg, modifiers = EMPTY_OBJ] = directives[i]
if (dir) {
currentBlock && currentBlock.push(vnode)
if (isFunction(dir)) {
dir = {
mounted: dir,
Expand Down

0 comments on commit 9917dd7

Please sign in to comment.