@@ -32,7 +32,7 @@ module.exports = compile
3232
3333function compile ( el , options , partial , transcluded ) {
3434 // link function for the node itself.
35- var nodeLinkFn = options . _asComponent && ! partial
35+ var nodeLinkFn = ! partial
3636 ? compileRoot ( el , options )
3737 : compileNode ( el , options )
3838 // link function for the childNodes
@@ -118,7 +118,7 @@ function teardownDirs (vm, dirs, destroying) {
118118}
119119
120120/**
121- * Compile the root element of a component . There are
121+ * Compile the root element of an instance . There are
122122 * 3 types of things to process here:
123123 *
124124 * 1. props on parent container (child scope)
@@ -135,23 +135,31 @@ function teardownDirs (vm, dirs, destroying) {
135135 */
136136
137137function compileRoot ( el , options ) {
138- var isBlock = el . nodeType === 11 // DocumentFragment
139138 var containerAttrs = options . _containerAttrs
140139 var replacerAttrs = options . _replacerAttrs
141140 var props = options . props
142141 var propsLinkFn , parentLinkFn , replacerLinkFn
143142 // 1. props
144- propsLinkFn = props
143+ propsLinkFn = props && containerAttrs
145144 ? compileProps ( el , containerAttrs , props )
146145 : null
147- if ( ! isBlock ) {
148- // 2. container attributes
149- if ( containerAttrs ) {
150- parentLinkFn = compileDirectives ( containerAttrs , options )
151- }
152- if ( replacerAttrs ) {
153- // 3. replacer attributes
154- replacerLinkFn = compileDirectives ( replacerAttrs , options )
146+ // only need to compile other attributes for
147+ // non-block instances
148+ if ( el . nodeType !== 11 ) {
149+ // for components, container and replacer need to be
150+ // compiled separately and linked in different scopes.
151+ if ( options . _asComponent ) {
152+ // 2. container attributes
153+ if ( containerAttrs ) {
154+ parentLinkFn = compileDirectives ( containerAttrs , options )
155+ }
156+ if ( replacerAttrs ) {
157+ // 3. replacer attributes
158+ replacerLinkFn = compileDirectives ( replacerAttrs , options )
159+ }
160+ } else {
161+ // non-component, just compile as a normal element.
162+ replacerLinkFn = compileDirectives ( el , options )
155163 }
156164 }
157165 return function rootLinkFn ( vm , el , host ) {
@@ -192,17 +200,16 @@ function compileNode (node, options) {
192200 */
193201
194202function compileElement ( el , options ) {
195- if ( checkTransclusion ( el ) ) {
203+ var hasAttrs = el . hasAttributes ( )
204+ if ( hasAttrs && checkTransclusion ( el ) ) {
196205 // unwrap textNode
197206 if ( el . hasAttribute ( '__vue__wrap' ) ) {
198207 el = el . firstChild
199208 }
200209 return compile ( el , options . _parent . $options , true , true )
201210 }
202- var linkFn
203- var hasAttrs = el . hasAttributes ( )
204211 // check element directives
205- linkFn = checkElementDirectives ( el , options )
212+ var linkFn = checkElementDirectives ( el , options )
206213 // check terminal direcitves (repeat & if)
207214 if ( ! linkFn && hasAttrs ) {
208215 linkFn = checkTerminalDirectives ( el , options )
@@ -406,7 +413,7 @@ function compileProps (el, attrs, propNames) {
406413 if ( value != null ) {
407414 prop = {
408415 name : name ,
409- value : value
416+ raw : value
410417 }
411418 var tokens = textParser . parse ( value )
412419 if ( tokens ) {
@@ -447,14 +454,22 @@ function makePropsLinkFn (props) {
447454 // so we need to wrap the path here
448455 path = _ . camelize ( prop . name . replace ( dataAttrRE , '' ) )
449456 if ( prop . dynamic ) {
450- vm . _bindDir ( 'prop' , el , {
451- arg : path ,
452- expression : prop . value ,
453- oneWay : prop . oneTime
454- } , propDef )
457+ if ( vm . $parent ) {
458+ vm . _bindDir ( 'prop' , el , {
459+ arg : path ,
460+ expression : prop . value ,
461+ oneWay : prop . oneTime
462+ } , propDef )
463+ } else {
464+ _ . warn (
465+ 'Cannot bind dynamic prop on a root instance' +
466+ ' with no parent: ' + prop . name + '="' +
467+ prop . raw + '"'
468+ )
469+ }
455470 } else {
456471 // just set once
457- vm . $set ( path , prop . value )
472+ vm . $set ( path , prop . raw )
458473 }
459474 }
460475 }
0 commit comments