feat(transform): update for Directive.host

This commit is contained in:
Victor Berchet 2015-06-09 12:54:47 +02:00 committed by Tobias Bosch
parent 20953ed492
commit 591f742d42
12 changed files with 45 additions and 52 deletions

View File

@ -53,13 +53,11 @@ class _DirectiveMetadataVisitor extends Object
void _createEmptyMetadata(num type) { void _createEmptyMetadata(num type) {
assert(type >= 0); assert(type >= 0);
meta = new DirectiveMetadata( meta = DirectiveMetadata.create(
type: type, type: type,
compileChildren: true, compileChildren: true,
properties: [], properties: [],
hostListeners: {}, host: {},
hostProperties: {},
hostAttributes: {},
readAttributes: [], readAttributes: [],
exportAs: null, exportAs: null,
callOnDestroy: false, callOnDestroy: false,
@ -124,14 +122,8 @@ class _DirectiveMetadataVisitor extends Object
case 'properties': case 'properties':
_populateProperties(node.expression); _populateProperties(node.expression);
break; break;
case 'hostProperties': case 'host':
_populateHostProperties(node.expression); _populateHost(node.expression);
break;
case 'hostAttributes':
_populateHostAttributes(node.expression);
break;
case 'hostListeners':
_populateHostListeners(node.expression);
break; break;
case 'lifecycle': case 'lifecycle':
_populateLifecycle(node.expression); _populateLifecycle(node.expression);
@ -210,22 +202,17 @@ class _DirectiveMetadataVisitor extends Object
_populateList(propertiesValue, meta.properties, 'Directive#properties'); _populateList(propertiesValue, meta.properties, 'Directive#properties');
} }
void _populateHostListeners(Expression hostListenersValue) { void _populateHost(Expression hostValue) {
_checkMeta(); _checkMeta();
_populateMap( var host = new Map();
hostListenersValue, meta.hostListeners, 'Directive#hostListeners'); _populateMap(hostValue, host, 'Directive#host');
}
void _populateHostProperties(Expression hostPropertyValue) { var hostConfig = DirectiveMetadata.parseHostConfig(host);
_checkMeta();
_populateMap(
hostPropertyValue, meta.hostProperties, 'Directive#hostProperties');
}
void _populateHostAttributes(Expression hostAttributeValue) { meta.hostListeners = hostConfig['hostListeners'];
_checkMeta(); meta.hostProperties = hostConfig['hostProperties'];
_populateMap( meta.hostActions = hostConfig['hostActions'];
hostAttributeValue, meta.hostAttributes, 'Directive#hostAttributes'); meta.hostAttributes = hostConfig['hostAttributes'];
} }
void _populateExportAs(Expression exportAsValue) { void _populateExportAs(Expression exportAsValue) {

View File

@ -75,15 +75,28 @@ void allTests() {
expect(metadata.exportAs).toEqual('exportAsName'); expect(metadata.exportAs).toEqual('exportAsName');
}); });
it('should parse host listeners.', () async { it('should parse host.', () async {
var metadata = await readMetadata('directive_metadata_extractor/' var metadata = await readMetadata('directive_metadata_extractor/'
'directive_metadata_files/host_listeners.ng_deps.dart'); 'directive_metadata_files/host_listeners.ng_deps.dart');
expect(metadata.hostListeners).toBeNotNull(); expect(metadata.hostListeners).toBeNotNull();
expect(metadata.hostListeners.length).toBe(2); expect(metadata.hostListeners.length).toBe(1);
expect(metadata.hostListeners).toContain('change'); expect(metadata.hostListeners).toContain('change');
expect(metadata.hostListeners['change']).toEqual('onChange(\$event)'); 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 { it('should parse lifecycle events.', () async {

View File

@ -14,9 +14,11 @@ void initReflector(reflector) {
'parameters': const [const []], 'parameters': const [const []],
'annotations': const [ 'annotations': const [
const Component( const Component(
hostListeners: const { host: const {
'change': 'onChange(\$event)', '(change)': 'onChange(\$event)',
'keyDown': 'onKeyDown(\$event)' '[value]': 'value',
'@actionName': 'actionValue',
'attName': 'attValue'
}) })
] ]
}); });

View File

@ -3,10 +3,10 @@
"id": "MyComponent", "id": "MyComponent",
"selector": "[soup]", "selector": "[soup]",
"compileChildren": true, "compileChildren": true,
"hostListeners": {},
"hostProperties": {}, "hostProperties": {},
"hostListeners": {},
"hostActions": {},
"hostAttributes": {}, "hostAttributes": {},
"hostActions": null,
"properties": [], "properties": [],
"readAttributes": [], "readAttributes": [],
"type": 1, "type": 1,

View File

@ -4,8 +4,7 @@
"id":"HelloCmp", "id":"HelloCmp",
"selector":"hello-app", "selector":"hello-app",
"compileChildren":true, "compileChildren":true,
"hostListeners":{}, "host":{},
"hostProperties":{},
"properties":[], "properties":[],
"readAttributes":[], "readAttributes":[],
"type":1, "type":1,

View File

@ -4,8 +4,7 @@
"id":"HelloCmp", "id":"HelloCmp",
"selector":"hello-app", "selector":"hello-app",
"compileChildren":true, "compileChildren":true,
"hostListeners":{}, "host":{},
"hostProperties":{},
"properties":[], "properties":[],
"readAttributes":[], "readAttributes":[],
"type":1, "type":1,

View File

@ -4,8 +4,7 @@
"id":"HelloCmp", "id":"HelloCmp",
"selector":"hello-app", "selector":"hello-app",
"compileChildren":true, "compileChildren":true,
"hostListeners":{}, "host":{},
"hostProperties":{},
"properties":[], "properties":[],
"readAttributes":[], "readAttributes":[],
"type":1, "type":1,

View File

@ -4,8 +4,7 @@
"id":"HelloCmp", "id":"HelloCmp",
"selector":"hello-app", "selector":"hello-app",
"compileChildren":true, "compileChildren":true,
"hostListeners":{}, "host":{},
"hostProperties":{},
"properties":[], "properties":[],
"readAttributes":[], "readAttributes":[],
"type":1, "type":1,
@ -15,8 +14,7 @@
"id":"GoodbyeCmp", "id":"GoodbyeCmp",
"selector":"goodbye-app", "selector":"goodbye-app",
"compileChildren":true, "compileChildren":true,
"hostListeners":{}, "host":{},
"hostProperties":{},
"properties":[], "properties":[],
"readAttributes":[], "readAttributes":[],
"type":1, "type":1,

View File

@ -4,8 +4,7 @@
"id":"HelloCmp", "id":"HelloCmp",
"selector":"hello-app", "selector":"hello-app",
"compileChildren":true, "compileChildren":true,
"hostListeners":{}, "host":{},
"hostProperties":{},
"properties":[], "properties":[],
"readAttributes":[], "readAttributes":[],
"type":1, "type":1,

View File

@ -4,8 +4,7 @@
"id":"HelloCmp", "id":"HelloCmp",
"selector":"hello-app", "selector":"hello-app",
"compileChildren":true, "compileChildren":true,
"hostListeners":{}, "host":{},
"hostProperties":{},
"properties":[], "properties":[],
"readAttributes":[], "readAttributes":[],
"type":1, "type":1,

View File

@ -3,8 +3,7 @@
"id":"GoodbyeCmp", "id":"GoodbyeCmp",
"selector":"goodbye-app", "selector":"goodbye-app",
"compileChildren":true, "compileChildren":true,
"hostListeners":{}, "host":{},
"hostProperties":{},
"properties":[], "properties":[],
"readAttributes":[], "readAttributes":[],
"type":1, "type":1,

View File

@ -4,8 +4,7 @@
"id":"HelloCmp", "id":"HelloCmp",
"selector":"hello-app", "selector":"hello-app",
"compileChildren":true, "compileChildren":true,
"hostListeners":{}, "host":{},
"hostProperties":{},
"properties":[], "properties":[],
"readAttributes":[], "readAttributes":[],
"type":1, "type":1,