Skip to content
This repository has been archived by the owner on Feb 22, 2018. It is now read-only.

Commit

Permalink
refactor(AstParser): make AstParser private, no more injectable
Browse files Browse the repository at this point in the history
follow up for #788

Closes #818
  • Loading branch information
vicb authored and mhevery committed Mar 31, 2014
1 parent 1e67cbb commit b8ad7b6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
1 change: 0 additions & 1 deletion lib/core/module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class NgCoreModule extends Module {
type(ScopeStatsEmitter);
factory(ScopeStatsConfig, (i) => new ScopeStatsConfig());
value(Object, {}); // RootScope context
type(AstParser);
type(NgZone);

type(Parser, implementedBy: DynamicParser);
Expand Down
19 changes: 9 additions & 10 deletions lib/core/scope.dart
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ class RootScope extends Scope {
static final STATE_FLUSH_ASSERT = 'assert';

final ExceptionHandler _exceptionHandler;
final AstParser _astParser;
final _AstParser _astParser;
final Parser _parser;
final ScopeDigestTTL _ttl;
final NgZone _zone;
Expand All @@ -529,7 +529,7 @@ class RootScope extends Scope {
ScopeStats _scopeStats)
: _scopeStats = _scopeStats,
_parser = parser,
_astParser = new AstParser(parser),
_astParser = new _AstParser(parser),
super(context, null, null,
new RootWatchGroup(fieldGetterFactory,
new DirtyCheckingChangeDetector(fieldGetterFactory), context),
Expand Down Expand Up @@ -948,25 +948,24 @@ class _FunctionChain {
}
}

@NgInjectableService()
class AstParser {
class _AstParser {
final Parser _parser;
int _id = 0;
ExpressionVisitor _visitor = new ExpressionVisitor();

AstParser(this._parser);
_AstParser(this._parser);

AST call(String exp, { FilterMap filters,
bool collection: false,
Object context: null }) {
AST call(String input, {FilterMap filters,
bool collection: false,
Object context: null }) {
_visitor.filters = filters;
AST contextRef = _visitor.contextRef;
try {
if (context != null) {
_visitor.contextRef = new ConstantAST(context, '#${_id++}');
}
var ast = _parser(exp);
return collection ? _visitor.visitCollection(ast) : _visitor.visit(ast);
var exp = _parser(input);
return collection ? _visitor.visitCollection(exp) : _visitor.visit(exp);
} finally {
_visitor.contextRef = contextRef;
_visitor.filters = null;
Expand Down
1 change: 0 additions & 1 deletion test/angular_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ main() {
"angular.core.UnboundedCache", // internal?
"angular.core.ScopeStream", // internal?
"angular.core.FilterMap", // internal?
"angular.core.AstParser", // internal?
"angular.watch_group.FunctionApply", // internal?
"angular.watch_group.WatchGroup", // internal?
"angular.watch_group.ContextReferenceAST", // internal?
Expand Down
8 changes: 5 additions & 3 deletions test/change_detection/watch_group_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,20 @@ void main() {
var watchGrp;
DirtyCheckingChangeDetector changeDetector;
Logger logger;
AstParser parser;
Parser parser;
ExpressionVisitor visitor;

beforeEach(inject((Logger _logger, AstParser _parser) {
beforeEach(inject((Logger _logger, Parser _parser) {
context = {};
var getterFactory = new DynamicFieldGetterFactory();
changeDetector = new DirtyCheckingChangeDetector(getterFactory);
watchGrp = new RootWatchGroup(getterFactory, changeDetector, context);
visitor = new ExpressionVisitor();
logger = _logger;
parser = _parser;
}));

AST parse(String expression) => parser(expression);
AST parse(String expression) => visitor.visit(parser(expression));

eval(String expression, [evalContext]) {
AST ast = parse(expression);
Expand Down

0 comments on commit b8ad7b6

Please sign in to comment.