refactor(view_compiler): codegen DI and Queries
BREAKING CHANGE: - Renderer: * renderComponent method is removed form `Renderer`, only present on `RootRenderer` * Renderer.setDebugInfo is removed. Renderer.createElement / createText / createTemplateAnchor now take the DebugInfo directly. - Query semantics: * Queries don't work with dynamically loaded components. * e.g. for router-outlet: loaded components can't be queries via @ViewQuery, but router-outlet emits an event `activate` now that emits the activated component - Exception classes and the context inside changed (renamed fields) - DebugElement.attributes is an Object and not a Map in JS any more - ChangeDetectorGenConfig was renamed into CompilerConfig - AppViewManager.createEmbeddedViewInContainer / AppViewManager.createHostViewInContainer are removed, use the methods in ViewContainerRef instead - Change detection order changed: * 1. dirty check component inputs * 2. dirty check content children * 3. update render nodes Closes #6301 Closes #6567
This commit is contained in:
@ -20,7 +20,7 @@ void allTests() {
|
||||
|
||||
final buf = new StringBuffer();
|
||||
final writer = new NgDepsWriter(buf);
|
||||
writer.writeNgDepsModel(ngDeps);
|
||||
writer.writeNgDepsModel(ngDeps, '');
|
||||
|
||||
var compilationUnit = parseCompilationUnit(buf.toString());
|
||||
|
||||
@ -40,7 +40,25 @@ void allTests() {
|
||||
|
||||
final buf = new StringBuffer();
|
||||
final writer = new NgDepsWriter(buf);
|
||||
writer.writeNgDepsModel(ngDeps);
|
||||
writer.writeNgDepsModel(ngDeps, '');
|
||||
|
||||
var compilationUnit = parseCompilationUnit(buf.toString());
|
||||
|
||||
expect(compilationUnit, isNotNull);
|
||||
expect(compilationUnit.declarations, isNotNull);
|
||||
expect(compilationUnit.declarations.length > 0, isTrue);
|
||||
});
|
||||
|
||||
test('should add the given templateSource', () async {
|
||||
final ngDeps = new NgDepsModel()
|
||||
..libraryUri = 'test.foo'
|
||||
..imports.add(new ImportModel()
|
||||
..uri = 'bar.dart'
|
||||
..prefix = 'dep');
|
||||
|
||||
final buf = new StringBuffer();
|
||||
final writer = new NgDepsWriter(buf);
|
||||
writer.writeNgDepsModel(ngDeps, 'import \'foo.dart\';\nvar x = true;');
|
||||
|
||||
var compilationUnit = parseCompilationUnit(buf.toString());
|
||||
|
||||
|
@ -6,7 +6,6 @@ final ngFor = {
|
||||
"value": {
|
||||
"class": "Directive",
|
||||
"isComponent": false,
|
||||
"dynamicLoadable": true,
|
||||
"selector": "[ngFor][ngForOf]",
|
||||
"exportAs": null,
|
||||
"type": {
|
||||
|
@ -1,10 +1,10 @@
|
||||
library angular2.test.transform.common.ng_meta_helper;
|
||||
|
||||
import 'package:angular2/src/compiler/directive_metadata.dart';
|
||||
import 'package:angular2/src/compiler/compile_metadata.dart';
|
||||
import 'package:angular2/src/core/change_detection/change_detection.dart';
|
||||
import 'package:angular2/src/core/metadata/view.dart' show ViewEncapsulation;
|
||||
|
||||
export 'package:angular2/src/compiler/directive_metadata.dart';
|
||||
export 'package:angular2/src/compiler/compile_metadata.dart';
|
||||
export 'package:angular2/src/core/change_detection/change_detection.dart';
|
||||
export 'package:angular2/src/core/metadata/view.dart' show ViewEncapsulation;
|
||||
export 'package:angular2/src/transform/common/model/annotation_model.pb.dart';
|
||||
@ -45,7 +45,6 @@ CompileDirectiveMetadata createDirectiveMetadataForTest(
|
||||
return CompileDirectiveMetadata.create(
|
||||
type: new CompileTypeMetadata(name: name, moduleUrl: moduleUrl),
|
||||
isComponent: template != null,
|
||||
dynamicLoadable: true,
|
||||
selector: selector,
|
||||
exportAs: null,
|
||||
changeDetection: ChangeDetectionStrategy.Default,
|
||||
|
@ -3,7 +3,7 @@ library angular2.test.transform.common.annotation_matcher_test;
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'package:angular2/src/core/render/api.dart';
|
||||
import 'package:angular2/src/compiler/directive_metadata.dart';
|
||||
import 'package:angular2/src/compiler/compile_metadata.dart';
|
||||
import 'package:angular2/src/transform/common/ng_meta.dart';
|
||||
|
||||
main() => allTests();
|
||||
|
@ -8,7 +8,7 @@ import 'package:angular2/src/transform/common/url_resolver.dart';
|
||||
main() => allTests();
|
||||
|
||||
void allTests() {
|
||||
var urlResolver = const TransformerUrlResolver();
|
||||
var urlResolver = createOfflineCompileUrlResolver();
|
||||
|
||||
group('toAssetUri', () {
|
||||
test('should convert `AssetId`s to asset: uris', () {
|
||||
@ -141,29 +141,9 @@ void allTests() {
|
||||
equals('asset:angular2/lib/src/transform/transformer.dart'));
|
||||
});
|
||||
|
||||
test('should throw if passed a null uri', () {
|
||||
expect(() => urlResolver.resolve('package:angular2/angular2.dart', null),
|
||||
throwsArgumentError);
|
||||
});
|
||||
|
||||
test('should gracefully handle an empty uri', () {
|
||||
expect(urlResolver.resolve('package:angular2/angular2.dart', ''),
|
||||
equals('asset:angular2/lib/angular2.dart'));
|
||||
});
|
||||
|
||||
test('should throw if passed a relative uri and a null baseUri', () {
|
||||
expect(() => urlResolver.resolve(null, 'angular2/angular2.dart'),
|
||||
throwsArgumentError);
|
||||
});
|
||||
|
||||
test('should throw if passed a relative uri and an empty baseUri', () {
|
||||
expect(() => urlResolver.resolve('', 'angular2/angular2.dart'),
|
||||
throwsArgumentError);
|
||||
});
|
||||
|
||||
test('should throw if the resolved uri is relative', () {
|
||||
expect(() => urlResolver.resolve('/angular2/', 'angular2.dart'),
|
||||
throwsArgumentError);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -5,7 +5,6 @@
|
||||
"value": {
|
||||
"class": "Directive",
|
||||
"isComponent": true,
|
||||
"dynamicLoadable": true,
|
||||
"selector":"hello-app",
|
||||
"exportAs": null,
|
||||
"type": {
|
||||
|
@ -5,7 +5,6 @@
|
||||
"value": {
|
||||
"class": "Directive",
|
||||
"isComponent": true,
|
||||
"dynamicLoadable": true,
|
||||
"selector":"hello-app",
|
||||
"exportAs": null,
|
||||
"type": {
|
||||
|
@ -134,13 +134,13 @@ void allTests() {
|
||||
new CompileTypeMetadata(name: 'Service', moduleUrl: 'moduleUrl');
|
||||
|
||||
fooComponentMeta.queries = [
|
||||
new CompileQueryMetadata(selectors: [new CompileIdentifierMetadata(name: 'Service')]),
|
||||
new CompileQueryMetadata(selectors: ['one'])
|
||||
new CompileQueryMetadata(selectors: [new CompileTokenMetadata(identifier: new CompileIdentifierMetadata(name: 'Service'))]),
|
||||
new CompileQueryMetadata(selectors: [new CompileTokenMetadata(value: 'one')])
|
||||
];
|
||||
|
||||
fooComponentMeta.viewQueries = [
|
||||
new CompileQueryMetadata(selectors: [new CompileIdentifierMetadata(name: 'Service')]),
|
||||
new CompileQueryMetadata(selectors: ['one'])
|
||||
new CompileQueryMetadata(selectors: [new CompileTokenMetadata(identifier: new CompileIdentifierMetadata(name: 'Service'))]),
|
||||
new CompileQueryMetadata(selectors: [new CompileTokenMetadata(value: 'one')])
|
||||
];
|
||||
|
||||
fooNgMeta.ngDeps.imports.add(new ImportModel()..uri = 'bar.dart');
|
||||
@ -153,13 +153,13 @@ void allTests() {
|
||||
expect(cmp.queries.length, equals(2));
|
||||
expect(cmp.viewQueries.length, equals(2));
|
||||
|
||||
expect(cmp.queries[0].selectors[0].name, equals("Service"));
|
||||
expect(cmp.queries[0].selectors[0].moduleUrl, equals("moduleUrl"));
|
||||
expect(cmp.queries[1].selectors[0], equals("one"));
|
||||
expect(cmp.queries[0].selectors[0].identifier.name, equals("Service"));
|
||||
expect(cmp.queries[0].selectors[0].identifier.moduleUrl, equals("moduleUrl"));
|
||||
expect(cmp.queries[1].selectors[0].value, equals("one"));
|
||||
|
||||
expect(cmp.viewQueries[0].selectors[0].name, equals("Service"));
|
||||
expect(cmp.viewQueries[0].selectors[0].moduleUrl, equals("moduleUrl"));
|
||||
expect(cmp.viewQueries[1].selectors[0], 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[1].selectors[0].value, equals("one"));
|
||||
});
|
||||
|
||||
test('should resolve providers from types.', () async {
|
||||
@ -171,7 +171,8 @@ void allTests() {
|
||||
];
|
||||
fooComponentMeta.type.diDeps = [
|
||||
new CompileDiDependencyMetadata(
|
||||
token: new CompileIdentifierMetadata(name: 'Service'))
|
||||
token: new CompileTokenMetadata(identifier:
|
||||
new CompileIdentifierMetadata(name: 'Service')))
|
||||
];
|
||||
|
||||
fooNgMeta.ngDeps.imports.add(new ImportModel()..uri = 'bar.dart');
|
||||
@ -183,14 +184,14 @@ void allTests() {
|
||||
|
||||
expect(cmp.providers.length, equals(1));
|
||||
|
||||
expect(cmp.providers[0].token.name, equals("Service"));
|
||||
expect(cmp.providers[0].token.moduleUrl, equals("moduleUrl"));
|
||||
expect(cmp.providers[0].useClass.name, equals("Service"));
|
||||
expect(cmp.providers[0].useClass.moduleUrl, equals("moduleUrl"));
|
||||
expect(cmp.providers[0].token.identifier.name, equals("Service"));
|
||||
expect(cmp.providers[0].token.identifier.moduleUrl, equals("moduleUrl"));
|
||||
expect(cmp.providers[0].useClass.identifier.name, equals("Service"));
|
||||
expect(cmp.providers[0].useClass.identifier.moduleUrl, equals("moduleUrl"));
|
||||
|
||||
expect(cmp.type.diDeps.length, equals(1));
|
||||
expect(cmp.type.diDeps[0].token.name, equals("Service"));
|
||||
expect(cmp.type.diDeps[0].token.moduleUrl, equals("moduleUrl"));
|
||||
expect(cmp.type.diDeps[0].token.identifier.name, equals("Service"));
|
||||
expect(cmp.type.diDeps[0].token.identifier.moduleUrl, equals("moduleUrl"));
|
||||
});
|
||||
|
||||
test('should resolve providers from functions.', () async {
|
||||
@ -200,11 +201,11 @@ void allTests() {
|
||||
fooNgMeta.identifiers['factory'] =
|
||||
new CompileFactoryMetadata(name: 'factory', moduleUrl: 'moduleUrl', diDeps: [
|
||||
new CompileDiDependencyMetadata(
|
||||
token: new CompileIdentifierMetadata(name: 'Service'))
|
||||
token: new CompileTokenMetadata(identifier: new CompileIdentifierMetadata(name: 'Service')))
|
||||
]);
|
||||
|
||||
fooComponentMeta.providers = [
|
||||
new CompileProviderMetadata(token: 'someFunc', useFactory:
|
||||
new CompileProviderMetadata(token: new CompileTokenMetadata(value: 'someFunc'), useFactory:
|
||||
new CompileFactoryMetadata(name: 'factory'))
|
||||
];
|
||||
|
||||
@ -217,12 +218,12 @@ void allTests() {
|
||||
|
||||
expect(cmp.providers.length, equals(1));
|
||||
|
||||
expect(cmp.providers[0].token, equals("someFunc"));
|
||||
expect(cmp.providers[0].token.value, equals("someFunc"));
|
||||
expect(cmp.providers[0].useFactory.name, equals("factory"));
|
||||
expect(cmp.providers[0].useFactory.moduleUrl, equals("moduleUrl"));
|
||||
|
||||
expect(cmp.providers[0].useFactory.diDeps[0].token.name, equals("Service"));
|
||||
expect(cmp.providers[0].useFactory.diDeps[0].token.moduleUrl, equals("moduleUrl"));
|
||||
expect(cmp.providers[0].useFactory.diDeps[0].token.identifier.name, equals("Service"));
|
||||
expect(cmp.providers[0].useFactory.diDeps[0].token.identifier.moduleUrl, equals("moduleUrl"));
|
||||
});
|
||||
|
||||
test('should resolve viewProviders from types.', () async {
|
||||
@ -231,7 +232,7 @@ void allTests() {
|
||||
|
||||
fooComponentMeta.viewProviders = [
|
||||
new CompileProviderMetadata(
|
||||
token: new CompileIdentifierMetadata(name: 'Service'))
|
||||
token: new CompileTokenMetadata(identifier: new CompileIdentifierMetadata(name: 'Service')))
|
||||
];
|
||||
fooNgMeta.ngDeps.imports.add(new ImportModel()..uri = 'bar.dart');
|
||||
|
||||
@ -241,8 +242,8 @@ void allTests() {
|
||||
final cmp = extracted.identifiers["FooComponent"];
|
||||
|
||||
expect(cmp.viewProviders.length, equals(1));
|
||||
expect(cmp.viewProviders[0].token.name, equals("Service"));
|
||||
expect(cmp.viewProviders[0].token.moduleUrl, equals("moduleUrl"));
|
||||
expect(cmp.viewProviders[0].token.identifier.name, equals("Service"));
|
||||
expect(cmp.viewProviders[0].token.identifier.moduleUrl, equals("moduleUrl"));
|
||||
});
|
||||
|
||||
test('should resolve providers from Provider objects (literals).', () async {
|
||||
@ -253,11 +254,11 @@ void allTests() {
|
||||
new CompileTemplateMetadata(template: "import 'bar.dart';");
|
||||
fooComponentMeta.providers = [
|
||||
new CompileProviderMetadata(
|
||||
token: "StrService",
|
||||
token: new CompileTokenMetadata(value: "StrService"),
|
||||
useClass: new CompileTypeMetadata(name: 'Service'))
|
||||
];
|
||||
fooComponentMeta.type.diDeps = [
|
||||
new CompileDiDependencyMetadata(token: "StrService")
|
||||
new CompileDiDependencyMetadata(token: new CompileTokenMetadata(value: "StrService"))
|
||||
];
|
||||
|
||||
fooNgMeta.ngDeps.imports
|
||||
@ -270,12 +271,12 @@ void allTests() {
|
||||
|
||||
expect(cmp.providers.length, equals(1));
|
||||
|
||||
expect(cmp.providers[0].token, equals("StrService"));
|
||||
expect(cmp.providers[0].token.value, equals("StrService"));
|
||||
expect(cmp.providers[0].useClass.name, equals("Service"));
|
||||
expect(cmp.providers[0].useClass.moduleUrl, equals("moduleUrl"));
|
||||
|
||||
expect(cmp.type.diDeps.length, equals(1));
|
||||
expect(cmp.type.diDeps[0].token, equals("StrService"));
|
||||
expect(cmp.type.diDeps[0].token.value, equals("StrService"));
|
||||
});
|
||||
|
||||
test('should resolve providers from references', () async {
|
||||
@ -285,7 +286,7 @@ void allTests() {
|
||||
fooNgMeta.identifiers["PROVIDER"] = new CompileIdentifierMetadata(
|
||||
name: 'PROVIDER',
|
||||
value: new CompileProviderMetadata(
|
||||
token: new CompileIdentifierMetadata(name: 'Service')));
|
||||
token: new CompileTokenMetadata(identifier: new CompileIdentifierMetadata(name: 'Service'))));
|
||||
|
||||
fooComponentMeta.providers = [
|
||||
new CompileIdentifierMetadata(name: 'PROVIDER')
|
||||
@ -299,8 +300,8 @@ void allTests() {
|
||||
final cmp = extracted.identifiers["FooComponent"];
|
||||
|
||||
expect(cmp.providers.length, equals(1));
|
||||
expect(cmp.providers[0].token.name, equals("Service"));
|
||||
expect(cmp.providers[0].token.moduleUrl, equals("moduleUrl"));
|
||||
expect(cmp.providers[0].token.identifier.name, equals("Service"));
|
||||
expect(cmp.providers[0].token.identifier.moduleUrl, equals("moduleUrl"));
|
||||
});
|
||||
|
||||
test('should resolve providers from lists.', () async {
|
||||
@ -324,8 +325,8 @@ void allTests() {
|
||||
final cmp = extracted.identifiers["FooComponent"];
|
||||
|
||||
expect(cmp.providers.length, equals(1));
|
||||
expect(cmp.providers[0].token.name, equals("Service"));
|
||||
expect(cmp.providers[0].token.moduleUrl, equals("moduleUrl"));
|
||||
expect(cmp.providers[0].token.identifier.name, equals("Service"));
|
||||
expect(cmp.providers[0].token.identifier.moduleUrl, equals("moduleUrl"));
|
||||
});
|
||||
|
||||
test('should resolve providers from lists (two lists in the same file).', () async {
|
||||
@ -355,8 +356,8 @@ void allTests() {
|
||||
final cmp = extracted.identifiers["FooComponent"];
|
||||
|
||||
expect(cmp.providers.length, equals(1));
|
||||
expect(cmp.providers[0].token.name, equals("Service"));
|
||||
expect(cmp.providers[0].token.moduleUrl, equals("moduleUrl"));
|
||||
expect(cmp.providers[0].token.identifier.name, equals("Service"));
|
||||
expect(cmp.providers[0].token.identifier.moduleUrl, equals("moduleUrl"));
|
||||
});
|
||||
|
||||
test('should resolve providers when there is a level of indirection.', () async {
|
||||
@ -388,8 +389,8 @@ void allTests() {
|
||||
final cmp = extracted.identifiers["FooComponent"];
|
||||
|
||||
expect(cmp.providers.length, equals(1));
|
||||
expect(cmp.providers[0].token.name, equals("Service"));
|
||||
expect(cmp.providers[0].token.moduleUrl, equals("moduleUrl"));
|
||||
expect(cmp.providers[0].token.identifier.name, equals("Service"));
|
||||
expect(cmp.providers[0].token.identifier.moduleUrl, equals("moduleUrl"));
|
||||
});
|
||||
|
||||
test('should generate generate diDeps of injectable services.', () async {
|
||||
@ -401,12 +402,12 @@ void allTests() {
|
||||
moduleUrl: 'moduleUrl',
|
||||
diDeps: [
|
||||
new CompileDiDependencyMetadata(
|
||||
token: new CompileIdentifierMetadata(name: 'Service2'))
|
||||
token: new CompileTokenMetadata(identifier: new CompileIdentifierMetadata(name: 'Service2')))
|
||||
]);
|
||||
|
||||
fooComponentMeta.providers = [
|
||||
new CompileProviderMetadata(
|
||||
token: new CompileIdentifierMetadata(name: 'Service'),
|
||||
token: new CompileTokenMetadata(identifier: new CompileIdentifierMetadata(name: 'Service')),
|
||||
useClass: new CompileTypeMetadata(name: 'Service'))
|
||||
];
|
||||
|
||||
@ -419,8 +420,8 @@ void allTests() {
|
||||
|
||||
expect(cmp.providers[0].useClass.name, equals("Service"));
|
||||
expect(cmp.providers[0].useClass.moduleUrl, equals("moduleUrl"));
|
||||
expect(cmp.providers[0].useClass.diDeps.first.token.name, equals("Service2"));
|
||||
expect(cmp.providers[0].useClass.diDeps.first.token.moduleUrl, equals("moduleUrl"));
|
||||
expect(cmp.providers[0].useClass.diDeps.first.token.identifier.name, equals("Service2"));
|
||||
expect(cmp.providers[0].useClass.diDeps.first.token.identifier.moduleUrl, equals("moduleUrl"));
|
||||
});
|
||||
|
||||
test('should resolve queries and viewQueries.', () async {
|
||||
@ -431,13 +432,13 @@ void allTests() {
|
||||
new CompileTemplateMetadata(template: "import 'bar.dart';");
|
||||
fooComponentMeta.type.diDeps = [
|
||||
new CompileDiDependencyMetadata(
|
||||
token: 'someToken',
|
||||
token: new CompileTokenMetadata(value: 'someToken'),
|
||||
query: new CompileQueryMetadata(
|
||||
selectors: [new CompileIdentifierMetadata(name: 'Service')])),
|
||||
selectors: [new CompileTokenMetadata(identifier: new CompileIdentifierMetadata(name: 'Service'))])),
|
||||
new CompileDiDependencyMetadata(
|
||||
token: 'someToken',
|
||||
token: new CompileTokenMetadata(value: 'someToken'),
|
||||
viewQuery: new CompileQueryMetadata(
|
||||
selectors: [new CompileIdentifierMetadata(name: 'Service')]))
|
||||
selectors: [new CompileTokenMetadata(identifier: new CompileIdentifierMetadata(name: 'Service'))]))
|
||||
];
|
||||
|
||||
fooNgMeta.ngDeps.imports
|
||||
@ -450,10 +451,10 @@ void allTests() {
|
||||
|
||||
expect(cmp.type.diDeps.length, equals(2));
|
||||
|
||||
expect(cmp.type.diDeps[0].query.selectors[0].name, equals("Service"));
|
||||
expect(cmp.type.diDeps[0].query.selectors[0].moduleUrl, equals("moduleUrl"));
|
||||
expect(cmp.type.diDeps[1].viewQuery.selectors[0].name, equals("Service"));
|
||||
expect(cmp.type.diDeps[1].viewQuery.selectors[0].moduleUrl, equals("moduleUrl"));
|
||||
expect(cmp.type.diDeps[0].query.selectors[0].identifier.name, equals("Service"));
|
||||
expect(cmp.type.diDeps[0].query.selectors[0].identifier.moduleUrl, equals("moduleUrl"));
|
||||
expect(cmp.type.diDeps[1].viewQuery.selectors[0].identifier.name, equals("Service"));
|
||||
expect(cmp.type.diDeps[1].viewQuery.selectors[0].identifier.moduleUrl, equals("moduleUrl"));
|
||||
});
|
||||
|
||||
test('should generate providers from Provider objects (references).',
|
||||
@ -465,23 +466,23 @@ void allTests() {
|
||||
barNgMeta.identifiers['factory'] =
|
||||
new CompileFactoryMetadata(name: 'factory', moduleUrl: 'moduleUrl', diDeps: [
|
||||
new CompileDiDependencyMetadata(
|
||||
token: new CompileIdentifierMetadata(name: 'Service2', moduleUrl: 'moduleUrl'))
|
||||
token: new CompileTokenMetadata(identifier: new CompileIdentifierMetadata(name: 'Service2', moduleUrl: 'moduleUrl')))
|
||||
]);
|
||||
|
||||
fooComponentMeta.template =
|
||||
new CompileTemplateMetadata(template: "import 'bar.dart';");
|
||||
fooComponentMeta.providers = [
|
||||
new CompileProviderMetadata(
|
||||
token: new CompileIdentifierMetadata(name: 'Service1'),
|
||||
token: new CompileTokenMetadata(identifier: new CompileIdentifierMetadata(name: 'Service1')),
|
||||
useClass: new CompileTypeMetadata(name: 'Service2')),
|
||||
new CompileProviderMetadata(
|
||||
token: new CompileIdentifierMetadata(name: 'Service1'),
|
||||
useExisting: new CompileIdentifierMetadata(name: 'Service2')),
|
||||
token: new CompileTokenMetadata(identifier: new CompileIdentifierMetadata(name: 'Service1')),
|
||||
useExisting: new CompileTokenMetadata(identifier: new CompileIdentifierMetadata(name: 'Service2'))),
|
||||
new CompileProviderMetadata(
|
||||
token: new CompileIdentifierMetadata(name: 'Service1'),
|
||||
token: new CompileTokenMetadata(identifier: new CompileIdentifierMetadata(name: 'Service1')),
|
||||
useValue: new CompileIdentifierMetadata(name: 'Service2')),
|
||||
new CompileProviderMetadata(
|
||||
token: new CompileIdentifierMetadata(name: 'Service1'),
|
||||
token: new CompileTokenMetadata(identifier: new CompileIdentifierMetadata(name: 'Service1')),
|
||||
useFactory: new CompileFactoryMetadata(name: 'factory'))
|
||||
];
|
||||
|
||||
@ -495,27 +496,25 @@ void allTests() {
|
||||
|
||||
expect(cmp.providers.length, equals(4));
|
||||
|
||||
expect(cmp.providers[0].token.name, equals("Service1"));
|
||||
expect(cmp.providers[0].token.moduleUrl, equals("moduleUrl"));
|
||||
expect(cmp.providers[0].token.identifier.name, equals("Service1"));
|
||||
expect(cmp.providers[0].token.identifier.moduleUrl, equals("moduleUrl"));
|
||||
expect(cmp.providers[0].useClass.name, equals("Service2"));
|
||||
expect(cmp.providers[0].useClass.moduleUrl, equals("moduleUrl"));
|
||||
|
||||
expect(cmp.providers[1].token.name, equals("Service1"));
|
||||
expect(cmp.providers[1].token.moduleUrl, equals("moduleUrl"));
|
||||
expect(cmp.providers[1].useExisting.name, equals("Service2"));
|
||||
expect(cmp.providers[1].useExisting.moduleUrl, equals("moduleUrl"));
|
||||
expect(cmp.providers[1].token.identifier.name, equals("Service1"));
|
||||
expect(cmp.providers[1].token.identifier.moduleUrl, equals("moduleUrl"));
|
||||
expect(cmp.providers[1].useExisting.identifier.name, equals("Service2"));
|
||||
expect(cmp.providers[1].useExisting.identifier.moduleUrl, equals("moduleUrl"));
|
||||
|
||||
expect(cmp.providers[2].token.name, equals("Service1"));
|
||||
expect(cmp.providers[2].token.moduleUrl, equals("moduleUrl"));
|
||||
expect(cmp.providers[2].token.identifier.name, equals("Service1"));
|
||||
expect(cmp.providers[2].token.identifier.moduleUrl, equals("moduleUrl"));
|
||||
expect(cmp.providers[2].useValue.name, equals("Service2"));
|
||||
expect(cmp.providers[2].useValue.moduleUrl, equals("moduleUrl"));
|
||||
|
||||
expect(cmp.providers[3].token.name, equals("Service1"));
|
||||
expect(cmp.providers[3].token.moduleUrl, equals("moduleUrl"));
|
||||
expect(cmp.providers[3].token.identifier.name, equals("Service1"));
|
||||
expect(cmp.providers[3].token.identifier.moduleUrl, equals("moduleUrl"));
|
||||
expect(cmp.providers[3].useFactory.name, equals("factory"));
|
||||
expect(cmp.providers[3].useFactory.moduleUrl, equals("moduleUrl"));
|
||||
expect(cmp.providers[3].useFactory.diDeps[0].token.name, equals("Service2"));
|
||||
expect(cmp.providers[3].useFactory.diDeps[0].token.moduleUrl, equals("moduleUrl"));
|
||||
});
|
||||
|
||||
test('should fallback to the list of resolved identifiers.', () async {
|
||||
@ -524,7 +523,7 @@ void allTests() {
|
||||
|
||||
fooComponentMeta.providers = [
|
||||
new CompileProviderMetadata(
|
||||
token: new CompileIdentifierMetadata(name: 'Service1'),
|
||||
token: new CompileTokenMetadata(identifier: new CompileIdentifierMetadata(name: 'Service1')),
|
||||
useClass: new CompileTypeMetadata(name: 'Service2'))
|
||||
];
|
||||
|
||||
@ -536,8 +535,8 @@ void allTests() {
|
||||
|
||||
expect(cmp.providers.length, equals(1));
|
||||
|
||||
expect(cmp.providers[0].token.name, equals("Service1"));
|
||||
expect(cmp.providers[0].token.moduleUrl, equals("someModuleUrl"));
|
||||
expect(cmp.providers[0].token.identifier.name, equals("Service1"));
|
||||
expect(cmp.providers[0].token.identifier.moduleUrl, equals("someModuleUrl"));
|
||||
expect(cmp.providers[0].useClass.name, equals("Service2"));
|
||||
expect(cmp.providers[0].useClass.moduleUrl, equals("moduleUrl"));
|
||||
});
|
||||
@ -545,12 +544,12 @@ void allTests() {
|
||||
test('should resolve circular references.', () async {
|
||||
barNgMeta.identifiers['Service1'] =
|
||||
new CompileTypeMetadata(name: 'Service1', moduleUrl: 'moduleUrl',
|
||||
diDeps: [new CompileDiDependencyMetadata(token: new CompileIdentifierMetadata(name: "Service2"))]);
|
||||
diDeps: [new CompileDiDependencyMetadata(token: new CompileTokenMetadata(identifier: new CompileIdentifierMetadata(name: "Service2")))]);
|
||||
barNgMeta.ngDeps.imports.add(new ImportModel()..uri = 'foo.dart');
|
||||
|
||||
fooNgMeta.identifiers['Service2'] =
|
||||
new CompileTypeMetadata(name: 'Service2', moduleUrl: 'moduleUrl',
|
||||
diDeps: [new CompileDiDependencyMetadata(token: new CompileIdentifierMetadata(name: "Service1"))]);
|
||||
diDeps: [new CompileDiDependencyMetadata(token: new CompileTokenMetadata(identifier: new CompileIdentifierMetadata(name: "Service1")))]);
|
||||
fooNgMeta.ngDeps.imports.add(new ImportModel()..uri = 'bar.dart');
|
||||
|
||||
updateReader();
|
||||
@ -558,8 +557,8 @@ void allTests() {
|
||||
final extracted = await _testLink(reader, fooAssetId, fooMetaAssetId);
|
||||
final service2 = extracted.identifiers["Service2"];
|
||||
|
||||
expect(service2.diDeps[0].token.name, equals("Service1"));
|
||||
expect(service2.diDeps[0].token.moduleUrl, equals("moduleUrl"));
|
||||
expect(service2.diDeps[0].token.identifier.name, equals("Service1"));
|
||||
expect(service2.diDeps[0].token.identifier.moduleUrl, equals("moduleUrl"));
|
||||
});
|
||||
|
||||
test('should link dependencies (imports and exports first).', () async {
|
||||
@ -571,13 +570,13 @@ void allTests() {
|
||||
moduleUrl: 'moduleUrl',
|
||||
diDeps: [
|
||||
new CompileDiDependencyMetadata(
|
||||
token: new CompileIdentifierMetadata(name: 'Service2'))
|
||||
token: new CompileTokenMetadata(identifier: new CompileIdentifierMetadata(name: 'Service2')))
|
||||
]);
|
||||
barNgMeta.ngDeps..imports.add(new ImportModel()..uri = 'baz.dart');
|
||||
|
||||
fooComponentMeta.providers = [
|
||||
new CompileProviderMetadata(
|
||||
token: new CompileIdentifierMetadata(name: 'Service1'))
|
||||
token: new CompileTokenMetadata(identifier: new CompileIdentifierMetadata(name: 'Service1')))
|
||||
];
|
||||
fooNgMeta.ngDeps..imports.add(new ImportModel()..uri = 'bar.dart');
|
||||
|
||||
@ -594,8 +593,8 @@ void allTests() {
|
||||
expect(cmp.providers.length, equals(1));
|
||||
final firstProvider = cmp.providers[0];
|
||||
|
||||
expect(firstProvider.token.diDeps[0].token.name, equals("Service2"));
|
||||
expect(firstProvider.token.diDeps[0].token.moduleUrl, equals("moduleUrl"));
|
||||
expect(firstProvider.token.identifier.diDeps[0].token.identifier.name, equals("Service2"));
|
||||
expect(firstProvider.token.identifier.diDeps[0].token.identifier.moduleUrl, equals("moduleUrl"));
|
||||
});
|
||||
|
||||
test('should not resolve when not needed', () async {
|
||||
|
@ -6,14 +6,11 @@ import 'package:barback/barback.dart';
|
||||
import 'package:dart_style/dart_style.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'package:angular2/src/compiler/directive_metadata.dart'
|
||||
show
|
||||
CompileIdentifierMetadata,
|
||||
CompileProviderMetadata,
|
||||
CompileTypeMetadata;
|
||||
import 'package:angular2/src/compiler/compile_metadata.dart'
|
||||
show CompileIdentifierMetadata, CompileProviderMetadata, CompileTypeMetadata, CompileTokenMetadata;
|
||||
import 'package:angular2/src/core/change_detection/change_detection.dart';
|
||||
import 'package:angular2/src/platform/server/html_adapter.dart';
|
||||
import 'package:angular2/src/core/linker/interfaces.dart' show LifecycleHooks;
|
||||
import 'package:angular2/src/core/metadata/lifecycle_hooks.dart' show LifecycleHooks;
|
||||
import 'package:angular2/src/transform/common/annotation_matcher.dart';
|
||||
import 'package:angular2/src/transform/common/asset_reader.dart';
|
||||
import 'package:angular2/src/transform/common/code/ng_deps_code.dart';
|
||||
@ -33,17 +30,6 @@ main() {
|
||||
allTests();
|
||||
}
|
||||
|
||||
void _expectSelector(ReflectionInfoModel model, Matcher matcher) {
|
||||
expect(model.annotations.isNotEmpty, isTrue);
|
||||
var componentAnnotation = model.annotations
|
||||
.firstWhere((e) => e.name == 'Component', orElse: () => null);
|
||||
expect(componentAnnotation, isNotNull);
|
||||
var selectorArg = componentAnnotation.namedParameters
|
||||
.firstWhere((e) => e.name == 'selector', orElse: () => null);
|
||||
expect(selectorArg, isNotNull);
|
||||
return expect(selectorArg.value, matcher);
|
||||
}
|
||||
|
||||
var oldTest = test;
|
||||
void allTests() {
|
||||
var test = (name, fn) {
|
||||
@ -82,22 +68,17 @@ void allTests() {
|
||||
test('should list part contributions first.', () async {
|
||||
var model = await modelFuture;
|
||||
expect(model.reflectables.first.name, equals('PartComponent'));
|
||||
_expectSelector(model.reflectables.first, equals("'[part]'"));
|
||||
});
|
||||
|
||||
test('should list main contributions second.', () async {
|
||||
var model = await modelFuture;
|
||||
expect(model.reflectables[1].name, equals('MainComponent'));
|
||||
_expectSelector(model.reflectables[1], equals("'[main]'"));
|
||||
});
|
||||
|
||||
test('should handle multiple `part` directives.', () async {
|
||||
var model =
|
||||
(await _testCreateModel('multiple_part_files/main.dart')).ngDeps;
|
||||
expect(model.reflectables.length, equals(3));
|
||||
_expectSelector(model.reflectables.first, equals("'[part1]'"));
|
||||
_expectSelector(model.reflectables[1], equals("'[part2]'"));
|
||||
_expectSelector(model.reflectables[2], equals("'[main]'"));
|
||||
});
|
||||
|
||||
test('should not generate anything for `part` files.', () async {
|
||||
@ -209,94 +190,6 @@ void allTests() {
|
||||
});
|
||||
});
|
||||
|
||||
group('property metadata', () {
|
||||
test('should be recorded on fields', () async {
|
||||
var model =
|
||||
(await _testCreateModel('prop_metadata_files/fields.dart')).ngDeps;
|
||||
|
||||
expect(model.reflectables.first.propertyMetadata, isNotNull);
|
||||
expect(model.reflectables.first.propertyMetadata.isNotEmpty, isTrue);
|
||||
expect(model.reflectables.first.propertyMetadata.first.name,
|
||||
equals('field'));
|
||||
expect(
|
||||
model.reflectables.first.propertyMetadata.first.annotations
|
||||
.firstWhere((a) => a.name == 'FieldDecorator',
|
||||
orElse: () => null),
|
||||
isNotNull);
|
||||
});
|
||||
|
||||
test('should be recorded on getters', () async {
|
||||
var model =
|
||||
(await _testCreateModel('prop_metadata_files/getters.dart')).ngDeps;
|
||||
|
||||
expect(model.reflectables.first.propertyMetadata, isNotNull);
|
||||
expect(model.reflectables.first.propertyMetadata.isNotEmpty, isTrue);
|
||||
expect(model.reflectables.first.propertyMetadata.first.name,
|
||||
equals('getVal'));
|
||||
|
||||
var getDecoratorAnnotation = model
|
||||
.reflectables.first.propertyMetadata.first.annotations
|
||||
.firstWhere((a) => a.name == 'GetDecorator', orElse: () => null);
|
||||
expect(getDecoratorAnnotation, isNotNull);
|
||||
expect(getDecoratorAnnotation.isConstObject, isFalse);
|
||||
});
|
||||
|
||||
test('should gracefully handle const instances of annotations', () async {
|
||||
// Regression test for i/4481
|
||||
var model =
|
||||
(await _testCreateModel('prop_metadata_files/override.dart')).ngDeps;
|
||||
|
||||
expect(model.reflectables.first.propertyMetadata, isNotNull);
|
||||
expect(model.reflectables.first.propertyMetadata.isNotEmpty, isTrue);
|
||||
expect(model.reflectables.first.propertyMetadata.first.name,
|
||||
equals('getVal'));
|
||||
var overrideAnnotation = model
|
||||
.reflectables.first.propertyMetadata.first.annotations
|
||||
.firstWhere((a) => a.name == 'override', orElse: () => null);
|
||||
|
||||
expect(overrideAnnotation, isNotNull);
|
||||
expect(overrideAnnotation.isConstObject, isTrue);
|
||||
|
||||
var buf = new StringBuffer();
|
||||
new NgDepsWriter(buf).writeAnnotationModel(overrideAnnotation);
|
||||
expect(buf.toString(), equals('override'));
|
||||
});
|
||||
|
||||
test('should be recorded on setters', () async {
|
||||
var model =
|
||||
(await _testCreateModel('prop_metadata_files/setters.dart')).ngDeps;
|
||||
|
||||
expect(model.reflectables.first.propertyMetadata, isNotNull);
|
||||
expect(model.reflectables.first.propertyMetadata.isNotEmpty, isTrue);
|
||||
expect(model.reflectables.first.propertyMetadata.first.name,
|
||||
equals('setVal'));
|
||||
expect(
|
||||
model.reflectables.first.propertyMetadata.first.annotations
|
||||
.firstWhere((a) => a.name == 'SetDecorator', orElse: () => null),
|
||||
isNotNull);
|
||||
});
|
||||
|
||||
test('should be coalesced when getters and setters have the same name',
|
||||
() async {
|
||||
var model = (await _testCreateModel(
|
||||
'prop_metadata_files/getters_and_setters.dart'))
|
||||
.ngDeps;
|
||||
|
||||
expect(model.reflectables.first.propertyMetadata, isNotNull);
|
||||
expect(model.reflectables.first.propertyMetadata.length, equals(1));
|
||||
expect(model.reflectables.first.propertyMetadata.first.name,
|
||||
equals('myVal'));
|
||||
expect(
|
||||
model.reflectables.first.propertyMetadata.first.annotations
|
||||
.firstWhere((a) => a.name == 'GetDecorator', orElse: () => null),
|
||||
isNotNull);
|
||||
expect(
|
||||
model.reflectables.first.propertyMetadata.first.annotations
|
||||
.firstWhere((a) => a.name == 'SetDecorator', orElse: () => null),
|
||||
isNotNull);
|
||||
});
|
||||
});
|
||||
|
||||
test('should record information about abstract classes', () async {
|
||||
var model =
|
||||
(await _testCreateModel('abstract_classes/classes.dart')).ngDeps;
|
||||
@ -456,24 +349,14 @@ void allTests() {
|
||||
});
|
||||
|
||||
test('should handle prefixed annotations', () async {
|
||||
var model =
|
||||
(await _testCreateModel('prefixed_annotations_files/soup.dart'))
|
||||
.ngDeps;
|
||||
|
||||
expect(model.reflectables.isEmpty, isFalse);
|
||||
final annotations = model.reflectables.first.annotations;
|
||||
final viewAnnotation =
|
||||
annotations.firstWhere((m) => m.isView, orElse: () => null);
|
||||
final componentAnnotation =
|
||||
annotations.firstWhere((m) => m.isComponent, orElse: () => null);
|
||||
expect(viewAnnotation, isNotNull);
|
||||
expect(viewAnnotation.namedParameters.first.name, equals('template'));
|
||||
expect(viewAnnotation.namedParameters.first.value, contains('SoupView'));
|
||||
expect(componentAnnotation, isNotNull);
|
||||
var ngMeta =
|
||||
(await _testCreateModel('prefixed_annotations_files/soup.dart'));
|
||||
expect(ngMeta.identifiers.isNotEmpty, isTrue);
|
||||
expect(ngMeta.identifiers['SoupComponent'], isNotNull);
|
||||
expect(
|
||||
componentAnnotation.namedParameters.first.name, equals('selector'));
|
||||
ngMeta.identifiers['SoupComponent'].selector, equals('[soup]'));
|
||||
expect(
|
||||
componentAnnotation.namedParameters.first.value, contains('[soup]'));
|
||||
ngMeta.identifiers['SoupComponent'].template.template, equals('SoupView'));
|
||||
});
|
||||
});
|
||||
|
||||
@ -527,7 +410,7 @@ void allTests() {
|
||||
expect(
|
||||
model.identifiers['a'].value.toJson(),
|
||||
equals(new CompileProviderMetadata(
|
||||
token: 'someToken',
|
||||
token: new CompileTokenMetadata(value: 'someToken'),
|
||||
useClass: new CompileTypeMetadata(name: 'SomeClass'))
|
||||
.toJson()));
|
||||
});
|
||||
@ -542,7 +425,7 @@ void allTests() {
|
||||
expect(list[0].name, equals("SomeClass"));
|
||||
expect(list[1].name, equals("a"));
|
||||
expect(list[2].toJson(), equals(new CompileProviderMetadata(
|
||||
token: 'someOtherToken',
|
||||
token: new CompileTokenMetadata(value: 'someOtherToken'),
|
||||
useClass: new CompileTypeMetadata(name: 'SomeClass'))
|
||||
.toJson()));
|
||||
});
|
||||
@ -698,34 +581,35 @@ void allTests() {
|
||||
var deps = cmp.type.diDeps;
|
||||
expect(deps, isNotNull);
|
||||
expect(deps.length, equals(13));
|
||||
expect(deps[0].token.name, equals("ServiceDep"));
|
||||
expect(deps[1].token.name, equals("ServiceDep"));
|
||||
expect(deps[2].token, "one");
|
||||
expect(deps[0].token.identifier.name, equals("ServiceDep"));
|
||||
expect(deps[1].token.identifier.name, equals("ServiceDep"));
|
||||
expect(deps[2].token.value, "one");
|
||||
expect(deps[2].isAttribute, isTrue);
|
||||
expect(deps[3].isSelf, isTrue);
|
||||
expect(deps[4].isSkipSelf, isTrue);
|
||||
expect(deps[5].isOptional, isTrue);
|
||||
expect(deps[6].query.selectors[0].name, equals("ServiceDep"));
|
||||
expect(deps[6].query.descendants, isTrue);
|
||||
expect(deps[7].query.selectors[0].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], equals("one"));
|
||||
expect(deps[8].viewQuery.selectors[1], equals("two"));
|
||||
expect(deps[9].viewQuery.selectors[0], equals("one"));
|
||||
expect(deps[9].viewQuery.selectors[1], equals("two"));
|
||||
expect(deps[10].token.name, equals("ServiceDep"));
|
||||
expect(deps[11].token.name, equals("ServiceDep"));
|
||||
expect(deps[12].token.name, equals("ServiceDep"));
|
||||
expect(deps[8].viewQuery.selectors[0].value, equals("one"));
|
||||
expect(deps[8].viewQuery.selectors[1].value, equals("two"));
|
||||
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"));
|
||||
expect(deps[11].token.identifier.name, equals("ServiceDep"));
|
||||
expect(deps[12].token.identifier.name, equals("ServiceDep"));
|
||||
});
|
||||
|
||||
test('should populate `diDependency` using a string token.', () async {
|
||||
var cmp = (await _testCreateModel('directives_files/components.dart'))
|
||||
.identifiers['ComponentWithDiDepsStrToken'];
|
||||
test('should populate `diDependency` using a string token.',
|
||||
() async {
|
||||
var cmp =
|
||||
(await _testCreateModel('directives_files/components.dart')).identifiers['ComponentWithDiDepsStrToken'];
|
||||
|
||||
var deps = cmp.type.diDeps;
|
||||
expect(deps, isNotNull);
|
||||
expect(deps.length, equals(1));
|
||||
expect(deps[0].token, equals("StringDep"));
|
||||
expect(deps[0].token.value, equals("StringDep"));
|
||||
});
|
||||
|
||||
test('should populate `services`.', () async {
|
||||
@ -737,8 +621,8 @@ void allTests() {
|
||||
var deps = service.diDeps;
|
||||
expect(deps, isNotNull);
|
||||
expect(deps.length, equals(2));
|
||||
expect(deps[0].token.name, equals("ServiceDep"));
|
||||
expect(deps[1].token.name, equals("ServiceDep"));
|
||||
expect(deps[0].token.identifier.name, equals("ServiceDep"));
|
||||
expect(deps[1].token.identifier.name, equals("ServiceDep"));
|
||||
});
|
||||
|
||||
test('should populate `providers` using types.', () async {
|
||||
@ -750,12 +634,12 @@ void allTests() {
|
||||
expect(cmp.providers.length, equals(2));
|
||||
|
||||
var firstToken = cmp.providers.first;
|
||||
expect(firstToken.prefix, isNull);
|
||||
expect(firstToken.name, equals("ServiceDep"));
|
||||
expect(firstToken.identifier.prefix, isNull);
|
||||
expect(firstToken.identifier.name, equals("ServiceDep"));
|
||||
|
||||
var secondToken = cmp.providers[1];
|
||||
expect(secondToken.prefix, equals("dep2"));
|
||||
expect(secondToken.name, equals("ServiceDep"));
|
||||
expect(secondToken.identifier.prefix, equals("dep2"));
|
||||
expect(secondToken.identifier.name, equals("ServiceDep"));
|
||||
});
|
||||
|
||||
test('should populate `viewProviders` using types.', () async {
|
||||
@ -807,8 +691,8 @@ void allTests() {
|
||||
|
||||
var token = cmp.providers.first.token;
|
||||
var useClass = cmp.providers.first.useClass;
|
||||
expect(token.prefix, isNull);
|
||||
expect(token.name, equals("ServiceDep"));
|
||||
expect(token.identifier.prefix, isNull);
|
||||
expect(token.identifier.name, equals("ServiceDep"));
|
||||
|
||||
expect(useClass.prefix, isNull);
|
||||
expect(useClass.name, equals("ServiceDep"));
|
||||
@ -823,7 +707,7 @@ void allTests() {
|
||||
expect(cmp.providers.length, equals(1));
|
||||
|
||||
var token = cmp.providers.first.token;
|
||||
expect(token, equals("StringDep"));
|
||||
expect(token.value, equals("StringDep"));
|
||||
});
|
||||
|
||||
test('should populate `providers` using toClass.', () async {
|
||||
@ -852,7 +736,7 @@ void allTests() {
|
||||
var token = cmp.providers.first.token;
|
||||
var useExisting = cmp.providers.first.useExisting;
|
||||
|
||||
expect(useExisting.prefix, isNull);
|
||||
expect(useExisting.identifier.prefix, isNull);
|
||||
expect(useExisting.name, equals("ServiceDep"));
|
||||
});
|
||||
|
||||
@ -867,8 +751,8 @@ void allTests() {
|
||||
var token = cmp.providers.first.token;
|
||||
var useExisting = cmp.providers.first.useExisting;
|
||||
|
||||
expect(useExisting.prefix, isNull);
|
||||
expect(useExisting.name, equals("ServiceDep"));
|
||||
expect(useExisting.identifier.prefix, isNull);
|
||||
expect(useExisting.identifier.name, equals("ServiceDep"));
|
||||
});
|
||||
|
||||
test('should populate `providers` using useExisting (string token).',
|
||||
@ -883,7 +767,7 @@ void allTests() {
|
||||
var token = cmp.providers.first.token;
|
||||
var useExisting = cmp.providers.first.useExisting;
|
||||
|
||||
expect(useExisting, equals("StrToken"));
|
||||
expect(useExisting.value, equals("StrToken"));
|
||||
});
|
||||
|
||||
test('should populate `providers` using useValue.', () async {
|
||||
@ -987,14 +871,14 @@ void allTests() {
|
||||
expect(useFactory.prefix, isNull);
|
||||
expect(useFactory.name, equals("funcDep"));
|
||||
|
||||
expect(deps[0].token.name, equals("ServiceDep"));
|
||||
expect(deps[1].token, equals("Str"));
|
||||
expect(deps[2].token.name, equals("ServiceDep"));
|
||||
expect(deps[3].token.name, equals("ServiceDep"));
|
||||
expect(deps[0].token.identifier.name, equals("ServiceDep"));
|
||||
expect(deps[1].token.value, equals("Str"));
|
||||
expect(deps[2].token.identifier.name, equals("ServiceDep"));
|
||||
expect(deps[3].token.identifier.name, equals("ServiceDep"));
|
||||
expect(deps[3].isSelf, equals(true));
|
||||
expect(deps[4].token.name, equals("ServiceDep"));
|
||||
expect(deps[4].token.identifier.name, equals("ServiceDep"));
|
||||
expect(deps[4].isSkipSelf, equals(true));
|
||||
expect(deps[5].token.name, equals("ServiceDep"));
|
||||
expect(deps[5].token.identifier.name, equals("ServiceDep"));
|
||||
expect(deps[5].isOptional, equals(true));
|
||||
});
|
||||
|
||||
@ -1011,6 +895,28 @@ void allTests() {
|
||||
expect(useFactory.name, equals("funcDep"));
|
||||
});
|
||||
|
||||
test('should populate factories', () async {
|
||||
var factory = (await _testCreateModel('directives_files/components.dart'))
|
||||
.identifiers['factoryWithDeps'];
|
||||
|
||||
expect(factory, isNotNull);
|
||||
|
||||
expect(factory.prefix, isNull);
|
||||
expect(factory.name, equals("factoryWithDeps"));
|
||||
|
||||
var factoryDeps = factory.diDeps;
|
||||
|
||||
expect(factoryDeps[0].token.identifier.name, equals("ServiceDep"));
|
||||
expect(factoryDeps[1].token.value, equals("Str"));
|
||||
expect(factoryDeps[2].token.identifier.name, equals("ServiceDep"));
|
||||
expect(factoryDeps[3].token.identifier.name, equals("ServiceDep"));
|
||||
expect(factoryDeps[3].isSelf, equals(true));
|
||||
expect(factoryDeps[4].token.identifier.name, equals("ServiceDep"));
|
||||
expect(factoryDeps[4].isSkipSelf, equals(true));
|
||||
expect(factoryDeps[5].token.identifier.name, equals("ServiceDep"));
|
||||
expect(factoryDeps[5].isOptional, equals(true));
|
||||
});
|
||||
|
||||
test('should populate `providers` using a const token.', () async {
|
||||
var cmp = (await _testCreateModel('directives_files/components.dart'))
|
||||
.identifiers['ComponentWithProvidersConstToken'];
|
||||
@ -1020,8 +926,8 @@ void allTests() {
|
||||
expect(cmp.providers.length, equals(1));
|
||||
|
||||
var token = cmp.providers.first.token;
|
||||
expect(token.name, equals("ServiceDep"));
|
||||
expect(token.constConstructor, isTrue);
|
||||
expect(token.identifier.name, equals("ServiceDep"));
|
||||
expect(token.identifierIsInstance, isTrue);
|
||||
});
|
||||
|
||||
test('should populate `queries`.', () async {
|
||||
@ -1031,26 +937,26 @@ void allTests() {
|
||||
expect(cmp, isNotNull);
|
||||
expect(cmp.queries, isNotNull);
|
||||
expect(cmp.queries.length, equals(4));
|
||||
expect(cmp.queries[0].selectors, equals(["child"]));
|
||||
expect(cmp.queries[0].selectors[0].name, equals("child"));
|
||||
expect(cmp.queries[0].first, isTrue);
|
||||
expect(cmp.queries[1].selectors, equals(["child"]));
|
||||
expect(cmp.queries[1].selectors[0].name, equals("child"));
|
||||
expect(cmp.queries[1].first, isFalse);
|
||||
expect(cmp.queries[1].descendants, isTrue);
|
||||
expect(cmp.queries[2].selectors, equals(["child"]));
|
||||
expect(cmp.queries[2].selectors[0].name, equals("child"));
|
||||
expect(cmp.queries[2].first, isTrue);
|
||||
expect(cmp.queries[3].selectors, equals(["child"]));
|
||||
expect(cmp.queries[3].selectors[0].name, equals("child"));
|
||||
expect(cmp.queries[3].first, isFalse);
|
||||
expect(cmp.queries[3].descendants, isTrue);
|
||||
|
||||
expect(cmp.viewQueries, isNotNull);
|
||||
expect(cmp.viewQueries.length, equals(4));
|
||||
expect(cmp.viewQueries[0].selectors, equals(["child"]));
|
||||
expect(cmp.viewQueries[0].selectors[0].value, equals("child"));
|
||||
expect(cmp.viewQueries[0].first, isTrue);
|
||||
expect(cmp.viewQueries[1].selectors, equals(["child"]));
|
||||
expect(cmp.viewQueries[1].selectors[0].value, equals("child"));
|
||||
expect(cmp.viewQueries[1].first, isFalse);
|
||||
expect(cmp.viewQueries[2].selectors, equals(["child"]));
|
||||
expect(cmp.viewQueries[2].selectors[0].value, equals("child"));
|
||||
expect(cmp.viewQueries[2].first, isTrue);
|
||||
expect(cmp.viewQueries[3].selectors, equals(["child"]));
|
||||
expect(cmp.viewQueries[3].selectors[0].value, equals("child"));
|
||||
expect(cmp.viewQueries[3].first, isFalse);
|
||||
});
|
||||
|
||||
|
@ -261,3 +261,11 @@ class ComponentWithQueries {
|
||||
}
|
||||
|
||||
funcDep() {}
|
||||
|
||||
@Injectable()
|
||||
factoryWithDeps(ServiceDep a,
|
||||
@Inject("Str") b,
|
||||
@Inject(ServiceDep) c,
|
||||
@Self ServiceDep d,
|
||||
@SkipSelf ServiceDep e,
|
||||
@Optional ServiceDep f) {}
|
@ -101,16 +101,8 @@ void allTests() {
|
||||
'a|web/bar.template.dart':
|
||||
'two_annotations_files/expected/bar.template.dart'
|
||||
}),
|
||||
new IntegrationTestConfig('should generate getters for output events defined on a Component.',
|
||||
inputs: {
|
||||
'a|web/index.dart': 'event_getter_files/index.dart',
|
||||
'a|web/bar.dart': 'event_getter_files/bar.dart'
|
||||
},
|
||||
outputs: {
|
||||
'a|web/bar.template.dart':
|
||||
'event_getter_files/expected/bar.template.dart'
|
||||
}),
|
||||
new IntegrationTestConfig('should handle Directive dependencies declared on a View.',
|
||||
new IntegrationTestConfig(
|
||||
'should handle Directive dependencies declared on a View.',
|
||||
inputs: {
|
||||
'a|web/index.dart': 'directive_dep_files/index.dart',
|
||||
'a|web/foo.dart': 'directive_dep_files/foo.dart',
|
||||
@ -137,35 +129,11 @@ void allTests() {
|
||||
'a|web/bar.dart': 'empty_ng_deps_files/bar.dart'
|
||||
},
|
||||
outputs: {
|
||||
'a|web/foo.template.dart':
|
||||
'empty_ng_deps_files/expected/foo.template.dart',
|
||||
'a|web/bar.template.dart':
|
||||
'empty_ng_deps_files/expected/bar.template.dart'
|
||||
}),
|
||||
new IntegrationTestConfig('should generate setters for annotated properties.',
|
||||
inputs: {
|
||||
'a|web/bar.dart': 'queries_prop_annotation_files/bar.dart'
|
||||
},
|
||||
outputs: {
|
||||
'a|web/bar.template.dart':
|
||||
'queries_prop_annotation_files/expected/bar.template.dart'
|
||||
}),
|
||||
new IntegrationTestConfig('should generate setters for `queries` values in Directives.',
|
||||
inputs: {
|
||||
'a|web/bar.dart': 'queries_class_annotation_files/bar.dart'
|
||||
},
|
||||
outputs: {
|
||||
'a|web/bar.template.dart':
|
||||
'queries_class_annotation_files/expected/bar.template.dart'
|
||||
}),
|
||||
new IntegrationTestConfig('should handle @override annotations in properties on Directives.',
|
||||
inputs: {
|
||||
'a|web/bar.dart': 'override_annotation_files/bar.dart'
|
||||
},
|
||||
outputs: {
|
||||
'a|web/bar.template.dart':
|
||||
'override_annotation_files/expected/bar.template.dart'
|
||||
})
|
||||
'a|web/foo.template.dart':
|
||||
'empty_ng_deps_files/expected/foo.template.dart',
|
||||
'a|web/bar.template.dart':
|
||||
'empty_ng_deps_files/expected/bar.template.dart'
|
||||
})
|
||||
];
|
||||
|
||||
var cache = {};
|
||||
|
@ -13,10 +13,7 @@ void initReflector() {
|
||||
_ngRef.reflector
|
||||
..registerType(
|
||||
MyComponent,
|
||||
new _ngRef.ReflectionInfo(const [
|
||||
const Component(selector: '[soup]'),
|
||||
const View(template: ''),
|
||||
hostViewFactory_MyComponent
|
||||
], const [], () => new MyComponent()));
|
||||
new _ngRef.ReflectionInfo(const [hostViewFactory_MyComponent], const [],
|
||||
() => new MyComponent()));
|
||||
i0.initReflector();
|
||||
}
|
||||
|
@ -15,11 +15,8 @@ void initReflector() {
|
||||
_ngRef.reflector
|
||||
..registerType(
|
||||
MyComponent,
|
||||
new _ngRef.ReflectionInfo(const [
|
||||
const Component(selector: 'soup'),
|
||||
const View(directives: [Foo], template: 'foo'),
|
||||
hostViewFactory_MyComponent
|
||||
], const [], () => new MyComponent()));
|
||||
new _ngRef.ReflectionInfo(const [hostViewFactory_MyComponent], const [],
|
||||
() => new MyComponent()));
|
||||
i0.initReflector();
|
||||
i1.initReflector();
|
||||
}
|
||||
|
@ -15,11 +15,8 @@ void initReflector() {
|
||||
_ngRef.reflector
|
||||
..registerType(
|
||||
MyComponent,
|
||||
new _ngRef.ReflectionInfo(const [
|
||||
const Component(selector: 'soup'),
|
||||
const View(directives: [prefix.Foo], template: 'foo'),
|
||||
hostViewFactory_MyComponent
|
||||
], const [], () => new MyComponent()));
|
||||
new _ngRef.ReflectionInfo(const [hostViewFactory_MyComponent], const [],
|
||||
() => new MyComponent()));
|
||||
i0.initReflector();
|
||||
i1.initReflector();
|
||||
}
|
||||
|
@ -15,11 +15,8 @@ void initReflector() {
|
||||
_ngRef.reflector
|
||||
..registerType(
|
||||
MyComponent,
|
||||
new _ngRef.ReflectionInfo(const [
|
||||
const Component(selector: '[soup]'),
|
||||
const View(directives: const [directiveAlias], template: ''),
|
||||
hostViewFactory_MyComponent
|
||||
], const [], () => new MyComponent()));
|
||||
new _ngRef.ReflectionInfo(const [hostViewFactory_MyComponent], const [],
|
||||
() => new MyComponent()));
|
||||
i0.initReflector();
|
||||
i1.initReflector();
|
||||
}
|
||||
|
@ -1,9 +0,0 @@
|
||||
library bar;
|
||||
|
||||
import 'package:angular2/src/core/metadata.dart';
|
||||
|
||||
@Component(selector: '[soup]', outputs: ['eventName1', 'eventName2: propName2'])
|
||||
@View(template: '')
|
||||
class MyComponent {
|
||||
MyComponent();
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
library bar.template.dart;
|
||||
|
||||
import 'bar.dart';
|
||||
import 'package:angular2/src/core/reflection/reflection.dart' as _ngRef;
|
||||
import 'package:angular2/src/core/metadata.dart';
|
||||
import 'package:angular2/src/core/metadata.template.dart' as i0;
|
||||
export 'bar.dart';
|
||||
|
||||
var _visited = false;
|
||||
void initReflector() {
|
||||
if (_visited) return;
|
||||
_visited = true;
|
||||
_ngRef.reflector
|
||||
..registerType(
|
||||
MyComponent,
|
||||
new _ngRef.ReflectionInfo(const [
|
||||
const Component(
|
||||
outputs: ['eventName1', 'eventName2: propName2'],
|
||||
selector: '[soup]'),
|
||||
const View(template: ''),
|
||||
hostViewFactory_MyComponent
|
||||
], const [], () => new MyComponent()))
|
||||
..registerGetters(
|
||||
{'eventName1': (o) => o.eventName1, 'eventName2': (o) => o.eventName2});
|
||||
i0.initReflector();
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
library web_foo;
|
||||
|
||||
import 'package:angular2/platform/browser.dart';
|
||||
import 'package:angular2/src/core/reflection/reflection.dart';
|
||||
import 'package:angular2/src/core/reflection/reflection_capabilities.dart';
|
||||
import 'bar.dart';
|
||||
|
||||
void main() {
|
||||
reflector.reflectionCapabilities = new ReflectionCapabilities();
|
||||
bootstrap(MyComponent);
|
||||
}
|
@ -15,11 +15,7 @@ void initReflector() {
|
||||
_ngRef.reflector
|
||||
..registerType(
|
||||
MyComponent,
|
||||
new _ngRef.ReflectionInfo(const [
|
||||
const Component(componentServices: const [MyContext]),
|
||||
const View(template: ''),
|
||||
hostViewFactory_MyComponent
|
||||
], const [
|
||||
new _ngRef.ReflectionInfo(const [hostViewFactory_MyComponent], const [
|
||||
const [MyContext]
|
||||
], (MyContext c) => new MyComponent(c)));
|
||||
i0.initReflector();
|
||||
|
@ -1,10 +0,0 @@
|
||||
library bar;
|
||||
|
||||
import 'package:angular2/src/core/metadata.dart';
|
||||
|
||||
@Component(selector: '[soup]')
|
||||
@View(template: '')
|
||||
class MyComponent implements QueryFieldProvider {
|
||||
@override
|
||||
String queryField;
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
library bar.template.dart;
|
||||
|
||||
import 'bar.dart';
|
||||
import 'package:angular2/src/core/reflection/reflection.dart' as _ngRef;
|
||||
import 'package:angular2/src/core/metadata.dart';
|
||||
import 'package:angular2/src/core/metadata.template.dart' as i0;
|
||||
export 'bar.dart';
|
||||
|
||||
var _visited = false;
|
||||
void initReflector() {
|
||||
if (_visited) return;
|
||||
_visited = true;
|
||||
_ngRef.reflector
|
||||
..registerType(
|
||||
MyComponent,
|
||||
new _ngRef.ReflectionInfo(
|
||||
const [
|
||||
const Component(selector: '[soup]'),
|
||||
const View(template: ''),
|
||||
hostViewFactory_MyComponent
|
||||
],
|
||||
const [],
|
||||
() => new MyComponent(),
|
||||
const [QueryFieldProvider],
|
||||
const {
|
||||
'queryField': const [override]
|
||||
}));
|
||||
i0.initReflector();
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
library bar;
|
||||
|
||||
import 'package:angular2/src/core/metadata.dart';
|
||||
|
||||
@Component(
|
||||
selector: '[soup]',
|
||||
queries: const {'queryField': const ContentChild('child')})
|
||||
@View(template: '')
|
||||
class MyComponent {}
|
@ -1,25 +0,0 @@
|
||||
library bar.template.dart;
|
||||
|
||||
import 'bar.dart';
|
||||
import 'package:angular2/src/core/reflection/reflection.dart' as _ngRef;
|
||||
import 'package:angular2/src/core/metadata.dart';
|
||||
import 'package:angular2/src/core/metadata.template.dart' as i0;
|
||||
export 'bar.dart';
|
||||
|
||||
var _visited = false;
|
||||
void initReflector() {
|
||||
if (_visited) return;
|
||||
_visited = true;
|
||||
_ngRef.reflector
|
||||
..registerType(
|
||||
MyComponent,
|
||||
new _ngRef.ReflectionInfo(const [
|
||||
const Component(
|
||||
queries: const {'queryField': const ContentChild('child')},
|
||||
selector: '[soup]'),
|
||||
const View(template: ''),
|
||||
hostViewFactory_MyComponent
|
||||
], const [], () => new MyComponent()))
|
||||
..registerSetters({'queryField': (o, v) => o.queryField = v});
|
||||
i0.initReflector();
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
library bar;
|
||||
|
||||
import 'package:angular2/src/core/metadata.dart';
|
||||
|
||||
@Component(selector: '[soup]')
|
||||
@View(template: '')
|
||||
class MyComponent {
|
||||
@ContentChild('child') String queryField;
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
library bar.template.dart;
|
||||
|
||||
import 'bar.dart';
|
||||
import 'package:angular2/src/core/reflection/reflection.dart' as _ngRef;
|
||||
import 'package:angular2/src/core/metadata.dart';
|
||||
import 'package:angular2/src/core/metadata.template.dart' as i0;
|
||||
export 'bar.dart';
|
||||
|
||||
var _visited = false;
|
||||
void initReflector() {
|
||||
if (_visited) return;
|
||||
_visited = true;
|
||||
_ngRef.reflector
|
||||
..registerType(
|
||||
MyComponent,
|
||||
new _ngRef.ReflectionInfo(
|
||||
const [
|
||||
const Component(selector: '[soup]'),
|
||||
const View(template: ''),
|
||||
hostViewFactory_MyComponent
|
||||
],
|
||||
const [],
|
||||
() => new MyComponent(),
|
||||
const [],
|
||||
const {
|
||||
'queryField': const [const ContentChild('child')]
|
||||
}))
|
||||
..registerSetters({'queryField': (o, v) => o.queryField = v});
|
||||
i0.initReflector();
|
||||
}
|
@ -13,9 +13,7 @@ void initReflector() {
|
||||
_ngRef.reflector
|
||||
..registerType(
|
||||
MyComponent,
|
||||
new _ngRef.ReflectionInfo(const [
|
||||
const Component(selector: '[soup]', template: 'aa'),
|
||||
hostViewFactory_MyComponent
|
||||
], const [], () => new MyComponent()));
|
||||
new _ngRef.ReflectionInfo(const [hostViewFactory_MyComponent], const [],
|
||||
() => new MyComponent()));
|
||||
i0.initReflector();
|
||||
}
|
||||
|
@ -13,10 +13,7 @@ void initReflector() {
|
||||
_ngRef.reflector
|
||||
..registerType(
|
||||
MyComponent,
|
||||
new _ngRef.ReflectionInfo(const [
|
||||
const Component(selector: '[soup]'),
|
||||
const View(template: ''),
|
||||
hostViewFactory_MyComponent
|
||||
], const [], () => new MyComponent()));
|
||||
new _ngRef.ReflectionInfo(const [hostViewFactory_MyComponent], const [],
|
||||
() => new MyComponent()));
|
||||
i0.initReflector();
|
||||
}
|
||||
|
@ -1,9 +1,10 @@
|
||||
library bar;
|
||||
|
||||
import 'package:angular2/src/core/metadata.dart';
|
||||
import 'package:angular2/core.dart';
|
||||
|
||||
@Component(selector: '[soup]')
|
||||
@View(template: 'Salad: {{myNum}} is awesome')
|
||||
@Annotation1(prop1: 'value1')
|
||||
@Annotation2(prop2: 'value2')
|
||||
@Component(selector: 'xyz', template: '')
|
||||
class MyComponent {
|
||||
int myNum;
|
||||
|
||||
|
@ -2,8 +2,8 @@ library bar.template.dart;
|
||||
|
||||
import 'bar.dart';
|
||||
import 'package:angular2/src/core/reflection/reflection.dart' as _ngRef;
|
||||
import 'package:angular2/src/core/metadata.dart';
|
||||
import 'package:angular2/src/core/metadata.template.dart' as i0;
|
||||
import 'package:angular2/core.dart';
|
||||
import 'package:angular2/core.template.dart' as i0;
|
||||
export 'bar.dart';
|
||||
|
||||
var _visited = false;
|
||||
@ -14,8 +14,8 @@ void initReflector() {
|
||||
..registerType(
|
||||
MyComponent,
|
||||
new _ngRef.ReflectionInfo(const [
|
||||
const Component(selector: '[soup]'),
|
||||
const View(template: 'Salad: {{myNum}} is awesome'),
|
||||
const Annotation1(prop1: 'value1'),
|
||||
const Annotation2(prop2: 'value2'),
|
||||
hostViewFactory_MyComponent
|
||||
], const [], () => new MyComponent()));
|
||||
i0.initReflector();
|
||||
|
@ -16,11 +16,7 @@ void initReflector() {
|
||||
..registerType(
|
||||
MyComponent,
|
||||
new _ngRef.ReflectionInfo(
|
||||
const [
|
||||
const Component(selector: 'soup'),
|
||||
const View(template: ''),
|
||||
hostViewFactory_MyComponent
|
||||
],
|
||||
const [hostViewFactory_MyComponent],
|
||||
const [
|
||||
const [prefix.MyContext],
|
||||
const [prefix.MyDep]
|
||||
|
@ -8,8 +8,6 @@ import 'package:dart_style/dart_style.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:guinness/guinness.dart';
|
||||
|
||||
import 'package:angular2/src/core/change_detection/codegen_name_util.dart'
|
||||
show CONTEXT_ACCESSOR;
|
||||
import 'package:angular2/src/platform/server/html_adapter.dart';
|
||||
import 'package:angular2/src/transform/common/code/ng_deps_code.dart';
|
||||
import 'package:angular2/src/transform/common/code/source_module.dart';
|
||||
@ -27,6 +25,7 @@ import '../common/recording_logger.dart';
|
||||
var formatter = new DartFormatter();
|
||||
TestAssetReader reader;
|
||||
RecordingLogger logger;
|
||||
const CONTEXT_ACCESSOR = 'context';
|
||||
|
||||
main() => allTests();
|
||||
|
||||
@ -142,8 +141,7 @@ void allTests() {
|
||||
fooComponentMeta.template =
|
||||
new CompileTemplateMetadata(template: '<${barComponentMeta.selector}>');
|
||||
final viewAnnotation = new AnnotationModel()
|
||||
..name = 'View'
|
||||
..isView = true;
|
||||
..name = 'View';
|
||||
viewAnnotation.namedParameters.add(new NamedParameter()
|
||||
..name = 'directives'
|
||||
..value = 'const [${barComponentMeta.type.name}]');
|
||||
@ -173,8 +171,7 @@ void allTests() {
|
||||
fooComponentMeta.template =
|
||||
new CompileTemplateMetadata(template: '<${barComponentMeta.selector}>');
|
||||
final componentAnnotation = new AnnotationModel()
|
||||
..name = 'View'
|
||||
..isView = true;
|
||||
..name = 'View';
|
||||
fooNgMeta.ngDeps.reflectables.first.annotations.add(componentAnnotation);
|
||||
fooNgMeta.ngDeps.reflectables.first.directives.add(new PrefixedType()
|
||||
..name = barComponentMeta.type.name
|
||||
@ -203,8 +200,7 @@ void allTests() {
|
||||
fooComponentMeta.template =
|
||||
new CompileTemplateMetadata(template: '<${barComponentMeta.selector}>');
|
||||
final componentAnnotation = new AnnotationModel()
|
||||
..name = 'View'
|
||||
..isView = true;
|
||||
..name = 'View';
|
||||
fooNgMeta.ngDeps.reflectables.first.annotations.add(componentAnnotation);
|
||||
fooNgMeta.ngDeps.reflectables.first.directives
|
||||
.add(new PrefixedType()..name = 'directiveAlias');
|
||||
@ -240,71 +236,6 @@ void allTests() {
|
||||
expect(_generatedCode(firstOutputs)).toEqual(_generatedCode(secondOutputs));
|
||||
});
|
||||
|
||||
it('should generate getters for Component#outputs.', () async {
|
||||
fooComponentMeta.template = new CompileTemplateMetadata(
|
||||
template: '<div>{{greeting}}</div>', templateUrl: 'template.html');
|
||||
fooComponentMeta.outputs = {'eventName': 'eventName'};
|
||||
updateReader();
|
||||
|
||||
final outputs = await process(fooAssetId);
|
||||
final ngDeps = outputs.ngDeps;
|
||||
expect(ngDeps.getters).toContain('eventName');
|
||||
});
|
||||
|
||||
it('should generate getters for Directive#outputs.', () async {
|
||||
fooComponentMeta
|
||||
..template = null
|
||||
..isComponent = false;
|
||||
fooComponentMeta.outputs = {'eventName': 'eventName'};
|
||||
updateReader();
|
||||
|
||||
final outputs = await process(fooAssetId);
|
||||
final ngDeps = outputs.ngDeps;
|
||||
expect(ngDeps.getters).toContain('eventName');
|
||||
});
|
||||
|
||||
it('should generate setters for Component#inputs.', () async {
|
||||
fooComponentMeta.template = new CompileTemplateMetadata(
|
||||
template: '<div>{{greeting}}</div>', templateUrl: 'template.html');
|
||||
fooComponentMeta.inputs = {'text': 'tool-tip'};
|
||||
updateReader();
|
||||
|
||||
final outputs = await process(fooAssetId);
|
||||
final ngDeps = outputs.ngDeps;
|
||||
expect(ngDeps.setters).toContain('text');
|
||||
});
|
||||
|
||||
it('should generate setters for Directive#inputs.', () async {
|
||||
fooComponentMeta
|
||||
..template = null
|
||||
..isComponent = false;
|
||||
fooComponentMeta.inputs = {'text': 'tool-tip'};
|
||||
updateReader();
|
||||
|
||||
final outputs = await process(fooAssetId);
|
||||
final ngDeps = outputs.ngDeps;
|
||||
expect(ngDeps.setters).toContain('text');
|
||||
});
|
||||
|
||||
it(
|
||||
'should generate a single setter for two `Directive`s '
|
||||
'with the same inputs.', () async {
|
||||
fooComponentMeta
|
||||
..template = null
|
||||
..isComponent = false;
|
||||
fooComponentMeta.inputs = {'text': 'tool-tip'};
|
||||
barComponentMeta
|
||||
..template = null
|
||||
..isComponent = false;
|
||||
barComponentMeta.inputs = {'text': 'tool-tip'};
|
||||
updateReader();
|
||||
|
||||
final outputs = await process(fooAssetId);
|
||||
final ngDeps = outputs.ngDeps;
|
||||
expect(ngDeps.setters).toContain('text');
|
||||
expect(ngDeps.setters.length).toEqual(1);
|
||||
});
|
||||
|
||||
it('should gracefully handle null .ng_meta.json files', () async {
|
||||
final dne =
|
||||
new AssetId('package', 'lib/file_that_does_not_exist.ng_meta.json');
|
||||
@ -337,8 +268,7 @@ void allTests() {
|
||||
fooComponentMeta.template =
|
||||
new CompileTemplateMetadata(template: '<bar></bar>');
|
||||
final viewAnnotation = new AnnotationModel()
|
||||
..name = 'View'
|
||||
..isView = true;
|
||||
..name = 'View';
|
||||
|
||||
barNgMeta.aliases['PLATFORM'] = [barComponentMeta.type.name];
|
||||
updateReader();
|
||||
@ -356,8 +286,7 @@ void allTests() {
|
||||
fooComponentMeta.template =
|
||||
new CompileTemplateMetadata(template: '<bar></bar>');
|
||||
final viewAnnotation = new AnnotationModel()
|
||||
..name = 'View'
|
||||
..isView = true;
|
||||
..name = 'View';
|
||||
|
||||
barNgMeta.identifiers['PLATFORM'] = barComponentMeta;
|
||||
updateReader();
|
||||
@ -404,8 +333,7 @@ void allTests() {
|
||||
fooComponentMeta.template =
|
||||
new CompileTemplateMetadata(template: '{{1 | bar}}');
|
||||
final viewAnnotation = new AnnotationModel()
|
||||
..name = 'View'
|
||||
..isView = true;
|
||||
..name = 'View';
|
||||
viewAnnotation.namedParameters.add(new NamedParameter()
|
||||
..name = 'pipes'
|
||||
..value = 'const [${barPipeMeta.type.name}]');
|
||||
|
@ -15,6 +15,5 @@ void initReflector(reflector) {
|
||||
const Directive(selector: 'hello', outputs: const ['eventName'])
|
||||
], const [
|
||||
const []
|
||||
], () => new HelloDirective()))
|
||||
..registerGetters({'eventName': (o) => o.eventName});
|
||||
], () => new HelloDirective()));
|
||||
}
|
||||
|
@ -19,6 +19,5 @@ void initReflector(reflector) {
|
||||
_templates.HostHelloCmpTemplate
|
||||
], const [
|
||||
const []
|
||||
], () => new HelloCmp()))
|
||||
..registerGetters({'eventName': (o) => o.eventName});
|
||||
], () => new HelloCmp()));
|
||||
}
|
||||
|
@ -83,26 +83,6 @@ void initReflector(reflector) {
|
||||
directives: const [NgFor])
|
||||
], const [
|
||||
const []
|
||||
], () => new RecursiveCmp()))
|
||||
..registerGetters({
|
||||
'eventName': (o) => o.eventName,
|
||||
'hprop': (o) => o.hprop,
|
||||
'propValue': (o) => o.propValue,
|
||||
'textBindings': (o) => o.textBindings,
|
||||
'thing': (o) => o.thing,
|
||||
'things': (o) => o.things
|
||||
})
|
||||
..registerSetters({
|
||||
'field': (o, v) => o.field = v,
|
||||
'hprop': (o, v) => o.hprop = v,
|
||||
'ngForOf': (o, v) => o.ngForOf = v,
|
||||
'prop': (o, v) => o.prop = v,
|
||||
'propName': (o, v) => o.propName = v,
|
||||
'recursiveProp': (o, v) => o.recursiveProp = v
|
||||
})
|
||||
..registerMethods({
|
||||
'doAThing': (o, List args) => Function.apply(o.doAThing, args),
|
||||
'onMouseOver': (o, List args) => Function.apply(o.onMouseOver, args)
|
||||
});
|
||||
], () => new RecursiveCmp()));
|
||||
i0.initReflector();
|
||||
}
|
||||
|
Reference in New Issue
Block a user