@@ -622,6 +622,9 @@ function isStateless($filter, filterName) {
622
622
return ! fn . $stateful ;
623
623
}
624
624
625
+ var PURITY_ABSOLUTE = 1 ;
626
+ var PURITY_RELATIVE = 2 ;
627
+
625
628
// Detect nodes which could depend on non-shallow state of objects
626
629
function isPure ( node , parentIsPure ) {
627
630
switch ( node . type ) {
@@ -634,18 +637,18 @@ function isPure(node, parentIsPure) {
634
637
635
638
// Unary always convert to primative
636
639
case AST . UnaryExpression :
637
- return true ;
640
+ return PURITY_ABSOLUTE ;
638
641
639
642
// The binary + operator can invoke a stateful toString().
640
643
case AST . BinaryExpression :
641
- return node . operator !== '+' ;
644
+ return node . operator !== '+' ? PURITY_ABSOLUTE : false ;
642
645
643
646
// Functions / filters probably read state from within objects
644
647
case AST . CallExpression :
645
648
return false ;
646
649
}
647
650
648
- return ( undefined === parentIsPure ) || parentIsPure ;
651
+ return ( undefined === parentIsPure ) ? PURITY_RELATIVE : parentIsPure ;
649
652
}
650
653
651
654
function findConstantAndWatchExpressions ( ast , $filter , parentIsPure ) {
@@ -873,7 +876,7 @@ ASTCompiler.prototype = {
873
876
forEach ( inputs , function ( input ) {
874
877
result . push ( 'var ' + input . name + '=' + self . generateFunction ( input . name , 's' ) ) ;
875
878
if ( input . isPure ) {
876
- result . push ( input . name , '.isPure=true ;' ) ;
879
+ result . push ( input . name , '.isPure=' + JSON . stringify ( input . isPure ) + ' ;') ;
877
880
}
878
881
} ) ;
879
882
if ( inputs . length ) {
@@ -1960,10 +1963,16 @@ function $ParseProvider() {
1960
1963
fn . $$watchDelegate = watchDelegate ;
1961
1964
fn . inputs = parsedExpression . inputs ;
1962
1965
} else if ( ! interceptorFn . $stateful ) {
1963
- // If there is an interceptor, but no watchDelegate then treat the interceptor like
1964
- // we treat filters - it is assumed to be a pure function unless flagged with $stateful
1966
+ // Treat interceptor like filters - assume non-stateful by default and use the inputsWatchDelegate
1965
1967
fn . $$watchDelegate = inputsWatchDelegate ;
1966
- fn . inputs = parsedExpression . inputs ? parsedExpression . inputs : [ parsedExpression ] ;
1968
+ fn . inputs = ( parsedExpression . inputs ? parsedExpression . inputs : [ parsedExpression ] ) . map ( function ( e ) {
1969
+ // Remove the isPure flag of inputs when it is not absolute because they are now wrapped in a
1970
+ // potentially non-pure interceptor function.
1971
+ if ( e . isPure === PURITY_RELATIVE ) {
1972
+ return function depurifier ( s ) { return e ( s ) ; } ;
1973
+ }
1974
+ return e ;
1975
+ } ) ;
1967
1976
}
1968
1977
1969
1978
return fn ;
0 commit comments