From 591f742d42b4ed2d56fcbc227980b0317d82de8b Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Tue, 9 Jun 2015 12:54:47 +0200 Subject: [PATCH] feat(transform): update for Directive.host --- .../common/directive_metadata_reader.dart | 37 ++++++------------- .../all_tests.dart | 21 +++++++++-- .../host_listeners.ng_deps.dart | 8 ++-- .../expected/bar.ng_meta.json | 4 +- .../duplicate_files/hello.ng_meta.json | 3 +- .../hello.ng_meta.json | 3 +- .../inline_method_files/hello.ng_meta.json | 3 +- .../one_directive_files/hello.ng_meta.json | 6 +-- .../url_expression_files/hello.ng_meta.json | 3 +- .../url_method_files/hello.ng_meta.json | 3 +- .../with_prefix_files/goodbye.ng_meta.json | 3 +- .../with_prefix_files/hello.ng_meta.json | 3 +- 12 files changed, 45 insertions(+), 52 deletions(-) diff --git a/modules/angular2/src/transform/common/directive_metadata_reader.dart b/modules/angular2/src/transform/common/directive_metadata_reader.dart index e40495d118..c3621942ae 100644 --- a/modules/angular2/src/transform/common/directive_metadata_reader.dart +++ b/modules/angular2/src/transform/common/directive_metadata_reader.dart @@ -53,13 +53,11 @@ class _DirectiveMetadataVisitor extends Object void _createEmptyMetadata(num type) { assert(type >= 0); - meta = new DirectiveMetadata( + meta = DirectiveMetadata.create( type: type, compileChildren: true, properties: [], - hostListeners: {}, - hostProperties: {}, - hostAttributes: {}, + host: {}, readAttributes: [], exportAs: null, callOnDestroy: false, @@ -124,14 +122,8 @@ class _DirectiveMetadataVisitor extends Object case 'properties': _populateProperties(node.expression); break; - case 'hostProperties': - _populateHostProperties(node.expression); - break; - case 'hostAttributes': - _populateHostAttributes(node.expression); - break; - case 'hostListeners': - _populateHostListeners(node.expression); + case 'host': + _populateHost(node.expression); break; case 'lifecycle': _populateLifecycle(node.expression); @@ -210,22 +202,17 @@ class _DirectiveMetadataVisitor extends Object _populateList(propertiesValue, meta.properties, 'Directive#properties'); } - void _populateHostListeners(Expression hostListenersValue) { + void _populateHost(Expression hostValue) { _checkMeta(); - _populateMap( - hostListenersValue, meta.hostListeners, 'Directive#hostListeners'); - } + var host = new Map(); + _populateMap(hostValue, host, 'Directive#host'); - void _populateHostProperties(Expression hostPropertyValue) { - _checkMeta(); - _populateMap( - hostPropertyValue, meta.hostProperties, 'Directive#hostProperties'); - } + var hostConfig = DirectiveMetadata.parseHostConfig(host); - void _populateHostAttributes(Expression hostAttributeValue) { - _checkMeta(); - _populateMap( - hostAttributeValue, meta.hostAttributes, 'Directive#hostAttributes'); + meta.hostListeners = hostConfig['hostListeners']; + meta.hostProperties = hostConfig['hostProperties']; + meta.hostActions = hostConfig['hostActions']; + meta.hostAttributes = hostConfig['hostAttributes']; } void _populateExportAs(Expression exportAsValue) { 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 e799e1b5e6..d569685142 100644 --- a/modules/angular2/test/transform/directive_metadata_extractor/all_tests.dart +++ b/modules/angular2/test/transform/directive_metadata_extractor/all_tests.dart @@ -75,15 +75,28 @@ void allTests() { expect(metadata.exportAs).toEqual('exportAsName'); }); - it('should parse host listeners.', () async { + it('should parse host.', () 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.length).toBe(1); expect(metadata.hostListeners).toContain('change'); expect(metadata.hostListeners['change']).toEqual('onChange(\$event)'); - expect(metadata.hostListeners).toContain('keyDown'); - expect(metadata.hostListeners['keyDown']).toEqual('onKeyDown(\$event)'); + + expect(metadata.hostProperties).toBeNotNull(); + expect(metadata.hostProperties.length).toBe(1); + expect(metadata.hostProperties).toContain('value'); + expect(metadata.hostProperties['value']).toEqual('value'); + + expect(metadata.hostAttributes).toBeNotNull(); + expect(metadata.hostAttributes.length).toBe(1); + expect(metadata.hostAttributes).toContain('attName'); + expect(metadata.hostAttributes['attName']).toEqual('attValue'); + + expect(metadata.hostActions).toBeNotNull(); + expect(metadata.hostActions.length).toBe(1); + expect(metadata.hostActions).toContain('actionName'); + expect(metadata.hostActions['actionName']).toEqual('actionValue'); }); it('should parse lifecycle events.', () async { diff --git a/modules/angular2/test/transform/directive_metadata_extractor/directive_metadata_files/host_listeners.ng_deps.dart b/modules/angular2/test/transform/directive_metadata_extractor/directive_metadata_files/host_listeners.ng_deps.dart index f0ea2ed9e1..6f86384db0 100644 --- a/modules/angular2/test/transform/directive_metadata_extractor/directive_metadata_files/host_listeners.ng_deps.dart +++ b/modules/angular2/test/transform/directive_metadata_extractor/directive_metadata_files/host_listeners.ng_deps.dart @@ -14,9 +14,11 @@ void initReflector(reflector) { 'parameters': const [const []], 'annotations': const [ const Component( - hostListeners: const { - 'change': 'onChange(\$event)', - 'keyDown': 'onKeyDown(\$event)' + host: const { + '(change)': 'onChange(\$event)', + '[value]': 'value', + '@actionName': 'actionValue', + 'attName': 'attValue' }) ] }); 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 93383b3b37..fe247de602 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 @@ -3,10 +3,10 @@ "id": "MyComponent", "selector": "[soup]", "compileChildren": true, - "hostListeners": {}, "hostProperties": {}, + "hostListeners": {}, + "hostActions": {}, "hostAttributes": {}, - "hostActions": null, "properties": [], "readAttributes": [], "type": 1, diff --git a/modules/angular2/test/transform/template_compiler/duplicate_files/hello.ng_meta.json b/modules/angular2/test/transform/template_compiler/duplicate_files/hello.ng_meta.json index e2d05ba227..eab28548e9 100644 --- a/modules/angular2/test/transform/template_compiler/duplicate_files/hello.ng_meta.json +++ b/modules/angular2/test/transform/template_compiler/duplicate_files/hello.ng_meta.json @@ -4,8 +4,7 @@ "id":"HelloCmp", "selector":"hello-app", "compileChildren":true, - "hostListeners":{}, - "hostProperties":{}, + "host":{}, "properties":[], "readAttributes":[], "type":1, diff --git a/modules/angular2/test/transform/template_compiler/inline_expression_files/hello.ng_meta.json b/modules/angular2/test/transform/template_compiler/inline_expression_files/hello.ng_meta.json index e2d05ba227..eab28548e9 100644 --- a/modules/angular2/test/transform/template_compiler/inline_expression_files/hello.ng_meta.json +++ b/modules/angular2/test/transform/template_compiler/inline_expression_files/hello.ng_meta.json @@ -4,8 +4,7 @@ "id":"HelloCmp", "selector":"hello-app", "compileChildren":true, - "hostListeners":{}, - "hostProperties":{}, + "host":{}, "properties":[], "readAttributes":[], "type":1, diff --git a/modules/angular2/test/transform/template_compiler/inline_method_files/hello.ng_meta.json b/modules/angular2/test/transform/template_compiler/inline_method_files/hello.ng_meta.json index e2d05ba227..eab28548e9 100644 --- a/modules/angular2/test/transform/template_compiler/inline_method_files/hello.ng_meta.json +++ b/modules/angular2/test/transform/template_compiler/inline_method_files/hello.ng_meta.json @@ -4,8 +4,7 @@ "id":"HelloCmp", "selector":"hello-app", "compileChildren":true, - "hostListeners":{}, - "hostProperties":{}, + "host":{}, "properties":[], "readAttributes":[], "type":1, diff --git a/modules/angular2/test/transform/template_compiler/one_directive_files/hello.ng_meta.json b/modules/angular2/test/transform/template_compiler/one_directive_files/hello.ng_meta.json index f6258dffd6..6bb779796b 100644 --- a/modules/angular2/test/transform/template_compiler/one_directive_files/hello.ng_meta.json +++ b/modules/angular2/test/transform/template_compiler/one_directive_files/hello.ng_meta.json @@ -4,8 +4,7 @@ "id":"HelloCmp", "selector":"hello-app", "compileChildren":true, - "hostListeners":{}, - "hostProperties":{}, + "host":{}, "properties":[], "readAttributes":[], "type":1, @@ -15,8 +14,7 @@ "id":"GoodbyeCmp", "selector":"goodbye-app", "compileChildren":true, - "hostListeners":{}, - "hostProperties":{}, + "host":{}, "properties":[], "readAttributes":[], "type":1, diff --git a/modules/angular2/test/transform/template_compiler/url_expression_files/hello.ng_meta.json b/modules/angular2/test/transform/template_compiler/url_expression_files/hello.ng_meta.json index e2d05ba227..eab28548e9 100644 --- a/modules/angular2/test/transform/template_compiler/url_expression_files/hello.ng_meta.json +++ b/modules/angular2/test/transform/template_compiler/url_expression_files/hello.ng_meta.json @@ -4,8 +4,7 @@ "id":"HelloCmp", "selector":"hello-app", "compileChildren":true, - "hostListeners":{}, - "hostProperties":{}, + "host":{}, "properties":[], "readAttributes":[], "type":1, diff --git a/modules/angular2/test/transform/template_compiler/url_method_files/hello.ng_meta.json b/modules/angular2/test/transform/template_compiler/url_method_files/hello.ng_meta.json index e2d05ba227..eab28548e9 100644 --- a/modules/angular2/test/transform/template_compiler/url_method_files/hello.ng_meta.json +++ b/modules/angular2/test/transform/template_compiler/url_method_files/hello.ng_meta.json @@ -4,8 +4,7 @@ "id":"HelloCmp", "selector":"hello-app", "compileChildren":true, - "hostListeners":{}, - "hostProperties":{}, + "host":{}, "properties":[], "readAttributes":[], "type":1, diff --git a/modules/angular2/test/transform/template_compiler/with_prefix_files/goodbye.ng_meta.json b/modules/angular2/test/transform/template_compiler/with_prefix_files/goodbye.ng_meta.json index f3ff092394..56cf16b9e3 100644 --- a/modules/angular2/test/transform/template_compiler/with_prefix_files/goodbye.ng_meta.json +++ b/modules/angular2/test/transform/template_compiler/with_prefix_files/goodbye.ng_meta.json @@ -3,8 +3,7 @@ "id":"GoodbyeCmp", "selector":"goodbye-app", "compileChildren":true, - "hostListeners":{}, - "hostProperties":{}, + "host":{}, "properties":[], "readAttributes":[], "type":1, diff --git a/modules/angular2/test/transform/template_compiler/with_prefix_files/hello.ng_meta.json b/modules/angular2/test/transform/template_compiler/with_prefix_files/hello.ng_meta.json index e2d05ba227..eab28548e9 100644 --- a/modules/angular2/test/transform/template_compiler/with_prefix_files/hello.ng_meta.json +++ b/modules/angular2/test/transform/template_compiler/with_prefix_files/hello.ng_meta.json @@ -4,8 +4,7 @@ "id":"HelloCmp", "selector":"hello-app", "compileChildren":true, - "hostListeners":{}, - "hostProperties":{}, + "host":{}, "properties":[], "readAttributes":[], "type":1,