MCPcopy Create free account
hub / github.com/angular-ui/ui-router / $ParseProvider

Function $ParseProvider

test/angular/1.3/angular.js:12757–13004  ·  view source on GitHub ↗

* @ngdoc provider * @name $parseProvider * * @description * `$parseProvider` can be used for configuring the default behavior of the ng.$parse $parse * service.

()

Source from the content-addressed store, hash-verified

12755 * service.
12756 */
12757function $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);

Callers

nothing calls this directly

Calls 3

wrapSharedExpressionFunction · 0.85
createMapFunction · 0.70
addInterceptorFunction · 0.70

Tested by

no test coverage detected