Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
forked fromvuejs/vue

Commita71853b

Browse files
haoqunjiangyyx990803
authored andcommitted
fix(v-pre): skip compiling custom component tags in v-pre blocks (fixvuejs#8286) (vuejs#8376)
1 parent504d5da commita71853b

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

‎src/compiler/codegen/index.js‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ export function generate (
5252
}
5353

5454
exportfunctiongenElement(el:ASTElement,state:CodegenState):string{
55+
if(el.parent){
56+
el.pre=el.pre||el.parent.pre
57+
}
58+
5559
if(el.staticRoot&&!el.staticProcessed){
5660
returngenStatic(el,state)
5761
}elseif(el.once&&!el.onceProcessed){
@@ -70,7 +74,10 @@ export function genElement (el: ASTElement, state: CodegenState): string {
7074
if(el.component){
7175
code=genComponent(el.component,el,state)
7276
}else{
73-
constdata=el.plain ?undefined :genData(el,state)
77+
letdata
78+
if(!el.plain||el.pre){
79+
data=genData(el,state)
80+
}
7481

7582
constchildren=el.inlineTemplate ?null :genChildren(el,state,true)
7683
code=`_c('${el.tag}'${

‎src/core/vdom/create-element.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export function _createElement (
102102
config.parsePlatformTagName(tag),data,children,
103103
undefined,undefined,context
104104
)
105-
}elseif(isDef(Ctor=resolveAsset(context.$options,'components',tag))){
105+
}elseif((!data||!data.pre)&&isDef(Ctor=resolveAsset(context.$options,'components',tag))){
106106
// component
107107
vnode=createComponent(Ctor,data,context,children,tag)
108108
}else{

‎test/unit/features/directives/pre.spec.js‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ describe('Directive v-pre', function () {
77
<div v-pre>{{ a }}</div>
88
<div>{{ a }}</div>
99
<div v-pre>
10-
<component></component>
10+
<component is="div"></component>
1111
</div>
1212
</div>`,
1313
data:{
@@ -17,7 +17,7 @@ describe('Directive v-pre', function () {
1717
vm.$mount()
1818
expect(vm.$el.firstChild.textContent).toBe('{{ a }}')
1919
expect(vm.$el.children[1].textContent).toBe('123')
20-
expect(vm.$el.lastChild.innerHTML).toBe('<component></component>')
20+
expect(vm.$el.lastChild.innerHTML).toBe('<component is="div"></component>')
2121
})
2222

2323
it('should not compile on root node',function(){
@@ -31,4 +31,15 @@ describe('Directive v-pre', function () {
3131
vm.$mount()
3232
expect(vm.$el.firstChild.textContent).toBe('{{ a }}')
3333
})
34+
35+
// #8286
36+
it('should not compile custom component tags',function(){
37+
Vue.component('vtest',{template:` <div>Hello World</div>`})
38+
constvm=newVue({
39+
template:'<div v-pre><vtest></vtest></div>',
40+
replace:true
41+
})
42+
vm.$mount()
43+
expect(vm.$el.firstChild.tagName).toBe('VTEST')
44+
})
3445
})

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp