diff options
| author | Misko Hevery | 2011-11-03 15:59:18 -0700 |
|---|---|---|
| committer | Misko Hevery | 2011-11-14 20:31:09 -0800 |
| commit | cb6f832f38b11499a6d1dd2caf14d15e68211635 (patch) | |
| tree | adb837d60cb080712319122d3a7103e20e07c2e0 /src/service/parse.js | |
| parent | 6022f3df399a5d98830dfe7904f0ad2baaa308c7 (diff) | |
| download | angular.js-cb6f832f38b11499a6d1dd2caf14d15e68211635.tar.bz2 | |
refactor(filter): filters are now injectable and services
BREAK:
- removed CSS support from filters
Diffstat (limited to 'src/service/parse.js')
| -rw-r--r-- | src/service/parse.js | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/src/service/parse.js b/src/service/parse.js index 465f416e..36f6b715 100644 --- a/src/service/parse.js +++ b/src/service/parse.js @@ -217,7 +217,7 @@ function lex(text){ ///////////////////////////////////////// -function parser(text, json){ +function parser(text, json, $filter){ var ZERO = valueFn(0), value, tokens = lex(text), @@ -227,8 +227,7 @@ function parser(text, json){ fieldAccess = _fieldAccess, objectIndex = _objectIndex, filterChain = _filterChain, - functionIdent = _functionIdent, - pipeFunction = _pipeFunction; + functionIdent = _functionIdent; 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. @@ -239,7 +238,6 @@ function parser(text, json){ assignable = filterChain = functionIdent = - pipeFunction = function() { throwError("is not valid json", {text:text, index:0}); }; value = primary(); } else { @@ -346,13 +344,9 @@ function parser(text, json){ } function filter() { - return pipeFunction(angularFilter); - } - - function _pipeFunction(fnScope){ - var fn = functionIdent(fnScope); + var token = expect(); + var fn = $filter(token.text); var argsFn = []; - var token; while(true) { if ((token = expect(':'))) { argsFn.push(expression()); @@ -719,13 +713,13 @@ function getterFn(path) { function $ParseProvider() { var cache = {}; - this.$get = ['$injector', function($injector) { + this.$get = ['$filter', function($filter) { return function(exp) { switch(typeof exp) { case 'string': return cache.hasOwnProperty(exp) ? cache[exp] - : cache[exp] = parser(exp); + : cache[exp] = parser(exp, false, $filter); case 'function': return exp; default: @@ -735,10 +729,14 @@ function $ParseProvider() { }]; } +function noFilters(){ + throw Error('Filters not supported!'); +} + // This is a special access for JSON parser which bypasses the injector var parseJson = function(json) { - return parser(json, true); + return parser(json, true, noFilters); }; // TODO(misko): temporary hack, until we get rid of the type augmentation -var expressionCompile = new $ParseProvider().$get[1](null); +var expressionCompile = new $ParseProvider().$get[1](noFilters); |
