Skip to content

Commit 66bf120

Browse files
defccyyx990803
authored andcommitted
enforce to loop through children to get the correct normalize type (#4572)
1 parent 2b67eec commit 66bf120

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

Diff for: src/compiler/codegen/index.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -307,18 +307,20 @@ function genChildren (el: ASTElement, checkSkip?: boolean): string | void {
307307
// 1: simple normalization needed (possible 1-level deep nested array)
308308
// 2: full nomralization needed
309309
function getNormalizationType (children): number {
310+
let res = 0
310311
for (let i = 0; i < children.length; i++) {
311312
const el: any = children[i]
312313
if (needsNormalization(el) ||
313314
(el.if && el.ifConditions.some(c => needsNormalization(c.block)))) {
314-
return 2
315+
res = 2
316+
break
315317
}
316318
if (maybeComponent(el) ||
317319
(el.if && el.ifConditions.some(c => maybeComponent(c.block)))) {
318-
return 1
320+
res = 1
319321
}
320322
}
321-
return 0
323+
return res
322324
}
323325

324326
function needsNormalization (el: ASTElement) {

Diff for: test/unit/modules/compiler/codegen.spec.js

+8
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,14 @@ describe('codegen', () => {
434434
)
435435
})
436436

437+
it('generate component with v-for', () => {
438+
// normalize type: 2
439+
assertCodegen(
440+
'<div><child></child><template v-for="item in list">{{ item }}</template></div>',
441+
`with(this){return _c('div',[_c('child'),_l((list),function(item){return [_v(_s(item))]})],2)}`
442+
)
443+
})
444+
437445
it('not specified ast type', () => {
438446
const res = generate(null, baseOptions)
439447
expect(res.render).toBe(`with(this){return _c("div")}`)

0 commit comments

Comments
 (0)