refactor(transformer): updates in properties syntax
This commit is contained in:
parent
d7df853bde
commit
35f0ee510a
|
@ -48,9 +48,16 @@ Map<String, String> _createBindMap(NgDeps ngDeps) {
|
|||
var visitor = new ExtractSettersVisitor();
|
||||
var bindMap = {};
|
||||
ngDeps.registeredTypes.forEach((RegisteredType t) {
|
||||
visitor.bindMappings.clear();
|
||||
visitor.bindConfig.clear();
|
||||
t.annotations.accept(visitor);
|
||||
visitor.bindMappings.forEach((String prop, _) {
|
||||
visitor.bindConfig.forEach((String config) {
|
||||
var prop;
|
||||
var idx = config.indexOf(':');
|
||||
if (idx > 0) {
|
||||
prop = config.substring(0, idx).trim();
|
||||
} else {
|
||||
prop = config;
|
||||
}
|
||||
if (bindMap.containsKey(prop)) {
|
||||
bindMap[prop] = '';
|
||||
} else {
|
||||
|
|
|
@ -7,21 +7,17 @@ import 'package:angular2/src/transform/common/logging.dart';
|
|||
/// `registerType` call and pulling out the properties of any "bind"
|
||||
/// values found.
|
||||
class ExtractSettersVisitor extends Object with RecursiveAstVisitor<Object> {
|
||||
final Map<String, String> bindMappings = {};
|
||||
final ConstantEvaluator _evaluator = new ConstantEvaluator();
|
||||
final List<String> bindConfig = [];
|
||||
|
||||
@override
|
||||
Object visitNamedExpression(NamedExpression node) {
|
||||
if ('${node.name.label}' == 'properties') {
|
||||
var evaluated = node.expression.accept(_evaluator);
|
||||
if (evaluated is Map) {
|
||||
evaluated.forEach((key, value) {
|
||||
if (value != null) {
|
||||
bindMappings[key] = '$value';
|
||||
}
|
||||
});
|
||||
if (evaluated is List) {
|
||||
bindConfig.addAll(evaluated);
|
||||
} else {
|
||||
logger.error('`properties` currently only supports Map values');
|
||||
logger.error('`properties` currently only supports List values');
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -179,9 +179,23 @@ class _DirectiveMetadataVisitor extends Object
|
|||
});
|
||||
}
|
||||
|
||||
/// Evaluates the [List] represented by `expression` and adds all values,
|
||||
/// to `list`. If `expression` does not evaluate to a [List], throws a
|
||||
/// descriptive [FormatException].
|
||||
void _populateList(Expression expression, List list, String propertyName) {
|
||||
var evaluated = expression.accept(_evaluator);
|
||||
if (evaluated is! List) {
|
||||
throw new FormatException(
|
||||
'Angular 2 expects a List but could not understand the value for '
|
||||
'$propertyName.', '$expression' /* source */);
|
||||
}
|
||||
list.addAll(evaluated);
|
||||
|
||||
}
|
||||
|
||||
void _populateProperties(Expression propertiesValue) {
|
||||
_checkMeta();
|
||||
_populateMap(propertiesValue, meta.properties, 'Directive#properties');
|
||||
_populateList(propertiesValue, meta.properties, 'Directive#properties');
|
||||
}
|
||||
|
||||
void _populateHostListeners(Expression hostListenersValue) {
|
||||
|
|
|
@ -63,10 +63,8 @@ void allTests() {
|
|||
'directive_metadata_files/properties.ng_deps.dart');
|
||||
expect(metadata.properties).toBeNotNull();
|
||||
expect(metadata.properties.length).toBe(2);
|
||||
expect(metadata.properties).toContain('key1');
|
||||
expect(metadata.properties['key1']).toEqual('val1');
|
||||
expect(metadata.properties).toContain('key2');
|
||||
expect(metadata.properties['key2']).toEqual('val2');
|
||||
expect(metadata.properties).toContain('key1: val1');
|
||||
expect(metadata.properties).toContain('key2: val2');
|
||||
});
|
||||
|
||||
it('should parse host listeners.', () async {
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
"hostProperties": {},
|
||||
"hostAttributes": {},
|
||||
"hostActions": null,
|
||||
"properties": {},
|
||||
"properties": [],
|
||||
"readAttributes": [],
|
||||
"type": 1,
|
||||
"version": 1
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
"compileChildren":true,
|
||||
"hostListeners":{},
|
||||
"hostProperties":{},
|
||||
"properties":{},
|
||||
"properties":[],
|
||||
"readAttributes":[],
|
||||
"type":1,
|
||||
"version":1
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
"compileChildren":true,
|
||||
"hostListeners":{},
|
||||
"hostProperties":{},
|
||||
"properties":{},
|
||||
"properties":[],
|
||||
"readAttributes":[],
|
||||
"type":1,
|
||||
"version":1
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
"compileChildren":true,
|
||||
"hostListeners":{},
|
||||
"hostProperties":{},
|
||||
"properties":{},
|
||||
"properties":[],
|
||||
"readAttributes":[],
|
||||
"type":1,
|
||||
"version":1
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
"selector":"hello-app",
|
||||
"compileChildren":true,
|
||||
"hostListeners":{},
|
||||
"hostProperties":{},
|
||||
"properties":{},
|
||||
"hostProperties":[],
|
||||
"properties":[],
|
||||
"readAttributes":[],
|
||||
"type":1,
|
||||
"version":1
|
||||
|
@ -17,7 +17,7 @@
|
|||
"compileChildren":true,
|
||||
"hostListeners":{},
|
||||
"hostProperties":{},
|
||||
"properties":{},
|
||||
"properties":[],
|
||||
"readAttributes":[],
|
||||
"type":1,
|
||||
"version":1
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
"compileChildren":true,
|
||||
"hostListeners":{},
|
||||
"hostProperties":{},
|
||||
"properties":{},
|
||||
"properties":[],
|
||||
"readAttributes":[],
|
||||
"type":1,
|
||||
"version":1
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
"compileChildren":true,
|
||||
"hostListeners":{},
|
||||
"hostProperties":{},
|
||||
"properties":{},
|
||||
"properties":[],
|
||||
"readAttributes":[],
|
||||
"type":1,
|
||||
"version":1
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
"selector":"goodbye-app",
|
||||
"compileChildren":true,
|
||||
"hostListeners":{},
|
||||
"hostProperties":{},
|
||||
"properties":{},
|
||||
"hostProperties":[],
|
||||
"properties":[],
|
||||
"readAttributes":[],
|
||||
"type":1,
|
||||
"version":1
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
"compileChildren":true,
|
||||
"hostListeners":{},
|
||||
"hostProperties":{},
|
||||
"properties":{},
|
||||
"properties":[],
|
||||
"readAttributes":[],
|
||||
"type":1,
|
||||
"version":1
|
||||
|
|
Loading…
Reference in New Issue