@@ -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 ) {
@@ -1963,7 +1966,14 @@ function $ParseProvider() {
1963
1966
// If there is an interceptor, but no watchDelegate then treat the interceptor like
1964
1967
// we treat filters - it is assumed to be a pure function unless flagged with $stateful
1965
1968
fn . $$watchDelegate = inputsWatchDelegate ;
1966
- fn . inputs = parsedExpression . inputs ? parsedExpression . inputs : [ parsedExpression ] ;
1969
+ fn . inputs = ( parsedExpression . inputs ? parsedExpression . inputs : [ parsedExpression ] ) . map ( function ( e ) {
1970
+ // Remove the isPure flag of inputs when it is not absolute because they are now wrapped in a
1971
+ // potentially non-pure interceptor function.
1972
+ if ( e . isPure === PURITY_RELATIVE ) {
1973
+ return function depurifier ( s ) { return e ( s ) ; } ;
1974
+ }
1975
+ return e ;
1976
+ } ) ;
1967
1977
}
1968
1978
1969
1979
return fn ;
0 commit comments