Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 88505d8

Browse files
committed
refactor($parse): remove the support of JSON parsing mode
It's a feature that isn't exposed to the public, and is no longer used internally.
1 parent c241a57 commit 88505d8

File tree

1 file changed

+15
-47
lines changed

1 file changed

+15
-47
lines changed

src/ng/parse.js

+15-47
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,6 @@ Lexer.prototype = {
129129

130130
this.tokens = [];
131131

132-
var token;
133-
var json = [];
134-
135132
while (this.index < this.text.length) {
136133
this.ch = this.text.charAt(this.index);
137134
if (this.is('"\'')) {
@@ -140,19 +137,11 @@ Lexer.prototype = {
140137
this.readNumber();
141138
} else if (this.isIdent(this.ch)) {
142139
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-
}
148140
} else if (this.is('(){}[].,;:?')) {
149141
this.tokens.push({
150142
index: this.index,
151-
text: this.ch,
152-
json: (this.was(':[,') && this.is('{[')) || this.is('}]:,')
143+
text: this.ch
153144
});
154-
if (this.is('{[')) json.unshift(this.ch);
155-
if (this.is('}]')) json.shift();
156145
this.index++;
157146
} else if (this.isWhitespace(this.ch)) {
158147
this.index++;
@@ -173,8 +162,7 @@ Lexer.prototype = {
173162
this.tokens.push({
174163
index: this.index,
175164
text: this.ch,
176-
fn: fn,
177-
json: (this.was('[,:') && this.is('+-'))
165+
fn: fn
178166
});
179167
this.index += 1;
180168
} else {
@@ -257,7 +245,8 @@ Lexer.prototype = {
257245
this.tokens.push({
258246
index: start,
259247
text: number,
260-
json: true,
248+
literal: true,
249+
constant: true,
261250
fn: function() { return number; }
262251
});
263252
},
@@ -309,7 +298,8 @@ Lexer.prototype = {
309298
// OPERATORS is our own object so we don't need to use special hasOwnPropertyFn
310299
if (OPERATORS.hasOwnProperty(ident)) {
311300
token.fn = OPERATORS[ident];
312-
token.json = OPERATORS[ident];
301+
token.literal = true;
302+
token.constant = true;
313303
} else {
314304
var getter = getterFn(ident, this.options, this.text);
315305
token.fn = extend(function(self, locals) {
@@ -326,13 +316,11 @@ Lexer.prototype = {
326316
if (methodName) {
327317
this.tokens.push({
328318
index:lastDot,
329-
text: '.',
330-
json: false
319+
text: '.'
331320
});
332321
this.tokens.push({
333322
index: lastDot + 1,
334-
text: methodName,
335-
json: false
323+
text: methodName
336324
});
337325
}
338326
},
@@ -370,7 +358,8 @@ Lexer.prototype = {
370358
index: start,
371359
text: rawString,
372360
string: string,
373-
json: true,
361+
literal: true,
362+
constant: true,
374363
fn: function() { return string; }
375364
});
376365
return;
@@ -402,28 +391,12 @@ Parser.ZERO = extend(function () {
402391
Parser.prototype = {
403392
constructor: Parser,
404393

405-
parse: function (text, json) {
394+
parse: function (text) {
406395
this.text = text;
407396

408-
//TODO(i): strip all the obsolte json stuff from this file
409-
this.json = json;
410-
411397
this.tokens = this.lexer.lex(text);
412398

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();
427400

428401
if (this.tokens.length !== 0) {
429402
this.throwError('is an unexpected token', this.tokens[0]);
@@ -450,10 +423,8 @@ Parser.prototype = {
450423
if (!primary) {
451424
this.throwError('not a primary expression', token);
452425
}
453-
if (token.json) {
454-
primary.constant = true;
455-
primary.literal = true;
456-
}
426+
primary.literal = !!token.literal;
427+
primary.constant = !!token.constant;
457428
}
458429

459430
var next, context;
@@ -501,9 +472,6 @@ Parser.prototype = {
501472
expect: function(e1, e2, e3, e4){
502473
var token = this.peek(e1, e2, e3, e4);
503474
if (token) {
504-
if (this.json && !token.json) {
505-
this.throwError('is not valid json', token);
506-
}
507475
this.tokens.shift();
508476
return token;
509477
}
@@ -1257,7 +1225,7 @@ function $ParseProvider() {
12571225

12581226
var lexer = new Lexer($parseOptions);
12591227
var parser = new Parser(lexer, $filter, $parseOptions);
1260-
parsedExpression = parser.parse(exp, false);
1228+
parsedExpression = parser.parse(exp);
12611229

12621230
if (exp !== 'hasOwnProperty') {
12631231
// Only cache the value if it's not going to mess up the cache object

0 commit comments

Comments
 (0)