@@ -19,8 +19,8 @@ import 'package:code_transformers/assets.dart';
1919///
2020/// The returned value wraps the [NgDeps] at `entryPoint` as well as these
2121/// created objects.
22- Future <CompileDataResults > createCompileData (
23- AssetReader reader, AssetId entryPoint) async {
22+ Future <CompileDataResults > createCompileData (AssetReader reader,
23+ AssetId entryPoint) async {
2424 return new _CompileDataCreator (reader, entryPoint).createCompileData ();
2525}
2626
@@ -43,6 +43,14 @@ bool _isViewAnnotation(InstanceCreationExpression node) {
4343 return constructorName.name == 'View' ;
4444}
4545
46+ bool _isComponentAnnotation (InstanceCreationExpression node) {
47+ var constructorName = node.constructorName.type.name;
48+ if (constructorName is PrefixedIdentifier ) {
49+ constructorName = constructorName.identifier;
50+ }
51+ return constructorName.name == 'Component' ;
52+ }
53+
4654/// Creates [ViewDefinition] objects for all `View` `Directive` s defined in
4755/// `entryPoint` .
4856class _CompileDataCreator {
@@ -68,6 +76,7 @@ class _CompileDataCreator {
6876 // Note: we use '' because the current file maps to the default prefix.
6977 var ngMeta = visitor._metadataMap['' ];
7078 var typeName = '${rType .typeName }' ;
79+
7180 if (ngMeta.types.containsKey (typeName)) {
7281 visitor.compileData.component = ngMeta.types[typeName];
7382 } else {
@@ -161,7 +170,6 @@ class _CompileDataCreator {
161170 return retVal;
162171 }
163172}
164-
165173/// Visitor responsible for processing the `annotations` property of a
166174/// [RegisterType] object, extracting the `directives` dependencies, and adding
167175/// their associated [CompileDirectiveMetadata] to the `directives` of a
@@ -187,7 +195,8 @@ class _DirectiveDependenciesVisitor extends Object
187195 /// reflector.
188196 @override
189197 Object visitInstanceCreationExpression (InstanceCreationExpression node) {
190- if (_isViewAnnotation (node)) {
198+ // if (_isViewAnnotation(node)) {
199+ if (_isViewAnnotation (node) || _isComponentAnnotation (node)) {
191200 compileData = new NormalizedComponentWithViewDirectives (
192201 null , < CompileDirectiveMetadata > []);
193202 node.visitChildren (this );
@@ -202,7 +211,7 @@ class _DirectiveDependenciesVisitor extends Object
202211 if (node.name is ! Label || node.name.label is ! SimpleIdentifier ) {
203212 logger.error (
204213 'Angular 2 currently only supports simple identifiers in directives.'
205- ' Source: ${node }' );
214+ ' Source: ${node }' );
206215 return null ;
207216 }
208217 if ('${node .name .label }' == 'directives' ) {
@@ -234,7 +243,7 @@ class _DirectiveDependenciesVisitor extends Object
234243 } else {
235244 logger.error (
236245 'Angular 2 currently only supports simple and prefixed identifiers '
237- 'as values for "directives". Source: $node ' );
246+ 'as values for "directives". Source: $node ' );
238247 return ;
239248 }
240249 if (ngMeta.types.containsKey (name)) {
0 commit comments