@@ -6,7 +6,7 @@ var templateParser = require('../parsers/template')
66
77// internal directives
88var propDef = require ( '../directives/prop' )
9- // var componentDef = require('../directives/component')
9+ var componentDef = require ( '../directives/component' )
1010
1111module . exports = compile
1212
@@ -192,24 +192,19 @@ function compileElement (el, options) {
192192 }
193193 return compile ( el , options . _parent . $options , true , true )
194194 }
195- var linkFn , tag , component
196- // check custom element component, but only on non-root
197- if ( ! el . __vue__ ) {
198- tag = el . tagName . toLowerCase ( )
199- component =
200- tag . indexOf ( '-' ) > 0 &&
201- options . components [ tag ]
202- if ( component ) {
203- el . setAttribute ( config . prefix + 'component' , tag )
204- }
205- }
206- if ( component || el . hasAttributes ( ) ) {
207- // check terminal direcitves
195+ var linkFn
196+ var hasAttrs = el . hasAttributes ( )
197+ // check terminal direcitves (repeat & if)
198+ if ( hasAttrs ) {
208199 linkFn = checkTerminalDirectives ( el , options )
209- // if not terminal, build normal link function
210- if ( ! linkFn ) {
211- linkFn = compileDirectives ( el , options )
212- }
200+ }
201+ // check component
202+ if ( ! linkFn ) {
203+ linkFn = checkComponent ( el , options )
204+ }
205+ // normal directives
206+ if ( ! linkFn && hasAttrs ) {
207+ linkFn = compileDirectives ( el , options )
213208 }
214209 // if the element is a textarea, we need to interpolate
215210 // its content on initial render.
@@ -449,6 +444,28 @@ function makePropsLinkFn (props) {
449444 }
450445}
451446
447+ /**
448+ * Check if an element is a component. If yes, return
449+ * a component link function.
450+ *
451+ * @param {Element } el
452+ * @param {Object } options
453+ * @return {Function|undefined }
454+ */
455+
456+ function checkComponent ( el , options ) {
457+ var componentId = _ . checkComponent ( el , options )
458+ if ( componentId ) {
459+ var componentLinkFn = function ( vm , el , host ) {
460+ vm . _bindDir ( 'component' , el , {
461+ expression : componentId
462+ } , componentDef , host )
463+ }
464+ componentLinkFn . terminal = true
465+ return componentLinkFn
466+ }
467+ }
468+
452469/**
453470 * Check an element for terminal directives in fixed order.
454471 * If it finds one, return a terminal link function.
0 commit comments