* @ngdoc provider * @name $parseProvider * * @description * `$parseProvider` can be used for configuring the default behavior of the ng.$parse $parse * service.
()
| 12755 | * service. |
| 12756 | */ |
| 12757 | function $ParseProvider() { |
| 12758 | var cacheDefault = createMap(); |
| 12759 | var cacheExpensive = createMap(); |
| 12760 | |
| 12761 | |
| 12762 | |
| 12763 | this.$get = ['$filter', '$sniffer', function($filter, $sniffer) { |
| 12764 | var $parseOptions = { |
| 12765 | csp: $sniffer.csp, |
| 12766 | expensiveChecks: false |
| 12767 | }, |
| 12768 | $parseOptionsExpensive = { |
| 12769 | csp: $sniffer.csp, |
| 12770 | expensiveChecks: true |
| 12771 | }; |
| 12772 | |
| 12773 | function wrapSharedExpression(exp) { |
| 12774 | var wrapped = exp; |
| 12775 | |
| 12776 | if (exp.sharedGetter) { |
| 12777 | wrapped = function $parseWrapper(self, locals) { |
| 12778 | return exp(self, locals); |
| 12779 | }; |
| 12780 | wrapped.literal = exp.literal; |
| 12781 | wrapped.constant = exp.constant; |
| 12782 | wrapped.assign = exp.assign; |
| 12783 | } |
| 12784 | |
| 12785 | return wrapped; |
| 12786 | } |
| 12787 | |
| 12788 | return function $parse(exp, interceptorFn, expensiveChecks) { |
| 12789 | var parsedExpression, oneTime, cacheKey; |
| 12790 | |
| 12791 | switch (typeof exp) { |
| 12792 | case 'string': |
| 12793 | cacheKey = exp = exp.trim(); |
| 12794 | |
| 12795 | var cache = (expensiveChecks ? cacheExpensive : cacheDefault); |
| 12796 | parsedExpression = cache[cacheKey]; |
| 12797 | |
| 12798 | if (!parsedExpression) { |
| 12799 | if (exp.charAt(0) === ':' && exp.charAt(1) === ':') { |
| 12800 | oneTime = true; |
| 12801 | exp = exp.substring(2); |
| 12802 | } |
| 12803 | |
| 12804 | var parseOptions = expensiveChecks ? $parseOptionsExpensive : $parseOptions; |
| 12805 | var lexer = new Lexer(parseOptions); |
| 12806 | var parser = new Parser(lexer, $filter, parseOptions); |
| 12807 | parsedExpression = parser.parse(exp); |
| 12808 | |
| 12809 | if (parsedExpression.constant) { |
| 12810 | parsedExpression.$$watchDelegate = constantWatchDelegate; |
| 12811 | } else if (oneTime) { |
| 12812 | //oneTime is not part of the exp passed to the Parser so we may have to |
| 12813 | //wrap the parsedExpression before adding a $$watchDelegate |
| 12814 | parsedExpression = wrapSharedExpression(parsedExpression); |
nothing calls this directly
no test coverage detected