@@ -396,21 +396,29 @@ function makeChildLinkFn (linkFns) {
396396 *
397397 * @param {Element|DocumentFragment } el
398398 * @param {Object } attrs
399- * @param {Array } propNames
399+ * @param {Array } propDescriptors
400400 * @return {Function } propsLinkFn
401401 */
402402
403403var dataAttrRE = / ^ d a t a - /
404404var 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 . * /
406406var identRE = require ( '../parsers/path' ) . identRE
407407
408- function compileProps ( el , attrs , propNames ) {
408+ function compileProps ( el , attrs , propDescriptors ) {
409409 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
412412 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+ }
414422 // props could contain dashes, which will be
415423 // interpreted as minus calculations by the parser
416424 // so we need to camelize the path here
@@ -437,6 +445,7 @@ function compileProps (el, attrs, propNames) {
437445 name : name ,
438446 raw : value ,
439447 path : path ,
448+ assertions : descriptor ,
440449 mode : propBindingModes . ONE_WAY
441450 }
442451 var tokens = textParser . parse ( value )
@@ -485,15 +494,18 @@ function compileProps (el, attrs, propNames) {
485494function makePropsLinkFn ( props ) {
486495 return function propsLinkFn ( vm , el ) {
487496 var i = props . length
488- var prop , path
497+ var prop , path , value
489498 while ( i -- ) {
490499 prop = props [ i ]
491500 path = prop . path
492501 if ( prop . dynamic ) {
493502 if ( vm . $parent ) {
494503 if ( prop . mode === propBindingModes . ONE_TIME ) {
495504 // 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+ }
497509 } else {
498510 // dynamic binding
499511 vm . _bindDir ( 'prop' , el , prop , propDef )
@@ -506,8 +518,11 @@ function makePropsLinkFn (props) {
506518 )
507519 }
508520 } 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+ }
511526 }
512527 }
513528 }
0 commit comments