* @ngdoc provider * @name $parseProvider * * @description * `$parseProvider` can be used for configuring the default behavior of the ng.$parse $parse * service.
()
| 12574 | * service. |
| 12575 | */ |
| 12576 | function $ParseProvider() { |
| 12577 | var cacheDefault = createMap(); |
| 12578 | var cacheExpensive = createMap(); |
| 12579 | |
| 12580 | |
| 12581 | |
| 12582 | this.$get = ['$filter', '$sniffer', function($filter, $sniffer) { |
| 12583 | var $parseOptions = { |
| 12584 | csp: $sniffer.csp, |
| 12585 | expensiveChecks: false |
| 12586 | }, |
| 12587 | $parseOptionsExpensive = { |
| 12588 | csp: $sniffer.csp, |
| 12589 | expensiveChecks: true |
| 12590 | }; |
| 12591 | |
| 12592 | function wrapSharedExpression(exp) { |
| 12593 | var wrapped = exp; |
| 12594 | |
| 12595 | if (exp.sharedGetter) { |
| 12596 | wrapped = function $parseWrapper(self, locals) { |
| 12597 | return exp(self, locals); |
| 12598 | }; |
| 12599 | wrapped.literal = exp.literal; |
| 12600 | wrapped.constant = exp.constant; |
| 12601 | wrapped.assign = exp.assign; |
| 12602 | } |
| 12603 | |
| 12604 | return wrapped; |
| 12605 | } |
| 12606 | |
| 12607 | return function $parse(exp, interceptorFn, expensiveChecks) { |
| 12608 | var parsedExpression, oneTime, cacheKey; |
| 12609 | |
| 12610 | switch (typeof exp) { |
| 12611 | case 'string': |
| 12612 | cacheKey = exp = exp.trim(); |
| 12613 | |
| 12614 | var cache = (expensiveChecks ? cacheExpensive : cacheDefault); |
| 12615 | parsedExpression = cache[cacheKey]; |
| 12616 | |
| 12617 | if (!parsedExpression) { |
| 12618 | if (exp.charAt(0) === ':' && exp.charAt(1) === ':') { |
| 12619 | oneTime = true; |
| 12620 | exp = exp.substring(2); |
| 12621 | } |
| 12622 | |
| 12623 | var parseOptions = expensiveChecks ? $parseOptionsExpensive : $parseOptions; |
| 12624 | var lexer = new Lexer(parseOptions); |
| 12625 | var parser = new Parser(lexer, $filter, parseOptions); |
| 12626 | parsedExpression = parser.parse(exp); |
| 12627 | |
| 12628 | if (parsedExpression.constant) { |
| 12629 | parsedExpression.$$watchDelegate = constantWatchDelegate; |
| 12630 | } else if (oneTime) { |
| 12631 | //oneTime is not part of the exp passed to the Parser so we may have to |
| 12632 | //wrap the parsedExpression before adding a $$watchDelegate |
| 12633 | parsedExpression = wrapSharedExpression(parsedExpression); |
nothing calls this directly
no test coverage detected