1- import { isPresent , isBlank , BaseException , Type , isString } from 'angular2/src/facade/lang' ;
1+ import { BaseException , Type , isBlank , isPresent , isString } from 'angular2/src/facade/lang' ;
22import { List , ListWrapper , MapWrapper , StringMapWrapper } from 'angular2/src/facade/collection' ;
33
44import {
@@ -109,37 +109,30 @@ class ProtoRecordBuilder {
109109 constructor ( ) { this . records = [ ] ; }
110110
111111 addAst ( b : BindingRecord , variableNames : List < string > = null ) {
112- var last = ListWrapper . last ( this . records ) ;
113- if ( isPresent ( last ) && last . bindingRecord . directiveRecord == b . directiveRecord ) {
114- last . lastInDirective = false ;
112+ var oldLast = ListWrapper . last ( this . records ) ;
113+ if ( isPresent ( oldLast ) && oldLast . bindingRecord . directiveRecord == b . directiveRecord ) {
114+ oldLast . lastInDirective = false ;
115115 }
116116
117- var pr = _ConvertAstIntoProtoRecords . convert ( b , this . records . length , variableNames ) ;
118- if ( ! ListWrapper . isEmpty ( pr ) ) {
119- var last = ListWrapper . last ( pr ) ;
120- last . lastInBinding = true ;
121- last . lastInDirective = true ;
122-
123- this . records = ListWrapper . concat ( this . records , pr ) ;
117+ _ConvertAstIntoProtoRecords . append ( this . records , b , variableNames ) ;
118+ var newLast = ListWrapper . last ( this . records ) ;
119+ if ( isPresent ( newLast ) && newLast !== oldLast ) {
120+ newLast . lastInBinding = true ;
121+ newLast . lastInDirective = true ;
124122 }
125123 }
126124}
127125
128126class _ConvertAstIntoProtoRecords {
129- protoRecords : List < any > ;
130-
131- constructor ( private bindingRecord : BindingRecord , private contextIndex : number ,
132- private expressionAsString : string , private variableNames : List < any > ) {
133- this . protoRecords = [ ] ;
134- }
127+ constructor ( private _records : List < ProtoRecord > , private _bindingRecord : BindingRecord ,
128+ private _expressionAsString : string , private _variableNames : List < any > ) { }
135129
136- static convert ( b : BindingRecord , contextIndex : number , variableNames : List < any > ) {
137- var c = new _ConvertAstIntoProtoRecords ( b , contextIndex , b . ast . toString ( ) , variableNames ) ;
130+ static append ( records : List < ProtoRecord > , b : BindingRecord , variableNames : List < any > ) {
131+ var c = new _ConvertAstIntoProtoRecords ( records , b , b . ast . toString ( ) , variableNames ) ;
138132 b . ast . visit ( c ) ;
139- return c . protoRecords ;
140133 }
141134
142- visitImplicitReceiver ( ast : ImplicitReceiver ) { return this . bindingRecord . implicitReceiver ; }
135+ visitImplicitReceiver ( ast : ImplicitReceiver ) { return this . _bindingRecord . implicitReceiver ; }
143136
144137 visitInterpolation ( ast : Interpolation ) {
145138 var args = this . _visitAll ( ast . expressions ) ;
@@ -153,7 +146,7 @@ class _ConvertAstIntoProtoRecords {
153146
154147 visitAccessMember ( ast : AccessMember ) {
155148 var receiver = ast . receiver . visit ( this ) ;
156- if ( isPresent ( this . variableNames ) && ListWrapper . contains ( this . variableNames , ast . name ) &&
149+ if ( isPresent ( this . _variableNames ) && ListWrapper . contains ( this . _variableNames , ast . name ) &&
157150 ast . receiver instanceof
158151 ImplicitReceiver ) {
159152 return this . _addRecord ( RECORD_TYPE_LOCAL , ast . name , ast . name , [ ] , null , receiver ) ;
@@ -163,10 +156,9 @@ class _ConvertAstIntoProtoRecords {
163156 }
164157
165158 visitMethodCall ( ast : MethodCall ) {
166- ;
167159 var receiver = ast . receiver . visit ( this ) ;
168160 var args = this . _visitAll ( ast . args ) ;
169- if ( isPresent ( this . variableNames ) && ListWrapper . contains ( this . variableNames , ast . name ) ) {
161+ if ( isPresent ( this . _variableNames ) && ListWrapper . contains ( this . _variableNames , ast . name ) ) {
170162 var target = this . _addRecord ( RECORD_TYPE_LOCAL , ast . name , ast . name , [ ] , null , receiver ) ;
171163 return this . _addRecord ( RECORD_TYPE_INVOKE_CLOSURE , "closure" , null , args , null , target ) ;
172164 } else {
@@ -236,17 +228,15 @@ class _ConvertAstIntoProtoRecords {
236228 }
237229
238230 _addRecord ( type , name , funcOrValue , args , fixedArgs , context ) {
239- var selfIndex = ++ this . contextIndex ;
231+ var selfIndex = this . _records . length + 1 ;
240232 if ( context instanceof DirectiveIndex ) {
241- ListWrapper . push (
242- this . protoRecords ,
243- new ProtoRecord ( type , name , funcOrValue , args , fixedArgs , - 1 , context , selfIndex ,
244- this . bindingRecord , this . expressionAsString , false , false ) ) ;
233+ ListWrapper . push ( this . _records , new ProtoRecord ( type , name , funcOrValue , args , fixedArgs , - 1 ,
234+ context , selfIndex , this . _bindingRecord ,
235+ this . _expressionAsString , false , false ) ) ;
245236 } else {
246- ListWrapper . push (
247- this . protoRecords ,
248- new ProtoRecord ( type , name , funcOrValue , args , fixedArgs , context , null , selfIndex ,
249- this . bindingRecord , this . expressionAsString , false , false ) ) ;
237+ ListWrapper . push ( this . _records , new ProtoRecord ( type , name , funcOrValue , args , fixedArgs ,
238+ context , null , selfIndex , this . _bindingRecord ,
239+ this . _expressionAsString , false , false ) ) ;
250240 }
251241 return selfIndex ;
252242 }
0 commit comments