From 0520ca68b4798c2f4cc1036e57d9b8f8957005a6 Mon Sep 17 00:00:00 2001 From: Tim Blasi Date: Fri, 1 May 2015 13:57:44 -0700 Subject: [PATCH] feat(dart/transform): Add DirectiveMetadataExtractor transform step Add a step that reads `DirectiveMetadata` object off annotated classes into `.ng_meta.dart` files. These will be used by the `TemplateCompiler` step as inputs to the Angular 2 render compiler. Update one test to avoid unsupported functionality, format others. --- .../directive_metadata_reader.dart | 6 +- .../angular2/src/transform/common/names.dart | 1 + .../extractor.dart | 28 +++++++ .../transformer.dart | 56 ++++++++++++++ .../angular2/src/transform/transformer.dart | 3 +- .../all_tests.dart | 73 +++++++++++++++++++ .../compile_children.ng_deps.dart | 0 .../host_listeners.ng_deps.dart | 0 .../properties.ng_deps.dart | 0 .../selector.ng_deps.dart | 0 .../too_many_directives.ng_deps.dart | 0 .../simple_files/expected/foo.ng_deps.dart | 16 ++++ .../simple_files/expected/foo.ng_meta.dart | 1 + .../simple_files/foo.ng_deps.dart | 16 ++++ .../test/transform/integration/all_tests.dart | 4 +- .../expected/bar.ng_deps.dart | 3 +- .../expected/bar.ng_deps.dart | 3 +- .../expected/bar.ng_deps.dart | 3 +- .../expected/bar.ng_deps.dart | 3 +- .../integration/two_deps_files/bar.dart | 2 +- .../two_deps_files/expected/bar.ng_deps.dart | 6 +- .../integration/two_deps_files/foo.dart | 2 - .../debug_mirrors_files/expected/index.dart | 2 +- .../expected/index.dart | 2 +- .../verbose_files/expected/index.dart | 2 +- .../template_compiler/all_tests.dart | 58 --------------- .../test/transform/transform.server.spec.dart | 2 + 27 files changed, 214 insertions(+), 78 deletions(-) rename modules/angular2/src/transform/{template_compiler => common}/directive_metadata_reader.dart (96%) create mode 100644 modules/angular2/src/transform/directive_metadata_extractor/extractor.dart create mode 100644 modules/angular2/src/transform/directive_metadata_extractor/transformer.dart create mode 100644 modules/angular2/test/transform/directive_metadata_extractor/all_tests.dart rename modules/angular2/test/transform/{template_compiler => directive_metadata_extractor}/directive_metadata_files/compile_children.ng_deps.dart (100%) rename modules/angular2/test/transform/{template_compiler => directive_metadata_extractor}/directive_metadata_files/host_listeners.ng_deps.dart (100%) rename modules/angular2/test/transform/{template_compiler => directive_metadata_extractor}/directive_metadata_files/properties.ng_deps.dart (100%) rename modules/angular2/test/transform/{template_compiler => directive_metadata_extractor}/directive_metadata_files/selector.ng_deps.dart (100%) rename modules/angular2/test/transform/{template_compiler => directive_metadata_extractor}/directive_metadata_files/too_many_directives.ng_deps.dart (100%) create mode 100644 modules/angular2/test/transform/directive_metadata_extractor/simple_files/expected/foo.ng_deps.dart create mode 100644 modules/angular2/test/transform/directive_metadata_extractor/simple_files/expected/foo.ng_meta.dart create mode 100644 modules/angular2/test/transform/directive_metadata_extractor/simple_files/foo.ng_deps.dart diff --git a/modules/angular2/src/transform/template_compiler/directive_metadata_reader.dart b/modules/angular2/src/transform/common/directive_metadata_reader.dart similarity index 96% rename from modules/angular2/src/transform/template_compiler/directive_metadata_reader.dart rename to modules/angular2/src/transform/common/directive_metadata_reader.dart index c95fcdb7fe..c775672459 100644 --- a/modules/angular2/src/transform/template_compiler/directive_metadata_reader.dart +++ b/modules/angular2/src/transform/common/directive_metadata_reader.dart @@ -1,9 +1,9 @@ -library angular2.transform.template_compiler.directive_metadata_reader; +library angular2.transform.common.directive_metadata_reader; import 'package:analyzer/analyzer.dart'; import 'package:angular2/src/render/api.dart'; -import 'package:angular2/src/transform/common/logging.dart'; -import 'package:angular2/src/transform/common/parser.dart'; +import 'logging.dart'; +import 'parser.dart'; /// Reads [DirectiveMetadata] from the `attributes` of `t`. DirectiveMetadata readDirectiveMetadata(RegisteredType t) { diff --git a/modules/angular2/src/transform/common/names.dart b/modules/angular2/src/transform/common/names.dart index 15059e6ff1..dc7b2fa7bb 100644 --- a/modules/angular2/src/transform/common/names.dart +++ b/modules/angular2/src/transform/common/names.dart @@ -4,6 +4,7 @@ const SETUP_METHOD_NAME = 'initReflector'; const REFLECTOR_VAR_NAME = 'reflector'; const TRANSFORM_DYNAMIC_MODE = 'transform_dynamic'; const DEPS_EXTENSION = '.ng_deps.dart'; +const META_EXTENSION = '.ng_meta.dart'; const REFLECTION_CAPABILITIES_NAME = 'ReflectionCapabilities'; const REGISTER_TYPE_METHOD_NAME = 'registerType'; const REGISTER_GETTERS_METHOD_NAME = 'registerGetters'; diff --git a/modules/angular2/src/transform/directive_metadata_extractor/extractor.dart b/modules/angular2/src/transform/directive_metadata_extractor/extractor.dart new file mode 100644 index 0000000000..dbfbea3cba --- /dev/null +++ b/modules/angular2/src/transform/directive_metadata_extractor/extractor.dart @@ -0,0 +1,28 @@ +library angular2.transform.directive_metadata_extractor.extractor; + +import 'dart:async'; + +import 'package:angular2/src/render/api.dart'; +import 'package:angular2/src/transform/common/asset_reader.dart'; +import 'package:angular2/src/transform/common/directive_metadata_reader.dart'; +import 'package:angular2/src/transform/common/parser.dart'; +import 'package:barback/barback.dart'; + +/// Returns a map from a class name (that is, its `Identifier` stringified) +/// to its [DirectiveMetadata]. +/// Will return `null` if there are no `Directive`-annotated classes in +/// `entryPoint`. +Future> extractDirectiveMetadata( + AssetReader reader, AssetId entryPoint) async { + var parser = new Parser(reader); + NgDeps ngDeps = await parser.parse(entryPoint); + if (ngDeps == null || ngDeps.registeredTypes.isEmpty) return null; + var retVal = {}; + ngDeps.registeredTypes.forEach((rType) { + var meta = readDirectiveMetadata(rType); + if (meta != null) { + retVal['${rType.typeName}'] = meta; + } + }); + return retVal; +} diff --git a/modules/angular2/src/transform/directive_metadata_extractor/transformer.dart b/modules/angular2/src/transform/directive_metadata_extractor/transformer.dart new file mode 100644 index 0000000000..8d4a41b060 --- /dev/null +++ b/modules/angular2/src/transform/directive_metadata_extractor/transformer.dart @@ -0,0 +1,56 @@ +library angular2.transform.directive_metadata_extractor.transformer; + +import 'dart:async'; +import 'dart:convert'; + +import 'package:angular2/src/render/dom/convert.dart'; +import 'package:angular2/src/transform/common/asset_reader.dart'; +import 'package:angular2/src/transform/common/logging.dart' as log; +import 'package:angular2/src/transform/common/names.dart'; +import 'package:barback/barback.dart'; + +import 'extractor.dart'; + +/// Transformer responsible for processing .ng_deps.dart files created by +/// {@link DirectiveProcessor} and creating associated `.ng_meta.dart` files. +/// These files contain commented Json-formatted representations of all +/// `Directive`s in the associated file. +class DirectiveMetadataExtractor extends Transformer { + DirectiveMetadataExtractor(); + + @override + bool isPrimary(AssetId id) => id.path.endsWith(DEPS_EXTENSION); + + @override + Future apply(Transform transform) async { + log.init(transform); + + try { + var reader = new AssetReader.fromTransform(transform); + var fromAssetId = transform.primaryInput.id; + + var metadataMap = await extractDirectiveMetadata(reader, fromAssetId); + if (metadataMap != null) { + var jsonMap = {}; + metadataMap.forEach((k, v) { + jsonMap[k] = directiveMetadataToMap(v); + }); + transform.addOutput(new Asset.fromString( + _outputAssetId(fromAssetId), '// ${JSON.encode(jsonMap)}')); + } + } catch (ex, stackTrace) { + log.logger.error('Extracting ng metadata failed.\n' + 'Exception: $ex\n' + 'Stack Trace: $stackTrace'); + } + return null; + } +} + +AssetId _outputAssetId(AssetId inputAssetId) { + assert(inputAssetId.path.endsWith(DEPS_EXTENSION)); + var pathIn = inputAssetId.path; + return new AssetId(inputAssetId.package, + '${pathIn.substring(0, pathIn.length - DEPS_EXTENSION.length)}' + '${META_EXTENSION}'); +} diff --git a/modules/angular2/src/transform/transformer.dart b/modules/angular2/src/transform/transformer.dart index ded793d04b..966869a0ee 100644 --- a/modules/angular2/src/transform/transformer.dart +++ b/modules/angular2/src/transform/transformer.dart @@ -4,6 +4,7 @@ import 'package:barback/barback.dart'; import 'package:dart_style/dart_style.dart'; import 'directive_linker/transformer.dart'; +import 'directive_metadata_extractor/transformer.dart'; import 'directive_processor/transformer.dart'; import 'bind_generator/transformer.dart'; import 'reflection_remover/transformer.dart'; @@ -24,7 +25,7 @@ class AngularTransformerGroup extends TransformerGroup { var phases = [ [new ReflectionRemover(options)], [new DirectiveProcessor(options)], - [new DirectiveLinker()], + [new DirectiveLinker(), new DirectiveMetadataExtractor()], [new BindGenerator(options)], [new TemplateCompiler(options)] ]; diff --git a/modules/angular2/test/transform/directive_metadata_extractor/all_tests.dart b/modules/angular2/test/transform/directive_metadata_extractor/all_tests.dart new file mode 100644 index 0000000000..93938980f4 --- /dev/null +++ b/modules/angular2/test/transform/directive_metadata_extractor/all_tests.dart @@ -0,0 +1,73 @@ +library angular2.test.transform.directive_metadata_extractor.all_tests; + +import 'dart:async'; +import 'package:angular2/src/render/api.dart'; +import 'package:angular2/src/transform/common/directive_metadata_reader.dart'; +import 'package:angular2/src/transform/common/logging.dart'; +import 'package:angular2/src/transform/common/parser.dart'; +import 'package:barback/barback.dart'; +import 'package:dart_style/dart_style.dart'; +import 'package:guinness/guinness.dart'; + +import '../common/read_file.dart'; + +var formatter = new DartFormatter(); + +void allTests() { + var reader = new TestAssetReader(); + var parser = new Parser(reader); + + beforeEach(() => setLogger(new PrintLogger())); + + Future readMetadata(inputPath) async { + var ngDeps = await parser.parse(new AssetId('a', inputPath)); + return readDirectiveMetadata(ngDeps.registeredTypes.first); + } + + it('should parse selectors', () async { + var metadata = await readMetadata( + 'directive_metadata_extractor/directive_metadata_files/selector.ng_deps.dart'); + expect(metadata.selector).toEqual('hello-app'); + }); + + it('should parse compile children values', () async { + var metadata = await readMetadata('directive_metadata_extractor/' + 'directive_metadata_files/compile_children.ng_deps.dart'); + expect(metadata.compileChildren).toBeTrue(); + + metadata = await readMetadata( + 'directive_metadata_extractor/directive_metadata_files/selector.ng_deps.dart'); + expect(metadata.compileChildren).toBeFalse(); + }); + + it('should parse properties.', () async { + var metadata = await readMetadata('directive_metadata_extractor/' + 'directive_metadata_files/properties.ng_deps.dart'); + expect(metadata.properties).toBeNotNull(); + expect(metadata.properties.length).toBe(2); + expect(metadata.properties).toContain('key1'); + expect(metadata.properties['key1']).toEqual('val1'); + expect(metadata.properties).toContain('key2'); + expect(metadata.properties['key2']).toEqual('val2'); + }); + + it('should parse host listeners.', () async { + var metadata = await readMetadata('directive_metadata_extractor/' + 'directive_metadata_files/host_listeners.ng_deps.dart'); + expect(metadata.hostListeners).toBeNotNull(); + expect(metadata.hostListeners.length).toBe(2); + expect(metadata.hostListeners).toContain('change'); + expect(metadata.hostListeners['change']).toEqual('onChange(\$event)'); + expect(metadata.hostListeners).toContain('keyDown'); + expect(metadata.hostListeners['keyDown']).toEqual('onKeyDown(\$event)'); + }); + + it('should fail when a class is annotated with multiple Directives.', + () async { + var ngDeps = await parser.parse(new AssetId('a', + 'directive_metadata_extractor/' + 'directive_metadata_files/too_many_directives.ng_deps.dart')); + expect(() => readDirectiveMetadata(ngDeps.registeredTypes.first)) + .toThrowWith(anInstanceOf: PrintLoggerError); + }); +} diff --git a/modules/angular2/test/transform/template_compiler/directive_metadata_files/compile_children.ng_deps.dart b/modules/angular2/test/transform/directive_metadata_extractor/directive_metadata_files/compile_children.ng_deps.dart similarity index 100% rename from modules/angular2/test/transform/template_compiler/directive_metadata_files/compile_children.ng_deps.dart rename to modules/angular2/test/transform/directive_metadata_extractor/directive_metadata_files/compile_children.ng_deps.dart diff --git a/modules/angular2/test/transform/template_compiler/directive_metadata_files/host_listeners.ng_deps.dart b/modules/angular2/test/transform/directive_metadata_extractor/directive_metadata_files/host_listeners.ng_deps.dart similarity index 100% rename from modules/angular2/test/transform/template_compiler/directive_metadata_files/host_listeners.ng_deps.dart rename to modules/angular2/test/transform/directive_metadata_extractor/directive_metadata_files/host_listeners.ng_deps.dart diff --git a/modules/angular2/test/transform/template_compiler/directive_metadata_files/properties.ng_deps.dart b/modules/angular2/test/transform/directive_metadata_extractor/directive_metadata_files/properties.ng_deps.dart similarity index 100% rename from modules/angular2/test/transform/template_compiler/directive_metadata_files/properties.ng_deps.dart rename to modules/angular2/test/transform/directive_metadata_extractor/directive_metadata_files/properties.ng_deps.dart diff --git a/modules/angular2/test/transform/template_compiler/directive_metadata_files/selector.ng_deps.dart b/modules/angular2/test/transform/directive_metadata_extractor/directive_metadata_files/selector.ng_deps.dart similarity index 100% rename from modules/angular2/test/transform/template_compiler/directive_metadata_files/selector.ng_deps.dart rename to modules/angular2/test/transform/directive_metadata_extractor/directive_metadata_files/selector.ng_deps.dart diff --git a/modules/angular2/test/transform/template_compiler/directive_metadata_files/too_many_directives.ng_deps.dart b/modules/angular2/test/transform/directive_metadata_extractor/directive_metadata_files/too_many_directives.ng_deps.dart similarity index 100% rename from modules/angular2/test/transform/template_compiler/directive_metadata_files/too_many_directives.ng_deps.dart rename to modules/angular2/test/transform/directive_metadata_extractor/directive_metadata_files/too_many_directives.ng_deps.dart diff --git a/modules/angular2/test/transform/directive_metadata_extractor/simple_files/expected/foo.ng_deps.dart b/modules/angular2/test/transform/directive_metadata_extractor/simple_files/expected/foo.ng_deps.dart new file mode 100644 index 0000000000..afa3650415 --- /dev/null +++ b/modules/angular2/test/transform/directive_metadata_extractor/simple_files/expected/foo.ng_deps.dart @@ -0,0 +1,16 @@ +library foo.ng_deps.dart; + +import 'foo.dart'; +import 'package:angular2/src/core/annotations/annotations.dart'; + +var _visited = false; +void initReflector(reflector) { + if (_visited) return; + _visited = true; + reflector + ..registerType(DependencyComponent, { + 'factory': () => new DependencyComponent(), + 'parameters': const [], + 'annotations': const [const Component(selector: '[salad]')] + }); +} diff --git a/modules/angular2/test/transform/directive_metadata_extractor/simple_files/expected/foo.ng_meta.dart b/modules/angular2/test/transform/directive_metadata_extractor/simple_files/expected/foo.ng_meta.dart new file mode 100644 index 0000000000..b4483579d1 --- /dev/null +++ b/modules/angular2/test/transform/directive_metadata_extractor/simple_files/expected/foo.ng_meta.dart @@ -0,0 +1 @@ +// {selector: '[salad]', type: 1} diff --git a/modules/angular2/test/transform/directive_metadata_extractor/simple_files/foo.ng_deps.dart b/modules/angular2/test/transform/directive_metadata_extractor/simple_files/foo.ng_deps.dart new file mode 100644 index 0000000000..afa3650415 --- /dev/null +++ b/modules/angular2/test/transform/directive_metadata_extractor/simple_files/foo.ng_deps.dart @@ -0,0 +1,16 @@ +library foo.ng_deps.dart; + +import 'foo.dart'; +import 'package:angular2/src/core/annotations/annotations.dart'; + +var _visited = false; +void initReflector(reflector) { + if (_visited) return; + _visited = true; + reflector + ..registerType(DependencyComponent, { + 'factory': () => new DependencyComponent(), + 'parameters': const [], + 'annotations': const [const Component(selector: '[salad]')] + }); +} diff --git a/modules/angular2/test/transform/integration/all_tests.dart b/modules/angular2/test/transform/integration/all_tests.dart index 6f6c2e4207..df4024f815 100644 --- a/modules/angular2/test/transform/integration/all_tests.dart +++ b/modules/angular2/test/transform/integration/all_tests.dart @@ -1,7 +1,6 @@ library angular2.test.transform.integration; import 'package:angular2/src/dom/html_adapter.dart'; -import 'package:angular2/src/transform/common/names.dart'; import 'package:angular2/transformer.dart'; import 'package:code_transformers/tests.dart'; import 'package:dart_style/dart_style.dart'; @@ -62,8 +61,7 @@ void allTests() { 'simple_annotation_files/expected/index.ng_deps.dart' }), new IntegrationTestConfig( - 'should generate proper code for a Component using a selector defined ' - 'in another file.', + 'should generate proper code for a Component with multiple deps.', inputs: { 'a|web/index.dart': 'two_deps_files/index.dart', 'a|web/foo.dart': 'two_deps_files/foo.dart', diff --git a/modules/angular2/test/transform/integration/list_of_types_files/expected/bar.ng_deps.dart b/modules/angular2/test/transform/integration/list_of_types_files/expected/bar.ng_deps.dart index 1615a6ff42..bb384647e3 100644 --- a/modules/angular2/test/transform/integration/list_of_types_files/expected/bar.ng_deps.dart +++ b/modules/angular2/test/transform/integration/list_of_types_files/expected/bar.ng_deps.dart @@ -2,7 +2,8 @@ library bar.ng_deps.dart; import 'bar.dart'; import 'package:angular2/src/core/annotations_impl/annotations.dart'; -import 'package:angular2/src/core/annotations_impl/annotations.ng_deps.dart' as i0; +import 'package:angular2/src/core/annotations_impl/annotations.ng_deps.dart' + as i0; import 'foo.dart'; import 'foo.ng_deps.dart' as i1; diff --git a/modules/angular2/test/transform/integration/simple_annotation_files/expected/bar.ng_deps.dart b/modules/angular2/test/transform/integration/simple_annotation_files/expected/bar.ng_deps.dart index 4c831b92d3..a6616a9ac0 100644 --- a/modules/angular2/test/transform/integration/simple_annotation_files/expected/bar.ng_deps.dart +++ b/modules/angular2/test/transform/integration/simple_annotation_files/expected/bar.ng_deps.dart @@ -2,7 +2,8 @@ library bar.ng_deps.dart; import 'bar.dart'; import 'package:angular2/src/core/annotations_impl/annotations.dart'; -import 'package:angular2/src/core/annotations_impl/annotations.ng_deps.dart' as i0; +import 'package:angular2/src/core/annotations_impl/annotations.ng_deps.dart' + as i0; var _visited = false; void initReflector(reflector) { diff --git a/modules/angular2/test/transform/integration/synthetic_ctor_files/expected/bar.ng_deps.dart b/modules/angular2/test/transform/integration/synthetic_ctor_files/expected/bar.ng_deps.dart index 4c831b92d3..a6616a9ac0 100644 --- a/modules/angular2/test/transform/integration/synthetic_ctor_files/expected/bar.ng_deps.dart +++ b/modules/angular2/test/transform/integration/synthetic_ctor_files/expected/bar.ng_deps.dart @@ -2,7 +2,8 @@ library bar.ng_deps.dart; import 'bar.dart'; import 'package:angular2/src/core/annotations_impl/annotations.dart'; -import 'package:angular2/src/core/annotations_impl/annotations.ng_deps.dart' as i0; +import 'package:angular2/src/core/annotations_impl/annotations.ng_deps.dart' + as i0; var _visited = false; void initReflector(reflector) { diff --git a/modules/angular2/test/transform/integration/two_annotations_files/expected/bar.ng_deps.dart b/modules/angular2/test/transform/integration/two_annotations_files/expected/bar.ng_deps.dart index 26d6cb682b..d60dc80e2a 100644 --- a/modules/angular2/test/transform/integration/two_annotations_files/expected/bar.ng_deps.dart +++ b/modules/angular2/test/transform/integration/two_annotations_files/expected/bar.ng_deps.dart @@ -2,7 +2,8 @@ library bar.ng_deps.dart; import 'bar.dart'; import 'package:angular2/src/core/annotations_impl/annotations.dart'; -import 'package:angular2/src/core/annotations_impl/annotations.ng_deps.dart' as i0; +import 'package:angular2/src/core/annotations_impl/annotations.ng_deps.dart' + as i0; import 'package:angular2/src/core/annotations_impl/view.dart'; import 'package:angular2/src/core/annotations_impl/view.ng_deps.dart' as i1; diff --git a/modules/angular2/test/transform/integration/two_deps_files/bar.dart b/modules/angular2/test/transform/integration/two_deps_files/bar.dart index 5510ef2628..bfbf1cc444 100644 --- a/modules/angular2/test/transform/integration/two_deps_files/bar.dart +++ b/modules/angular2/test/transform/integration/two_deps_files/bar.dart @@ -3,7 +3,7 @@ library bar; import 'package:angular2/src/core/annotations_impl/annotations.dart'; import 'foo.dart' as prefix; -@Component(selector: prefix.preDefinedSelector) +@Component(selector: 'soup') class MyComponent { final prefix.MyContext c; final String generatedValue; diff --git a/modules/angular2/test/transform/integration/two_deps_files/expected/bar.ng_deps.dart b/modules/angular2/test/transform/integration/two_deps_files/expected/bar.ng_deps.dart index 43dadfd8bc..2cc2d28912 100644 --- a/modules/angular2/test/transform/integration/two_deps_files/expected/bar.ng_deps.dart +++ b/modules/angular2/test/transform/integration/two_deps_files/expected/bar.ng_deps.dart @@ -2,7 +2,8 @@ library bar.ng_deps.dart; import 'bar.dart'; import 'package:angular2/src/core/annotations_impl/annotations.dart'; -import 'package:angular2/src/core/annotations_impl/annotations.ng_deps.dart' as i0; +import 'package:angular2/src/core/annotations_impl/annotations.ng_deps.dart' + as i0; import 'foo.dart' as prefix; import 'foo.ng_deps.dart' as i1; @@ -15,8 +16,7 @@ void initReflector(reflector) { 'factory': (prefix.MyContext c, String inValue) => new MyComponent(c, inValue), 'parameters': const [const [prefix.MyContext], const [String]], - 'annotations': - const [const Component(selector: prefix.preDefinedSelector)] + 'annotations': const [const Component(selector: 'soup')] }); i0.initReflector(reflector); i1.initReflector(reflector); diff --git a/modules/angular2/test/transform/integration/two_deps_files/foo.dart b/modules/angular2/test/transform/integration/two_deps_files/foo.dart index 444220e3d4..e2ccc6af66 100644 --- a/modules/angular2/test/transform/integration/two_deps_files/foo.dart +++ b/modules/angular2/test/transform/integration/two_deps_files/foo.dart @@ -1,7 +1,5 @@ library foo; -const preDefinedSelector = 'soup'; - class MyContext { final String selector; const MyContext(this.selector); diff --git a/modules/angular2/test/transform/reflection_remover/debug_mirrors_files/expected/index.dart b/modules/angular2/test/transform/reflection_remover/debug_mirrors_files/expected/index.dart index f81f56e599..9576d93c8e 100644 --- a/modules/angular2/test/transform/reflection_remover/debug_mirrors_files/expected/index.dart +++ b/modules/angular2/test/transform/reflection_remover/debug_mirrors_files/expected/index.dart @@ -1,4 +1,4 @@ -library angular2.test.transform.debug_reflection_remover_files; +library angular2.test.transform.reflection_remover.debug_mirrors_files.expected; // This file is intentionally formatted as a string to avoid having the // automatic transformer prettify it. diff --git a/modules/angular2/test/transform/reflection_remover/reflection_remover_files/expected/index.dart b/modules/angular2/test/transform/reflection_remover/reflection_remover_files/expected/index.dart index 09833f1113..d8b7d4b9fa 100644 --- a/modules/angular2/test/transform/reflection_remover/reflection_remover_files/expected/index.dart +++ b/modules/angular2/test/transform/reflection_remover/reflection_remover_files/expected/index.dart @@ -1,4 +1,4 @@ -library angular2.test.transform.reflection_remover_files; +library angular2.test.transform.reflection_remover.reflection_remover_files; // This file is intentionally formatted as a string to avoid having the // automatic transformer prettify it. diff --git a/modules/angular2/test/transform/reflection_remover/verbose_files/expected/index.dart b/modules/angular2/test/transform/reflection_remover/verbose_files/expected/index.dart index c03c2c0557..65884c6cb8 100644 --- a/modules/angular2/test/transform/reflection_remover/verbose_files/expected/index.dart +++ b/modules/angular2/test/transform/reflection_remover/verbose_files/expected/index.dart @@ -1,4 +1,4 @@ -library angular2.test.transform.debug_reflection_remover_files; +library angular2.test.transform.reflection_remover.verbose_files.expected; // This file is intentionally formatted as a string to avoid having the // automatic transformer prettify it. diff --git a/modules/angular2/test/transform/template_compiler/all_tests.dart b/modules/angular2/test/transform/template_compiler/all_tests.dart index 19c0bade90..61e60414be 100644 --- a/modules/angular2/test/transform/template_compiler/all_tests.dart +++ b/modules/angular2/test/transform/template_compiler/all_tests.dart @@ -1,13 +1,9 @@ library angular2.test.transform.template_compiler.all_tests; -import 'dart:async'; import 'package:barback/barback.dart'; import 'package:angular2/src/dom/html_adapter.dart'; -import 'package:angular2/src/render/api.dart'; import 'package:angular2/src/transform/common/asset_reader.dart'; import 'package:angular2/src/transform/common/logging.dart'; -import 'package:angular2/src/transform/common/parser.dart'; -import 'package:angular2/src/transform/template_compiler/directive_metadata_reader.dart'; import 'package:angular2/src/transform/template_compiler/generator.dart'; import 'package:dart_style/dart_style.dart'; import 'package:guinness/guinness.dart'; @@ -19,7 +15,6 @@ var formatter = new DartFormatter(); void allTests() { Html5LibDomAdapter.makeCurrent(); AssetReader reader = new TestAssetReader(); - var parser = new Parser(reader); beforeEach(() => setLogger(new PrintLogger())); @@ -63,59 +58,6 @@ void allTests() { var output = await processTemplates(reader, new AssetId('a', inputPath)); _formatThenExpectEquals(output, expected); }); - - describe('DirectiveMetadataReader', () { - Future readMetadata(inputPath) async { - var ngDeps = await parser.parse(new AssetId('a', inputPath)); - return readDirectiveMetadata(ngDeps.registeredTypes.first); - } - - it('should parse selectors', () async { - var metadata = await readMetadata( - 'template_compiler/directive_metadata_files/selector.ng_deps.dart'); - expect(metadata.selector).toEqual('hello-app'); - }); - - it('should parse compile children values', () async { - var metadata = await readMetadata('template_compiler/' - 'directive_metadata_files/compile_children.ng_deps.dart'); - expect(metadata.compileChildren).toBeTrue(); - - metadata = await readMetadata( - 'template_compiler/directive_metadata_files/selector.ng_deps.dart'); - expect(metadata.compileChildren).toBeFalse(); - }); - - it('should parse properties.', () async { - var metadata = await readMetadata('template_compiler/' - 'directive_metadata_files/properties.ng_deps.dart'); - expect(metadata.properties).toBeNotNull(); - expect(metadata.properties.length).toBe(2); - expect(metadata.properties).toContain('key1'); - expect(metadata.properties['key1']).toEqual('val1'); - expect(metadata.properties).toContain('key2'); - expect(metadata.properties['key2']).toEqual('val2'); - }); - - it('should parse host listeners.', () async { - var metadata = await readMetadata('template_compiler/' - 'directive_metadata_files/host_listeners.ng_deps.dart'); - expect(metadata.hostListeners).toBeNotNull(); - expect(metadata.hostListeners.length).toBe(2); - expect(metadata.hostListeners).toContain('change'); - expect(metadata.hostListeners['change']).toEqual('onChange(\$event)'); - expect(metadata.hostListeners).toContain('keyDown'); - expect(metadata.hostListeners['keyDown']).toEqual('onKeyDown(\$event)'); - }); - - it('should fail when a class is annotated with multiple Directives.', - () async { - var ngDeps = await parser.parse(new AssetId('a', 'template_compiler/' - 'directive_metadata_files/too_many_directives.ng_deps.dart')); - expect(() => readDirectiveMetadata(ngDeps.registeredTypes.first)) - .toThrowWith(anInstanceOf: PrintLoggerError); - }); - }); } void _formatThenExpectEquals(String actual, String expected) { diff --git a/modules/angular2/test/transform/transform.server.spec.dart b/modules/angular2/test/transform/transform.server.spec.dart index 4028580fee..38ab159f1f 100644 --- a/modules/angular2/test/transform/transform.server.spec.dart +++ b/modules/angular2/test/transform/transform.server.spec.dart @@ -6,6 +6,7 @@ import 'package:unittest/vm_config.dart'; import 'bind_generator/all_tests.dart' as bindGenerator; import 'directive_linker/all_tests.dart' as directiveLinker; +import 'directive_metadata_extractor/all_tests.dart' as directiveMeta; import 'directive_processor/all_tests.dart' as directiveProcessor; import 'integration/all_tests.dart' as integration; import 'reflection_remover/all_tests.dart' as reflectionRemover; @@ -15,6 +16,7 @@ main() { useVMConfiguration(); describe('Bind Generator', bindGenerator.allTests); describe('Directive Linker', directiveLinker.allTests); + describe('Directive Metadata Extractor', directiveMeta.allTests); describe('Directive Processor', directiveProcessor.allTests); describe('Reflection Remover', reflectionRemover.allTests); describe('Template Compiler', templateCompiler.allTests);