@@ -6,7 +6,7 @@ var templateParser = require('../parsers/template')
6
6
7
7
// internal directives
8
8
var propDef = require ( '../directives/prop' )
9
- // var componentDef = require('../directives/component')
9
+ var componentDef = require ( '../directives/component' )
10
10
11
11
module . exports = compile
12
12
@@ -192,24 +192,19 @@ function compileElement (el, options) {
192
192
}
193
193
return compile ( el , options . _parent . $options , true , true )
194
194
}
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 ) {
208
199
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 )
213
208
}
214
209
// if the element is a textarea, we need to interpolate
215
210
// its content on initial render.
@@ -449,6 +444,28 @@ function makePropsLinkFn (props) {
449
444
}
450
445
}
451
446
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
+
452
469
/**
453
470
* Check an element for terminal directives in fixed order.
454
471
* If it finds one, return a terminal link function.
0 commit comments