feat(transformers): collect information for CompileDiDependencyMetadata

This commit is contained in:
vsavkin
2016-02-26 12:43:38 -08:00
parent f60fa14767
commit 39b6e0efba
7 changed files with 146 additions and 12 deletions

View File

@ -185,9 +185,34 @@ class _CompileTypeMetadataVisitor extends Object
final typeToken = p is SimpleFormalParameter && p.type != null ? _readIdentifier(p.type.name) : null;
final injectTokens = p.metadata.where((m) => m.name.toString() == "Inject").map((m) => _readIdentifier(m.arguments.arguments[0]));
final token = injectTokens.isNotEmpty ? injectTokens.first : typeToken;
return new CompileDiDependencyMetadata(token: token);
final query = _hasAnnotation(p, "Query") ? _createQueryMetadata(_getAnnotation(p, "Query")) : null;
final viewQuery = _hasAnnotation(p, "ViewQuery") ? _createQueryMetadata(_getAnnotation(p, "ViewQuery")) : null;
return new CompileDiDependencyMetadata(
token: token,
isAttribute: _hasAnnotation(p, "Attribute"),
isSelf: _hasAnnotation(p, "Self"),
isHost: _hasAnnotation(p, "Host"),
isSkipSelf: _hasAnnotation(p, "SkipSelf"),
isOptional: _hasAnnotation(p, "Optional"),
query: query,
viewQuery: viewQuery);
}).toList();
}
_getAnnotation(p, String attrName) => p.metadata.where((m) => m.name.toString() == attrName).first;
_hasAnnotation(p, String attrName) => p.metadata.where((m) => m.name.toString() == attrName).isNotEmpty;
_createQueryMetadata(Annotation a) {
final selector = _readIdentifier(a.arguments.arguments.first);
var descendants = false;
a.arguments.arguments.skip(0).forEach((arg) {
if (arg is NamedExpression && arg.name.toString() == "descendants:")
descendants = naiveEval(arg.expression);
});
final selectors = selector is String ? selector.split(",") : [selector];
return new CompileQueryMetadata(selectors: selectors, descendants: descendants);
}
}

View File

@ -174,6 +174,12 @@ class _CompileDataCreator {
if (deps == null) return;
for (var dep in deps) {
dep.token = _resolveIdentifier(ngMetaMap, neededBy, dep.token);
if (dep.query != null) {
dep.query.selectors = dep.query.selectors.map((s) => _resolveIdentifier(ngMetaMap, neededBy, s)).toList();
}
if (dep.viewQuery != null) {
dep.viewQuery.selectors = dep.viewQuery.selectors.map((s) => _resolveIdentifier(ngMetaMap, neededBy, s)).toList();
}
}
}