Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 584308f

Browse files
jbedardNarretz
authored andcommitted
refactor($parse): move duplicate $parse interpreter/compiler logic into Parser
- the construction of the AST is now in the Parser - the assigning of the literal and constant flags is now in the Parser - remove unused references to the lexer, $filter and options on the Parser
1 parent 48ad2c4 commit 584308f

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

src/ng/parse.js

+13-20
Original file line numberDiff line numberDiff line change
@@ -769,15 +769,13 @@ function isConstant(ast) {
769769
return ast.constant;
770770
}
771771

772-
function ASTCompiler(astBuilder, $filter) {
773-
this.astBuilder = astBuilder;
772+
function ASTCompiler($filter) {
774773
this.$filter = $filter;
775774
}
776775

777776
ASTCompiler.prototype = {
778-
compile: function(expression) {
777+
compile: function(ast) {
779778
var self = this;
780-
var ast = this.astBuilder.ast(expression);
781779
this.state = {
782780
nextId: 0,
783781
filters: {},
@@ -832,8 +830,6 @@ ASTCompiler.prototype = {
832830
ifDefined,
833831
plusFn);
834832
this.state = this.stage = undefined;
835-
fn.literal = isLiteral(ast);
836-
fn.constant = isConstant(ast);
837833
return fn;
838834
},
839835

@@ -1236,15 +1232,13 @@ ASTCompiler.prototype = {
12361232
};
12371233

12381234

1239-
function ASTInterpreter(astBuilder, $filter) {
1240-
this.astBuilder = astBuilder;
1235+
function ASTInterpreter($filter) {
12411236
this.$filter = $filter;
12421237
}
12431238

12441239
ASTInterpreter.prototype = {
1245-
compile: function(expression) {
1240+
compile: function(ast) {
12461241
var self = this;
1247-
var ast = this.astBuilder.ast(expression);
12481242
findConstantAndWatchExpressions(ast, self.$filter);
12491243
var assignable;
12501244
var assign;
@@ -1283,8 +1277,6 @@ ASTInterpreter.prototype = {
12831277
if (inputs) {
12841278
fn.inputs = inputs;
12851279
}
1286-
fn.literal = isLiteral(ast);
1287-
fn.constant = isConstant(ast);
12881280
return fn;
12891281
},
12901282

@@ -1613,20 +1605,21 @@ ASTInterpreter.prototype = {
16131605
/**
16141606
* @constructor
16151607
*/
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) {
16201609
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+
}
16241613

16251614
Parser.prototype = {
16261615
constructor: Parser,
16271616

16281617
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;
16301623
}
16311624
};
16321625

0 commit comments

Comments
 (0)