From 386cc5dbb63ecfa0ab1ddd6690b3fe5170a65f8c Mon Sep 17 00:00:00 2001 From: Tobias Bosch Date: Thu, 21 Apr 2016 08:05:08 -0700 Subject: [PATCH] fix(transformers): support `query.read` Closes #8172 --- .../test/compiler/compile_metadata_spec.ts | 6 ++++-- .../transform/common/type_metadata_reader.dart | 14 +++++++++++--- .../ng_meta_linker.dart | 3 +++ .../directive_metadata_linker/all_tests.dart | 18 ++++++++++++++---- .../directive_processor/all_tests.dart | 2 ++ .../directives_files/components.dart | 4 ++-- 6 files changed, 36 insertions(+), 11 deletions(-) diff --git a/modules/angular2/test/compiler/compile_metadata_spec.ts b/modules/angular2/test/compiler/compile_metadata_spec.ts index 3c3d852230..2a6009666f 100644 --- a/modules/angular2/test/compiler/compile_metadata_spec.ts +++ b/modules/angular2/test/compiler/compile_metadata_spec.ts @@ -103,7 +103,8 @@ export function main() { selectors: [new CompileTokenMetadata({value: 'selector'})], descendants: true, first: false, - propertyName: 'prop' + propertyName: 'prop', + read: new CompileTokenMetadata({value: 'readToken'}) }) ], viewQueries: [ @@ -111,7 +112,8 @@ export function main() { selectors: [new CompileTokenMetadata({value: 'selector'})], descendants: true, first: false, - propertyName: 'prop' + propertyName: 'prop', + read: new CompileTokenMetadata({value: 'readToken'}) }) ] }); diff --git a/modules_dart/transform/lib/src/transform/common/type_metadata_reader.dart b/modules_dart/transform/lib/src/transform/common/type_metadata_reader.dart index c83e738a4d..023daf2643 100644 --- a/modules_dart/transform/lib/src/transform/common/type_metadata_reader.dart +++ b/modules_dart/transform/lib/src/transform/common/type_metadata_reader.dart @@ -1010,16 +1010,24 @@ List _readDeps(ListLiteral deps) { _createQueryMetadata(Annotation a, bool defaultDescendantsValue, bool first, String propertyName) { final selector = _readToken(a.arguments.arguments.first); var descendants = defaultDescendantsValue; + var read = null; a.arguments.arguments.skip(0).forEach((arg) { - if (arg is NamedExpression && arg.name.toString() == "descendants:") - descendants = naiveEval(arg.expression); + if (arg is NamedExpression) { + var name = arg.name.toString(); + if (name == "descendants:") { + descendants = naiveEval(arg.expression); + } else if (name == "read:") { + read = _readToken(arg.expression); + } + } }); final selectors = selector.value is String ? selector.value.split(",").map( (value) => new CompileTokenMetadata(value: value) ).toList() : [selector]; return new CompileQueryMetadata( - selectors: selectors, descendants: descendants, first: first, propertyName: propertyName); + selectors: selectors, descendants: descendants, first: first, + read: read, propertyName: propertyName); } List _getCompileDiDependencyMetadata( diff --git a/modules_dart/transform/lib/src/transform/directive_metadata_linker/ng_meta_linker.dart b/modules_dart/transform/lib/src/transform/directive_metadata_linker/ng_meta_linker.dart index 29319430f8..f0c7487f5c 100644 --- a/modules_dart/transform/lib/src/transform/directive_metadata_linker/ng_meta_linker.dart +++ b/modules_dart/transform/lib/src/transform/directive_metadata_linker/ng_meta_linker.dart @@ -260,6 +260,9 @@ class _NgMetaIdentifierResolver { void _resolveQueries(Map ngMetaMap, List queries, String neededBy) { queries.forEach((q) { q.selectors.forEach((s) => s.identifier = _resolveIdentifier(ngMetaMap, neededBy, s.identifier)); + if (q.read != null) { + q.read.identifier = _resolveIdentifier(ngMetaMap, neededBy, q.read.identifier); + } }); } diff --git a/modules_dart/transform/test/transform/directive_metadata_linker/all_tests.dart b/modules_dart/transform/test/transform/directive_metadata_linker/all_tests.dart index 5be344b98f..a9c3de067d 100644 --- a/modules_dart/transform/test/transform/directive_metadata_linker/all_tests.dart +++ b/modules_dart/transform/test/transform/directive_metadata_linker/all_tests.dart @@ -134,13 +134,17 @@ void allTests() { new CompileTypeMetadata(name: 'Service', moduleUrl: 'moduleUrl'); fooComponentMeta.queries = [ - new CompileQueryMetadata(selectors: [new CompileTokenMetadata(identifier: new CompileIdentifierMetadata(name: 'Service'))]), - new CompileQueryMetadata(selectors: [new CompileTokenMetadata(value: 'one')]) + new CompileQueryMetadata(selectors: [new CompileTokenMetadata(identifier: new CompileIdentifierMetadata(name: 'Service'))], + read: new CompileTokenMetadata(identifier: new CompileIdentifierMetadata(name: 'Service'))), + new CompileQueryMetadata(selectors: [new CompileTokenMetadata(value: 'one')], + read: new CompileTokenMetadata(value: 'one')) ]; fooComponentMeta.viewQueries = [ - new CompileQueryMetadata(selectors: [new CompileTokenMetadata(identifier: new CompileIdentifierMetadata(name: 'Service'))]), - new CompileQueryMetadata(selectors: [new CompileTokenMetadata(value: 'one')]) + new CompileQueryMetadata(selectors: [new CompileTokenMetadata(identifier: new CompileIdentifierMetadata(name: 'Service'))], + read: new CompileTokenMetadata(identifier: new CompileIdentifierMetadata(name: 'Service'))), + new CompileQueryMetadata(selectors: [new CompileTokenMetadata(value: 'one')], + read: new CompileTokenMetadata(value: 'one')) ]; fooNgMeta.ngDeps.imports.add(new ImportModel()..uri = 'bar.dart'); @@ -155,11 +159,17 @@ void allTests() { expect(cmp.queries[0].selectors[0].identifier.name, equals("Service")); expect(cmp.queries[0].selectors[0].identifier.moduleUrl, equals("moduleUrl")); + expect(cmp.queries[0].read.identifier.name, equals("Service")); + expect(cmp.queries[0].read.identifier.moduleUrl, equals("moduleUrl")); expect(cmp.queries[1].selectors[0].value, equals("one")); + expect(cmp.queries[1].read.value, equals("one")); expect(cmp.viewQueries[0].selectors[0].identifier.name, equals("Service")); expect(cmp.viewQueries[0].selectors[0].identifier.moduleUrl, equals("moduleUrl")); + expect(cmp.viewQueries[0].read.identifier.name, equals("Service")); + expect(cmp.viewQueries[0].read.identifier.moduleUrl, equals("moduleUrl")); expect(cmp.viewQueries[1].selectors[0].value, equals("one")); + expect(cmp.viewQueries[1].read.value, equals("one")); }); test('should resolve providers from types.', () async { diff --git a/modules_dart/transform/test/transform/directive_processor/all_tests.dart b/modules_dart/transform/test/transform/directive_processor/all_tests.dart index ff81dd7b5c..76337af479 100644 --- a/modules_dart/transform/test/transform/directive_processor/all_tests.dart +++ b/modules_dart/transform/test/transform/directive_processor/all_tests.dart @@ -590,10 +590,12 @@ void allTests() { expect(deps[5].isOptional, isTrue); expect(deps[6].query.selectors[0].name, equals("ServiceDep")); expect(deps[6].query.descendants, isTrue); + expect(deps[6].query.read.identifier.name, equals("ServiceDep")); expect(deps[7].query.selectors[0].identifier.name, equals("ServiceDep")); expect(deps[7].query.descendants, isTrue); expect(deps[8].viewQuery.selectors[0].value, equals("one")); expect(deps[8].viewQuery.selectors[1].value, equals("two")); + expect(deps[8].viewQuery.read.value, equals("three")); expect(deps[9].viewQuery.selectors[0].value, equals("one")); expect(deps[9].viewQuery.selectors[1].value, equals("two")); expect(deps[10].token.identifier.name, equals("ServiceDep")); diff --git a/modules_dart/transform/test/transform/directive_processor/directives_files/components.dart b/modules_dart/transform/test/transform/directive_processor/directives_files/components.dart index 8842c3f7ac..dbc4b81070 100644 --- a/modules_dart/transform/test/transform/directive_processor/directives_files/components.dart +++ b/modules_dart/transform/test/transform/directive_processor/directives_files/components.dart @@ -141,9 +141,9 @@ class ComponentWithDiDeps { @Self() ServiceDep arg4, @SkipSelf() ServiceDep arg5, @Optional() ServiceDep arg6, - @Query(ServiceDep, descendants: true) arg7, + @Query(ServiceDep, descendants: true, read: ServiceDep) arg7, @ContentChildren(ServiceDep) arg8, - @ViewQuery("one,two") arg9, + @ViewQuery("one,two", read: "three") arg9, @ViewChildren("one,two") arg10, this.arg11, [@Optional() ServiceDep arg12,