@@ -8,9 +8,11 @@ var templateParser = require('../parsers/template')
8
8
var resolveAsset = _ . resolveAsset
9
9
10
10
// special binding prefixes
11
- var bindRE = / ^ b i n d - | ^ : /
12
- var onRE = / ^ o n - /
13
- var transitionRE = / ^ ( b i n d - | : ) ? t r a n s i t i o n $ /
11
+ var bindRE = / ^ v - b i n d : | ^ : /
12
+ var onRE = / ^ v - o n : | ^ @ /
13
+ var literalRE = / # $ /
14
+ var argRE = / : ( .* ) $ /
15
+ var transitionRE = / ^ ( v - b i n d : | : ) ? t r a n s i t i o n $ /
14
16
var nodeRefRE = / ^ \$ \$ \. /
15
17
16
18
// terminal directives
@@ -262,7 +264,7 @@ function compileElement (el, options) {
262
264
if ( el . tagName === 'TEXTAREA' ) {
263
265
var tokens = textParser . parse ( el . value )
264
266
if ( tokens ) {
265
- el . setAttribute ( 'bind- value' , textParser . tokensToExp ( tokens ) )
267
+ el . setAttribute ( ': value' , textParser . tokensToExp ( tokens ) )
266
268
el . value = ''
267
269
}
268
270
}
@@ -545,49 +547,15 @@ function makeTerminalNodeLinkFn (el, dirName, value, options, def) {
545
547
function compileDirectives ( attrs , options ) {
546
548
var i = attrs . length
547
549
var dirs = [ ]
548
- var attr , name , value , dirName , dirDef , isLiteral
550
+ var attr , name , value , dirName , arg , dirDef , isLiteral
549
551
while ( i -- ) {
550
552
attr = attrs [ i ]
551
553
name = attr . name
552
554
value = attr . value
553
- // Core directive
554
- if ( name . indexOf ( 'v-' ) === 0 ) {
555
- dirName = name . slice ( 2 )
556
-
557
- // check literal
558
- if ( dirName . charAt ( dirName . length - 1 ) === '#' ) {
559
- isLiteral = true
560
- dirName = dirName . slice ( 0 , - 1 )
561
- } else {
562
- isLiteral = false
563
- }
564
-
565
- dirDef = resolveAsset ( options , 'directives' , dirName )
566
- if ( process . env . NODE_ENV !== 'production' ) {
567
- _ . assertAsset ( dirDef , 'directive' , dirName )
568
- }
569
- if ( dirDef ) {
570
- if ( ! isLiteral && _ . isLiteral ( value ) ) {
571
- value = _ . stripQuotes ( value )
572
- isLiteral = true
573
- }
574
- pushDir ( dirName , dirDef , {
575
- literal : isLiteral
576
- } )
577
- }
578
- } else
579
-
580
- // event handlers
581
- if ( onRE . test ( name ) ) {
582
- pushDir ( 'on' , internalDirectives . on , {
583
- arg : name . replace ( onRE , '' )
584
- } )
585
- } else
586
555
587
556
// special attribute: transition
588
557
if ( transitionRE . test ( name ) ) {
589
- dirName = name . replace ( bindRE , '' )
590
- pushDir ( dirName , internalDirectives [ dirName ] , {
558
+ pushDir ( 'transition' , internalDirectives . transition , {
591
559
literal : ! bindRE . test ( name )
592
560
} )
593
561
} else
@@ -600,6 +568,13 @@ function compileDirectives (attrs, options) {
600
568
} )
601
569
} else
602
570
571
+ // event handlers
572
+ if ( onRE . test ( name ) ) {
573
+ pushDir ( 'on' , internalDirectives . on , {
574
+ arg : name . replace ( onRE , '' )
575
+ } )
576
+ } else
577
+
603
578
// attribute bindings
604
579
if ( bindRE . test ( name ) ) {
605
580
dirName = name . replace ( bindRE , '' )
@@ -610,6 +585,37 @@ function compileDirectives (attrs, options) {
610
585
arg : dirName
611
586
} )
612
587
}
588
+ } else
589
+
590
+ // normal directives
591
+ if ( name . indexOf ( 'v-' ) === 0 ) {
592
+ // check literal
593
+ isLiteral = literalRE . test ( dirName )
594
+ if ( isLiteral ) {
595
+ name = name . replace ( literalRE , '' )
596
+ }
597
+ // check arg
598
+ arg = ( arg = name . match ( argRE ) ) && arg [ 1 ]
599
+ if ( arg ) {
600
+ name = name . replace ( argRE , '' )
601
+ }
602
+ // extract directive name
603
+ dirName = name . slice ( 2 )
604
+ dirDef = resolveAsset ( options , 'directives' , dirName )
605
+
606
+ if ( process . env . NODE_ENV !== 'production' ) {
607
+ _ . assertAsset ( dirDef , 'directive' , dirName )
608
+ }
609
+
610
+ if ( dirDef ) {
611
+ if ( ! isLiteral && _ . isLiteral ( value ) ) {
612
+ value = _ . stripQuotes ( value )
613
+ isLiteral = true
614
+ }
615
+ pushDir ( dirName , dirDef , {
616
+ literal : isLiteral
617
+ } )
618
+ }
613
619
}
614
620
}
615
621
0 commit comments