fix(dart/transform): Handle hostAttributes in DirectiveMetadata

Handle `hostAttributes` in the transformer.
`hostAttributes` was introduced in 51839ca677

Closes #1742
This commit is contained in:
Tim Blasi
2015-05-08 09:35:44 -07:00
committed by Misko Hevery
parent 44f829dbc6
commit 200e190f70
4 changed files with 54 additions and 6 deletions

View File

@ -47,6 +47,7 @@ class _DirectiveMetadataVisitor extends Object
properties: {},
hostListeners: {},
hostProperties: {},
hostAttributes: {},
readAttributes: []);
super.visitInstanceCreationExpression(node);
}
@ -80,6 +81,9 @@ class _DirectiveMetadataVisitor extends Object
case 'hostProperties':
_populateHostProperties(node.expression);
break;
case 'hostAttributes':
_populateHostAttributes(node.expression);
break;
case 'hostListeners':
_populateHostListeners(node.expression);
}
@ -155,4 +159,20 @@ class _DirectiveMetadataVisitor extends Object
meta.hostProperties[sKey] = sVal;
}
}
void _populateHostAttributes(Expression hostAttributeValue) {
if (hostAttributeValue is! MapLiteral) {
logger.error('Angular 2 currently only supports map literal values for '
'Directive#hostAttributes.'
' Source: ${hostAttributeValue}');
return;
}
for (MapLiteralEntry entry in (hostAttributeValue as MapLiteral).entries) {
var sKey =
_expressionToString(entry.key, 'Directive#hostAttributes keys');
var sVal =
_expressionToString(entry.value, 'Directive#hostAttributes values');
meta.hostAttributes[sKey] = sVal;
}
}
}