@@ -127,16 +127,30 @@ function teardownDirs (vm, dirs, destroying) {
127127}
128128
129129/**
130- * Compile the root element of an instance. There are
131- * 3 types of things to process here:
130+ * Compile link props on an instance.
132131 *
133- * 1. props on parent container (child scope)
134- * 2. other attrs on parent container (parent scope)
135- * 3. attrs on the component template root node, if
132+ * @param {Vue } vm
133+ * @param {Element } el
134+ * @param {Object } options
135+ * @return {Function }
136+ */
137+
138+ exports . compileAndLinkProps = function ( vm , el , props ) {
139+ var propsLinkFn = compileProps ( el , props )
140+ var propDirs = linkAndCapture ( function ( ) {
141+ propsLinkFn ( vm , null )
142+ } , vm )
143+ return makeUnlinkFn ( vm , propDirs )
144+ }
145+
146+ /**
147+ * Compile the root element of an instance.
148+ *
149+ * 1. attrs on parent container (parent scope)
150+ * 2. attrs on the component template root node, if
136151 * replace:true (child scope)
137152 *
138- * Also, if this is a block instance, we only need to
139- * compile 1 & 2 here.
153+ * If this is a block instance, we only need to compile 1.
140154 *
141155 * This function does compile and link at the same time,
142156 * since root linkers can not be reused. It returns the
@@ -152,13 +166,7 @@ function teardownDirs (vm, dirs, destroying) {
152166 exports . compileAndLinkRoot = function ( vm , el , options ) {
153167 var containerAttrs = options . _containerAttrs
154168 var replacerAttrs = options . _replacerAttrs
155- var props = options . props
156- var propsLinkFn , parentLinkFn , replacerLinkFn
157-
158- // 1. props
159- propsLinkFn = props
160- ? compileProps ( el , containerAttrs || { } , props )
161- : null
169+ var parentLinkFn , replacerLinkFn
162170
163171 // only need to compile other attributes for
164172 // non-block instances
@@ -191,7 +199,6 @@ function teardownDirs (vm, dirs, destroying) {
191199
192200 // link self
193201 var selfDirs = linkAndCapture ( function ( ) {
194- if ( propsLinkFn ) propsLinkFn ( vm , null )
195202 if ( replacerLinkFn ) replacerLinkFn ( vm , el )
196203 } , vm )
197204
@@ -406,7 +413,6 @@ function makeChildLinkFn (linkFns) {
406413 * a props link function.
407414 *
408415 * @param {Element|DocumentFragment } el
409- * @param {Object } attrs
410416 * @param {Array } propDescriptors
411417 * @return {Function } propsLinkFn
412418 */
@@ -416,7 +422,7 @@ var settablePathRE = /^[A-Za-z_$][\w$]*(\.[A-Za-z_$][\w$]*|\[[^\[\]]+\])*$/
416422var literalValueRE = / ^ ( t r u e | f a l s e ) $ | ^ \d .* /
417423var identRE = require ( '../parsers/path' ) . identRE
418424
419- function compileProps ( el , attrs , propDescriptors ) {
425+ function compileProps ( el , propDescriptors ) {
420426 var props = [ ]
421427 var i = propDescriptors . length
422428 var descriptor , name , assertions , value , path , prop , literal , single
@@ -449,9 +455,12 @@ function compileProps (el, attrs, propDescriptors) {
449455 'must be valid identifiers.'
450456 )
451457 }
452- value = attrs [ name ]
453- /* jshint eqeqeq:false */
454- if ( value != null ) {
458+ value = el . getAttribute ( name )
459+ if ( value !== null ) {
460+ // important so that this doesn't get compiled
461+ // again as a normal attribute binding
462+ el . removeAttribute ( name )
463+ // create a prop descriptor
455464 prop = {
456465 name : name ,
457466 raw : value ,
@@ -464,9 +473,6 @@ function compileProps (el, attrs, propDescriptors) {
464473 if ( el && el . nodeType === 1 ) {
465474 el . removeAttribute ( name )
466475 }
467- // important so that this doesn't get compiled
468- // again as a normal attribute binding
469- attrs [ name ] = null
470476 prop . dynamic = true
471477 prop . parentPath = textParser . tokensToExp ( tokens )
472478 // check prop binding type.
@@ -491,9 +497,7 @@ function compileProps (el, attrs, propDescriptors) {
491497 }
492498 props . push ( prop )
493499 } else if ( assertions && assertions . required ) {
494- _ . warn (
495- 'Missing required prop: ' + name
496- )
500+ _ . warn ( 'Missing required prop: ' + name )
497501 }
498502 }
499503 return makePropsLinkFn ( props )
@@ -514,6 +518,7 @@ function makePropsLinkFn (props) {
514518 prop = props [ i ]
515519 path = prop . path
516520 if ( prop . dynamic ) {
521+ // dynamic prop
517522 if ( vm . $parent ) {
518523 if ( prop . mode === propBindingModes . ONE_TIME ) {
519524 // one time binding
@@ -654,7 +659,6 @@ function compileDirectives (elOrAttrs, options) {
654659 attr = attrs [ i ]
655660 name = attr . name
656661 value = attr . value
657- if ( value === null ) continue
658662 if ( name . indexOf ( config . prefix ) === 0 ) {
659663 dirName = name . slice ( config . prefix . length )
660664 dirDef = resolveAsset ( options , 'directives' , dirName )
0 commit comments