Skip to content

Commit 4e549e1

Browse files
committed
feat(compiler): add fast-remove flag
1 parent c69e8ca commit 4e549e1

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

packages/compiler/src/transforms/vFor.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
import {
1313
findProp,
1414
isConstant,
15+
isEmptyText,
1516
isJSXComponent,
1617
propToExpression,
1718
resolveExpression,
@@ -58,7 +59,7 @@ export function processFor(
5859
const isOnlyChild =
5960
parent &&
6061
parent.block.node !== parent.node &&
61-
parent.node.children.length === 1
62+
parent.node.children.filter((child) => !isEmptyText(child)).length === 1
6263

6364
context.dynamic.operation = {
6465
type: IRNodeTypes.FOR,

packages/compiler/test/transforms/__snapshots__/vFor.spec.ts.snap

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,20 @@ exports[`compiler: v-for > basic v-for 1`] = `
3737
"
3838
`;
3939

40+
exports[`compiler: v-for > fast-remove flag 1`] = `
41+
"
42+
const n3 = t1()
43+
_setInsertionState(n3)
44+
const n0 = _createFor(() => (i), (_for_item0) => {
45+
const n2 = t0()
46+
const x2 = _child(n2)
47+
_setNodes(x2, () => (_for_item0.value+i))
48+
return n2
49+
}, undefined, 1)
50+
return n3
51+
"
52+
`;
53+
4054
exports[`compiler: v-for > key only binding pattern 1`] = `
4155
"
4256
const n0 = _createFor(() => (rows), (_for_item0) => {

packages/compiler/test/transforms/vFor.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,4 +366,17 @@ describe('compiler: v-for', () => {
366366
index: undefined,
367367
})
368368
})
369+
test('fast-remove flag', () => {
370+
const { code, ir } = compileWithVFor(
371+
`<div>
372+
<span v-for={j in i}>{ j+i }</span>
373+
</div>`,
374+
)
375+
376+
const op = ir.block.dynamic.children[0].children[1].operation
377+
expect(op).toMatchObject({
378+
onlyChild: true,
379+
})
380+
expect(code).toMatchSnapshot()
381+
})
369382
})

packages/vue-jsx-vapor/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@
147147
"esbuild": "*",
148148
"rollup": "^3",
149149
"vite": ">=3",
150-
"vue": "^3.5.0",
150+
"vue": "^3.6.0",
151151
"webpack": "^4 || ^5"
152152
},
153153
"peerDependenciesMeta": {

0 commit comments

Comments
 (0)