From e5419febe478b402493f56401ad49b3180861aa2 Mon Sep 17 00:00:00 2001 From: vsavkin Date: Thu, 4 Jun 2015 13:45:23 -0700 Subject: [PATCH] feat(transformers): updated transformers --- .../common/directive_metadata_reader.dart | 9 +++++++++ .../all_tests.dart | 6 ++++++ .../directive_export_as.ng_deps.dart | 19 +++++++++++++++++++ .../expected/bar.ng_meta.json | 1 + 4 files changed, 35 insertions(+) create mode 100644 modules/angular2/test/transform/directive_metadata_extractor/directive_metadata_files/directive_export_as.ng_deps.dart diff --git a/modules/angular2/src/transform/common/directive_metadata_reader.dart b/modules/angular2/src/transform/common/directive_metadata_reader.dart index 3ba0b2322c..a747da1f96 100644 --- a/modules/angular2/src/transform/common/directive_metadata_reader.dart +++ b/modules/angular2/src/transform/common/directive_metadata_reader.dart @@ -61,6 +61,7 @@ class _DirectiveMetadataVisitor extends Object hostProperties: {}, hostAttributes: {}, readAttributes: [], + exportAs: null, callOnDestroy: false, callOnChange: false, callOnCheck: false, @@ -136,6 +137,9 @@ class _DirectiveMetadataVisitor extends Object case 'lifecycle': _populateLifecycle(node.expression); break; + case 'exportAs': + _populateExportAs(node.expression); + break; } return null; } @@ -225,6 +229,11 @@ class _DirectiveMetadataVisitor extends Object hostAttributeValue, meta.hostAttributes, 'Directive#hostAttributes'); } + void _populateExportAs(Expression exportAsValue) { + _checkMeta(); + meta.exportAs = _expressionToString(exportAsValue, 'Directive#exportAs'); + } + void _populateLifecycle(Expression lifecycleValue) { _checkMeta(); if (lifecycleValue is! ListLiteral) { diff --git a/modules/angular2/test/transform/directive_metadata_extractor/all_tests.dart b/modules/angular2/test/transform/directive_metadata_extractor/all_tests.dart index 12137f69fd..3d37a02669 100644 --- a/modules/angular2/test/transform/directive_metadata_extractor/all_tests.dart +++ b/modules/angular2/test/transform/directive_metadata_extractor/all_tests.dart @@ -67,6 +67,12 @@ void allTests() { expect(metadata.properties).toContain('key2: val2'); }); + it('should parse exportAs.', () async { + var metadata = await readMetadata('directive_metadata_extractor/' + 'directive_metadata_files/directive_export_as.ng_deps.dart'); + expect(metadata.exportAs).toEqual('exportAsName'); + }); + it('should parse host listeners.', () async { var metadata = await readMetadata('directive_metadata_extractor/' 'directive_metadata_files/host_listeners.ng_deps.dart'); diff --git a/modules/angular2/test/transform/directive_metadata_extractor/directive_metadata_files/directive_export_as.ng_deps.dart b/modules/angular2/test/transform/directive_metadata_extractor/directive_metadata_files/directive_export_as.ng_deps.dart new file mode 100644 index 0000000000..5b46d20b98 --- /dev/null +++ b/modules/angular2/test/transform/directive_metadata_extractor/directive_metadata_files/directive_export_as.ng_deps.dart @@ -0,0 +1,19 @@ +library examples.hello_world.index_common_dart.ng_deps.dart; + +import 'hello.dart'; +import 'package:angular2/angular2.dart' + show bootstrap, Component, Directive, View, NgElement, onChange, onDestroy, onInit, onCheck, onAllChangesDone; + +var _visited = false; +void initReflector(reflector) { + if (_visited) return; + _visited = true; + reflector + ..registerType(HelloCmp, { + 'factory': () => new HelloCmp(), + 'parameters': const [const []], + 'annotations': const [ + const Directive(exportAs: 'exportAsName') + ] + }); +} diff --git a/modules/angular2/test/transform/integration/simple_annotation_files/expected/bar.ng_meta.json b/modules/angular2/test/transform/integration/simple_annotation_files/expected/bar.ng_meta.json index 23e312aaf1..93383b3b37 100644 --- a/modules/angular2/test/transform/integration/simple_annotation_files/expected/bar.ng_meta.json +++ b/modules/angular2/test/transform/integration/simple_annotation_files/expected/bar.ng_meta.json @@ -10,6 +10,7 @@ "properties": [], "readAttributes": [], "type": 1, + "exportAs": null, "callOnDestroy": false, "callOnCheck": false, "callOnInit": false,