@@ -574,6 +574,31 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
574
574
// 'on' and be composed of only English letters.
575
575
var EVENT_HANDLER_ATTR_REGEXP = / ^ ( o n [ a - z ] + | f o r m a c t i o n ) $ / ;
576
576
577
+ function parseIsolateBindings ( scope , directiveName ) {
578
+ var LOCAL_REGEXP = / ^ \s * ( [ @ = & ] ) ( \? ? ) \s * ( \w * ) \s * $ / ;
579
+
580
+ var bindings = { } ;
581
+
582
+ forEach ( scope , function ( definition , scopeName ) {
583
+ var match = definition . match ( LOCAL_REGEXP ) ;
584
+
585
+ if ( ! match ) {
586
+ throw $compileMinErr ( 'iscp' ,
587
+ "Invalid isolate scope definition for directive '{0}'." +
588
+ " Definition: {... {1}: '{2}' ...}" ,
589
+ directiveName , scopeName , definition ) ;
590
+ }
591
+
592
+ bindings [ scopeName ] = {
593
+ attrName : match [ 3 ] || scopeName ,
594
+ mode : match [ 1 ] ,
595
+ optional : match [ 2 ] === '?'
596
+ } ;
597
+ } ) ;
598
+
599
+ return bindings ;
600
+ }
601
+
577
602
/**
578
603
* @ngdoc method
579
604
* @name $compileProvider#directive
@@ -611,6 +636,9 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
611
636
directive . name = directive . name || name ;
612
637
directive . require = directive . require || ( directive . controller && directive . name ) ;
613
638
directive . restrict = directive . restrict || 'EA' ;
639
+ if ( isObject ( directive . scope ) ) {
640
+ directive . $$isolateBindings = parseIsolateBindings ( directive . scope , directive . name ) ;
641
+ }
614
642
directives . push ( directive ) ;
615
643
} catch ( e ) {
616
644
$exceptionHandler ( e ) ;
@@ -1657,16 +1685,14 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
1657
1685
newIsolateScopeDirective . bindToController === true ) {
1658
1686
isolateBindingContext = isolateScopeController . instance ;
1659
1687
}
1660
- forEach ( newIsolateScopeDirective . scope , function ( definition , scopeName ) {
1661
- var match = definition . match ( LOCAL_REGEXP ) || [ ] ,
1662
- attrName = match [ 3 ] || scopeName ,
1663
- optional = ( match [ 2 ] == '?' ) ,
1664
- mode = match [ 1 ] , // @, =, or &
1688
+
1689
+ forEach ( isolateScope . $$isolateBindings = newIsolateScopeDirective . $$isolateBindings , function ( definition , scopeName ) {
1690
+ var attrName = definition . attrName ,
1691
+ optional = definition . optional ,
1692
+ mode = definition . mode , // @, =, or &
1665
1693
lastValue ,
1666
1694
parentGet , parentSet , compare ;
1667
1695
1668
- isolateScope . $$isolateBindings [ scopeName ] = mode + attrName ;
1669
-
1670
1696
switch ( mode ) {
1671
1697
1672
1698
case '@' :
@@ -1721,12 +1747,6 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
1721
1747
return parentGet ( scope , locals ) ;
1722
1748
} ;
1723
1749
break ;
1724
-
1725
- default :
1726
- throw $compileMinErr ( 'iscp' ,
1727
- "Invalid isolate scope definition for directive '{0}'." +
1728
- " Definition: {... {1}: '{2}' ...}" ,
1729
- newIsolateScopeDirective . name , scopeName , definition ) ;
1730
1750
}
1731
1751
} ) ;
1732
1752
}
0 commit comments