@@ -396,21 +396,29 @@ function makeChildLinkFn (linkFns) {
396
396
*
397
397
* @param {Element|DocumentFragment } el
398
398
* @param {Object } attrs
399
- * @param {Array } propNames
399
+ * @param {Array } propDescriptors
400
400
* @return {Function } propsLinkFn
401
401
*/
402
402
403
403
var dataAttrRE = / ^ d a t a - /
404
404
var settablePathRE = / ^ [ A - Z a - z _ $ ] [ \w $ ] * ( \. [ A - Z a - z _ $ ] [ \w $ ] * | \[ [ ^ \[ \] ] + \] ) * $ /
405
- var literalValueRE = / ^ ( t r u e | f a l s e | \d + ) $ /
405
+ var literalValueRE = / ^ ( t r u e | f a l s e ) $ | \d . * /
406
406
var identRE = require ( '../parsers/path' ) . identRE
407
407
408
- function compileProps ( el , attrs , propNames ) {
408
+ function compileProps ( el , attrs , propDescriptors ) {
409
409
var props = [ ]
410
- var i = propNames . length
411
- var name , value , path , prop , literal , single
410
+ var i = propDescriptors . length
411
+ var descriptor , name , assertions , value , path , prop , literal , single
412
412
while ( i -- ) {
413
- name = propNames [ i ]
413
+ descriptor = propDescriptors [ i ]
414
+ // normalize prop string/descriptor
415
+ if ( typeof descriptor === 'object' ) {
416
+ name = descriptor . name
417
+ assertions = descriptor . assertions
418
+ } else {
419
+ name = descriptor
420
+ assertions = null
421
+ }
414
422
// props could contain dashes, which will be
415
423
// interpreted as minus calculations by the parser
416
424
// so we need to camelize the path here
@@ -437,6 +445,7 @@ function compileProps (el, attrs, propNames) {
437
445
name : name ,
438
446
raw : value ,
439
447
path : path ,
448
+ assertions : descriptor ,
440
449
mode : propBindingModes . ONE_WAY
441
450
}
442
451
var tokens = textParser . parse ( value )
@@ -485,15 +494,18 @@ function compileProps (el, attrs, propNames) {
485
494
function makePropsLinkFn ( props ) {
486
495
return function propsLinkFn ( vm , el ) {
487
496
var i = props . length
488
- var prop , path
497
+ var prop , path , value
489
498
while ( i -- ) {
490
499
prop = props [ i ]
491
500
path = prop . path
492
501
if ( prop . dynamic ) {
493
502
if ( vm . $parent ) {
494
503
if ( prop . mode === propBindingModes . ONE_TIME ) {
495
504
// one time binding
496
- vm . $set ( path , vm . $parent . $get ( prop . parentPath ) )
505
+ value = vm . $parent . $get ( prop . parentPath )
506
+ if ( _ . assertProp ( prop , value ) ) {
507
+ vm . $set ( path , value )
508
+ }
497
509
} else {
498
510
// dynamic binding
499
511
vm . _bindDir ( 'prop' , el , prop , propDef )
@@ -506,8 +518,11 @@ function makePropsLinkFn (props) {
506
518
)
507
519
}
508
520
} else {
509
- // literal, just set once
510
- vm . $set ( path , _ . toNumber ( prop . raw ) )
521
+ // literal, cast it and just set once
522
+ value = _ . toBoolean ( _ . toNumber ( prop . raw ) )
523
+ if ( _ . assertProp ( prop , value ) ) {
524
+ vm . $set ( path , value )
525
+ }
511
526
}
512
527
}
513
528
}
0 commit comments