Skip to content
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

fix(v-pre): skip compiling custom component tags in v-pre blocks (fix… #8376

Merged
merged 1 commit into from
Oct 24, 2018
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
9 changes: 8 additions & 1 deletion src/compiler/codegen/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ export function generate (
}

export function genElement (el: ASTElement, state: CodegenState): string {
if (el.parent) {
el.pre = el.pre || el.parent.pre
}

if (el.staticRoot && !el.staticProcessed) {
return genStatic(el, state)
} else if (el.once && !el.onceProcessed) {
Expand All @@ -68,7 +72,10 @@ export function genElement (el: ASTElement, state: CodegenState): string {
if (el.component) {
code = genComponent(el.component, el, state)
} else {
const data = el.plain ? undefined : genData(el, state)
let data
if (!el.plain || el.pre) {
data = genData(el, state)
}

const children = el.inlineTemplate ? null : genChildren(el, state, true)
code = `_c('${el.tag}'${
Expand Down
2 changes: 1 addition & 1 deletion src/core/vdom/create-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export function _createElement (
config.parsePlatformTagName(tag), data, children,
undefined, undefined, context
)
} else if (isDef(Ctor = resolveAsset(context.$options, 'components', tag))) {
} else if ((!data || !data.pre) && isDef(Ctor = resolveAsset(context.$options, 'components', tag))) {
// component
vnode = createComponent(Ctor, data, context, children, tag)
} else {
Expand Down
15 changes: 13 additions & 2 deletions test/unit/features/directives/pre.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe('Directive v-pre', function () {
<div v-pre>{{ a }}</div>
<div>{{ a }}</div>
<div v-pre>
<component></component>
<component is="div"></component>
</div>
</div>`,
data: {
Expand All @@ -17,7 +17,7 @@ describe('Directive v-pre', function () {
vm.$mount()
expect(vm.$el.firstChild.textContent).toBe('{{ a }}')
expect(vm.$el.children[1].textContent).toBe('123')
expect(vm.$el.lastChild.innerHTML).toBe('<component></component>')
expect(vm.$el.lastChild.innerHTML).toBe('<component is="div"></component>')
})

it('should not compile on root node', function () {
Expand All @@ -31,4 +31,15 @@ describe('Directive v-pre', function () {
vm.$mount()
expect(vm.$el.firstChild.textContent).toBe('{{ a }}')
})

// #8286
it('should not compile custom component tags', function () {
Vue.component('vtest', { template: ` <div>Hello World</div>` })
const vm = new Vue({
template: '<div v-pre><vtest></vtest></div>',
replace: true
})
vm.$mount()
expect(vm.$el.firstChild.tagName).toBe('VTEST')
})
})