diff --git a/modules/angular2/src/transform/template_compiler/directive_metadata_reader.dart b/modules/angular2/src/transform/template_compiler/directive_metadata_reader.dart index b53135949f..a796501285 100644 --- a/modules/angular2/src/transform/template_compiler/directive_metadata_reader.dart +++ b/modules/angular2/src/transform/template_compiler/directive_metadata_reader.dart @@ -147,7 +147,8 @@ class _DirectiveMetadataVisitor extends Object return; } for (MapLiteralEntry entry in (hostPropertyValue as MapLiteral).entries) { - var sKey = _expressionToString(entry.key, 'Directive#hostProperties keys'); + var sKey = + _expressionToString(entry.key, 'Directive#hostProperties keys'); var sVal = _expressionToString(entry.value, 'Directive#hostProperties values'); meta.hostProperties[sKey] = sVal; diff --git a/modules/angular2/src/transform/template_compiler/generator.dart b/modules/angular2/src/transform/template_compiler/generator.dart index fd474c9929..97bd2cb452 100644 --- a/modules/angular2/src/transform/template_compiler/generator.dart +++ b/modules/angular2/src/transform/template_compiler/generator.dart @@ -62,7 +62,8 @@ Future processTemplates(AssetReader reader, AssetId entryPoint) async { '${code.substring(codeInjectIdx)}'; } -Iterable _generateGetters(String typeName, List getterNames) { +Iterable _generateGetters( + String typeName, Iterable getterNames) { // TODO(kegluneq): Include `typeName` where possible. return getterNames.map((getterName) { if (!prop.isValid(getterName)) { @@ -74,7 +75,8 @@ Iterable _generateGetters(String typeName, List getterNames) { }); } -Iterable _generateSetters(String typeName, List setterName) { +Iterable _generateSetters( + String typeName, Iterable setterName) { return setterName.map((setterName) { if (!prop.isValid(setterName)) { // TODO(kegluenq): Eagerly throw here once #1295 is addressed. @@ -86,7 +88,8 @@ Iterable _generateSetters(String typeName, List setterName) { }); } -Iterable _generateMethods(String typeName, List methodNames) { +Iterable _generateMethods( + String typeName, Iterable methodNames) { return methodNames.map((methodName) { if (!prop.isValid(methodName)) { // TODO(kegluenq): Eagerly throw here once #1295 is addressed. diff --git a/modules/angular2/src/transform/template_compiler/recording_reflection_capabilities.dart b/modules/angular2/src/transform/template_compiler/recording_reflection_capabilities.dart index 2bfd492717..9f3a4f63dc 100644 --- a/modules/angular2/src/transform/template_compiler/recording_reflection_capabilities.dart +++ b/modules/angular2/src/transform/template_compiler/recording_reflection_capabilities.dart @@ -8,11 +8,11 @@ import 'package:angular2/src/reflection/types.dart'; /// reflectively accessed at runtime. class RecordingReflectionCapabilities implements ReflectionCapabilities { /// The names of all requested `getter`s. - final List getterNames = []; + final Set getterNames = new Set(); /// The names of all requested `setter`s. - final List setterNames = []; + final Set setterNames = new Set(); /// The names of all requested `method`s. - final List methodNames = []; + final Set methodNames = new Set(); _notImplemented(String name) => throw 'Not implemented: $name'; diff --git a/modules/angular2/test/transform/template_compiler/all_tests.dart b/modules/angular2/test/transform/template_compiler/all_tests.dart index 8505c8572a..19c0bade90 100644 --- a/modules/angular2/test/transform/template_compiler/all_tests.dart +++ b/modules/angular2/test/transform/template_compiler/all_tests.dart @@ -56,6 +56,14 @@ void allTests() { _formatThenExpectEquals(output, expected); }); + it('should not generated duplicate getters/setters', () async { + var inputPath = 'template_compiler/duplicate_files/hello.ng_deps.dart'; + var expected = readFile( + 'template_compiler/duplicate_files/expected/hello.ng_deps.dart'); + var output = await processTemplates(reader, new AssetId('a', inputPath)); + _formatThenExpectEquals(output, expected); + }); + describe('DirectiveMetadataReader', () { Future readMetadata(inputPath) async { var ngDeps = await parser.parse(new AssetId('a', inputPath)); diff --git a/modules/angular2/test/transform/template_compiler/duplicate_files/expected/hello.ng_deps.dart b/modules/angular2/test/transform/template_compiler/duplicate_files/expected/hello.ng_deps.dart new file mode 100644 index 0000000000..0d47211b63 --- /dev/null +++ b/modules/angular2/test/transform/template_compiler/duplicate_files/expected/hello.ng_deps.dart @@ -0,0 +1,22 @@ +library examples.hello_world.index_common_dart.ng_deps.dart; + +import 'hello.dart'; +import 'package:angular2/angular2.dart' + show bootstrap, Component, Decorator, View, NgElement; + +var _visited = false; +void initReflector(reflector) { + if (_visited) return; + _visited = true; + reflector + ..registerType(HelloCmp, { + 'factory': () => new HelloCmp(), + 'parameters': const [const []], + 'annotations': const [ + const Component(selector: 'hello-app'), + const View(template: '{{greeting}}, {{greeting}}') + ] + }) + ..registerGetters({'greeting': (o) => o.greeting}) + ..registerSetters({'greeting': (o, v) => o.greeting = v}); +} diff --git a/modules/angular2/test/transform/template_compiler/duplicate_files/hello.ng_deps.dart b/modules/angular2/test/transform/template_compiler/duplicate_files/hello.ng_deps.dart new file mode 100644 index 0000000000..5106eb4d18 --- /dev/null +++ b/modules/angular2/test/transform/template_compiler/duplicate_files/hello.ng_deps.dart @@ -0,0 +1,20 @@ +library examples.hello_world.index_common_dart.ng_deps.dart; + +import 'hello.dart'; +import 'package:angular2/angular2.dart' + show bootstrap, Component, Decorator, View, NgElement; + +var _visited = false; +void initReflector(reflector) { + if (_visited) return; + _visited = true; + reflector + ..registerType(HelloCmp, { + 'factory': () => new HelloCmp(), + 'parameters': const [const []], + 'annotations': const [ + const Component(selector: 'hello-app'), + const View(template: '{{greeting}}, {{greeting}}') + ] + }); +}