From a593ffa6f3d7cb6062e9e1957aae1382bfcb666f Mon Sep 17 00:00:00 2001 From: vsavkin Date: Tue, 5 Jan 2016 18:56:59 -0800 Subject: [PATCH] fix(transformer): record HostBinding annotations applied to getters Closes #6283 --- .../lib/src/transform/common/type_metadata_reader.dart | 9 +++++++++ .../test/transform/directive_processor/all_tests.dart | 2 +- .../directive_processor/directives_files/components.dart | 6 ++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/modules_dart/transform/lib/src/transform/common/type_metadata_reader.dart b/modules_dart/transform/lib/src/transform/common/type_metadata_reader.dart index a9200d1ed7..3191630314 100644 --- a/modules_dart/transform/lib/src/transform/common/type_metadata_reader.dart +++ b/modules_dart/transform/lib/src/transform/common/type_metadata_reader.dart @@ -294,6 +294,15 @@ class _DirectiveMetadataVisitor extends Object final params = _getHostListenerParams(meta); _host['(${eventName})'] = '${node.name}($params)'; } + + if (_isAnnotation(meta, 'HostBinding') && node.isGetter) { + final renamed = _getRenamedValue(meta); + if (renamed != null) { + _host['[${renamed}]'] = '${node.name}'; + } else { + _host['[${node.name}]'] = '${node.name}'; + } + } } return null; } diff --git a/modules_dart/transform/test/transform/directive_processor/all_tests.dart b/modules_dart/transform/test/transform/directive_processor/all_tests.dart index 3ab1785e4a..871141f9e3 100644 --- a/modules_dart/transform/test/transform/directive_processor/all_tests.dart +++ b/modules_dart/transform/test/transform/directive_processor/all_tests.dart @@ -552,7 +552,7 @@ void allTests() { it('should merge host bindings from the annotation and fields.', () async { var model = await _testCreateModel('directives_files/components.dart'); expect(model.types['ComponentWithHostBindings'].hostProperties) - .toEqual({'a': 'a', 'b': 'b', 'renamed': 'c'}); + .toEqual({'a': 'a', 'b': 'b', 'renamed': 'c', 'd': 'd', 'get-renamed': 'e'}); }); it('should merge host listeners from the annotation and fields.', () async { diff --git a/modules_dart/transform/test/transform/directive_processor/directives_files/components.dart b/modules_dart/transform/test/transform/directive_processor/directives_files/components.dart index 28e3b8b869..b61aabc9e8 100644 --- a/modules_dart/transform/test/transform/directive_processor/directives_files/components.dart +++ b/modules_dart/transform/test/transform/directive_processor/directives_files/components.dart @@ -67,6 +67,12 @@ class ComponentWithInputs { class ComponentWithHostBindings { @HostBinding() Object b; @HostBinding('renamed') Object c; + + Object _d; + @HostBinding() Object get d => _d; + + Object _e; + @HostBinding('get-renamed') Object get e => _e; } @Component(