@@ -716,9 +716,9 @@ ASTCompiler.prototype = {
716
716
nextId : 0 ,
717
717
filters : { } ,
718
718
expensiveChecks : expensiveChecks ,
719
- closure : { vars : [ 'clean' ] , fns : { } } ,
720
719
fn : { vars : [ ] , body : [ ] , own : { } } ,
721
- assign : { vars : [ ] , body : [ ] , own : { } }
720
+ assign : { vars : [ ] , body : [ ] , own : { } } ,
721
+ inputs : [ ]
722
722
} ;
723
723
var lastExpression ;
724
724
var i ;
@@ -728,22 +728,19 @@ ASTCompiler.prototype = {
728
728
var toWatch = useInputs ( ast . body ) ? ast . body [ ast . body . length - 1 ] . expression . toWatch : [ ] ;
729
729
forEach ( toWatch , function ( watch , key ) {
730
730
var fnKey = 'fn' + key ;
731
- self . state . computing = 'closure' ;
732
- watch . fixedId = self . nextId ( ) ;
733
- watch . skipClean = true ;
734
- self . state . closure . fns [ fnKey ] = self . state [ fnKey ] = { vars : [ ] , body : [ ] , own : { } } ;
731
+ self . state [ fnKey ] = { vars : [ ] , body : [ ] , own : { } } ;
735
732
self . state . computing = fnKey ;
736
- self . recurse ( watch ) ;
737
- self . assign ( 'clean' , true ) ;
738
- self . return ( watch . fixedId ) ;
739
- watch . skipClean = false ;
733
+ var intoId = self . nextId ( ) ;
734
+ self . recurse ( watch , intoId ) ;
735
+ self . return ( intoId ) ;
736
+ self . state . inputs . push ( fnKey ) ;
737
+ watch . watchId = key ;
740
738
} ) ;
741
739
this . state . computing = 'fn' ;
742
740
for ( i = 0 ; i < ast . body . length ; ++ i ) {
743
741
if ( lastExpression ) this . current ( ) . body . push ( lastExpression , ';' ) ;
744
742
this . recurse ( ast . body [ i ] . expression , undefined , undefined , function ( expr ) { lastExpression = expr ; } ) ;
745
743
}
746
- this . assign ( 'clean' , false ) ;
747
744
if ( lastExpression ) this . return ( lastExpression ) ;
748
745
var extra = '' ;
749
746
if ( ast . body . length === 1 && isAssignable ( ast . body [ 0 ] . expression ) ) {
@@ -757,20 +754,17 @@ ASTCompiler.prototype = {
757
754
}
758
755
var fnString =
759
756
// The build and minification steps remove the string "use strict" from the code, but this is done using a regex.
760
- // This is a woraround for this until we do a better job at only removing the prefix only when we should.
757
+ // This is a workaround for this until we do a better job at only removing the prefix only when we should.
761
758
'"' + this . USE + ' ' + this . STRICT + '";\n' +
762
759
this . filterPrefix ( ) +
763
- 'return function(){' +
764
- this . varsPrefix ( 'closure' ) +
765
- 'var fn = function(s,l){' +
760
+ 'var fn = function(s,l,i){' +
766
761
this . varsPrefix ( 'fn' ) +
767
762
this . body ( 'fn' ) +
768
763
'};' +
769
764
extra +
770
765
this . watchFns ( ) +
771
766
'fn.literal=literal;fn.constant=constant;' +
772
- 'return fn;' +
773
- '};' ;
767
+ 'return fn;' ;
774
768
775
769
var isLiteral = ast . body . length === 1 && (
776
770
ast . body [ 0 ] . expression . type === AST . Literal ||
@@ -810,10 +804,9 @@ ASTCompiler.prototype = {
810
804
811
805
watchFns : function ( ) {
812
806
var result = [ ] ;
813
- var fns = [ ] ;
807
+ var fns = this . state . inputs ;
814
808
var self = this ;
815
- forEach ( this . state . closure . fns , function ( _ , name ) {
816
- fns . push ( name ) ;
809
+ forEach ( fns , function ( name ) {
817
810
result . push (
818
811
'var ' + name + ' = function(s,l){' +
819
812
self . varsPrefix ( name ) +
@@ -877,24 +870,24 @@ ASTCompiler.prototype = {
877
870
break ;
878
871
case AST . LogicalExpression :
879
872
intoId = intoId || this . nextId ( ) ;
880
- this . if ( ast . fixedId && ! ast . skipClean ? '!clean ' : true , function ( ) {
873
+ this . if ( isDefined ( ast . watchId ) ? '!i ' : true , function ( ) {
881
874
self . recurse ( ast . left , intoId ) ;
882
875
self . if ( ast . operator === '&&' ? intoId : self . not ( intoId ) , self . lazyRecurse ( ast . right , intoId ) ) ;
883
876
recursionFn ( intoId ) ;
884
877
self . assign ( ast . fixedId , intoId ) ;
885
878
} , function ( ) {
886
- self . assign ( intoId , ast . fixedId ) ;
879
+ self . assign ( intoId , self . computedMember ( 'i' , ast . watchId ) ) ;
887
880
} ) ;
888
881
break ;
889
882
case AST . ConditionalExpression :
890
883
intoId = intoId || this . nextId ( ) ;
891
- this . if ( ast . fixedId && ! ast . skipClean ? '!clean ' : true , function ( ) {
884
+ this . if ( isDefined ( ast . watchId ) ? '!i ' : true , function ( ) {
892
885
self . recurse ( ast . test , intoId ) ;
893
886
self . if ( intoId , self . lazyRecurse ( ast . alternate , intoId ) , self . lazyRecurse ( ast . consequent , intoId ) ) ;
894
887
recursionFn ( intoId ) ;
895
888
self . assign ( ast . fixedId , intoId ) ;
896
889
} , function ( ) {
897
- self . assign ( intoId , ast . fixedId ) ;
890
+ self . assign ( intoId , self . computedMember ( 'i' , ast . watchId ) ) ;
898
891
} ) ;
899
892
break ;
900
893
case AST . Identifier :
@@ -904,7 +897,7 @@ ASTCompiler.prototype = {
904
897
nameId . computed = false ;
905
898
nameId . name = ast . name ;
906
899
}
907
- this . if ( ast . fixedId && ! ast . skipClean ? '!clean ' : true , function ( ) {
900
+ this . if ( isDefined ( ast . watchId ) ? '!i ' : true , function ( ) {
908
901
ensureSafeMemberName ( ast . name ) ;
909
902
self . if ( self . not ( self . getHasOwnProperty ( 'l' , ast . name ) ) ,
910
903
function ( ) {
@@ -924,13 +917,13 @@ ASTCompiler.prototype = {
924
917
recursionFn ( intoId ) ;
925
918
self . assign ( ast . fixedId , intoId ) ;
926
919
} , function ( ) {
927
- self . assign ( intoId , ast . fixedId ) ;
920
+ self . assign ( intoId , self . computedMember ( 'i' , ast . watchId ) ) ;
928
921
} ) ;
929
922
break ;
930
923
case AST . MemberExpression :
931
924
left = nameId && ( nameId . context = this . nextId ( ) ) || this . nextId ( ) ;
932
925
intoId = intoId || this . nextId ( ) ;
933
- this . if ( ast . fixedId && ! ast . skipClean ? '!clean ' : true , function ( ) {
926
+ this . if ( isDefined ( ast . watchId ) ? '!i ' : true , function ( ) {
934
927
self . recurse ( ast . object , left , undefined , function ( ) {
935
928
self . if ( self . notNull ( left ) , function ( ) {
936
929
if ( ast . computed ) {
@@ -966,12 +959,12 @@ ASTCompiler.prototype = {
966
959
} , ! ! create ) ;
967
960
self . assign ( ast . fixedId , intoId ) ;
968
961
} , function ( ) {
969
- self . assign ( intoId , ast . fixedId ) ;
962
+ self . assign ( intoId , self . computedMember ( 'i' , ast . watchId ) ) ;
970
963
} ) ;
971
964
break ;
972
965
case AST . CallExpression :
973
966
intoId = intoId || this . nextId ( ) ;
974
- this . if ( ast . fixedId && ! ast . skipClean ? '!clean ' : true , function ( ) {
967
+ this . if ( isDefined ( ast . watchId ) ? '!i ' : true , function ( ) {
975
968
if ( ast . filter ) {
976
969
right = self . filter ( ast . callee . name ) ;
977
970
args = [ ] ;
@@ -1011,7 +1004,7 @@ ASTCompiler.prototype = {
1011
1004
}
1012
1005
self . assign ( ast . fixedId , intoId ) ;
1013
1006
} , function ( ) {
1014
- self . assign ( intoId , ast . fixedId ) ;
1007
+ self . assign ( intoId , self . computedMember ( 'i' , ast . watchId ) ) ;
1015
1008
} ) ;
1016
1009
break ;
1017
1010
case AST . AssignmentExpression :
@@ -1261,7 +1254,7 @@ ASTInterpreter.prototype = {
1261
1254
ast . body [ 0 ] . expression . type === AST . ArrayExpression ||
1262
1255
ast . body [ 0 ] . expression . type === AST . ObjectExpression ) ;
1263
1256
fn . constant = ast . body . length === 1 && ast . body [ 0 ] . expression . constant ;
1264
- return valueFn ( fn ) ;
1257
+ return fn ;
1265
1258
} ,
1266
1259
1267
1260
recurse : function ( ast , context , create ) {
@@ -1691,7 +1684,7 @@ function $ParseProvider() {
1691
1684
expressionFactory = parser . parse ( exp ) ;
1692
1685
cache [ cacheKey ] = expressionFactory ;
1693
1686
}
1694
- parsedExpression = expressionFactory ( ) ;
1687
+ parsedExpression = expressionFactory ;
1695
1688
if ( parsedExpression . constant ) {
1696
1689
parsedExpression . $$watchDelegate = constantWatchDelegate ;
1697
1690
} else if ( oneTime ) {
@@ -1745,7 +1738,7 @@ function $ParseProvider() {
1745
1738
return scope . $watch ( function expressionInputWatch ( scope ) {
1746
1739
var newInputValue = inputExpressions ( scope ) ;
1747
1740
if ( ! expressionInputDirtyCheck ( newInputValue , oldInputValue ) ) {
1748
- lastResult = parsedExpression ( scope ) ;
1741
+ lastResult = parsedExpression ( scope , undefined , [ newInputValue ] ) ;
1749
1742
oldInputValue = newInputValue && getValueOf ( newInputValue ) ;
1750
1743
}
1751
1744
return lastResult ;
@@ -1768,7 +1761,7 @@ function $ParseProvider() {
1768
1761
}
1769
1762
1770
1763
if ( changed ) {
1771
- lastResult = parsedExpression ( scope ) ;
1764
+ lastResult = parsedExpression ( scope , undefined , oldInputValueOfValues ) ;
1772
1765
}
1773
1766
1774
1767
return lastResult ;
0 commit comments