@@ -3,7 +3,7 @@ import {List, ListWrapper, MapWrapper, StringMapWrapper} from 'angular2/src/faca
33
44import { AbstractChangeDetector } from './abstract_change_detector' ;
55import { ChangeDetectionUtil } from './change_detection_util' ;
6- import { DirectiveRecord } from './directive_record' ;
6+ import { DirectiveIndex , DirectiveRecord } from './directive_record' ;
77
88import {
99 ProtoRecord ,
@@ -81,12 +81,12 @@ function hydrateTemplate(type:string, mode:string, fieldDefinitions:string, pipe
8181 directiveFieldNames :List < String > , detectorFieldNames :List < String > ) :string {
8282 var directiveInit = "" ;
8383 for ( var i = 0 ; i < directiveFieldNames . length ; ++ i ) {
84- directiveInit += `${ directiveFieldNames [ i ] } = directives.getDirectiveFor(this.directiveRecords[${ i } ]);\n` ;
84+ directiveInit += `${ directiveFieldNames [ i ] } = directives.getDirectiveFor(this.directiveRecords[${ i } ].directiveIndex );\n` ;
8585 }
8686
8787 var detectorInit = "" ;
8888 for ( var i = 0 ; i < detectorFieldNames . length ; ++ i ) {
89- detectorInit += `${ detectorFieldNames [ i ] } = directives.getDetectorFor(this.directiveRecords[${ i } ]);\n` ;
89+ detectorInit += `${ detectorFieldNames [ i ] } = directives.getDetectorFor(this.directiveRecords[${ i } ].directiveIndex );\n` ;
9090 }
9191
9292 return `
@@ -313,18 +313,18 @@ export class ChangeDetectorJITGenerator {
313313 }
314314
315315 getDirectiveFieldNames():List<string> {
316- return this.directiveRecords.map((d) => this.getDirective(d));
316+ return this.directiveRecords.map((d) => this.getDirective(d.directiveIndex ));
317317 }
318318
319319 getDetectorFieldNames():List<string> {
320- return this.directiveRecords.filter(r => r.isOnPushChangeDetection()).map((d) => this.getDetector(d));
320+ return this.directiveRecords.filter(r => r.isOnPushChangeDetection()).map((d) => this.getDetector(d.directiveIndex ));
321321 }
322322
323- getDirective(d:DirectiveRecord ) {
323+ getDirective(d:DirectiveIndex ) {
324324 return ` this . directive_$ { d . name } `;
325325 }
326326
327- getDetector(d:DirectiveRecord ) {
327+ getDetector(d:DirectiveIndex ) {
328328 return ` this . detector_$ { d . name } `;
329329 }
330330
@@ -359,7 +359,7 @@ export class ChangeDetectorJITGenerator {
359359 for (var i = dirs.length - 1; i >= 0; --i) {
360360 var dir = dirs[i];
361361 if (dir.callOnAllChangesDone) {
362- var directive = ` this . directive_$ { dir . name } `;
362+ var directive = ` this . directive_$ { dir . directiveIndex . name } `;
363363 notifications.push(onAllChangesDoneTemplate(directive));
364364 }
365365 }
@@ -425,7 +425,7 @@ export class ChangeDetectorJITGenerator {
425425 }
426426
427427 genUpdateCurrentValue(r:ProtoRecord):string {
428- var context = this.localNames[r.contextIndex] ;
428+ var context = this.getContext(r) ;
429429 var newValue = this.localNames[r.selfIndex];
430430 var args = this.genArgs(r);
431431
@@ -463,6 +463,14 @@ export class ChangeDetectorJITGenerator {
463463 }
464464 }
465465
466+ getContext(r:ProtoRecord):string {
467+ if (r.contextIndex == -1) {
468+ return this.getDirective(r.directiveIndex);
469+ } else {
470+ return this.localNames[r.contextIndex];
471+ }
472+ }
473+
466474 ifChangedGuard(r:ProtoRecord, body:string):string {
467475 return ifChangedGuardTemplate(r.args.map((a) => this.changeNames[a]), body);
468476 }
@@ -491,7 +499,7 @@ export class ChangeDetectorJITGenerator {
491499
492500 var br = r.bindingRecord;
493501 if (br.isDirective()) {
494- var directiveProperty = ` $ { this . getDirective ( br . directiveRecord ) } . ${br . propertyName } `;
502+ var directiveProperty = ` $ { this . getDirective ( br . directiveRecord . directiveIndex ) } . ${br . propertyName } `;
495503 return updateDirectiveTemplate ( oldValue , newValue , directiveProperty ) ;
496504 } else {
497505 return updateElementTemplate ( oldValue , newValue ) ;
@@ -513,7 +521,7 @@ export class ChangeDetectorJITGenerator {
513521 genNotifyOnChanges ( r :ProtoRecord ) :string {
514522 var br = r . bindingRecord ;
515523 if ( r . lastInDirective && br . callOnChange ( ) ) {
516- return notifyOnChangesTemplate ( this . getDirective ( br . directiveRecord ) ) ;
524+ return notifyOnChangesTemplate ( this . getDirective ( br . directiveRecord . directiveIndex ) ) ;
517525 } else {
518526 return "" ;
519527 }
@@ -522,7 +530,7 @@ export class ChangeDetectorJITGenerator {
522530 genNotifyOnPushDetectors ( r :ProtoRecord ) :string {
523531 var br = r . bindingRecord ;
524532 if ( r . lastInDirective && br . isOnPushChangeDetection ( ) ) {
525- return notifyOnPushDetectorsTemplate ( this . getDetector ( br . directiveRecord ) ) ;
533+ return notifyOnPushDetectorsTemplate ( this . getDetector ( br . directiveRecord . directiveIndex ) ) ;
526534 } else {
527535 return "" ;
528536 }
0 commit comments