From f918d4dd9ac7c777b0197a700fd6af58103e4129 Mon Sep 17 00:00:00 2001 From: Tommy Fortes Date: Fri, 28 Feb 2014 16:56:29 -0800 Subject: [PATCH] fix(template_cache_generator): support traversal of partial files Fixes #662 --- lib/tools/template_cache_generator.dart | 13 +++++++++--- test/io/test_files/templates/main.dart | 26 +++-------------------- test/io/test_files/templates/partial.dart | 26 +++++++++++++++++++++++ 3 files changed, 39 insertions(+), 26 deletions(-) create mode 100644 test/io/test_files/templates/partial.dart diff --git a/lib/tools/template_cache_generator.dart b/lib/tools/template_cache_generator.dart index 3c896b8c3..1ad8719f9 100644 --- a/lib/tools/template_cache_generator.dart +++ b/lib/tools/template_cache_generator.dart @@ -118,7 +118,15 @@ class TemplateCollectingVisitor { TemplateCollectingVisitor(this.templates, this.blacklistedClasses, this.sourceCrawler); - call(CompilationUnitElement cue, String srcPath) { + void call(CompilationUnitElement cue, String srcPath) { + processDeclarations(cue, srcPath); + + cue.enclosingElement.parts.forEach((CompilationUnitElement part) { + processDeclarations(part, srcPath); + }); + } + + void processDeclarations(CompilationUnitElement cue, String srcPath) { CompilationUnit cu = sourceCrawler.context .resolveCompilationUnit(cue.source, cue.library); cu.declarations.forEach((CompilationUnitMember declaration) { @@ -166,8 +174,7 @@ class TemplateCollectingVisitor { }); } - bool extractNgTemplateCache( - Annotation ann, List cacheUris) { + bool extractNgTemplateCache(Annotation ann, List cacheUris) { bool cache = true; ann.arguments.arguments.forEach((Expression arg) { if (arg is NamedExpression) { diff --git a/test/io/test_files/templates/main.dart b/test/io/test_files/templates/main.dart index 7e9cd6e4f..fa256b2a9 100644 --- a/test/io/test_files/templates/main.dart +++ b/test/io/test_files/templates/main.dart @@ -3,27 +3,7 @@ library test_files.main; import 'package:angular/core/module.dart'; import 'package:angular/tools/template_cache_annotation.dart'; -@NgComponent( - selector: 'my-component', - templateUrl: '/test/io/test_files/templates/main.html') -@NgTemplateCache() -class MyComponent -{ -} +part 'partial.dart'; -@NgComponent( - selector: 'my-component2', - templateUrl: '/test/io/test_files/templates/dont.html') -@NgTemplateCache(cache: false) -class MyComponent2 -{ -} - - -@NgComponent( - selector: 'my-component3', - templateUrl: '/test/io/test_files/templates/dont.html') -@NgTemplateCache(cache: true) -class MyComponent3 -{ -} +class MainClass { +} \ No newline at end of file diff --git a/test/io/test_files/templates/partial.dart b/test/io/test_files/templates/partial.dart new file mode 100644 index 000000000..0c3e1f05f --- /dev/null +++ b/test/io/test_files/templates/partial.dart @@ -0,0 +1,26 @@ +part of 'main.dart'; + +@NgComponent( + selector: 'my-component', + templateUrl: '/test/io/test_files/templates/main.html') +@NgTemplateCache() +class MyComponent +{ +} + +@NgComponent( + selector: 'my-component2', + templateUrl: '/test/io/test_files/templates/dont.html') +@NgTemplateCache(cache: false) +class MyComponent2 +{ +} + + +@NgComponent( + selector: 'my-component3', + templateUrl: '/test/io/test_files/templates/dont.html') +@NgTemplateCache(cache: true) +class MyComponent3 +{ +}