diff --git a/modules/angular2/src/transform/bind_generator/generator.dart b/modules/angular2/src/transform/bind_generator/generator.dart index 1f4769aac6..fded355bac 100644 --- a/modules/angular2/src/transform/bind_generator/generator.dart +++ b/modules/angular2/src/transform/bind_generator/generator.dart @@ -48,9 +48,16 @@ Map _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 { diff --git a/modules/angular2/src/transform/bind_generator/visitor.dart b/modules/angular2/src/transform/bind_generator/visitor.dart index 2b8b6cf60c..47d0a516e5 100644 --- a/modules/angular2/src/transform/bind_generator/visitor.dart +++ b/modules/angular2/src/transform/bind_generator/visitor.dart @@ -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 { - final Map bindMappings = {}; final ConstantEvaluator _evaluator = new ConstantEvaluator(); + final List 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; } diff --git a/modules/angular2/src/transform/common/directive_metadata_reader.dart b/modules/angular2/src/transform/common/directive_metadata_reader.dart index 9b2f89c04c..5ef485933e 100644 --- a/modules/angular2/src/transform/common/directive_metadata_reader.dart +++ b/modules/angular2/src/transform/common/directive_metadata_reader.dart @@ -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) { diff --git a/modules/angular2/test/transform/directive_metadata_extractor/all_tests.dart b/modules/angular2/test/transform/directive_metadata_extractor/all_tests.dart index 2e932032c4..79ff6c7c15 100644 --- a/modules/angular2/test/transform/directive_metadata_extractor/all_tests.dart +++ b/modules/angular2/test/transform/directive_metadata_extractor/all_tests.dart @@ -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 { diff --git a/modules/angular2/test/transform/integration/simple_annotation_files/expected/bar.ng_meta.json b/modules/angular2/test/transform/integration/simple_annotation_files/expected/bar.ng_meta.json index 676376544f..1d2415ab77 100644 --- a/modules/angular2/test/transform/integration/simple_annotation_files/expected/bar.ng_meta.json +++ b/modules/angular2/test/transform/integration/simple_annotation_files/expected/bar.ng_meta.json @@ -7,7 +7,7 @@ "hostProperties": {}, "hostAttributes": {}, "hostActions": null, - "properties": {}, + "properties": [], "readAttributes": [], "type": 1, "version": 1 diff --git a/modules/angular2/test/transform/template_compiler/duplicate_files/hello.ng_meta.json b/modules/angular2/test/transform/template_compiler/duplicate_files/hello.ng_meta.json index d933030dc4..e2d05ba227 100644 --- a/modules/angular2/test/transform/template_compiler/duplicate_files/hello.ng_meta.json +++ b/modules/angular2/test/transform/template_compiler/duplicate_files/hello.ng_meta.json @@ -6,7 +6,7 @@ "compileChildren":true, "hostListeners":{}, "hostProperties":{}, - "properties":{}, + "properties":[], "readAttributes":[], "type":1, "version":1 diff --git a/modules/angular2/test/transform/template_compiler/inline_expression_files/hello.ng_meta.json b/modules/angular2/test/transform/template_compiler/inline_expression_files/hello.ng_meta.json index d933030dc4..e2d05ba227 100644 --- a/modules/angular2/test/transform/template_compiler/inline_expression_files/hello.ng_meta.json +++ b/modules/angular2/test/transform/template_compiler/inline_expression_files/hello.ng_meta.json @@ -6,7 +6,7 @@ "compileChildren":true, "hostListeners":{}, "hostProperties":{}, - "properties":{}, + "properties":[], "readAttributes":[], "type":1, "version":1 diff --git a/modules/angular2/test/transform/template_compiler/inline_method_files/hello.ng_meta.json b/modules/angular2/test/transform/template_compiler/inline_method_files/hello.ng_meta.json index d933030dc4..e2d05ba227 100644 --- a/modules/angular2/test/transform/template_compiler/inline_method_files/hello.ng_meta.json +++ b/modules/angular2/test/transform/template_compiler/inline_method_files/hello.ng_meta.json @@ -6,7 +6,7 @@ "compileChildren":true, "hostListeners":{}, "hostProperties":{}, - "properties":{}, + "properties":[], "readAttributes":[], "type":1, "version":1 diff --git a/modules/angular2/test/transform/template_compiler/one_directive_files/hello.ng_meta.json b/modules/angular2/test/transform/template_compiler/one_directive_files/hello.ng_meta.json index 97b57bed1c..01105c97c0 100644 --- a/modules/angular2/test/transform/template_compiler/one_directive_files/hello.ng_meta.json +++ b/modules/angular2/test/transform/template_compiler/one_directive_files/hello.ng_meta.json @@ -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 diff --git a/modules/angular2/test/transform/template_compiler/url_expression_files/hello.ng_meta.json b/modules/angular2/test/transform/template_compiler/url_expression_files/hello.ng_meta.json index d933030dc4..e2d05ba227 100644 --- a/modules/angular2/test/transform/template_compiler/url_expression_files/hello.ng_meta.json +++ b/modules/angular2/test/transform/template_compiler/url_expression_files/hello.ng_meta.json @@ -6,7 +6,7 @@ "compileChildren":true, "hostListeners":{}, "hostProperties":{}, - "properties":{}, + "properties":[], "readAttributes":[], "type":1, "version":1 diff --git a/modules/angular2/test/transform/template_compiler/url_method_files/hello.ng_meta.json b/modules/angular2/test/transform/template_compiler/url_method_files/hello.ng_meta.json index d933030dc4..e2d05ba227 100644 --- a/modules/angular2/test/transform/template_compiler/url_method_files/hello.ng_meta.json +++ b/modules/angular2/test/transform/template_compiler/url_method_files/hello.ng_meta.json @@ -6,7 +6,7 @@ "compileChildren":true, "hostListeners":{}, "hostProperties":{}, - "properties":{}, + "properties":[], "readAttributes":[], "type":1, "version":1 diff --git a/modules/angular2/test/transform/template_compiler/with_prefix_files/goodbye.ng_meta.json b/modules/angular2/test/transform/template_compiler/with_prefix_files/goodbye.ng_meta.json index 158b2eac80..5752c9f9c9 100644 --- a/modules/angular2/test/transform/template_compiler/with_prefix_files/goodbye.ng_meta.json +++ b/modules/angular2/test/transform/template_compiler/with_prefix_files/goodbye.ng_meta.json @@ -4,8 +4,8 @@ "selector":"goodbye-app", "compileChildren":true, "hostListeners":{}, - "hostProperties":{}, - "properties":{}, + "hostProperties":[], + "properties":[], "readAttributes":[], "type":1, "version":1 diff --git a/modules/angular2/test/transform/template_compiler/with_prefix_files/hello.ng_meta.json b/modules/angular2/test/transform/template_compiler/with_prefix_files/hello.ng_meta.json index d933030dc4..e2d05ba227 100644 --- a/modules/angular2/test/transform/template_compiler/with_prefix_files/hello.ng_meta.json +++ b/modules/angular2/test/transform/template_compiler/with_prefix_files/hello.ng_meta.json @@ -6,7 +6,7 @@ "compileChildren":true, "hostListeners":{}, "hostProperties":{}, - "properties":{}, + "properties":[], "readAttributes":[], "type":1, "version":1