feat(transform): update for Directive.host
This commit is contained in:
parent
20953ed492
commit
591f742d42
|
@ -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) {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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'
|
||||
})
|
||||
]
|
||||
});
|
||||
|
|
|
@ -3,10 +3,10 @@
|
|||
"id": "MyComponent",
|
||||
"selector": "[soup]",
|
||||
"compileChildren": true,
|
||||
"hostListeners": {},
|
||||
"hostProperties": {},
|
||||
"hostListeners": {},
|
||||
"hostActions": {},
|
||||
"hostAttributes": {},
|
||||
"hostActions": null,
|
||||
"properties": [],
|
||||
"readAttributes": [],
|
||||
"type": 1,
|
||||
|
|
|
@ -4,8 +4,7 @@
|
|||
"id":"HelloCmp",
|
||||
"selector":"hello-app",
|
||||
"compileChildren":true,
|
||||
"hostListeners":{},
|
||||
"hostProperties":{},
|
||||
"host":{},
|
||||
"properties":[],
|
||||
"readAttributes":[],
|
||||
"type":1,
|
||||
|
|
|
@ -4,8 +4,7 @@
|
|||
"id":"HelloCmp",
|
||||
"selector":"hello-app",
|
||||
"compileChildren":true,
|
||||
"hostListeners":{},
|
||||
"hostProperties":{},
|
||||
"host":{},
|
||||
"properties":[],
|
||||
"readAttributes":[],
|
||||
"type":1,
|
||||
|
|
|
@ -4,8 +4,7 @@
|
|||
"id":"HelloCmp",
|
||||
"selector":"hello-app",
|
||||
"compileChildren":true,
|
||||
"hostListeners":{},
|
||||
"hostProperties":{},
|
||||
"host":{},
|
||||
"properties":[],
|
||||
"readAttributes":[],
|
||||
"type":1,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -4,8 +4,7 @@
|
|||
"id":"HelloCmp",
|
||||
"selector":"hello-app",
|
||||
"compileChildren":true,
|
||||
"hostListeners":{},
|
||||
"hostProperties":{},
|
||||
"host":{},
|
||||
"properties":[],
|
||||
"readAttributes":[],
|
||||
"type":1,
|
||||
|
|
|
@ -4,8 +4,7 @@
|
|||
"id":"HelloCmp",
|
||||
"selector":"hello-app",
|
||||
"compileChildren":true,
|
||||
"hostListeners":{},
|
||||
"hostProperties":{},
|
||||
"host":{},
|
||||
"properties":[],
|
||||
"readAttributes":[],
|
||||
"type":1,
|
||||
|
|
|
@ -3,8 +3,7 @@
|
|||
"id":"GoodbyeCmp",
|
||||
"selector":"goodbye-app",
|
||||
"compileChildren":true,
|
||||
"hostListeners":{},
|
||||
"hostProperties":{},
|
||||
"host":{},
|
||||
"properties":[],
|
||||
"readAttributes":[],
|
||||
"type":1,
|
||||
|
|
|
@ -4,8 +4,7 @@
|
|||
"id":"HelloCmp",
|
||||
"selector":"hello-app",
|
||||
"compileChildren":true,
|
||||
"hostListeners":{},
|
||||
"hostProperties":{},
|
||||
"host":{},
|
||||
"properties":[],
|
||||
"readAttributes":[],
|
||||
"type":1,
|
||||
|
|
Loading…
Reference in New Issue