@@ -127,16 +127,30 @@ function teardownDirs (vm, dirs, destroying) {
127
127
}
128
128
129
129
/**
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.
132
131
*
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
136
151
* replace:true (child scope)
137
152
*
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.
140
154
*
141
155
* This function does compile and link at the same time,
142
156
* since root linkers can not be reused. It returns the
@@ -152,13 +166,7 @@ function teardownDirs (vm, dirs, destroying) {
152
166
exports . compileAndLinkRoot = function ( vm , el , options ) {
153
167
var containerAttrs = options . _containerAttrs
154
168
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
162
170
163
171
// only need to compile other attributes for
164
172
// non-block instances
@@ -191,7 +199,6 @@ function teardownDirs (vm, dirs, destroying) {
191
199
192
200
// link self
193
201
var selfDirs = linkAndCapture ( function ( ) {
194
- if ( propsLinkFn ) propsLinkFn ( vm , null )
195
202
if ( replacerLinkFn ) replacerLinkFn ( vm , el )
196
203
} , vm )
197
204
@@ -406,7 +413,6 @@ function makeChildLinkFn (linkFns) {
406
413
* a props link function.
407
414
*
408
415
* @param {Element|DocumentFragment } el
409
- * @param {Object } attrs
410
416
* @param {Array } propDescriptors
411
417
* @return {Function } propsLinkFn
412
418
*/
@@ -416,7 +422,7 @@ var settablePathRE = /^[A-Za-z_$][\w$]*(\.[A-Za-z_$][\w$]*|\[[^\[\]]+\])*$/
416
422
var literalValueRE = / ^ ( t r u e | f a l s e ) $ | ^ \d .* /
417
423
var identRE = require ( '../parsers/path' ) . identRE
418
424
419
- function compileProps ( el , attrs , propDescriptors ) {
425
+ function compileProps ( el , propDescriptors ) {
420
426
var props = [ ]
421
427
var i = propDescriptors . length
422
428
var descriptor , name , assertions , value , path , prop , literal , single
@@ -449,9 +455,12 @@ function compileProps (el, attrs, propDescriptors) {
449
455
'must be valid identifiers.'
450
456
)
451
457
}
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
455
464
prop = {
456
465
name : name ,
457
466
raw : value ,
@@ -464,9 +473,6 @@ function compileProps (el, attrs, propDescriptors) {
464
473
if ( el && el . nodeType === 1 ) {
465
474
el . removeAttribute ( name )
466
475
}
467
- // important so that this doesn't get compiled
468
- // again as a normal attribute binding
469
- attrs [ name ] = null
470
476
prop . dynamic = true
471
477
prop . parentPath = textParser . tokensToExp ( tokens )
472
478
// check prop binding type.
@@ -491,9 +497,7 @@ function compileProps (el, attrs, propDescriptors) {
491
497
}
492
498
props . push ( prop )
493
499
} else if ( assertions && assertions . required ) {
494
- _ . warn (
495
- 'Missing required prop: ' + name
496
- )
500
+ _ . warn ( 'Missing required prop: ' + name )
497
501
}
498
502
}
499
503
return makePropsLinkFn ( props )
@@ -514,6 +518,7 @@ function makePropsLinkFn (props) {
514
518
prop = props [ i ]
515
519
path = prop . path
516
520
if ( prop . dynamic ) {
521
+ // dynamic prop
517
522
if ( vm . $parent ) {
518
523
if ( prop . mode === propBindingModes . ONE_TIME ) {
519
524
// one time binding
@@ -654,7 +659,6 @@ function compileDirectives (elOrAttrs, options) {
654
659
attr = attrs [ i ]
655
660
name = attr . name
656
661
value = attr . value
657
- if ( value === null ) continue
658
662
if ( name . indexOf ( config . prefix ) === 0 ) {
659
663
dirName = name . slice ( config . prefix . length )
660
664
dirDef = resolveAsset ( options , 'directives' , dirName )
0 commit comments