Skip to content

Enforce to loop through children to get the correct normalize type (fix #4564) #4572

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
enforce to loop through children to get the correct normalize type
  • Loading branch information
defcc committed Dec 26, 2016
commit ee9fa5ef443ab3bca3142494d0aa0a23a4cddb31
8 changes: 5 additions & 3 deletions src/compiler/codegen/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,18 +307,20 @@ function genChildren (el: ASTElement, checkSkip?: boolean): string | void {
// 1: simple normalization needed (possible 1-level deep nested array)
// 2: full nomralization needed
function getNormalizationType (children): number {
let res = 0
for (let i = 0; i < children.length; i++) {
const el: any = children[i]
if (needsNormalization(el) ||
(el.if && el.ifConditions.some(c => needsNormalization(c.block)))) {
return 2
res = 2
break
}
if (maybeComponent(el) ||
(el.if && el.ifConditions.some(c => maybeComponent(c.block)))) {
return 1
res = 1
}
}
return 0
return res
}

function needsNormalization (el: ASTElement) {
Expand Down
8 changes: 8 additions & 0 deletions test/unit/modules/compiler/codegen.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,14 @@ describe('codegen', () => {
)
})

it('generate component with v-for', () => {
// normalize type: 2
assertCodegen(
'<div><child></child><template v-for="item in list">{{ item }}</template></div>',
`with(this){return _c('div',[_c('child'),_l((list),function(item){return [_v(_s(item))]})],2)}`
)
})

it('not specified ast type', () => {
const res = generate(null, baseOptions)
expect(res.render).toBe(`with(this){return _c("div")}`)
Expand Down