@@ -169,57 +169,62 @@ function $InterpolateProvider() {
169
169
if ( ! mustHaveExpression || hasInterpolation ) {
170
170
var concat = new Array ( parts . length ) ,
171
171
expressions = { } ;
172
- forEach ( parts , function ( value , index ) {
172
+
173
+ forEach ( parts , function ( value , index ) {
173
174
if ( isFunction ( value ) ) {
174
175
expressions [ index ] = value ;
175
176
concat [ index ] = '' ;
176
177
} else {
177
178
concat [ index ] = value ;
178
179
}
179
180
} ) ;
181
+
180
182
// computes all the interpolations and returns the resulting string
181
- // a specific index might already be computed (cz of the scope's dirty-checking),
183
+ // a specific index might already be computed (thanks to the scope's dirty-checking),
182
184
// and so its expression shouldn't be executed a 2nd time
183
185
// also populates the lastValues of custom watchers for internal dirty-checking
184
- var getTextValue = function ( scope , computedIndex , computedValue , lastValues ) {
186
+ var getConcatValue = function ( scope , computedIndex , computedValue , lastValues ) {
185
187
try {
186
- forEach ( expressions , function ( expression , index ) {
187
- concat [ index ] = index == computedIndex
188
+
189
+ forEach ( expressions , function ( expression , index ) {
190
+ concat [ index ] = ( index === computedIndex )
188
191
? computedValue
189
192
: getStringValue ( expression ( scope ) ) ;
190
193
191
194
if ( lastValues ) lastValues [ index ] = concat [ index ] ;
192
195
} ) ;
193
196
return concat . join ( '' ) ;
194
- }
195
- catch ( err ) {
197
+
198
+ } catch ( err ) {
196
199
var newErr = $interpolateMinErr ( 'interr' , "Can't interpolate: {0}\n{1}" , text ,
197
200
err . toString ( ) ) ;
198
201
$exceptionHandler ( newErr ) ;
199
202
}
200
203
} ;
201
- var getStringValue = function ( value ) {
204
+
205
+ var getStringValue = function ( value ) {
202
206
value = trustedContext
203
207
? $sce . getTrusted ( trustedContext , value )
204
208
: $sce . valueOf ( value ) ;
205
209
206
- if ( value === null || isUndefined ( value ) ) {
210
+ if ( value == null ) {
207
211
return '' ;
208
212
}
209
213
return isString ( value ) ? value : toJson ( value ) ;
210
214
} ;
211
215
212
216
fn = function ( scope ) {
213
- return getTextValue ( scope ) ;
217
+ // we don't want others to be able to pass more than the first argument
218
+ return getConcatValue ( scope ) ;
214
219
} ;
215
220
fn . exp = text ;
216
221
fn . parts = parts ;
217
222
218
223
// watches each interpolation separately for performance
219
- fn . $$beWatched = function ( scope , origListener , objectEquality ) {
224
+ fn . $$beWatched = function ( scope , origListener , objectEquality ) {
220
225
var lastTextValue , lastValues = { } , watchersRm = [ ] ;
221
226
222
- forEach ( expressions , function ( expression , index ) {
227
+ forEach ( expressions , function ( expression , index ) {
223
228
watchersRm . push ( scope . $watch ( function watchInterpolatedExpr ( scope ) {
224
229
try {
225
230
return getStringValue ( expression ( scope ) ) ;
@@ -241,7 +246,7 @@ function $InterpolateProvider() {
241
246
// and ignore it when the listener of `b` gets triggered
242
247
// (unless the value of `b` changes again since the last computation)
243
248
if ( value !== lastValues [ index ] ) {
244
- var textValue = getTextValue ( scope , index , value , lastValues ) ;
249
+ var textValue = getConcatValue ( scope , index , value , lastValues ) ;
245
250
origListener . call ( this , textValue ,
246
251
value === oldValue ? textValue : lastTextValue , scope ) ;
247
252
lastTextValue = textValue ;
0 commit comments