Преглед изворни кода

fix #450 custom element component unnecessary warning

Evan You пре 11 година
родитељ
комит
b6e1ba4916
2 измењених фајлова са 24 додато и 26 уклоњено
  1. 23 26
      src/compile/compile.js
  2. 1 0
      test/unit/specs/compile/compile_spec.js

+ 23 - 26
src/compile/compile.js

@@ -65,33 +65,27 @@ function compileNode (node, options) {
  */
 
 function compileElement (el, options) {
-  var hasAttributes = el.hasAttributes()
-  var tag = el.tagName.toLowerCase()
-  if (hasAttributes) {
-    // check terminal direcitves
-    var terminalLinkFn
-    for (var i = 0; i < 3; i++) {
-      terminalLinkFn = checkTerminalDirectives(el, options)
-      if (terminalLinkFn) {
-        terminalLinkFn.terminal = true
-        return terminalLinkFn
-      }
+  var linkFn, tag, component
+  // check custom element component, but only on non-root
+  if (!el.__vue__) {
+    tag = el.tagName.toLowerCase()
+    component =
+      tag.indexOf('-') > 0 &&
+      options.components[tag]
+    if (component) {
+      el.setAttribute(config.prefix + 'component', tag)
     }
   }
-  // check custom element component
-  var component =
-    tag.indexOf('-') > 0 &&
-    options.components[tag]
-  if (component) {
-    return makeTeriminalLinkFn(el, 'component', tag, options)
-  }
-  // check other directives
-  var linkFn
-  if (hasAttributes) {
-    var directives = collectDirectives(el, options)
-    linkFn = directives.length
-      ? makeDirectivesLinkFn(directives)
-      : null
+  if (component || el.hasAttributes()) {
+    // check terminal direcitves
+    linkFn = checkTerminalDirectives(el, options)
+    // if not terminal, build normal link function
+    if (!linkFn) {
+      var directives = collectDirectives(el, options)
+      linkFn = directives.length
+        ? makeDirectivesLinkFn(directives)
+        : null
+    }
   }
   // if the element is a textarea, we need to interpolate
   // its content on initial render.
@@ -101,6 +95,7 @@ function compileElement (el, options) {
       el.value = vm.$interpolate(el.value)
       if (realLinkFn) realLinkFn(vm, el)      
     }
+    linkFn.terminal = true
   }
   return linkFn
 }
@@ -388,9 +383,11 @@ function checkTerminalDirectives (el, options) {
 function makeTeriminalLinkFn (el, dirName, value, options) {
   var descriptor = dirParser.parse(value)[0]
   var def = options.directives[dirName]
-  return function terminalLinkFn (vm, el) {
+  var terminalLinkFn = function (vm, el) {
     vm._bindDir(dirName, el, descriptor, def)
   }
+  terminalLinkFn.terminal = true
+  return terminalLinkFn
 }
 
 /**

+ 1 - 0
test/unit/specs/compile/compile_spec.js

@@ -128,6 +128,7 @@ if (_.inBrowser) {
       linker(vm, el)
       expect(vm._bindDir.calls.count()).toBe(1)
       expect(vm._bindDir).toHaveBeenCalledWith('component', el.firstChild, descriptor, def)
+      expect(_.warn).not.toHaveBeenCalled()
     })
 
     it('attribute interpolation', function () {