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

Commit 5205c14

Browse files
alexdembrkirov
authored andcommitted
fix(source_metadata_extractor): Fixed problem with processing Component and Decorator annotations when named import is used.
1 parent 47ae01c commit 5205c14

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

lib/tools/source_metadata_extractor.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ class SourceMetadataExtractor {
9595
class DirectiveMetadataCollectingAstVisitor extends RecursiveAstVisitor {
9696
final List<DirectiveMetadata> metadata;
9797
final List<String> templates;
98+
final RegExp _COMPONENT_OR_DECORATOR_EXPR = new RegExp(r"\.?(Component|Decorator)$");
9899

99100
DirectiveMetadataCollectingAstVisitor(this.metadata, this.templates);
100101

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

125127
var meta = new DirectiveMetadata()..className = clazz.name.name;
126128
metadata.add(meta);

test/tools/transformer/expression_generator_spec.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,28 @@ main() {
177177
htmlFiles.clear();
178178
});
179179
});
180+
181+
it('should extract functions as getters when named import is used', () {
182+
return generates(phases,
183+
inputs: {
184+
'a|web/main.dart': '''
185+
import 'package:angular/angular.dart' as ng;
186+
187+
@ng.Component(selector: 'cmp', template: '{{foo}}')
188+
class TestComponent {
189+
String foo = "foo";
190+
}
191+
192+
main() {} ''',
193+
'a|web/index.html': '''
194+
<cmp></cmp>
195+
<script src='main.dart' type='application/dart'></script>''',
196+
'angular|lib/angular.dart': libAngular,
197+
},
198+
getters: ['foo'],
199+
setters: ['foo'],
200+
symbols: []);
201+
});
180202
});
181203
}
182204

0 commit comments

Comments
 (0)