diff --git a/src/ng/parse.js b/src/ng/parse.js index 92279b05a0d6..f90f69debf9b 100644 --- a/src/ng/parse.js +++ b/src/ng/parse.js @@ -120,11 +120,8 @@ Lexer.prototype = { lex: function (text) { this.text = text; - this.index = 0; this.ch = undefined; - this.lastCh = ':'; // can start regexp - this.tokens = []; while (this.index < this.text.length) { @@ -143,7 +140,6 @@ Lexer.prototype = { this.index++; } else if (this.isWhitespace(this.ch)) { this.index++; - continue; } else { var ch2 = this.ch + this.peek(); var ch3 = ch2 + this.peek(2); @@ -167,7 +163,6 @@ Lexer.prototype = { this.throwError('Unexpected next character ', this.index, this.index + 1); } } - this.lastCh = this.ch; } return this.tokens; }, @@ -176,10 +171,6 @@ Lexer.prototype = { return chars.indexOf(this.ch) !== -1; }, - was: function(chars) { - return chars.indexOf(this.lastCh) !== -1; - }, - peek: function(i) { var num = i || 1; return (this.index + num < this.text.length) ? this.text.charAt(this.index + num) : false; @@ -243,7 +234,6 @@ Lexer.prototype = { this.tokens.push({ index: start, text: number, - literal: true, constant: true, fn: function() { return number; } }); @@ -296,7 +286,6 @@ 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.literal = true; token.constant = true; } else { var getter = getterFn(ident, this.options, this.text); @@ -304,7 +293,7 @@ Lexer.prototype = { return (getter(self, locals)); }, { assign: function(self, value) { - return setter(self, ident, value, parser.text, parser.options); + return setter(self, ident, value, parser.text); } }); } @@ -313,7 +302,7 @@ Lexer.prototype = { if (methodName) { this.tokens.push({ - index:lastDot, + index: lastDot, text: '.' }); this.tokens.push({ @@ -356,7 +345,6 @@ Lexer.prototype = { index: start, text: rawString, string: string, - literal: true, constant: true, fn: function() { return string; } }); @@ -391,7 +379,6 @@ Parser.prototype = { parse: function (text) { this.text = text; - this.tokens = this.lexer.lex(text); var value = this.statements(); @@ -421,8 +408,10 @@ Parser.prototype = { if (!primary) { this.throwError('not a primary expression', token); } - primary.literal = !!token.literal; - primary.constant = !!token.constant; + if (token.constant) { + primary.constant = true; + primary.literal = true; + } } var next, context; @@ -546,21 +535,17 @@ Parser.prototype = { var token = this.expect(); var fn = this.$filter(token.text); var argsFn = []; - while (true) { - if ((token = this.expect(':'))) { - argsFn.push(this.expression()); - } else { - var fnInvoke = function(self, locals, input) { - var args = [input]; - for (var i = 0; i < argsFn.length; i++) { - args.push(argsFn[i](self, locals)); - } - return fn.apply(self, args); - }; - return function() { - return fnInvoke; - }; + while(this.expect(':')) { + argsFn.push(this.expression()); + } + return valueFn(fnInvoke); + + function fnInvoke(self, locals, input) { + var args = [input]; + for (var i = 0; i < argsFn.length; i++) { + args.push(argsFn[i](self, locals)); } + return fn.apply(self, args); } }, @@ -680,7 +665,7 @@ Parser.prototype = { return getter(self || object(scope, locals)); }, { assign: function(scope, value, locals) { - return setter(object(scope, locals), field, value, parser.text, parser.options); + return setter(object(scope, locals), field, value, parser.text); } }); }, @@ -694,7 +679,7 @@ Parser.prototype = { return extend(function(self, locals) { var o = obj(self, locals), i = indexFn(self, locals), - v, p; + v; if (!o) return undefined; v = ensureSafeObject(o[i], parser.text); @@ -812,9 +797,7 @@ Parser.prototype = { // Parser helper functions ////////////////////////////////////////////////// -function setter(obj, path, setValue, fullExp, options) { - //needed? - options = options || {}; +function setter(obj, path, setValue, fullExp) { var element = path.split('.'), key; for (var i = 0; element.length > 1; i++) { @@ -838,7 +821,7 @@ var getterFnCache = {}; * - http://jsperf.com/angularjs-parse-getter/4 * - http://jsperf.com/path-evaluation-simplified/7 */ -function cspSafeGetterFn(key0, key1, key2, key3, key4, fullExp, options) { +function cspSafeGetterFn(key0, key1, key2, key3, key4, fullExp) { ensureSafeMemberName(key0, fullExp); ensureSafeMemberName(key1, fullExp); ensureSafeMemberName(key2, fullExp); @@ -911,14 +894,13 @@ function getterFn(path, options, fullExp) { fn = simpleGetterFn2(pathKeys[0], pathKeys[1], fullExp); } else if (options.csp) { if (pathKeysLength < 6) { - fn = cspSafeGetterFn(pathKeys[0], pathKeys[1], pathKeys[2], pathKeys[3], pathKeys[4], fullExp, - options); + fn = cspSafeGetterFn(pathKeys[0], pathKeys[1], pathKeys[2], pathKeys[3], pathKeys[4], fullExp); } else { fn = function(scope, locals) { var i = 0, val; do { val = cspSafeGetterFn(pathKeys[i++], pathKeys[i++], pathKeys[i++], pathKeys[i++], - pathKeys[i++], fullExp, options)(scope, locals); + pathKeys[i++], fullExp)(scope, locals); locals = undefined; // clear after first iteration scope = val; @@ -1014,7 +996,7 @@ function $ParseProvider() { }; - this.$get = ['$filter', '$sniffer', '$log', function($filter, $sniffer, $log) { + this.$get = ['$filter', '$sniffer', function($filter, $sniffer) { $parseOptions.csp = $sniffer.csp; return function(exp) {