From f7a0a386ee6e7f473bb61ae15ba8b974340f40d5 Mon Sep 17 00:00:00 2001 From: rodyhaddad Date: Thu, 22 May 2014 23:57:44 -0700 Subject: [PATCH 1/3] refactor($parse): don't make the lexer mark tokens as literals --- src/ng/parse.js | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/ng/parse.js b/src/ng/parse.js index 92279b05a0d6..3b582735a08e 100644 --- a/src/ng/parse.js +++ b/src/ng/parse.js @@ -120,11 +120,9 @@ 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) { @@ -243,7 +241,6 @@ Lexer.prototype = { this.tokens.push({ index: start, text: number, - literal: true, constant: true, fn: function() { return number; } }); @@ -296,7 +293,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); @@ -313,7 +309,7 @@ Lexer.prototype = { if (methodName) { this.tokens.push({ - index:lastDot, + index: lastDot, text: '.' }); this.tokens.push({ @@ -356,7 +352,6 @@ Lexer.prototype = { index: start, text: rawString, string: string, - literal: true, constant: true, fn: function() { return string; } }); @@ -391,7 +386,6 @@ Parser.prototype = { parse: function (text) { this.text = text; - this.tokens = this.lexer.lex(text); var value = this.statements(); @@ -421,8 +415,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; From 6fb121e64c6509e968e0c2aa7fce8a507fe1d5db Mon Sep 17 00:00:00 2001 From: Lucas Galfaso Date: Wed, 21 May 2014 21:37:59 -0300 Subject: [PATCH 2/3] refactor(parse): simplify the Parser's filter function --- src/ng/parse.js | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/ng/parse.js b/src/ng/parse.js index 3b582735a08e..0fe7a247c2b1 100644 --- a/src/ng/parse.js +++ b/src/ng/parse.js @@ -542,21 +542,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); } }, From ff0369883e73fa0f937d2bbb3c86e9267103d7f6 Mon Sep 17 00:00:00 2001 From: rodyhaddad Date: Fri, 23 May 2014 12:11:36 -0700 Subject: [PATCH 3/3] refactor($parse): remove unused parameters and methods After removing the json and unwrapPromise mode, some parameters and methods were no longer used. --- src/ng/parse.js | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/src/ng/parse.js b/src/ng/parse.js index 0fe7a247c2b1..f90f69debf9b 100644 --- a/src/ng/parse.js +++ b/src/ng/parse.js @@ -122,7 +122,6 @@ Lexer.prototype = { this.text = text; this.index = 0; this.ch = undefined; - this.lastCh = ':'; // can start regexp this.tokens = []; while (this.index < this.text.length) { @@ -141,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); @@ -165,7 +163,6 @@ Lexer.prototype = { this.throwError('Unexpected next character ', this.index, this.index + 1); } } - this.lastCh = this.ch; } return this.tokens; }, @@ -174,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; @@ -300,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); } }); } @@ -672,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); } }); }, @@ -686,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); @@ -804,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++) { @@ -830,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); @@ -903,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; @@ -1006,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) {