From 566d3ede04fa995e0b929b0c7eee701d0da9c61f Mon Sep 17 00:00:00 2001 From: Tim Blasi Date: Tue, 26 Jan 2016 16:36:13 -0800 Subject: [PATCH] test(dart/transform): Update unit tests to expect code in .template.dart Closes #6711 --- .../lib/src/transform/common/options.dart | 24 +++++-- .../template_compiler/generator.dart | 1 + .../template_compiler/transformer.dart | 11 +-- .../expected/index.dart | 2 +- .../expected/index.dart | 2 +- .../directive_metadata_linker/all_tests.dart | 6 +- .../test/transform/integration/all_tests.dart | 68 +++++++++++-------- .../{bar.ng_deps.dart => bar.template.dart} | 7 +- .../deferred_files/expected/output.dart | 4 +- .../{bar.ng_deps.dart => bar.template.dart} | 9 ++- .../{bar.ng_deps.dart => bar.template.dart} | 9 ++- .../{bar.ng_deps.dart => bar.template.dart} | 0 .../{foo.ng_deps.dart => foo.template.dart} | 9 ++- .../{bar.ng_deps.dart => bar.template.dart} | 7 +- .../{bar.ng_deps.dart => bar.template.dart} | 7 +- .../{bar.ng_deps.dart => bar.template.dart} | 7 +- .../{bar.ng_deps.dart => bar.template.dart} | 7 +- .../{bar.ng_deps.dart => bar.template.dart} | 7 +- .../{bar.ng_deps.dart => bar.template.dart} | 7 +- ...index.ng_deps.dart => index.template.dart} | 4 +- .../{bar.ng_deps.dart => bar.template.dart} | 7 +- .../{bar.ng_deps.dart => bar.template.dart} | 7 +- .../{bar.ng_deps.dart => bar.template.dart} | 7 +- .../bootstrap_files/expected/index.dart | 2 +- .../debug_files/expected/index.dart | 2 +- .../debug_mirrors_files/expected/index.dart | 2 +- .../expected/index.dart | 2 +- .../expected/index.dart | 2 +- .../expected/index.dart | 2 +- .../verbose_files/expected/index.dart | 2 +- .../template_compiler/all_tests.dart | 58 +++++++--------- 31 files changed, 148 insertions(+), 143 deletions(-) rename modules_dart/transform/test/transform/integration/deferred_files/expected/{bar.ng_deps.dart => bar.template.dart} (73%) rename modules_dart/transform/test/transform/integration/directive_chain_files/expected/{bar.ng_deps.dart => bar.template.dart} (72%) rename modules_dart/transform/test/transform/integration/directive_dep_files/expected/{bar.ng_deps.dart => bar.template.dart} (73%) rename modules_dart/transform/test/transform/integration/empty_ng_deps_files/expected/{bar.ng_deps.dart => bar.template.dart} (100%) rename modules_dart/transform/test/transform/integration/empty_ng_deps_files/expected/{foo.ng_deps.dart => foo.template.dart} (73%) rename modules_dart/transform/test/transform/integration/event_getter_files/expected/{bar.ng_deps.dart => bar.template.dart} (79%) rename modules_dart/transform/test/transform/integration/list_of_types_files/expected/{bar.ng_deps.dart => bar.template.dart} (76%) rename modules_dart/transform/test/transform/integration/override_annotation_files/expected/{bar.ng_deps.dart => bar.template.dart} (78%) rename modules_dart/transform/test/transform/integration/queries_class_annotation_files/expected/{bar.ng_deps.dart => bar.template.dart} (78%) rename modules_dart/transform/test/transform/integration/queries_prop_annotation_files/expected/{bar.ng_deps.dart => bar.template.dart} (80%) rename modules_dart/transform/test/transform/integration/simple_annotation_files/expected/{bar.ng_deps.dart => bar.template.dart} (72%) rename modules_dart/transform/test/transform/integration/simple_annotation_files/expected/{index.ng_deps.dart => index.template.dart} (85%) rename modules_dart/transform/test/transform/integration/synthetic_ctor_files/expected/{bar.ng_deps.dart => bar.template.dart} (73%) rename modules_dart/transform/test/transform/integration/two_annotations_files/expected/{bar.ng_deps.dart => bar.template.dart} (74%) rename modules_dart/transform/test/transform/integration/two_deps_files/expected/{bar.ng_deps.dart => bar.template.dart} (79%) diff --git a/modules_dart/transform/lib/src/transform/common/options.dart b/modules_dart/transform/lib/src/transform/common/options.dart index 822302fd4a..2186216310 100644 --- a/modules_dart/transform/lib/src/transform/common/options.dart +++ b/modules_dart/transform/lib/src/transform/common/options.dart @@ -73,6 +73,17 @@ class TransformerOptions { /// at any time. final bool lazyTransformers; + /// Whether to generate compiled templates. + /// + /// This option is strictly for internal testing and is not available as an + /// option on the transformer. + /// Setting this to `false` means that our generated .template.dart files do + /// not have any compiled templates or change detectors defined in them. + /// These files will not be usable, but this allows us to test the code output + /// of the transformer without breaking when compiled template internals + /// change. + final bool genCompiledTemplates; + TransformerOptions._internal( this.entryPoints, this.entryPointGlobs, @@ -80,13 +91,14 @@ class TransformerOptions { this.mirrorMode, this.initReflector, this.annotationMatcher, - {this.genChangeDetectionDebugInfo, - this.reflectPropertiesAsAttributes, - this.platformDirectives, - this.platformPipes, + {this.formatCode, + this.genChangeDetectionDebugInfo, + this.genCompiledTemplates, this.inlineViews, this.lazyTransformers, - this.formatCode}); + this.platformDirectives, + this.platformPipes, + this.reflectPropertiesAsAttributes}); factory TransformerOptions(List entryPoints, {String modeName: 'release', @@ -95,6 +107,7 @@ class TransformerOptions { List customAnnotationDescriptors: const [], bool inlineViews: false, bool genChangeDetectionDebugInfo: false, + bool genCompiledTemplates: true, bool reflectPropertiesAsAttributes: false, List platformDirectives, List platformPipes, @@ -108,6 +121,7 @@ class TransformerOptions { return new TransformerOptions._internal(entryPoints, entryPointGlobs, modeName, mirrorMode, initReflector, annotationMatcher, genChangeDetectionDebugInfo: genChangeDetectionDebugInfo, + genCompiledTemplates: genCompiledTemplates, reflectPropertiesAsAttributes: reflectPropertiesAsAttributes, platformDirectives: platformDirectives, platformPipes: platformPipes, diff --git a/modules_dart/transform/lib/src/transform/template_compiler/generator.dart b/modules_dart/transform/lib/src/transform/template_compiler/generator.dart index cb01396c7d..519feccb90 100644 --- a/modules_dart/transform/lib/src/transform/template_compiler/generator.dart +++ b/modules_dart/transform/lib/src/transform/template_compiler/generator.dart @@ -4,6 +4,7 @@ import 'dart:async'; import 'package:barback/barback.dart'; +import 'package:angular2/src/compiler/source_module.dart'; import 'package:angular2/src/core/change_detection/interfaces.dart'; import 'package:angular2/src/facade/lang.dart'; import 'package:angular2/src/core/reflection/reflection.dart'; diff --git a/modules_dart/transform/lib/src/transform/template_compiler/transformer.dart b/modules_dart/transform/lib/src/transform/template_compiler/transformer.dart index de0fa96c27..3418e2928f 100644 --- a/modules_dart/transform/lib/src/transform/template_compiler/transformer.dart +++ b/modules_dart/transform/lib/src/transform/template_compiler/transformer.dart @@ -52,16 +52,11 @@ class TemplateCompiler extends Transformer implements LazyTransformer { if (outputs != null) { if (outputs.ngDeps != null) { final buf = new StringBuffer(); + final templatesSrc = + options.genCompiledTemplates ? outputs.templatesSource : null; writeTemplateFile( - new NgDepsWriter(buf), outputs.ngDeps, outputs.templatesSource); + new NgDepsWriter(buf), outputs.ngDeps, templatesSrc); ngDepsCode = formatter.format(buf.toString()); - - if (primaryId.path.endsWith('index.ng_meta.json')) { - final buf2 = new StringBuffer(); - var writer = new NgDepsWriter(buf2); - outputs.ngDeps.imports.forEach(writer.writeImportModel); - print(buf2.toString()); - } } } transform.addOutput( diff --git a/modules_dart/transform/test/transform/deferred_rewriter/complex_deferred_example/expected/index.dart b/modules_dart/transform/test/transform/deferred_rewriter/complex_deferred_example/expected/index.dart index 6b8542cf52..5cfe0f67de 100644 --- a/modules_dart/transform/test/transform/deferred_rewriter/complex_deferred_example/expected/index.dart +++ b/modules_dart/transform/test/transform/deferred_rewriter/complex_deferred_example/expected/index.dart @@ -3,7 +3,7 @@ library web_foo; import 'package:angular2/src/core/application.dart'; import 'package:angular2/src/core/reflection/reflection.dart'; import 'package:angular2/src/core/reflection/reflection_capabilities.dart'; -import 'hello.ng_deps.dart' deferred as a; // ng_deps. Should be rewritten. +import 'hello.template.dart' deferred as a; // ng_deps. Should be rewritten. import 'b.dart' deferred as b; // No ng_deps. Shouldn't be rewritten. void main() { diff --git a/modules_dart/transform/test/transform/deferred_rewriter/simple_deferred_example/expected/index.dart b/modules_dart/transform/test/transform/deferred_rewriter/simple_deferred_example/expected/index.dart index 9dfb31e98b..18fc6151c1 100644 --- a/modules_dart/transform/test/transform/deferred_rewriter/simple_deferred_example/expected/index.dart +++ b/modules_dart/transform/test/transform/deferred_rewriter/simple_deferred_example/expected/index.dart @@ -3,7 +3,7 @@ library web_foo; import 'package:angular2/src/core/application.dart'; import 'package:angular2/src/core/reflection/reflection.dart'; import 'package:angular2/src/core/reflection/reflection_capabilities.dart'; -import 'hello.ng_deps.dart' deferred as a; +import 'hello.template.dart' deferred as a; void main() { reflector.reflectionCapabilities = new ReflectionCapabilities(); diff --git a/modules_dart/transform/test/transform/directive_metadata_linker/all_tests.dart b/modules_dart/transform/test/transform/directive_metadata_linker/all_tests.dart index 4b9b03a58c..fdfef58938 100644 --- a/modules_dart/transform/test/transform/directive_metadata_linker/all_tests.dart +++ b/modules_dart/transform/test/transform/directive_metadata_linker/all_tests.dart @@ -130,7 +130,7 @@ void allTests() { var linked = (await _testLink(reader, fooAssetId)).ngDeps; expect(linked).toBeNotNull(); var linkedImport = linked.depImports - .firstWhere((i) => i.uri.endsWith('bar.ng_deps.dart')); + .firstWhere((i) => i.uri.endsWith('bar.template.dart')); expect(linkedImport).toBeNotNull(); expect(linkedImport.prefix.startsWith('i')).toBeTrue(); }); @@ -145,7 +145,7 @@ void allTests() { var linked = (await _testLink(reader, fooAssetId)).ngDeps; expect(linked).toBeNotNull(); var linkedImport = linked.depImports - .firstWhere((i) => i.uri.endsWith('bar.ng_deps.dart')); + .firstWhere((i) => i.uri.endsWith('bar.template.dart')); expect(linkedImport).toBeNotNull(); expect(linkedImport.prefix.startsWith('i')).toBeTrue(); }); @@ -163,7 +163,7 @@ void allTests() { var linked = (await _testLink(reader, fooAssetId)).ngDeps; expect(linked).toBeNotNull(); var linkedImport = linked.depImports.firstWhere( - (i) => i.uri.endsWith('bar.ng_deps.dart'), + (i) => i.uri.endsWith('bar.template.dart'), orElse: () => null); expect(linkedImport).toBeNull(); }); diff --git a/modules_dart/transform/test/transform/integration/all_tests.dart b/modules_dart/transform/test/transform/integration/all_tests.dart index dc6e4a561f..2995598db6 100644 --- a/modules_dart/transform/test/transform/integration/all_tests.dart +++ b/modules_dart/transform/test/transform/integration/all_tests.dart @@ -13,8 +13,10 @@ main() { } var formatter = new DartFormatter(); -var transform = new AngularTransformerGroup( - new TransformerOptions(['web/index.dart'], formatCode: true)); +var transform = new AngularTransformerGroup(new TransformerOptions( + ['web/index.dart'], + formatCode: true, + genCompiledTemplates: false)); // Each test has its own directory for inputs & an `expected` directory for // expected outputs. @@ -56,10 +58,10 @@ void allTests() { 'a|web/bar.dart': 'simple_annotation_files/bar.dart' }, outputs: { - 'a|web/bar.ng_deps.dart': - 'simple_annotation_files/expected/bar.ng_deps.dart', - 'a|web/index.ng_deps.dart': - 'simple_annotation_files/expected/index.ng_deps.dart' + 'a|web/bar.template.dart': + 'simple_annotation_files/expected/bar.template.dart', + 'a|web/index.template.dart': + 'simple_annotation_files/expected/index.template.dart' }), new IntegrationTestConfig( 'should generate proper code for a Component with multiple deps.', @@ -69,7 +71,7 @@ void allTests() { 'a|web/bar.dart': 'two_deps_files/bar.dart' }, outputs: { - 'a|web/bar.ng_deps.dart': 'two_deps_files/expected/bar.ng_deps.dart' + 'a|web/bar.template.dart': 'two_deps_files/expected/bar.template.dart' }), new IntegrationTestConfig( 'should generate proper code for a Component declaring a ' @@ -80,7 +82,8 @@ void allTests() { 'a|web/bar.dart': 'list_of_types_files/bar.dart' }, outputs: { - 'a|web/bar.ng_deps.dart': 'list_of_types_files/expected/bar.ng_deps.dart' + 'a|web/bar.template.dart': + 'list_of_types_files/expected/bar.template.dart' }), new IntegrationTestConfig( 'should generate a factory for a class with no declared ctor.', @@ -89,7 +92,8 @@ void allTests() { 'a|web/bar.dart': 'synthetic_ctor_files/bar.dart' }, outputs: { - 'a|web/bar.ng_deps.dart': 'synthetic_ctor_files/expected/bar.ng_deps.dart' + 'a|web/bar.template.dart': + 'synthetic_ctor_files/expected/bar.template.dart' }), new IntegrationTestConfig('should preserve multiple annotations.', inputs: { 'a|web/index.dart': 'two_annotations_files/index.dart', @@ -97,8 +101,8 @@ void allTests() { 'angular2|lib/src/core/metadata.dart': '../../../lib/src/core/metadata.dart' }, outputs: { - 'a|web/bar.ng_deps.dart': - 'two_annotations_files/expected/bar.ng_deps.dart' + 'a|web/bar.template.dart': + 'two_annotations_files/expected/bar.template.dart' }), new IntegrationTestConfig( 'should generate getters for output events defined on a Component.', @@ -107,7 +111,7 @@ void allTests() { 'a|web/bar.dart': 'event_getter_files/bar.dart' }, outputs: { - 'a|web/bar.ng_deps.dart': 'event_getter_files/expected/bar.ng_deps.dart' + 'a|web/bar.template.dart': 'event_getter_files/expected/bar.template.dart' }), new IntegrationTestConfig( 'should handle Directive dependencies declared on a View.', @@ -117,7 +121,8 @@ void allTests() { 'a|web/bar.dart': 'directive_dep_files/bar.dart' }, outputs: { - 'a|web/bar.ng_deps.dart': 'directive_dep_files/expected/bar.ng_deps.dart' + 'a|web/bar.template.dart': + 'directive_dep_files/expected/bar.template.dart' }), new IntegrationTestConfig( 'should handle chained Directive dependencies declared on a View.', @@ -128,18 +133,20 @@ void allTests() { 'a|web/baz.dart': 'directive_chain_files/baz.dart' }, outputs: { - 'a|web/bar.ng_deps.dart': - 'directive_chain_files/expected/bar.ng_deps.dart' + 'a|web/bar.template.dart': + 'directive_chain_files/expected/bar.template.dart' }), new IntegrationTestConfig( - 'should handle empty ng_deps files that define directive aliases.', + 'should handle empty template files that define directive aliases.', inputs: { 'a|web/foo.dart': 'empty_ng_deps_files/foo.dart', 'a|web/bar.dart': 'empty_ng_deps_files/bar.dart' }, outputs: { - 'a|web/foo.ng_deps.dart': 'empty_ng_deps_files/expected/foo.ng_deps.dart', - 'a|web/bar.ng_deps.dart': 'empty_ng_deps_files/expected/bar.ng_deps.dart' + 'a|web/foo.template.dart': + 'empty_ng_deps_files/expected/foo.template.dart', + 'a|web/bar.template.dart': + 'empty_ng_deps_files/expected/bar.template.dart' }), new IntegrationTestConfig( 'should generate setters for annotated properties.', @@ -147,8 +154,8 @@ void allTests() { 'a|web/bar.dart': 'queries_prop_annotation_files/bar.dart' }, outputs: { - 'a|web/bar.ng_deps.dart': - 'queries_prop_annotation_files/expected/bar.ng_deps.dart' + 'a|web/bar.template.dart': + 'queries_prop_annotation_files/expected/bar.template.dart' }), new IntegrationTestConfig( 'should generate setters for `queries` values in Directives.', @@ -156,14 +163,18 @@ void allTests() { 'a|web/bar.dart': 'queries_class_annotation_files/bar.dart' }, outputs: { - 'a|web/bar.ng_deps.dart': - 'queries_class_annotation_files/expected/bar.ng_deps.dart' + 'a|web/bar.template.dart': + 'queries_class_annotation_files/expected/bar.template.dart' }), new IntegrationTestConfig( 'should handle @override annotations in properties on Directives.', - inputs: {'a|web/bar.dart': 'override_annotation_files/bar.dart'}, - outputs: - {'a|web/bar.ng_deps.dart': 'override_annotation_files/expected/bar.ng_deps.dart'}) + inputs: { + 'a|web/bar.dart': 'override_annotation_files/bar.dart' + }, + outputs: { + 'a|web/bar.template.dart': + 'override_annotation_files/expected/bar.template.dart' + }) ]; var cache = {}; @@ -181,6 +192,9 @@ void allTests() { config.assetPathToExpectedOutputPath.forEach((key, value) { config.assetPathToExpectedOutputPath[key] = cache.putIfAbsent(value, () { var code = _readFile(value); + if (code == null) { + throw 'Failed to read $value'; + } return value.endsWith('dart') ? formatter.format(code) : code; }); }); @@ -208,8 +222,8 @@ void _testDeferredRewriter() { inputs.addAll(commonInputs); inputs.keys.forEach((k) => inputs[k] = _readFile(inputs[k])); var outputs = { - 'a|web/bar.ng_deps.dart': - _readFile('deferred_files/expected/bar.ng_deps.dart'), + 'a|web/bar.template.dart': + _readFile('deferred_files/expected/bar.template.dart'), 'a|web/bar.dart': deferredOuts.barContents, 'a|web/index.dart': deferredOuts.indexContents }; diff --git a/modules_dart/transform/test/transform/integration/deferred_files/expected/bar.ng_deps.dart b/modules_dart/transform/test/transform/integration/deferred_files/expected/bar.template.dart similarity index 73% rename from modules_dart/transform/test/transform/integration/deferred_files/expected/bar.ng_deps.dart rename to modules_dart/transform/test/transform/integration/deferred_files/expected/bar.template.dart index c4c438c5e8..62d43aecc2 100644 --- a/modules_dart/transform/test/transform/integration/deferred_files/expected/bar.ng_deps.dart +++ b/modules_dart/transform/test/transform/integration/deferred_files/expected/bar.template.dart @@ -1,10 +1,9 @@ -library bar.ng_deps.dart; +library bar.template.dart; import 'bar.dart'; import 'package:angular2/src/core/reflection/reflection.dart' as _ngRef; import 'package:angular2/src/core/metadata.dart'; -import 'bar.template.dart' as _templates; -import 'package:angular2/src/core/metadata.ng_deps.dart' as i0; +import 'package:angular2/src/core/metadata.template.dart' as i0; export 'bar.dart'; var _visited = false; @@ -17,7 +16,7 @@ void initReflector() { new _ngRef.ReflectionInfo(const [ const Component(selector: '[soup]'), const View(template: ''), - _templates.hostViewFactory_MyComponent + hostViewFactory_MyComponent ], const [], () => new MyComponent())); i0.initReflector(); } diff --git a/modules_dart/transform/test/transform/integration/deferred_files/expected/output.dart b/modules_dart/transform/test/transform/integration/deferred_files/expected/output.dart index 547b950b86..00906a66a0 100644 --- a/modules_dart/transform/test/transform/integration/deferred_files/expected/output.dart +++ b/modules_dart/transform/test/transform/integration/deferred_files/expected/output.dart @@ -8,7 +8,7 @@ library angular2.test.transform.integration.deferred; const indexContents = ''' library web_foo; -import 'index.ng_deps.dart' as ngStaticInit;import 'bar.ng_deps.dart' deferred as bar; +import 'index.template.dart' as ngStaticInit;import 'bar.template.dart' deferred as bar; void main() { bar.loadLibrary().then((_) {bar.initReflector();}).then((_) { @@ -22,7 +22,7 @@ library bar; import 'package:angular2/src/core/metadata.dart'; -import 'dep.ng_deps.dart' deferred as dep; +import 'dep.template.dart' deferred as dep; @Component(selector: '[soup]') @View(template: '') diff --git a/modules_dart/transform/test/transform/integration/directive_chain_files/expected/bar.ng_deps.dart b/modules_dart/transform/test/transform/integration/directive_chain_files/expected/bar.template.dart similarity index 72% rename from modules_dart/transform/test/transform/integration/directive_chain_files/expected/bar.ng_deps.dart rename to modules_dart/transform/test/transform/integration/directive_chain_files/expected/bar.template.dart index ef0233c801..e21bfa093a 100644 --- a/modules_dart/transform/test/transform/integration/directive_chain_files/expected/bar.ng_deps.dart +++ b/modules_dart/transform/test/transform/integration/directive_chain_files/expected/bar.template.dart @@ -1,12 +1,11 @@ -library bar.ng_deps.dart; +library bar.template.dart; import 'bar.dart'; import 'package:angular2/src/core/reflection/reflection.dart' as _ngRef; import 'package:angular2/src/core/metadata.dart'; import 'baz.dart'; -import 'bar.template.dart' as _templates; -import 'package:angular2/src/core/metadata.ng_deps.dart' as i0; -import 'baz.ng_deps.dart' as i1; +import 'package:angular2/src/core/metadata.template.dart' as i0; +import 'baz.template.dart' as i1; export 'bar.dart'; var _visited = false; @@ -19,7 +18,7 @@ void initReflector() { new _ngRef.ReflectionInfo(const [ const Component(selector: 'soup'), const View(directives: [Foo], template: 'foo'), - _templates.hostViewFactory_MyComponent + hostViewFactory_MyComponent ], const [], () => new MyComponent())); i0.initReflector(); i1.initReflector(); diff --git a/modules_dart/transform/test/transform/integration/directive_dep_files/expected/bar.ng_deps.dart b/modules_dart/transform/test/transform/integration/directive_dep_files/expected/bar.template.dart similarity index 73% rename from modules_dart/transform/test/transform/integration/directive_dep_files/expected/bar.ng_deps.dart rename to modules_dart/transform/test/transform/integration/directive_dep_files/expected/bar.template.dart index a64aab4874..049eb4214b 100644 --- a/modules_dart/transform/test/transform/integration/directive_dep_files/expected/bar.ng_deps.dart +++ b/modules_dart/transform/test/transform/integration/directive_dep_files/expected/bar.template.dart @@ -1,12 +1,11 @@ -library bar.ng_deps.dart; +library bar.template.dart; import 'bar.dart'; import 'package:angular2/src/core/reflection/reflection.dart' as _ngRef; import 'package:angular2/src/core/metadata.dart'; import 'foo.dart' as prefix; -import 'bar.template.dart' as _templates; -import 'package:angular2/src/core/metadata.ng_deps.dart' as i0; -import 'foo.ng_deps.dart' as i1; +import 'package:angular2/src/core/metadata.template.dart' as i0; +import 'foo.template.dart' as i1; export 'bar.dart'; var _visited = false; @@ -19,7 +18,7 @@ void initReflector() { new _ngRef.ReflectionInfo(const [ const Component(selector: 'soup'), const View(directives: [prefix.Foo], template: 'foo'), - _templates.hostViewFactory_MyComponent + hostViewFactory_MyComponent ], const [], () => new MyComponent())); i0.initReflector(); i1.initReflector(); diff --git a/modules_dart/transform/test/transform/integration/empty_ng_deps_files/expected/bar.ng_deps.dart b/modules_dart/transform/test/transform/integration/empty_ng_deps_files/expected/bar.template.dart similarity index 100% rename from modules_dart/transform/test/transform/integration/empty_ng_deps_files/expected/bar.ng_deps.dart rename to modules_dart/transform/test/transform/integration/empty_ng_deps_files/expected/bar.template.dart diff --git a/modules_dart/transform/test/transform/integration/empty_ng_deps_files/expected/foo.ng_deps.dart b/modules_dart/transform/test/transform/integration/empty_ng_deps_files/expected/foo.template.dart similarity index 73% rename from modules_dart/transform/test/transform/integration/empty_ng_deps_files/expected/foo.ng_deps.dart rename to modules_dart/transform/test/transform/integration/empty_ng_deps_files/expected/foo.template.dart index c2d7ce4ce9..d242f26630 100644 --- a/modules_dart/transform/test/transform/integration/empty_ng_deps_files/expected/foo.ng_deps.dart +++ b/modules_dart/transform/test/transform/integration/empty_ng_deps_files/expected/foo.template.dart @@ -1,12 +1,11 @@ -library bar.ng_deps.dart; +library bar.template.dart; import 'foo.dart'; import 'package:angular2/src/core/reflection/reflection.dart' as _ngRef; import 'package:angular2/src/core/metadata.dart'; import 'bar.dart'; -import 'foo.template.dart' as _templates; -import 'package:angular2/src/core/metadata.ng_deps.dart' as i0; -import 'bar.ng_deps.dart' as i1; +import 'package:angular2/src/core/metadata.template.dart' as i0; +import 'bar.template.dart' as i1; export 'foo.dart'; var _visited = false; @@ -19,7 +18,7 @@ void initReflector() { new _ngRef.ReflectionInfo(const [ const Component(selector: '[soup]'), const View(directives: const [directiveAlias], template: ''), - _templates.hostViewFactory_MyComponent + hostViewFactory_MyComponent ], const [], () => new MyComponent())); i0.initReflector(); i1.initReflector(); diff --git a/modules_dart/transform/test/transform/integration/event_getter_files/expected/bar.ng_deps.dart b/modules_dart/transform/test/transform/integration/event_getter_files/expected/bar.template.dart similarity index 79% rename from modules_dart/transform/test/transform/integration/event_getter_files/expected/bar.ng_deps.dart rename to modules_dart/transform/test/transform/integration/event_getter_files/expected/bar.template.dart index d7e7b68a78..4b8fe128e2 100644 --- a/modules_dart/transform/test/transform/integration/event_getter_files/expected/bar.ng_deps.dart +++ b/modules_dart/transform/test/transform/integration/event_getter_files/expected/bar.template.dart @@ -1,10 +1,9 @@ -library bar.ng_deps.dart; +library bar.template.dart; import 'bar.dart'; import 'package:angular2/src/core/reflection/reflection.dart' as _ngRef; import 'package:angular2/src/core/metadata.dart'; -import 'bar.template.dart' as _templates; -import 'package:angular2/src/core/metadata.ng_deps.dart' as i0; +import 'package:angular2/src/core/metadata.template.dart' as i0; export 'bar.dart'; var _visited = false; @@ -19,7 +18,7 @@ void initReflector() { outputs: ['eventName1', 'eventName2: propName2'], selector: '[soup]'), const View(template: ''), - _templates.hostViewFactory_MyComponent + hostViewFactory_MyComponent ], const [], () => new MyComponent())) ..registerGetters( {'eventName1': (o) => o.eventName1, 'eventName2': (o) => o.eventName2}); diff --git a/modules_dart/transform/test/transform/integration/list_of_types_files/expected/bar.ng_deps.dart b/modules_dart/transform/test/transform/integration/list_of_types_files/expected/bar.template.dart similarity index 76% rename from modules_dart/transform/test/transform/integration/list_of_types_files/expected/bar.ng_deps.dart rename to modules_dart/transform/test/transform/integration/list_of_types_files/expected/bar.template.dart index f13458dea6..963598ded4 100644 --- a/modules_dart/transform/test/transform/integration/list_of_types_files/expected/bar.ng_deps.dart +++ b/modules_dart/transform/test/transform/integration/list_of_types_files/expected/bar.template.dart @@ -1,11 +1,10 @@ -library bar.ng_deps.dart; +library bar.template.dart; import 'bar.dart'; import 'package:angular2/src/core/reflection/reflection.dart' as _ngRef; import 'package:angular2/src/core/metadata.dart'; import 'foo.dart'; -import 'bar.template.dart' as _templates; -import 'package:angular2/src/core/metadata.ng_deps.dart' as i0; +import 'package:angular2/src/core/metadata.template.dart' as i0; export 'bar.dart'; var _visited = false; @@ -18,7 +17,7 @@ void initReflector() { new _ngRef.ReflectionInfo(const [ const Component(componentServices: const [MyContext]), const View(template: ''), - _templates.hostViewFactory_MyComponent + hostViewFactory_MyComponent ], const [ const [MyContext] ], (MyContext c) => new MyComponent(c))); diff --git a/modules_dart/transform/test/transform/integration/override_annotation_files/expected/bar.ng_deps.dart b/modules_dart/transform/test/transform/integration/override_annotation_files/expected/bar.template.dart similarity index 78% rename from modules_dart/transform/test/transform/integration/override_annotation_files/expected/bar.ng_deps.dart rename to modules_dart/transform/test/transform/integration/override_annotation_files/expected/bar.template.dart index 43fd420e50..4b49827af0 100644 --- a/modules_dart/transform/test/transform/integration/override_annotation_files/expected/bar.ng_deps.dart +++ b/modules_dart/transform/test/transform/integration/override_annotation_files/expected/bar.template.dart @@ -1,10 +1,9 @@ -library bar.ng_deps.dart; +library bar.template.dart; import 'bar.dart'; import 'package:angular2/src/core/reflection/reflection.dart' as _ngRef; import 'package:angular2/src/core/metadata.dart'; -import 'bar.template.dart' as _templates; -import 'package:angular2/src/core/metadata.ng_deps.dart' as i0; +import 'package:angular2/src/core/metadata.template.dart' as i0; export 'bar.dart'; var _visited = false; @@ -18,7 +17,7 @@ void initReflector() { const [ const Component(selector: '[soup]'), const View(template: ''), - _templates.hostViewFactory_MyComponent + hostViewFactory_MyComponent ], const [], () => new MyComponent(), diff --git a/modules_dart/transform/test/transform/integration/queries_class_annotation_files/expected/bar.ng_deps.dart b/modules_dart/transform/test/transform/integration/queries_class_annotation_files/expected/bar.template.dart similarity index 78% rename from modules_dart/transform/test/transform/integration/queries_class_annotation_files/expected/bar.ng_deps.dart rename to modules_dart/transform/test/transform/integration/queries_class_annotation_files/expected/bar.template.dart index 28b8e644d9..cd42bde063 100644 --- a/modules_dart/transform/test/transform/integration/queries_class_annotation_files/expected/bar.ng_deps.dart +++ b/modules_dart/transform/test/transform/integration/queries_class_annotation_files/expected/bar.template.dart @@ -1,10 +1,9 @@ -library bar.ng_deps.dart; +library bar.template.dart; import 'bar.dart'; import 'package:angular2/src/core/reflection/reflection.dart' as _ngRef; import 'package:angular2/src/core/metadata.dart'; -import 'bar.template.dart' as _templates; -import 'package:angular2/src/core/metadata.ng_deps.dart' as i0; +import 'package:angular2/src/core/metadata.template.dart' as i0; export 'bar.dart'; var _visited = false; @@ -19,7 +18,7 @@ void initReflector() { queries: const {'queryField': const ContentChild('child')}, selector: '[soup]'), const View(template: ''), - _templates.hostViewFactory_MyComponent + hostViewFactory_MyComponent ], const [], () => new MyComponent())) ..registerSetters({'queryField': (o, v) => o.queryField = v}); i0.initReflector(); diff --git a/modules_dart/transform/test/transform/integration/queries_prop_annotation_files/expected/bar.ng_deps.dart b/modules_dart/transform/test/transform/integration/queries_prop_annotation_files/expected/bar.template.dart similarity index 80% rename from modules_dart/transform/test/transform/integration/queries_prop_annotation_files/expected/bar.ng_deps.dart rename to modules_dart/transform/test/transform/integration/queries_prop_annotation_files/expected/bar.template.dart index 200405af27..414b86bf57 100644 --- a/modules_dart/transform/test/transform/integration/queries_prop_annotation_files/expected/bar.ng_deps.dart +++ b/modules_dart/transform/test/transform/integration/queries_prop_annotation_files/expected/bar.template.dart @@ -1,10 +1,9 @@ -library bar.ng_deps.dart; +library bar.template.dart; import 'bar.dart'; import 'package:angular2/src/core/reflection/reflection.dart' as _ngRef; import 'package:angular2/src/core/metadata.dart'; -import 'bar.template.dart' as _templates; -import 'package:angular2/src/core/metadata.ng_deps.dart' as i0; +import 'package:angular2/src/core/metadata.template.dart' as i0; export 'bar.dart'; var _visited = false; @@ -18,7 +17,7 @@ void initReflector() { const [ const Component(selector: '[soup]'), const View(template: ''), - _templates.hostViewFactory_MyComponent + hostViewFactory_MyComponent ], const [], () => new MyComponent(), diff --git a/modules_dart/transform/test/transform/integration/simple_annotation_files/expected/bar.ng_deps.dart b/modules_dart/transform/test/transform/integration/simple_annotation_files/expected/bar.template.dart similarity index 72% rename from modules_dart/transform/test/transform/integration/simple_annotation_files/expected/bar.ng_deps.dart rename to modules_dart/transform/test/transform/integration/simple_annotation_files/expected/bar.template.dart index 8b073ed8b6..4e728e0428 100644 --- a/modules_dart/transform/test/transform/integration/simple_annotation_files/expected/bar.ng_deps.dart +++ b/modules_dart/transform/test/transform/integration/simple_annotation_files/expected/bar.template.dart @@ -1,10 +1,9 @@ -library bar.ng_deps.dart; +library bar.template.dart; import 'bar.dart'; import 'package:angular2/src/core/reflection/reflection.dart' as _ngRef; import 'package:angular2/src/core/metadata.dart'; -import 'bar.template.dart' as _templates; -import 'package:angular2/src/core/metadata.ng_deps.dart' as i0; +import 'package:angular2/src/core/metadata.template.dart' as i0; export 'bar.dart'; var _visited = false; @@ -16,7 +15,7 @@ void initReflector() { MyComponent, new _ngRef.ReflectionInfo(const [ const Component(selector: '[soup]', template: 'aa'), - _templates.hostViewFactory_MyComponent + hostViewFactory_MyComponent ], const [], () => new MyComponent())); i0.initReflector(); } diff --git a/modules_dart/transform/test/transform/integration/simple_annotation_files/expected/index.ng_deps.dart b/modules_dart/transform/test/transform/integration/simple_annotation_files/expected/index.template.dart similarity index 85% rename from modules_dart/transform/test/transform/integration/simple_annotation_files/expected/index.ng_deps.dart rename to modules_dart/transform/test/transform/integration/simple_annotation_files/expected/index.template.dart index a79f7b8496..51c164f7c9 100644 --- a/modules_dart/transform/test/transform/integration/simple_annotation_files/expected/index.ng_deps.dart +++ b/modules_dart/transform/test/transform/integration/simple_annotation_files/expected/index.template.dart @@ -1,11 +1,11 @@ -library web_foo.ng_deps.dart; +library web_foo.template.dart; import 'index.dart'; import 'package:angular2/src/core/reflection/reflection.dart' as _ngRef; import 'package:angular2/bootstrap_static.dart' show bootstrapStatic; import 'package:angular2/src/core/reflection/reflection.dart'; import 'bar.dart'; -import 'bar.ng_deps.dart' as i0; +import 'bar.template.dart' as i0; export 'index.dart'; var _visited = false; diff --git a/modules_dart/transform/test/transform/integration/synthetic_ctor_files/expected/bar.ng_deps.dart b/modules_dart/transform/test/transform/integration/synthetic_ctor_files/expected/bar.template.dart similarity index 73% rename from modules_dart/transform/test/transform/integration/synthetic_ctor_files/expected/bar.ng_deps.dart rename to modules_dart/transform/test/transform/integration/synthetic_ctor_files/expected/bar.template.dart index c4c438c5e8..62d43aecc2 100644 --- a/modules_dart/transform/test/transform/integration/synthetic_ctor_files/expected/bar.ng_deps.dart +++ b/modules_dart/transform/test/transform/integration/synthetic_ctor_files/expected/bar.template.dart @@ -1,10 +1,9 @@ -library bar.ng_deps.dart; +library bar.template.dart; import 'bar.dart'; import 'package:angular2/src/core/reflection/reflection.dart' as _ngRef; import 'package:angular2/src/core/metadata.dart'; -import 'bar.template.dart' as _templates; -import 'package:angular2/src/core/metadata.ng_deps.dart' as i0; +import 'package:angular2/src/core/metadata.template.dart' as i0; export 'bar.dart'; var _visited = false; @@ -17,7 +16,7 @@ void initReflector() { new _ngRef.ReflectionInfo(const [ const Component(selector: '[soup]'), const View(template: ''), - _templates.hostViewFactory_MyComponent + hostViewFactory_MyComponent ], const [], () => new MyComponent())); i0.initReflector(); } diff --git a/modules_dart/transform/test/transform/integration/two_annotations_files/expected/bar.ng_deps.dart b/modules_dart/transform/test/transform/integration/two_annotations_files/expected/bar.template.dart similarity index 74% rename from modules_dart/transform/test/transform/integration/two_annotations_files/expected/bar.ng_deps.dart rename to modules_dart/transform/test/transform/integration/two_annotations_files/expected/bar.template.dart index 5e81fad675..57cf5d7fda 100644 --- a/modules_dart/transform/test/transform/integration/two_annotations_files/expected/bar.ng_deps.dart +++ b/modules_dart/transform/test/transform/integration/two_annotations_files/expected/bar.template.dart @@ -1,10 +1,9 @@ -library bar.ng_deps.dart; +library bar.template.dart; import 'bar.dart'; import 'package:angular2/src/core/reflection/reflection.dart' as _ngRef; import 'package:angular2/src/core/metadata.dart'; -import 'bar.template.dart' as _templates; -import 'package:angular2/src/core/metadata.ng_deps.dart' as i0; +import 'package:angular2/src/core/metadata.template.dart' as i0; export 'bar.dart'; var _visited = false; @@ -17,7 +16,7 @@ void initReflector() { new _ngRef.ReflectionInfo(const [ const Component(selector: '[soup]'), const View(template: 'Salad: {{myNum}} is awesome'), - _templates.hostViewFactory_MyComponent + hostViewFactory_MyComponent ], const [], () => new MyComponent())); i0.initReflector(); } diff --git a/modules_dart/transform/test/transform/integration/two_deps_files/expected/bar.ng_deps.dart b/modules_dart/transform/test/transform/integration/two_deps_files/expected/bar.template.dart similarity index 79% rename from modules_dart/transform/test/transform/integration/two_deps_files/expected/bar.ng_deps.dart rename to modules_dart/transform/test/transform/integration/two_deps_files/expected/bar.template.dart index 551d9cd577..f2a91f5a01 100644 --- a/modules_dart/transform/test/transform/integration/two_deps_files/expected/bar.ng_deps.dart +++ b/modules_dart/transform/test/transform/integration/two_deps_files/expected/bar.template.dart @@ -1,11 +1,10 @@ -library bar.ng_deps.dart; +library bar.template.dart; import 'bar.dart'; import 'package:angular2/src/core/reflection/reflection.dart' as _ngRef; import 'package:angular2/src/core/metadata.dart'; import 'foo.dart' as prefix; -import 'bar.template.dart' as _templates; -import 'package:angular2/src/core/metadata.ng_deps.dart' as i0; +import 'package:angular2/src/core/metadata.template.dart' as i0; export 'bar.dart'; var _visited = false; @@ -19,7 +18,7 @@ void initReflector() { const [ const Component(selector: 'soup'), const View(template: ''), - _templates.hostViewFactory_MyComponent + hostViewFactory_MyComponent ], const [ const [prefix.MyContext], diff --git a/modules_dart/transform/test/transform/reflection_remover/bootstrap_files/expected/index.dart b/modules_dart/transform/test/transform/reflection_remover/bootstrap_files/expected/index.dart index a6c7952d99..ba476bfe9c 100644 --- a/modules_dart/transform/test/transform/reflection_remover/bootstrap_files/expected/index.dart +++ b/modules_dart/transform/test/transform/reflection_remover/bootstrap_files/expected/index.dart @@ -11,7 +11,7 @@ library angular2.test.transform.reflection_remover.reflection_remover_files; var code = """ library web_foo; -import 'package:angular2/bootstrap_static.dart';import 'index.ng_deps.dart' as ngStaticInit; +import 'package:angular2/bootstrap_static.dart';import 'index.template.dart' as ngStaticInit; void main() async { var appRef = await bootstrapStatic(MyComponent, null, () { ngStaticInit.initReflector(); }); diff --git a/modules_dart/transform/test/transform/reflection_remover/debug_files/expected/index.dart b/modules_dart/transform/test/transform/reflection_remover/debug_files/expected/index.dart index a646accf77..a0c264cb24 100644 --- a/modules_dart/transform/test/transform/reflection_remover/debug_files/expected/index.dart +++ b/modules_dart/transform/test/transform/reflection_remover/debug_files/expected/index.dart @@ -11,7 +11,7 @@ library angular2.test.transform.debug_reflection_remover_files; var code = """ library web_foo; -import 'package:angular2/bootstrap.dart';import 'index.ng_deps.dart' as ngStaticInit; +import 'package:angular2/bootstrap.dart';import 'index.template.dart' as ngStaticInit; import 'package:angular2/src/core/reflection/reflection.dart'; import 'package:angular2/src/core/reflection/debug_reflection_capabilities.dart'; diff --git a/modules_dart/transform/test/transform/reflection_remover/debug_mirrors_files/expected/index.dart b/modules_dart/transform/test/transform/reflection_remover/debug_mirrors_files/expected/index.dart index 73797da4ec..ccf13f7187 100644 --- a/modules_dart/transform/test/transform/reflection_remover/debug_mirrors_files/expected/index.dart +++ b/modules_dart/transform/test/transform/reflection_remover/debug_mirrors_files/expected/index.dart @@ -11,7 +11,7 @@ library angular2.test.transform.reflection_remover.debug_mirrors_files.expected; var code = """ library web_foo; -import 'package:angular2/bootstrap_static.dart';import 'index.ng_deps.dart' as ngStaticInit; +import 'package:angular2/bootstrap_static.dart';import 'index.template.dart' as ngStaticInit; import 'package:angular2/src/core/reflection/reflection.dart'; import 'package:angular2/src/core/reflection/debug_reflection_capabilities.dart'; diff --git a/modules_dart/transform/test/transform/reflection_remover/function_annotation_files/expected/index.dart b/modules_dart/transform/test/transform/reflection_remover/function_annotation_files/expected/index.dart index 8da3f5ac97..0f0e4fadc6 100644 --- a/modules_dart/transform/test/transform/reflection_remover/function_annotation_files/expected/index.dart +++ b/modules_dart/transform/test/transform/reflection_remover/function_annotation_files/expected/index.dart @@ -11,7 +11,7 @@ library angular2.test.transform.reflection_remover.function_annotation_files; const code = """ library web_foo; -import 'package:angular2/bootstrap_static.dart';import 'index.ng_deps.dart' as ngStaticInit; +import 'package:angular2/bootstrap_static.dart';import 'index.template.dart' as ngStaticInit; import 'package:angular2/src/core/reflection/reflection.dart'; /*import 'package:angular2/src/core/reflection/reflection_capabilities.dart';*/ diff --git a/modules_dart/transform/test/transform/reflection_remover/method_annotation_files/expected/index.dart b/modules_dart/transform/test/transform/reflection_remover/method_annotation_files/expected/index.dart index e3bea8602b..417f804970 100644 --- a/modules_dart/transform/test/transform/reflection_remover/method_annotation_files/expected/index.dart +++ b/modules_dart/transform/test/transform/reflection_remover/method_annotation_files/expected/index.dart @@ -11,7 +11,7 @@ library angular2.test.transform.reflection_remover.method_annotation_files; const code = """ library web_foo; -import 'package:angular2/bootstrap_static.dart';import 'index.ng_deps.dart' as ngStaticInit; +import 'package:angular2/bootstrap_static.dart';import 'index.template.dart' as ngStaticInit; class TestBootstrapper { @AngularEntrypoint("Method entrypoint") diff --git a/modules_dart/transform/test/transform/reflection_remover/reflection_remover_files/expected/index.dart b/modules_dart/transform/test/transform/reflection_remover/reflection_remover_files/expected/index.dart index 84322bb849..f346e1c3fc 100644 --- a/modules_dart/transform/test/transform/reflection_remover/reflection_remover_files/expected/index.dart +++ b/modules_dart/transform/test/transform/reflection_remover/reflection_remover_files/expected/index.dart @@ -11,7 +11,7 @@ library angular2.test.transform.reflection_remover.reflection_remover_files; var code = """ library web_foo; -import 'package:angular2/bootstrap_static.dart';import 'index.ng_deps.dart' as ngStaticInit; +import 'package:angular2/bootstrap_static.dart';import 'index.template.dart' as ngStaticInit; import 'package:angular2/src/core/reflection/reflection.dart'; /*import 'package:angular2/src/core/reflection/reflection_capabilities.dart';*/ diff --git a/modules_dart/transform/test/transform/reflection_remover/verbose_files/expected/index.dart b/modules_dart/transform/test/transform/reflection_remover/verbose_files/expected/index.dart index 4a32b55f88..9ca2dd9c14 100644 --- a/modules_dart/transform/test/transform/reflection_remover/verbose_files/expected/index.dart +++ b/modules_dart/transform/test/transform/reflection_remover/verbose_files/expected/index.dart @@ -11,7 +11,7 @@ library angular2.test.transform.reflection_remover.verbose_files.expected; var code = """ library web_foo; -import 'package:angular2/bootstrap_static.dart';import 'index.ng_deps.dart' as ngStaticInit; +import 'package:angular2/bootstrap_static.dart';import 'index.template.dart' as ngStaticInit; import 'package:angular2/src/core/reflection/reflection.dart'; import 'package:angular2/src/core/reflection/debug_reflection_capabilities.dart'; diff --git a/modules_dart/transform/test/transform/template_compiler/all_tests.dart b/modules_dart/transform/test/transform/template_compiler/all_tests.dart index 80db1467f2..130dcdd9c6 100644 --- a/modules_dart/transform/test/transform/template_compiler/all_tests.dart +++ b/modules_dart/transform/test/transform/template_compiler/all_tests.dart @@ -11,8 +11,10 @@ import 'package:guinness/guinness.dart'; import 'package:angular2/src/core/change_detection/codegen_name_util.dart' show CONTEXT_ACCESSOR; import 'package:angular2/src/platform/server/html_adapter.dart'; -import 'package:angular2/src/transform/template_compiler/generator.dart'; +import 'package:angular2/src/transform/common/code/ng_deps_code.dart'; +import 'package:angular2/src/transform/common/code/source_module.dart'; import 'package:angular2/src/transform/common/zone.dart' as zone; +import 'package:angular2/src/transform/template_compiler/generator.dart'; import '../common/compile_directive_metadata/ng_for.ng_meta.dart' as ngMeta; import '../common/ng_meta_helper.dart'; @@ -109,7 +111,7 @@ void allTests() { final outputs = await process(fooAssetId); // TODO(kegluenq): Does this next line need to be updated as well? - expect(outputs.templatesCode).not.toContain('notifyDispatcher'); + expect(_generatedCode(outputs)).not.toContain('notifyDispatcher'); }); it('should parse simple expressions in inline templates.', () async { @@ -121,14 +123,11 @@ void allTests() { final outputs = await process(fooAssetId); final ngDeps = outputs.ngDeps; expect(ngDeps).toBeNotNull(); - expect(ngDeps.imports).toContain(new ImportModel() - ..uri = 'foo.template.dart' - ..prefix = '_templates'); expect(ngDeps.reflectables.first.annotations) .toContain(new AnnotationModel() - ..name = '_templates.hostViewFactory_FooComponent' + ..name = 'hostViewFactory_FooComponent' ..isConstObject = true); - expect(outputs.templatesCode) + expect(_generatedCode(outputs)) ..toContain('$CONTEXT_ACCESSOR.greeting') ..toContain('$CONTEXT_ACCESSOR.b'); }); @@ -142,14 +141,11 @@ void allTests() { final outputs = await process(fooAssetId); final ngDeps = outputs.ngDeps; expect(ngDeps).toBeNotNull(); - expect(ngDeps.imports).toContain(new ImportModel() - ..uri = 'foo.template.dart' - ..prefix = '_templates'); expect(ngDeps.reflectables.first.annotations) .toContain(new AnnotationModel() - ..name = '_templates.hostViewFactory_FooComponent' + ..name = 'hostViewFactory_FooComponent' ..isConstObject = true); - expect(outputs.templatesCode)..toContain('$CONTEXT_ACCESSOR.action()'); + expect(_generatedCode(outputs))..toContain('$CONTEXT_ACCESSOR.action()'); }); it('should parse `View` directives with a single dependency.', () async { @@ -172,15 +168,12 @@ void allTests() { final outputs = await process(fooAssetId); final ngDeps = outputs.ngDeps; expect(ngDeps).toBeNotNull(); - expect(ngDeps.imports).toContain(new ImportModel() - ..uri = 'foo.template.dart' - ..prefix = '_templates'); expect(ngDeps.reflectables.first.annotations) .toContain(new AnnotationModel() - ..name = '_templates.hostViewFactory_FooComponent' + ..name = 'hostViewFactory_FooComponent' ..isConstObject = true); - expect(outputs.templatesCode) + expect(_generatedCode(outputs)) ..toContain("import 'bar.dart'") ..toContain("import 'bar.template.dart'"); }); @@ -206,15 +199,12 @@ void allTests() { final outputs = await process(fooAssetId); final ngDeps = outputs.ngDeps; expect(ngDeps).toBeNotNull(); - expect(ngDeps.imports).toContain(new ImportModel() - ..uri = 'foo.template.dart' - ..prefix = '_templates'); expect(ngDeps.reflectables.first.annotations) .toContain(new AnnotationModel() - ..name = '_templates.hostViewFactory_FooComponent' + ..name = 'hostViewFactory_FooComponent' ..isConstObject = true); - expect(outputs.templatesCode) + expect(_generatedCode(outputs)) ..toContain("import 'bar.dart'") ..toContain("import 'bar.template.dart'"); }); @@ -238,15 +228,12 @@ void allTests() { final outputs = await process(fooAssetId); final ngDeps = outputs.ngDeps; expect(ngDeps).toBeNotNull(); - expect(ngDeps.imports).toContain(new ImportModel() - ..uri = 'foo.template.dart' - ..prefix = '_templates'); expect(ngDeps.reflectables.first.annotations) .toContain(new AnnotationModel() - ..name = '_templates.hostViewFactory_FooComponent' + ..name = 'hostViewFactory_FooComponent' ..isConstObject = true); - expect(outputs.templatesCode) + expect(_generatedCode(outputs)) ..toContain("import 'bar.dart'") ..toContain("import 'bar.template.dart'"); }); @@ -260,7 +247,7 @@ void allTests() { final firstOutputs = await process(fooAssetId); final secondOutputs = await process(fooAssetId); expect(firstOutputs.ngDeps).toEqual(secondOutputs.ngDeps); - expect(firstOutputs.templatesCode).toEqual(secondOutputs.templatesCode); + expect(_generatedCode(firstOutputs)).toEqual(_generatedCode(secondOutputs)); }); it('should generate getters for Component#outputs.', () async { @@ -370,7 +357,7 @@ void allTests() { platformDirectives: ['package:a/bar.dart#PLATFORM']); final ngDeps = outputs.ngDeps; expect(ngDeps).toBeNotNull(); - expect(outputs.templatesCode) + expect(_generatedCode(outputs)) ..toBeNotNull() ..toContain(barComponentMeta.template.template); }); @@ -389,7 +376,7 @@ void allTests() { platformDirectives: ['package:a/bar.dart#PLATFORM']); final ngDeps = outputs.ngDeps; expect(ngDeps).toBeNotNull(); - expect(outputs.templatesCode) + expect(_generatedCode(outputs)) ..toBeNotNull() ..toContain(barComponentMeta.template.template); }); @@ -440,7 +427,7 @@ void allTests() { final outputs = await process(fooAssetId); - expect(outputs.templatesCode) + expect(_generatedCode(outputs)) ..toContain("import 'bar.dart'") ..toContain(barPipeMeta.name); }); @@ -455,12 +442,19 @@ void allTests() { final outputs = await process(fooAssetId, platformPipes: ['package:a/bar.dart#PLATFORM']); - expect(outputs.templatesCode) + expect(_generatedCode(outputs)) ..toContain("import 'bar.dart'") ..toContain(barPipeMeta.name); }); } +String _generatedCode(Outputs outputs) { + final StringBuffer buf = new StringBuffer(); + final writer = new NgDepsWriter(buf); + writeTemplateFile(writer, outputs.ngDeps, outputs.templatesSource); + return buf.toString(); +} + void _formatThenExpectEquals(String actual, String expected) { expect(formatter.format(actual)).toEqual(formatter.format(expected)); }