@@ -10,8 +10,8 @@ var resolveAsset = _.resolveAsset
1010// special binding prefixes
1111var bindRE = / ^ v - b i n d : | ^ : /
1212var onRE = / ^ v - o n : | ^ @ /
13- var literalRE = / \. l i t e r a l $ /
1413var argRE = / : ( .* ) $ /
14+ var modifierRE = / \. [ ^ \. ] + / g
1515var transitionRE = / ^ ( v - b i n d : | : ) ? t r a n s i t i o n $ /
1616
1717// terminal directives
@@ -480,8 +480,10 @@ function checkComponent (el, options) {
480480 var descriptor = {
481481 name : 'component' ,
482482 expression : component . id ,
483- literal : ! component . dynamic ,
484- def : internalDirectives . component
483+ def : internalDirectives . component ,
484+ modifiers : {
485+ literal : ! component . dynamic
486+ }
485487 }
486488 var componentLinkFn = function ( vm , el , host , scope , frag ) {
487489 vm . _bindDir ( descriptor , el , host , scope , frag )
@@ -568,34 +570,35 @@ function makeTerminalNodeLinkFn (el, dirName, value, options, def) {
568570function compileDirectives ( attrs , options ) {
569571 var i = attrs . length
570572 var dirs = [ ]
571- var attr , name , raw , value , dirName , arg , dirDef , isLiteral , tokens
573+ var attr , name , value , rawName , rawValue , dirName , arg , modifiers , dirDef , tokens
572574 while ( i -- ) {
573575 attr = attrs [ i ]
574- name = attr . name
575- raw = value = attr . value
576+ name = rawName = attr . name
577+ value = rawValue = attr . value
576578 tokens = textParser . parse ( value )
579+ // reset arg
580+ arg = null
581+ // check modifiers
582+ modifiers = parseModifiers ( name )
583+ name = name . replace ( modifierRE , '' )
577584
578585 // attribute interpolations
579586 if ( tokens ) {
580587 value = textParser . tokensToExp ( tokens )
581- pushDir ( 'bind' , publicDirectives . bind , {
582- arg : name ,
583- interp : true
584- } )
588+ arg = name
589+ pushDir ( 'bind' , publicDirectives . bind , true )
585590 } else
586591
587592 // special attribute: transition
588593 if ( transitionRE . test ( name ) ) {
589- pushDir ( 'transition' , internalDirectives . transition , {
590- literal : ! bindRE . test ( name )
591- } )
594+ modifiers . literal = ! bindRE . test ( name )
595+ pushDir ( 'transition' , internalDirectives . transition )
592596 } else
593597
594598 // event handlers
595599 if ( onRE . test ( name ) ) {
596- pushDir ( 'on' , publicDirectives . on , {
597- arg : name . replace ( onRE , '' )
598- } )
600+ arg = name . replace ( onRE , '' )
601+ pushDir ( 'on' , publicDirectives . on )
599602 } else
600603
601604 // attribute bindings
@@ -604,19 +607,13 @@ function compileDirectives (attrs, options) {
604607 if ( dirName === 'style' || dirName === 'class' ) {
605608 pushDir ( dirName , internalDirectives [ dirName ] )
606609 } else {
607- pushDir ( 'bind' , publicDirectives . bind , {
608- arg : dirName
609- } )
610+ arg = dirName
611+ pushDir ( 'bind' , publicDirectives . bind )
610612 }
611613 } else
612614
613615 // normal directives
614616 if ( name . indexOf ( 'v-' ) === 0 ) {
615- // check literal
616- isLiteral = literalRE . test ( name )
617- if ( isLiteral ) {
618- name = name . replace ( literalRE , '' )
619- }
620617 // check arg
621618 arg = ( arg = name . match ( argRE ) ) && arg [ 1 ]
622619 if ( arg ) {
@@ -637,14 +634,11 @@ function compileDirectives (attrs, options) {
637634 }
638635
639636 if ( dirDef ) {
640- if ( ! isLiteral && _ . isLiteral ( value ) ) {
637+ if ( _ . isLiteral ( value ) ) {
641638 value = _ . stripQuotes ( value )
642- isLiteral = true
639+ modifiers . literal = true
643640 }
644- pushDir ( dirName , dirDef , {
645- arg : arg ,
646- literal : isLiteral
647- } )
641+ pushDir ( dirName , dirDef )
648642 }
649643 }
650644 }
@@ -654,30 +648,48 @@ function compileDirectives (attrs, options) {
654648 *
655649 * @param {String } dirName
656650 * @param {Object|Function } def
657- * @param {Object } [opts ]
651+ * @param {Boolean } [interp ]
658652 */
659653
660- function pushDir ( dirName , def , opts ) {
654+ function pushDir ( dirName , def , interp ) {
661655 var parsed = dirParser . parse ( value )
662- var dir = {
656+ dirs . push ( {
663657 name : dirName ,
664- attr : name ,
665- raw : raw ,
658+ attr : rawName ,
659+ raw : rawValue ,
666660 def : def ,
661+ arg : arg ,
662+ modifiers : modifiers ,
667663 expression : parsed . expression ,
668- filters : parsed . filters
669- }
670- if ( opts ) {
671- _ . extend ( dir , opts )
672- }
673- dirs . push ( dir )
664+ filters : parsed . filters ,
665+ interp : interp
666+ } )
674667 }
675668
676669 if ( dirs . length ) {
677670 return makeNodeLinkFn ( dirs )
678671 }
679672}
680673
674+ /**
675+ * Parse modifiers from directive attribute name.
676+ *
677+ * @param {String } name
678+ * @return {Object }
679+ */
680+
681+ function parseModifiers ( name ) {
682+ var res = Object . create ( null )
683+ var match = name . match ( modifierRE )
684+ if ( match ) {
685+ var i = match . length
686+ while ( i -- ) {
687+ res [ match [ i ] . slice ( 1 ) ] = true
688+ }
689+ }
690+ return res
691+ }
692+
681693/**
682694 * Build a link function for all directives on a single node.
683695 *
0 commit comments