diff --git a/src/ng/parse.js b/src/ng/parse.js index 50da14fa0770..51eed0376fa7 100644 --- a/src/ng/parse.js +++ b/src/ng/parse.js @@ -129,9 +129,6 @@ Lexer.prototype = { this.tokens = []; - var token; - var json = []; - while (this.index < this.text.length) { this.ch = this.text.charAt(this.index); if (this.is('"\'')) { @@ -140,19 +137,11 @@ Lexer.prototype = { this.readNumber(); } else if (this.isIdent(this.ch)) { this.readIdent(); - // identifiers can only be if the preceding char was a { or , - if (this.was('{,') && json[0] === '{' && - (token = this.tokens[this.tokens.length - 1])) { - token.json = token.text.indexOf('.') === -1; - } } else if (this.is('(){}[].,;:?')) { this.tokens.push({ index: this.index, - text: this.ch, - json: (this.was(':[,') && this.is('{[')) || this.is('}]:,') + text: this.ch }); - if (this.is('{[')) json.unshift(this.ch); - if (this.is('}]')) json.shift(); this.index++; } else if (this.isWhitespace(this.ch)) { this.index++; @@ -173,8 +162,7 @@ Lexer.prototype = { this.tokens.push({ index: this.index, text: this.ch, - fn: fn, - json: (this.was('[,:') && this.is('+-')) + fn: fn }); this.index += 1; } else { @@ -257,7 +245,8 @@ Lexer.prototype = { this.tokens.push({ index: start, text: number, - json: true, + literal: true, + constant: true, fn: function() { return number; } }); }, @@ -309,7 +298,8 @@ Lexer.prototype = { // OPERATORS is our own object so we don't need to use special hasOwnPropertyFn if (OPERATORS.hasOwnProperty(ident)) { token.fn = OPERATORS[ident]; - token.json = OPERATORS[ident]; + token.literal = true; + token.constant = true; } else { var getter = getterFn(ident, this.options, this.text); token.fn = extend(function(self, locals) { @@ -326,13 +316,11 @@ Lexer.prototype = { if (methodName) { this.tokens.push({ index:lastDot, - text: '.', - json: false + text: '.' }); this.tokens.push({ index: lastDot + 1, - text: methodName, - json: false + text: methodName }); } }, @@ -370,7 +358,8 @@ Lexer.prototype = { index: start, text: rawString, string: string, - json: true, + literal: true, + constant: true, fn: function() { return string; } }); return; @@ -402,28 +391,12 @@ Parser.ZERO = extend(function () { Parser.prototype = { constructor: Parser, - parse: function (text, json) { + parse: function (text) { this.text = text; - //TODO(i): strip all the obsolte json stuff from this file - this.json = json; - this.tokens = this.lexer.lex(text); - if (json) { - // The extra level of aliasing is here, just in case the lexer misses something, so that - // we prevent any accidental execution in JSON. - this.assignment = this.logicalOR; - - this.functionCall = - this.fieldAccess = - this.objectIndex = - this.filterChain = function() { - this.throwError('is not valid json', {text: text, index: 0}); - }; - } - - var value = json ? this.primary() : this.statements(); + var value = this.statements(); if (this.tokens.length !== 0) { this.throwError('is an unexpected token', this.tokens[0]); @@ -450,10 +423,8 @@ Parser.prototype = { if (!primary) { this.throwError('not a primary expression', token); } - if (token.json) { - primary.constant = true; - primary.literal = true; - } + primary.literal = !!token.literal; + primary.constant = !!token.constant; } var next, context; @@ -501,9 +472,6 @@ Parser.prototype = { expect: function(e1, e2, e3, e4){ var token = this.peek(e1, e2, e3, e4); if (token) { - if (this.json && !token.json) { - this.throwError('is not valid json', token); - } this.tokens.shift(); return token; } @@ -1257,7 +1225,7 @@ function $ParseProvider() { var lexer = new Lexer($parseOptions); var parser = new Parser(lexer, $filter, $parseOptions); - parsedExpression = parser.parse(exp, false); + parsedExpression = parser.parse(exp); if (exp !== 'hasOwnProperty') { // Only cache the value if it's not going to mess up the cache object