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

Commit

Permalink
fix(source_metadata_extractor): Fixed problem with processing Compone…
Browse files Browse the repository at this point in the history
…nt and Decorator annotations when named import is used.
  • Loading branch information
alexdemb authored and rkirov committed Jan 14, 2015
1 parent 47ae01c commit 5205c14
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/tools/source_metadata_extractor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class SourceMetadataExtractor {
class DirectiveMetadataCollectingAstVisitor extends RecursiveAstVisitor {
final List<DirectiveMetadata> metadata;
final List<String> templates;
final RegExp _COMPONENT_OR_DECORATOR_EXPR = new RegExp(r"\.?(Component|Decorator)$");

DirectiveMetadataCollectingAstVisitor(this.metadata, this.templates);

Expand All @@ -120,7 +121,8 @@ class DirectiveMetadataCollectingAstVisitor extends RecursiveAstVisitor {
if (ann.arguments == null) return; // Ignore non-class annotations.
// TODO(pavelj): this is not a safe check for the type of the
// annotations, but good enough for now.
if (ann.name.name != 'Component' && ann.name.name != 'Decorator') return;
if (!_COMPONENT_OR_DECORATOR_EXPR.hasMatch(ann.name.name))
return;

var meta = new DirectiveMetadata()..className = clazz.name.name;
metadata.add(meta);
Expand Down
22 changes: 22 additions & 0 deletions test/tools/transformer/expression_generator_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,28 @@ main() {
htmlFiles.clear();
});
});

it('should extract functions as getters when named import is used', () {
return generates(phases,
inputs: {
'a|web/main.dart': '''
import 'package:angular/angular.dart' as ng;
@ng.Component(selector: 'cmp', template: '{{foo}}')
class TestComponent {
String foo = "foo";
}
main() {} ''',
'a|web/index.html': '''
<cmp></cmp>
<script src='main.dart' type='application/dart'></script>''',
'angular|lib/angular.dart': libAngular,
},
getters: ['foo'],
setters: ['foo'],
symbols: []);
});
});
}

Expand Down

0 comments on commit 5205c14

Please sign in to comment.