(parsedExpression, interceptorFn)
| 17605 | } |
| 17606 | |
| 17607 | function addInterceptor(parsedExpression, interceptorFn) { |
| 17608 | if (!interceptorFn) return parsedExpression; |
| 17609 | |
| 17610 | // Extract any existing interceptors out of the parsedExpression |
| 17611 | // to ensure the original parsedExpression is always the $$intercepted |
| 17612 | if (parsedExpression.$$interceptor) { |
| 17613 | interceptorFn = chainInterceptors(parsedExpression.$$interceptor, interceptorFn); |
| 17614 | parsedExpression = parsedExpression.$$intercepted; |
| 17615 | } |
| 17616 | |
| 17617 | var useInputs = false; |
| 17618 | |
| 17619 | var fn = function interceptedExpression(scope, locals, assign, inputs) { |
| 17620 | var value = useInputs && inputs ? inputs[0] : parsedExpression(scope, locals, assign, inputs); |
| 17621 | return interceptorFn(value); |
| 17622 | }; |
| 17623 | |
| 17624 | // Maintain references to the interceptor/intercepted |
| 17625 | fn.$$intercepted = parsedExpression; |
| 17626 | fn.$$interceptor = interceptorFn; |
| 17627 | |
| 17628 | // Propogate the literal/oneTime/constant attributes |
| 17629 | fn.literal = parsedExpression.literal; |
| 17630 | fn.oneTime = parsedExpression.oneTime; |
| 17631 | fn.constant = parsedExpression.constant; |
| 17632 | |
| 17633 | // Treat the interceptor like filters. |
| 17634 | // If it is not $stateful then only watch its inputs. |
| 17635 | // If the expression itself has no inputs then use the full expression as an input. |
| 17636 | if (!interceptorFn.$stateful) { |
| 17637 | useInputs = !parsedExpression.inputs; |
| 17638 | fn.inputs = parsedExpression.inputs ? parsedExpression.inputs : [parsedExpression]; |
| 17639 | |
| 17640 | if (!interceptorFn.$$pure) { |
| 17641 | fn.inputs = fn.inputs.map(function(e) { |
| 17642 | // Remove the isPure flag of inputs when it is not absolute because they are now wrapped in a |
| 17643 | // non-pure interceptor function. |
| 17644 | if (e.isPure === PURITY_RELATIVE) { |
| 17645 | return function depurifier(s) { return e(s); }; |
| 17646 | } |
| 17647 | return e; |
| 17648 | }); |
| 17649 | } |
| 17650 | } |
| 17651 | |
| 17652 | return addWatchDelegate(fn); |
| 17653 | } |
| 17654 | }]; |
| 17655 | } |
| 17656 |
no test coverage detected