@@ -818,6 +818,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
818
818
var compositeLinkFn =
819
819
compileNodes ( $compileNodes , transcludeFn , $compileNodes ,
820
820
maxPriority , ignoreDirective , previousCompileContext ) ;
821
+ safeAddClass ( $compileNodes , 'ng-scope' ) ;
821
822
return function publicLinkFn ( scope , cloneConnectFn , transcludeControllers ) {
822
823
assertArg ( scope , 'scope' ) ;
823
824
// important!!: we must call our jqLite.clone() since the jQuery one is trying to be smart
@@ -832,12 +833,13 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
832
833
833
834
// Attach scope only to non-text nodes.
834
835
for ( var i = 0 , ii = $linkNode . length ; i < ii ; i ++ ) {
835
- var node = $linkNode [ i ] ;
836
- if ( node . nodeType == 1 /* element */ || node . nodeType == 9 /* document */ ) {
836
+ var node = $linkNode [ i ] ,
837
+ nodeType = node . nodeType ;
838
+ if ( nodeType === 1 /* element */ || nodeType === 9 /* document */ ) {
837
839
$linkNode . eq ( i ) . data ( '$scope' , scope ) ;
838
840
}
839
841
}
840
- safeAddClass ( $linkNode , 'ng-scope' ) ;
842
+
841
843
if ( cloneConnectFn ) cloneConnectFn ( $linkNode , scope ) ;
842
844
if ( compositeLinkFn ) compositeLinkFn ( scope , $linkNode , $linkNode ) ;
843
845
return $linkNode ;
@@ -871,9 +873,9 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
871
873
function compileNodes ( nodeList , transcludeFn , $rootElement , maxPriority , ignoreDirective ,
872
874
previousCompileContext ) {
873
875
var linkFns = [ ] ,
874
- nodeLinkFn , childLinkFn , directives , attrs , linkFnFound ;
876
+ attrs , directives , nodeLinkFn , childNodes , childLinkFn , linkFnFound ;
875
877
876
- for ( var i = 0 ; i < nodeList . length ; i ++ ) {
878
+ for ( var i = 0 ; i < nodeList . length ; i ++ ) {
877
879
attrs = new Attributes ( ) ;
878
880
879
881
// we must always refer to nodeList[i] since the nodes can be replaced underneath us.
@@ -885,16 +887,19 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
885
887
null , [ ] , [ ] , previousCompileContext )
886
888
: null ;
887
889
890
+ if ( nodeLinkFn && nodeLinkFn . scope ) {
891
+ safeAddClass ( jqLite ( nodeList [ i ] ) , 'ng-scope' ) ;
892
+ }
893
+
888
894
childLinkFn = ( nodeLinkFn && nodeLinkFn . terminal ||
889
- ! nodeList [ i ] . childNodes ||
890
- ! nodeList [ i ] . childNodes . length )
895
+ ! ( childNodes = nodeList [ i ] . childNodes ) ||
896
+ ! childNodes . length )
891
897
? null
892
- : compileNodes ( nodeList [ i ] . childNodes ,
898
+ : compileNodes ( childNodes ,
893
899
nodeLinkFn ? nodeLinkFn . transclude : transcludeFn ) ;
894
900
895
- linkFns . push ( nodeLinkFn ) ;
896
- linkFns . push ( childLinkFn ) ;
897
- linkFnFound = ( linkFnFound || nodeLinkFn || childLinkFn ) ;
901
+ linkFns . push ( nodeLinkFn , childLinkFn ) ;
902
+ linkFnFound = linkFnFound || nodeLinkFn || childLinkFn ;
898
903
//use the previous context only for the first element in the virtual group
899
904
previousCompileContext = null ;
900
905
}
@@ -906,9 +911,10 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
906
911
var nodeLinkFn , childLinkFn , node , $node , childScope , childTranscludeFn , i , ii , n ;
907
912
908
913
// copy nodeList so that linking doesn't break due to live list updates.
909
- var stableNodeList = [ ] ;
910
- for ( i = 0 , ii = nodeList . length ; i < ii ; i ++ ) {
911
- stableNodeList . push ( nodeList [ i ] ) ;
914
+ var nodeListLength = nodeList . length ,
915
+ stableNodeList = new Array ( nodeListLength ) ;
916
+ for ( i = 0 ; i < nodeListLength ; i ++ ) {
917
+ stableNodeList [ i ] = nodeList [ i ] ;
912
918
}
913
919
914
920
for ( i = 0 , n = 0 , ii = linkFns . length ; i < ii ; n ++ ) {
@@ -921,7 +927,6 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
921
927
if ( nodeLinkFn . scope ) {
922
928
childScope = scope . $new ( ) ;
923
929
$node . data ( '$scope' , childScope ) ;
924
- safeAddClass ( $node , 'ng-scope' ) ;
925
930
} else {
926
931
childScope = scope ;
927
932
}
0 commit comments