@@ -129,9 +129,6 @@ Lexer.prototype = {
129
129
130
130
this . tokens = [ ] ;
131
131
132
- var token ;
133
- var json = [ ] ;
134
-
135
132
while ( this . index < this . text . length ) {
136
133
this . ch = this . text . charAt ( this . index ) ;
137
134
if ( this . is ( '"\'' ) ) {
@@ -140,19 +137,11 @@ Lexer.prototype = {
140
137
this . readNumber ( ) ;
141
138
} else if ( this . isIdent ( this . ch ) ) {
142
139
this . readIdent ( ) ;
143
- // identifiers can only be if the preceding char was a { or ,
144
- if ( this . was ( '{,' ) && json [ 0 ] === '{' &&
145
- ( token = this . tokens [ this . tokens . length - 1 ] ) ) {
146
- token . json = token . text . indexOf ( '.' ) === - 1 ;
147
- }
148
140
} else if ( this . is ( '(){}[].,;:?' ) ) {
149
141
this . tokens . push ( {
150
142
index : this . index ,
151
- text : this . ch ,
152
- json : ( this . was ( ':[,' ) && this . is ( '{[' ) ) || this . is ( '}]:,' )
143
+ text : this . ch
153
144
} ) ;
154
- if ( this . is ( '{[' ) ) json . unshift ( this . ch ) ;
155
- if ( this . is ( '}]' ) ) json . shift ( ) ;
156
145
this . index ++ ;
157
146
} else if ( this . isWhitespace ( this . ch ) ) {
158
147
this . index ++ ;
@@ -173,8 +162,7 @@ Lexer.prototype = {
173
162
this . tokens . push ( {
174
163
index : this . index ,
175
164
text : this . ch ,
176
- fn : fn ,
177
- json : ( this . was ( '[,:' ) && this . is ( '+-' ) )
165
+ fn : fn
178
166
} ) ;
179
167
this . index += 1 ;
180
168
} else {
@@ -257,7 +245,8 @@ Lexer.prototype = {
257
245
this . tokens . push ( {
258
246
index : start ,
259
247
text : number ,
260
- json : true ,
248
+ literal : true ,
249
+ constant : true ,
261
250
fn : function ( ) { return number ; }
262
251
} ) ;
263
252
} ,
@@ -309,7 +298,8 @@ Lexer.prototype = {
309
298
// OPERATORS is our own object so we don't need to use special hasOwnPropertyFn
310
299
if ( OPERATORS . hasOwnProperty ( ident ) ) {
311
300
token . fn = OPERATORS [ ident ] ;
312
- token . json = OPERATORS [ ident ] ;
301
+ token . literal = true ;
302
+ token . constant = true ;
313
303
} else {
314
304
var getter = getterFn ( ident , this . options , this . text ) ;
315
305
token . fn = extend ( function ( self , locals ) {
@@ -326,13 +316,11 @@ Lexer.prototype = {
326
316
if ( methodName ) {
327
317
this . tokens . push ( {
328
318
index :lastDot ,
329
- text : '.' ,
330
- json : false
319
+ text : '.'
331
320
} ) ;
332
321
this . tokens . push ( {
333
322
index : lastDot + 1 ,
334
- text : methodName ,
335
- json : false
323
+ text : methodName
336
324
} ) ;
337
325
}
338
326
} ,
@@ -370,7 +358,8 @@ Lexer.prototype = {
370
358
index : start ,
371
359
text : rawString ,
372
360
string : string ,
373
- json : true ,
361
+ literal : true ,
362
+ constant : true ,
374
363
fn : function ( ) { return string ; }
375
364
} ) ;
376
365
return ;
@@ -402,28 +391,12 @@ Parser.ZERO = extend(function () {
402
391
Parser . prototype = {
403
392
constructor : Parser ,
404
393
405
- parse : function ( text , json ) {
394
+ parse : function ( text ) {
406
395
this . text = text ;
407
396
408
- //TODO(i): strip all the obsolte json stuff from this file
409
- this . json = json ;
410
-
411
397
this . tokens = this . lexer . lex ( text ) ;
412
398
413
- if ( json ) {
414
- // The extra level of aliasing is here, just in case the lexer misses something, so that
415
- // we prevent any accidental execution in JSON.
416
- this . assignment = this . logicalOR ;
417
-
418
- this . functionCall =
419
- this . fieldAccess =
420
- this . objectIndex =
421
- this . filterChain = function ( ) {
422
- this . throwError ( 'is not valid json' , { text : text , index : 0 } ) ;
423
- } ;
424
- }
425
-
426
- var value = json ? this . primary ( ) : this . statements ( ) ;
399
+ var value = this . statements ( ) ;
427
400
428
401
if ( this . tokens . length !== 0 ) {
429
402
this . throwError ( 'is an unexpected token' , this . tokens [ 0 ] ) ;
@@ -450,10 +423,8 @@ Parser.prototype = {
450
423
if ( ! primary ) {
451
424
this . throwError ( 'not a primary expression' , token ) ;
452
425
}
453
- if ( token . json ) {
454
- primary . constant = true ;
455
- primary . literal = true ;
456
- }
426
+ primary . literal = ! ! token . literal ;
427
+ primary . constant = ! ! token . constant ;
457
428
}
458
429
459
430
var next , context ;
@@ -501,9 +472,6 @@ Parser.prototype = {
501
472
expect : function ( e1 , e2 , e3 , e4 ) {
502
473
var token = this . peek ( e1 , e2 , e3 , e4 ) ;
503
474
if ( token ) {
504
- if ( this . json && ! token . json ) {
505
- this . throwError ( 'is not valid json' , token ) ;
506
- }
507
475
this . tokens . shift ( ) ;
508
476
return token ;
509
477
}
@@ -1257,7 +1225,7 @@ function $ParseProvider() {
1257
1225
1258
1226
var lexer = new Lexer ( $parseOptions ) ;
1259
1227
var parser = new Parser ( lexer , $filter , $parseOptions ) ;
1260
- parsedExpression = parser . parse ( exp , false ) ;
1228
+ parsedExpression = parser . parse ( exp ) ;
1261
1229
1262
1230
if ( exp !== 'hasOwnProperty' ) {
1263
1231
// Only cache the value if it's not going to mess up the cache object
0 commit comments