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

refactor(AstParser): make AstParser private, no more injectable #818

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -507,7 +507,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 @@ -525,7 +525,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 @@ -944,25 +944,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