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

Commit 6c4d52b

Browse files
Ted Sanderrkirov
authored andcommitted
feat(expression_transformer): Parse NgTemplateCache values
Parse html files from NgTemplateCache annotations for expressions, allowing developers the ease of including files needed to be parsed without specifying them individually in the pubspec.yaml definition. Closes #1644
1 parent 03044ff commit 6c4d52b

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

lib/tools/transformer/expression_generator.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ class ExpressionGenerator extends Transformer with ResolverTransformer {
8484
.toList();
8585

8686
// Get all of the contents of templates in @Component(templateUrl:'...')
87-
gatherReferencedUris(transform, resolver, options,
88-
templatesOnly: true).then((templates) {
87+
gatherReferencedUris(transform, resolver, options).then((templates) {
8988
templates.values.forEach(controller.add);
9089
}).then((_) {
9190
// Add any HTML files referencing this Dart file.

test/tools/transformer/expression_generator_spec.dart

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,33 @@ main() {
9292
symbols: []);
9393
});
9494

95+
it('should follow template cache uris', () {
96+
return generates(phases,
97+
inputs: {
98+
'a|web/main.dart': '''
99+
import 'package:angular/angular.dart';
100+
import 'package:angular/cacheAnnotation.dart';
101+
102+
@NgTemplateCache(
103+
preCacheUrls: ['lib/foo.html', 'packages/b/bar.html'])
104+
class FooClass {}
105+
106+
main() {}
107+
''',
108+
'a|lib/foo.html': '''
109+
<div>{{template.contents}}</div>''',
110+
'b|lib/bar.html': '''
111+
<div>{{bar}}</div>''',
112+
'a|web/index.html': '''
113+
<script src='main.dart' type='application/dart'></script>''',
114+
'angular|lib/angular.dart': libAngular,
115+
'angular|lib/cacheAnnotation.dart': libCacheAnnotation,
116+
},
117+
getters: ['template', 'contents', 'bar'],
118+
setters: ['template', 'contents', 'bar'],
119+
symbols: []);
120+
});
121+
95122
it('should generate expressions for variables found in superclass', () {
96123
return generates(phases,
97124
inputs: {
@@ -248,3 +275,11 @@ class NgAttr {
248275
const NgAttr(String attrName);
249276
}
250277
''';
278+
279+
const String libCacheAnnotation = '''
280+
library angular.template_cache_annotation;
281+
282+
class NgTemplateCache {
283+
const NgTemplateCache({List preCacheUrls, bool cache});
284+
}
285+
''';

0 commit comments

Comments
 (0)