@@ -469,7 +469,7 @@ function $CompileProvider($provide) {
469469
470470 //================================
471471
472- function compile ( $compileNodes , transcludeFn , maxPriority , ignoreDirective ) {
472+ function compile ( $compileNodes , transcludeFn , maxPriority , ignoreDirective , previousCompileContext ) {
473473 if ( ! ( $compileNodes instanceof jqLite ) ) {
474474 // jquery always rewraps, whereas we need to preserve the original selector so that we can modify it.
475475 $compileNodes = jqLite ( $compileNodes ) ;
@@ -481,7 +481,7 @@ function $CompileProvider($provide) {
481481 $compileNodes [ index ] = node = jqLite ( node ) . wrap ( '<span></span>' ) . parent ( ) [ 0 ] ;
482482 }
483483 } ) ;
484- var compositeLinkFn = compileNodes ( $compileNodes , transcludeFn , $compileNodes , maxPriority , ignoreDirective ) ;
484+ var compositeLinkFn = compileNodes ( $compileNodes , transcludeFn , $compileNodes , maxPriority , ignoreDirective , previousCompileContext ) ;
485485 return function publicLinkFn ( scope , cloneConnectFn ) {
486486 assertArg ( scope , 'scope' ) ;
487487 // important!!: we must call our jqLite.clone() since the jQuery one is trying to be smart
@@ -528,7 +528,7 @@ function $CompileProvider($provide) {
528528 * @param {number= } max directive priority
529529 * @returns {?function } A composite linking function of all of the matched directives or null.
530530 */
531- function compileNodes ( nodeList , transcludeFn , $rootElement , maxPriority , ignoreDirective ) {
531+ function compileNodes ( nodeList , transcludeFn , $rootElement , maxPriority , ignoreDirective , previousCompileContext ) {
532532 var linkFns = [ ] ,
533533 nodeLinkFn , childLinkFn , directives , attrs , linkFnFound ;
534534
@@ -539,7 +539,7 @@ function $CompileProvider($provide) {
539539 directives = collectDirectives ( nodeList [ i ] , [ ] , attrs , i == 0 ? maxPriority : undefined , ignoreDirective ) ;
540540
541541 nodeLinkFn = ( directives . length )
542- ? applyDirectivesToNode ( directives , nodeList [ i ] , attrs , transcludeFn , $rootElement , null , [ ] , [ ] )
542+ ? applyDirectivesToNode ( directives , nodeList [ i ] , attrs , transcludeFn , $rootElement , null , [ ] , [ ] , previousCompileContext )
543543 : null ;
544544
545545 childLinkFn = ( nodeLinkFn && nodeLinkFn . terminal || ! nodeList [ i ] . childNodes || ! nodeList [ i ] . childNodes . length )
@@ -550,6 +550,7 @@ function $CompileProvider($provide) {
550550 linkFns . push ( nodeLinkFn ) ;
551551 linkFns . push ( childLinkFn ) ;
552552 linkFnFound = ( linkFnFound || nodeLinkFn || childLinkFn ) ;
553+ previousCompileContext = null ; //use the previous context only for the first element in the virtual group
553554 }
554555
555556 // return a linking function if we have found anything, null otherwise
@@ -750,23 +751,26 @@ function $CompileProvider($provide) {
750751 * scope argument is auto-generated to the new child of the transcluded parent scope.
751752 * @param {JQLite } jqCollection If we are working on the root of the compile tree then this
752753 * argument has the root jqLite array so that we can replace nodes on it.
753- * @param {Object= } ignoreDirective An optional directive that will be ignored when compiling
754+ * @param {Object= } originalReplaceDirective An optional directive that will be ignored when compiling
754755 * the transclusion.
755756 * @param {Array.<Function> } preLinkFns
756757 * @param {Array.<Function> } postLinkFns
758+ * @param {Object } previousCompileContext Context used for previous compilation of the current node
757759 * @returns linkFn
758760 */
759761 function applyDirectivesToNode ( directives , compileNode , templateAttrs , transcludeFn , jqCollection ,
760- originalReplaceDirective , preLinkFns , postLinkFns ) {
762+ originalReplaceDirective , preLinkFns , postLinkFns , previousCompileContext ) {
763+ previousCompileContext = previousCompileContext || { } ;
764+
761765 var terminalPriority = - Number . MAX_VALUE ,
762- newScopeDirective = null ,
763- newIsolateScopeDirective = null ,
764- templateDirective = null ,
766+ newScopeDirective ,
767+ newIsolateScopeDirective = previousCompileContext . newIsolateScopeDirective ,
768+ templateDirective = previousCompileContext . templateDirective ,
765769 $compileNode = templateAttrs . $$element = jqLite ( compileNode ) ,
766770 directive ,
767771 directiveName ,
768772 $template ,
769- transcludeDirective ,
773+ transcludeDirective = previousCompileContext . transcludeDirective ,
770774 replaceDirective = originalReplaceDirective ,
771775 childTranscludeFn = transcludeFn ,
772776 controllerDirectives ,
@@ -815,19 +819,27 @@ function $CompileProvider($provide) {
815819 }
816820
817821 if ( directiveValue = directive . transclude ) {
818- assertNoDuplicate ( 'transclusion' , transcludeDirective , directive , $compileNode ) ;
819- transcludeDirective = directive ;
822+ // Special case ngRepeat so that we don't complain about duplicate transclusion, ngRepeat knows how to handle
823+ // this on its own.
824+ if ( directiveName !== 'ngRepeat' ) {
825+ assertNoDuplicate ( 'transclusion' , transcludeDirective , directive , $compileNode ) ;
826+ transcludeDirective = directive ;
827+ }
820828
821829 if ( directiveValue == 'element' ) {
822830 terminalPriority = directive . priority ;
823- $template = groupScan ( compileNode , attrStart , attrEnd )
831+ $template = groupScan ( compileNode , attrStart , attrEnd ) ;
824832 $compileNode = templateAttrs . $$element =
825833 jqLite ( document . createComment ( ' ' + directiveName + ': ' + templateAttrs [ directiveName ] + ' ' ) ) ;
826834 compileNode = $compileNode [ 0 ] ;
827835 replaceWith ( jqCollection , jqLite ( sliceArgs ( $template ) ) , compileNode ) ;
828836
829837 childTranscludeFn = compile ( $template , transcludeFn , terminalPriority ,
830- replaceDirective && replaceDirective . name ) ;
838+ replaceDirective && replaceDirective . name , {
839+ newIsolateScopeDirective : newIsolateScopeDirective ,
840+ transcludeDirective : transcludeDirective ,
841+ templateDirective : templateDirective
842+ } ) ;
831843 } else {
832844 $template = jqLite ( JQLiteClone ( compileNode ) ) . contents ( ) ;
833845 $compileNode . html ( '' ) ; // clear contents
@@ -889,7 +901,11 @@ function $CompileProvider($provide) {
889901 }
890902
891903 nodeLinkFn = compileTemplateUrl ( directives . splice ( i , directives . length - i ) , $compileNode ,
892- templateAttrs , jqCollection , childTranscludeFn , preLinkFns , postLinkFns ) ;
904+ templateAttrs , jqCollection , childTranscludeFn , preLinkFns , postLinkFns , {
905+ newIsolateScopeDirective : newIsolateScopeDirective ,
906+ transcludeDirective : transcludeDirective ,
907+ templateDirective : templateDirective
908+ } ) ;
893909 ii = directives . length ;
894910 } else if ( directive . compile ) {
895911 try {
@@ -1188,7 +1204,7 @@ function $CompileProvider($provide) {
11881204
11891205
11901206 function compileTemplateUrl ( directives , $compileNode , tAttrs ,
1191- $rootElement , childTranscludeFn , preLinkFns , postLinkFns ) {
1207+ $rootElement , childTranscludeFn , preLinkFns , postLinkFns , previousCompileContext ) {
11921208 var linkQueue = [ ] ,
11931209 afterTemplateNodeLinkFn ,
11941210 afterTemplateChildLinkFn ,
@@ -1231,7 +1247,7 @@ function $CompileProvider($provide) {
12311247 directives . unshift ( derivedSyncDirective ) ;
12321248
12331249 afterTemplateNodeLinkFn = applyDirectivesToNode ( directives , compileNode , tAttrs ,
1234- childTranscludeFn , $compileNode , origAsyncDirective , preLinkFns , postLinkFns ) ;
1250+ childTranscludeFn , $compileNode , origAsyncDirective , preLinkFns , postLinkFns , previousCompileContext ) ;
12351251 forEach ( $rootElement , function ( node , i ) {
12361252 if ( node == compileNode ) {
12371253 $rootElement [ i ] = $compileNode [ 0 ] ;
0 commit comments