Skip to content

Commit 9f8bf4f

Browse files
Jevon617sxzz
andauthored
fix(compiler-core): generate updateEffect for nested v-for (#171)
Co-authored-by: 三咲智子 Kevin Deng <[email protected]>
1 parent ba17fb9 commit 9f8bf4f

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

packages/compiler-vapor/src/generate.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ export class CodegenContext {
4141
delegates = new Set<string>()
4242

4343
identifiers: Record<string, string[]> = Object.create(null)
44+
45+
genEffects: Array<
46+
(effects: IREffect[], context: CodegenContext) => CodeFragment[]
47+
> = []
48+
4449
withId = <T>(fn: () => T, map: Record<string, string | null>): T => {
4550
const { identifiers } = this
4651
const ids = Object.keys(map)
@@ -55,7 +60,6 @@ export class CodegenContext {
5560

5661
return ret
5762
}
58-
genEffect?: (effects: IREffect[]) => CodeFragment[]
5963

6064
constructor(
6165
public ir: RootIRNode,

packages/compiler-vapor/src/generators/block.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ export function genBlockContent(
5050
}
5151

5252
push(...genOperations(operation, context))
53-
push(...(context.genEffect || genEffects)(effect, context))
53+
push(
54+
...(context.genEffects.length
55+
? context.genEffects[context.genEffects.length - 1]
56+
: genEffects)(effect, context),
57+
)
5458

5559
push(NEWLINE, `return `)
5660

packages/compiler-vapor/src/generators/for.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function genFor(
1818
oper: ForIRNode,
1919
context: CodegenContext,
2020
): CodeFragment[] {
21-
const { vaporHelper } = context
21+
const { vaporHelper, genEffects } = context
2222
const { source, value, key, index, render, keyProp } = oper
2323

2424
const rawValue = value && value.content
@@ -27,7 +27,8 @@ export function genFor(
2727

2828
const sourceExpr = ['() => (', ...genExpression(source, context), ')']
2929
let updateFn = '_updateEffect'
30-
context.genEffect = genEffectInFor
30+
31+
genEffects.push(genEffectInFor)
3132

3233
const idMap: Record<string, string> = {}
3334
if (rawValue) idMap[rawValue] = `_block.s[0]`
@@ -65,7 +66,7 @@ export function genFor(
6566
]
6667
}
6768

68-
context.genEffect = undefined
69+
genEffects.pop()
6970

7071
return [
7172
NEWLINE,

0 commit comments

Comments
 (0)