@@ -769,15 +769,13 @@ function isConstant(ast) {
769
769
return ast . constant ;
770
770
}
771
771
772
- function ASTCompiler ( astBuilder , $filter ) {
773
- this . astBuilder = astBuilder ;
772
+ function ASTCompiler ( $filter ) {
774
773
this . $filter = $filter ;
775
774
}
776
775
777
776
ASTCompiler . prototype = {
778
- compile : function ( expression ) {
777
+ compile : function ( ast ) {
779
778
var self = this ;
780
- var ast = this . astBuilder . ast ( expression ) ;
781
779
this . state = {
782
780
nextId : 0 ,
783
781
filters : { } ,
@@ -832,8 +830,6 @@ ASTCompiler.prototype = {
832
830
ifDefined ,
833
831
plusFn ) ;
834
832
this . state = this . stage = undefined ;
835
- fn . literal = isLiteral ( ast ) ;
836
- fn . constant = isConstant ( ast ) ;
837
833
return fn ;
838
834
} ,
839
835
@@ -1236,15 +1232,13 @@ ASTCompiler.prototype = {
1236
1232
} ;
1237
1233
1238
1234
1239
- function ASTInterpreter ( astBuilder , $filter ) {
1240
- this . astBuilder = astBuilder ;
1235
+ function ASTInterpreter ( $filter ) {
1241
1236
this . $filter = $filter ;
1242
1237
}
1243
1238
1244
1239
ASTInterpreter . prototype = {
1245
- compile : function ( expression ) {
1240
+ compile : function ( ast ) {
1246
1241
var self = this ;
1247
- var ast = this . astBuilder . ast ( expression ) ;
1248
1242
findConstantAndWatchExpressions ( ast , self . $filter ) ;
1249
1243
var assignable ;
1250
1244
var assign ;
@@ -1283,8 +1277,6 @@ ASTInterpreter.prototype = {
1283
1277
if ( inputs ) {
1284
1278
fn . inputs = inputs ;
1285
1279
}
1286
- fn . literal = isLiteral ( ast ) ;
1287
- fn . constant = isConstant ( ast ) ;
1288
1280
return fn ;
1289
1281
} ,
1290
1282
@@ -1613,20 +1605,21 @@ ASTInterpreter.prototype = {
1613
1605
/**
1614
1606
* @constructor
1615
1607
*/
1616
- var Parser = function Parser ( lexer , $filter , options ) {
1617
- this . lexer = lexer ;
1618
- this . $filter = $filter ;
1619
- this . options = options ;
1608
+ function Parser ( lexer , $filter , options ) {
1620
1609
this . ast = new AST ( lexer , options ) ;
1621
- this . astCompiler = options . csp ? new ASTInterpreter ( this . ast , $filter ) :
1622
- new ASTCompiler ( this . ast , $filter ) ;
1623
- } ;
1610
+ this . astCompiler = options . csp ? new ASTInterpreter ( $filter ) :
1611
+ new ASTCompiler ( $filter ) ;
1612
+ }
1624
1613
1625
1614
Parser . prototype = {
1626
1615
constructor : Parser ,
1627
1616
1628
1617
parse : function ( text ) {
1629
- return this . astCompiler . compile ( text ) ;
1618
+ var ast = this . ast . ast ( text ) ;
1619
+ var fn = this . astCompiler . compile ( ast ) ;
1620
+ fn . literal = isLiteral ( ast ) ;
1621
+ fn . constant = isConstant ( ast ) ;
1622
+ return fn ;
1630
1623
}
1631
1624
} ;
1632
1625
0 commit comments