From 0dc5721595dc13cfb0e6d608d16bf5f2bad3a2f4 Mon Sep 17 00:00:00 2001 From: Denis Karabaza Date: Tue, 12 Apr 2016 23:03:16 +0300 Subject: [PATCH 1/2] Fix handling multiple directives on a template tag --- src/fragment/factory.js | 11 ++++++++++- test/unit/specs/misc_spec.js | 9 +++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/fragment/factory.js b/src/fragment/factory.js index b4aff212802..5f4c423319b 100644 --- a/src/fragment/factory.js +++ b/src/fragment/factory.js @@ -18,7 +18,7 @@ export default function FragmentFactory (vm, el) { this.vm = vm var template var isString = typeof el === 'string' - if (isString || isTemplate(el)) { + if (isString || isTemplate(el) && !hasDirectives(el)) { template = parseTemplate(el, true) } else { template = document.createDocumentFragment() @@ -41,6 +41,15 @@ export default function FragmentFactory (vm, el) { this.linker = linker } +function hasDirectives (el) { + if (!el.hasAttributes()) return false + var i = el.attributes.length + while (i--) { + if (el.attributes[i].name.substring(0, 2) === 'v-') return true + } + return false +} + /** * Create a fragment instance with given host and scope. * diff --git a/test/unit/specs/misc_spec.js b/test/unit/specs/misc_spec.js index acdd1cedbf4..45c86daef5f 100644 --- a/test/unit/specs/misc_spec.js +++ b/test/unit/specs/misc_spec.js @@ -537,4 +537,13 @@ describe('Misc', function () { }) expect(vm.$el.querySelector('image-field').namespaceURI).not.toMatch(/svg/) }) + + // #2657 + it('template v-for with v-if', function () { + var vm = new Vue({ + el: document.createElement('div'), + template: '
' + }) + expect(vm.$el.textContent).toBe('135') + }) }) From e89a02e6faf32e9e78628608b556e0cea1a566c2 Mon Sep 17 00:00:00 2001 From: Denis Karabaza Date: Wed, 13 Apr 2016 23:07:49 +0300 Subject: [PATCH 2/2] Use a simpler check --- src/fragment/factory.js | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/fragment/factory.js b/src/fragment/factory.js index 5f4c423319b..c11b2dcc77d 100644 --- a/src/fragment/factory.js +++ b/src/fragment/factory.js @@ -18,7 +18,7 @@ export default function FragmentFactory (vm, el) { this.vm = vm var template var isString = typeof el === 'string' - if (isString || isTemplate(el) && !hasDirectives(el)) { + if (isString || isTemplate(el) && !el.hasAttribute('v-if')) { template = parseTemplate(el, true) } else { template = document.createDocumentFragment() @@ -41,15 +41,6 @@ export default function FragmentFactory (vm, el) { this.linker = linker } -function hasDirectives (el) { - if (!el.hasAttributes()) return false - var i = el.attributes.length - while (i--) { - if (el.attributes[i].name.substring(0, 2) === 'v-') return true - } - return false -} - /** * Create a fragment instance with given host and scope. *