From b8ad7b64a9b01e218037ac8bea9f5dbbd4730611 Mon Sep 17 00:00:00 2001 From: Victor Date: Mon, 31 Mar 2014 10:31:28 +0200 Subject: [PATCH] refactor(AstParser): make AstParser private, no more injectable follow up for #788 Closes #818 --- lib/core/module.dart | 1 - lib/core/scope.dart | 19 +++++++++---------- test/angular_spec.dart | 1 - test/change_detection/watch_group_spec.dart | 8 +++++--- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/lib/core/module.dart b/lib/core/module.dart index 0843d8206..72b500abe 100644 --- a/lib/core/module.dart +++ b/lib/core/module.dart @@ -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); diff --git a/lib/core/scope.dart b/lib/core/scope.dart index 730acf447..2893e67d1 100644 --- a/lib/core/scope.dart +++ b/lib/core/scope.dart @@ -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; @@ -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), @@ -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; diff --git a/test/angular_spec.dart b/test/angular_spec.dart index 968b7bbb6..b56c1c619 100644 --- a/test/angular_spec.dart +++ b/test/angular_spec.dart @@ -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? diff --git a/test/change_detection/watch_group_spec.dart b/test/change_detection/watch_group_spec.dart index d6eac2dfa..83e60801a 100644 --- a/test/change_detection/watch_group_spec.dart +++ b/test/change_detection/watch_group_spec.dart @@ -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);