Skip to content

Commit b6e1ba4

Browse files
committed
fix #450 custom element component unnecessary warning
1 parent 19cfc9d commit b6e1ba4

File tree

2 files changed

+24
-26
lines changed

2 files changed

+24
-26
lines changed

src/compile/compile.js

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -65,33 +65,27 @@ function compileNode (node, options) {
6565
*/
6666

6767
function compileElement (el, options) {
68-
var hasAttributes = el.hasAttributes()
69-
var tag = el.tagName.toLowerCase()
70-
if (hasAttributes) {
71-
// check terminal direcitves
72-
var terminalLinkFn
73-
for (var i = 0; i < 3; i++) {
74-
terminalLinkFn = checkTerminalDirectives(el, options)
75-
if (terminalLinkFn) {
76-
terminalLinkFn.terminal = true
77-
return terminalLinkFn
78-
}
68+
var linkFn, tag, component
69+
// check custom element component, but only on non-root
70+
if (!el.__vue__) {
71+
tag = el.tagName.toLowerCase()
72+
component =
73+
tag.indexOf('-') > 0 &&
74+
options.components[tag]
75+
if (component) {
76+
el.setAttribute(config.prefix + 'component', tag)
7977
}
8078
}
81-
// check custom element component
82-
var component =
83-
tag.indexOf('-') > 0 &&
84-
options.components[tag]
85-
if (component) {
86-
return makeTeriminalLinkFn(el, 'component', tag, options)
87-
}
88-
// check other directives
89-
var linkFn
90-
if (hasAttributes) {
91-
var directives = collectDirectives(el, options)
92-
linkFn = directives.length
93-
? makeDirectivesLinkFn(directives)
94-
: null
79+
if (component || el.hasAttributes()) {
80+
// check terminal direcitves
81+
linkFn = checkTerminalDirectives(el, options)
82+
// if not terminal, build normal link function
83+
if (!linkFn) {
84+
var directives = collectDirectives(el, options)
85+
linkFn = directives.length
86+
? makeDirectivesLinkFn(directives)
87+
: null
88+
}
9589
}
9690
// if the element is a textarea, we need to interpolate
9791
// its content on initial render.
@@ -101,6 +95,7 @@ function compileElement (el, options) {
10195
el.value = vm.$interpolate(el.value)
10296
if (realLinkFn) realLinkFn(vm, el)
10397
}
98+
linkFn.terminal = true
10499
}
105100
return linkFn
106101
}
@@ -388,9 +383,11 @@ function checkTerminalDirectives (el, options) {
388383
function makeTeriminalLinkFn (el, dirName, value, options) {
389384
var descriptor = dirParser.parse(value)[0]
390385
var def = options.directives[dirName]
391-
return function terminalLinkFn (vm, el) {
386+
var terminalLinkFn = function (vm, el) {
392387
vm._bindDir(dirName, el, descriptor, def)
393388
}
389+
terminalLinkFn.terminal = true
390+
return terminalLinkFn
394391
}
395392

396393
/**

test/unit/specs/compile/compile_spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ if (_.inBrowser) {
128128
linker(vm, el)
129129
expect(vm._bindDir.calls.count()).toBe(1)
130130
expect(vm._bindDir).toHaveBeenCalledWith('component', el.firstChild, descriptor, def)
131+
expect(_.warn).not.toHaveBeenCalled()
131132
})
132133

133134
it('attribute interpolation', function () {

0 commit comments

Comments
 (0)