Skip to content

Commit

Permalink
fix(compiler): fix codegen for v-for component inside template
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Dec 4, 2018
1 parent 448ba65 commit 1b4a8a0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/compiler/codegen/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,9 +406,7 @@ export function genChildren (
el.tag !== 'template' &&
el.tag !== 'slot'
) {
// because el may be a functional component and return an Array instead of a single root.
// In this case, just a simple normalization is needed
const normalizationType = state.maybeComponent(el) ? `,1` : ``
const normalizationType = checkSkip && state.maybeComponent(el) ? `,1` : ``
return `${(altGenElement || genElement)(el, state)}${normalizationType}`
}
const normalizationType = checkSkip
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 @@ -631,5 +631,13 @@ describe('codegen', () => {
{ isReservedTag }
)
})

// #9142
it('should compile single v-for component inside template', () => {
assertCodegen(
`<div><template v-if="ok"><foo v-for="i in 1" :key="i"></foo></template></div>`,
`with(this){return _c('div',[(ok)?_l((1),function(i){return _c('foo',{key:i})}):_e()],2)}`
)
})
})
/* eslint-enable quotes */

0 comments on commit 1b4a8a0

Please sign in to comment.