X Tutup
Skip to content

Commit 591f742

Browse files
vicbtbosch
authored andcommitted
feat(transform): update for Directive.host
1 parent 20953ed commit 591f742

File tree

12 files changed

+45
-52
lines changed

12 files changed

+45
-52
lines changed

modules/angular2/src/transform/common/directive_metadata_reader.dart

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,11 @@ class _DirectiveMetadataVisitor extends Object
5353

5454
void _createEmptyMetadata(num type) {
5555
assert(type >= 0);
56-
meta = new DirectiveMetadata(
56+
meta = DirectiveMetadata.create(
5757
type: type,
5858
compileChildren: true,
5959
properties: [],
60-
hostListeners: {},
61-
hostProperties: {},
62-
hostAttributes: {},
60+
host: {},
6361
readAttributes: [],
6462
exportAs: null,
6563
callOnDestroy: false,
@@ -124,14 +122,8 @@ class _DirectiveMetadataVisitor extends Object
124122
case 'properties':
125123
_populateProperties(node.expression);
126124
break;
127-
case 'hostProperties':
128-
_populateHostProperties(node.expression);
129-
break;
130-
case 'hostAttributes':
131-
_populateHostAttributes(node.expression);
132-
break;
133-
case 'hostListeners':
134-
_populateHostListeners(node.expression);
125+
case 'host':
126+
_populateHost(node.expression);
135127
break;
136128
case 'lifecycle':
137129
_populateLifecycle(node.expression);
@@ -210,22 +202,17 @@ class _DirectiveMetadataVisitor extends Object
210202
_populateList(propertiesValue, meta.properties, 'Directive#properties');
211203
}
212204

213-
void _populateHostListeners(Expression hostListenersValue) {
205+
void _populateHost(Expression hostValue) {
214206
_checkMeta();
215-
_populateMap(
216-
hostListenersValue, meta.hostListeners, 'Directive#hostListeners');
217-
}
207+
var host = new Map();
208+
_populateMap(hostValue, host, 'Directive#host');
218209

219-
void _populateHostProperties(Expression hostPropertyValue) {
220-
_checkMeta();
221-
_populateMap(
222-
hostPropertyValue, meta.hostProperties, 'Directive#hostProperties');
223-
}
210+
var hostConfig = DirectiveMetadata.parseHostConfig(host);
224211

225-
void _populateHostAttributes(Expression hostAttributeValue) {
226-
_checkMeta();
227-
_populateMap(
228-
hostAttributeValue, meta.hostAttributes, 'Directive#hostAttributes');
212+
meta.hostListeners = hostConfig['hostListeners'];
213+
meta.hostProperties = hostConfig['hostProperties'];
214+
meta.hostActions = hostConfig['hostActions'];
215+
meta.hostAttributes = hostConfig['hostAttributes'];
229216
}
230217

231218
void _populateExportAs(Expression exportAsValue) {

modules/angular2/test/transform/directive_metadata_extractor/all_tests.dart

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,28 @@ void allTests() {
7575
expect(metadata.exportAs).toEqual('exportAsName');
7676
});
7777

78-
it('should parse host listeners.', () async {
78+
it('should parse host.', () async {
7979
var metadata = await readMetadata('directive_metadata_extractor/'
8080
'directive_metadata_files/host_listeners.ng_deps.dart');
8181
expect(metadata.hostListeners).toBeNotNull();
82-
expect(metadata.hostListeners.length).toBe(2);
82+
expect(metadata.hostListeners.length).toBe(1);
8383
expect(metadata.hostListeners).toContain('change');
8484
expect(metadata.hostListeners['change']).toEqual('onChange(\$event)');
85-
expect(metadata.hostListeners).toContain('keyDown');
86-
expect(metadata.hostListeners['keyDown']).toEqual('onKeyDown(\$event)');
85+
86+
expect(metadata.hostProperties).toBeNotNull();
87+
expect(metadata.hostProperties.length).toBe(1);
88+
expect(metadata.hostProperties).toContain('value');
89+
expect(metadata.hostProperties['value']).toEqual('value');
90+
91+
expect(metadata.hostAttributes).toBeNotNull();
92+
expect(metadata.hostAttributes.length).toBe(1);
93+
expect(metadata.hostAttributes).toContain('attName');
94+
expect(metadata.hostAttributes['attName']).toEqual('attValue');
95+
96+
expect(metadata.hostActions).toBeNotNull();
97+
expect(metadata.hostActions.length).toBe(1);
98+
expect(metadata.hostActions).toContain('actionName');
99+
expect(metadata.hostActions['actionName']).toEqual('actionValue');
87100
});
88101

89102
it('should parse lifecycle events.', () async {

modules/angular2/test/transform/directive_metadata_extractor/directive_metadata_files/host_listeners.ng_deps.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ void initReflector(reflector) {
1414
'parameters': const [const []],
1515
'annotations': const [
1616
const Component(
17-
hostListeners: const {
18-
'change': 'onChange(\$event)',
19-
'keyDown': 'onKeyDown(\$event)'
17+
host: const {
18+
'(change)': 'onChange(\$event)',
19+
'[value]': 'value',
20+
'@actionName': 'actionValue',
21+
'attName': 'attValue'
2022
})
2123
]
2224
});

modules/angular2/test/transform/integration/simple_annotation_files/expected/bar.ng_meta.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
"id": "MyComponent",
44
"selector": "[soup]",
55
"compileChildren": true,
6-
"hostListeners": {},
76
"hostProperties": {},
7+
"hostListeners": {},
8+
"hostActions": {},
89
"hostAttributes": {},
9-
"hostActions": null,
1010
"properties": [],
1111
"readAttributes": [],
1212
"type": 1,

modules/angular2/test/transform/template_compiler/duplicate_files/hello.ng_meta.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
"id":"HelloCmp",
55
"selector":"hello-app",
66
"compileChildren":true,
7-
"hostListeners":{},
8-
"hostProperties":{},
7+
"host":{},
98
"properties":[],
109
"readAttributes":[],
1110
"type":1,

modules/angular2/test/transform/template_compiler/inline_expression_files/hello.ng_meta.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
"id":"HelloCmp",
55
"selector":"hello-app",
66
"compileChildren":true,
7-
"hostListeners":{},
8-
"hostProperties":{},
7+
"host":{},
98
"properties":[],
109
"readAttributes":[],
1110
"type":1,

modules/angular2/test/transform/template_compiler/inline_method_files/hello.ng_meta.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
"id":"HelloCmp",
55
"selector":"hello-app",
66
"compileChildren":true,
7-
"hostListeners":{},
8-
"hostProperties":{},
7+
"host":{},
98
"properties":[],
109
"readAttributes":[],
1110
"type":1,

modules/angular2/test/transform/template_compiler/one_directive_files/hello.ng_meta.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
"id":"HelloCmp",
55
"selector":"hello-app",
66
"compileChildren":true,
7-
"hostListeners":{},
8-
"hostProperties":{},
7+
"host":{},
98
"properties":[],
109
"readAttributes":[],
1110
"type":1,
@@ -15,8 +14,7 @@
1514
"id":"GoodbyeCmp",
1615
"selector":"goodbye-app",
1716
"compileChildren":true,
18-
"hostListeners":{},
19-
"hostProperties":{},
17+
"host":{},
2018
"properties":[],
2119
"readAttributes":[],
2220
"type":1,

modules/angular2/test/transform/template_compiler/url_expression_files/hello.ng_meta.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
"id":"HelloCmp",
55
"selector":"hello-app",
66
"compileChildren":true,
7-
"hostListeners":{},
8-
"hostProperties":{},
7+
"host":{},
98
"properties":[],
109
"readAttributes":[],
1110
"type":1,

modules/angular2/test/transform/template_compiler/url_method_files/hello.ng_meta.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
"id":"HelloCmp",
55
"selector":"hello-app",
66
"compileChildren":true,
7-
"hostListeners":{},
8-
"hostProperties":{},
7+
"host":{},
98
"properties":[],
109
"readAttributes":[],
1110
"type":1,

0 commit comments

Comments
 (0)
X Tutup