From 0fe9408d0eee6828d719eab28ce870deb4462c96 Mon Sep 17 00:00:00 2001 From: Lucas Galfaso Date: Tue, 23 Sep 2014 13:47:46 +0200 Subject: [PATCH] refactor($parse): Create idents lazily Create the ident functions lazily as these are not used for filters not object literal properties Closes #9131 --- src/ng/parse.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/ng/parse.js b/src/ng/parse.js index eaa5cb62045e..a615e41e3ab9 100644 --- a/src/ng/parse.js +++ b/src/ng/parse.js @@ -318,7 +318,11 @@ Lexer.prototype = { this.tokens.push({ index: start, text: ident, - fn: CONSTANTS[ident] || getterFn(ident, this.options, expression) + // An indent may reference a primary, a filter or an object literal property + // If the indent is not a constant then we create a lazy getter, this can be turned + // into a real getter if it turns out to be a primary + fn: CONSTANTS[ident], + lazyFn: CONSTANTS[ident] ? undefined : lazyGetterFn(ident, this.options, expression) }); if (methodName) { @@ -426,7 +430,7 @@ Parser.prototype = { primary = this.object(); } else { var token = this.expect(); - primary = token.fn; + primary = token.fn || token.lazyFn && token.lazyFn(); if (!primary) { this.throwError('not a primary expression', token); } @@ -945,6 +949,12 @@ function getterFn(path, options, fullExp) { return fn; } +function lazyGetterFn(ident, options, expression) { + return function() { + return getterFn(ident, options, expression); + }; +} + /////////////////////////////////// /**