X Tutup
Skip to content

Commit a593ffa

Browse files
committed
fix(transformer): record HostBinding annotations applied to getters
Closes #6283
1 parent 761c6d0 commit a593ffa

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

modules_dart/transform/lib/src/transform/common/type_metadata_reader.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,15 @@ class _DirectiveMetadataVisitor extends Object
294294
final params = _getHostListenerParams(meta);
295295
_host['(${eventName})'] = '${node.name}($params)';
296296
}
297+
298+
if (_isAnnotation(meta, 'HostBinding') && node.isGetter) {
299+
final renamed = _getRenamedValue(meta);
300+
if (renamed != null) {
301+
_host['[${renamed}]'] = '${node.name}';
302+
} else {
303+
_host['[${node.name}]'] = '${node.name}';
304+
}
305+
}
297306
}
298307
return null;
299308
}

modules_dart/transform/test/transform/directive_processor/all_tests.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ void allTests() {
552552
it('should merge host bindings from the annotation and fields.', () async {
553553
var model = await _testCreateModel('directives_files/components.dart');
554554
expect(model.types['ComponentWithHostBindings'].hostProperties)
555-
.toEqual({'a': 'a', 'b': 'b', 'renamed': 'c'});
555+
.toEqual({'a': 'a', 'b': 'b', 'renamed': 'c', 'd': 'd', 'get-renamed': 'e'});
556556
});
557557

558558
it('should merge host listeners from the annotation and fields.', () async {

modules_dart/transform/test/transform/directive_processor/directives_files/components.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ class ComponentWithInputs {
6767
class ComponentWithHostBindings {
6868
@HostBinding() Object b;
6969
@HostBinding('renamed') Object c;
70+
71+
Object _d;
72+
@HostBinding() Object get d => _d;
73+
74+
Object _e;
75+
@HostBinding('get-renamed') Object get e => _e;
7076
}
7177

7278
@Component(

0 commit comments

Comments
 (0)
X Tutup