Revert "feat(transformers): collect provider information"
This reverts commit 81beb1c788
.
Broke Google3.
This commit is contained in:
parent
6dce4f49c2
commit
b857fd1eeb
|
@ -177,10 +177,7 @@ export class CompileProviderMetadata {
|
||||||
static fromJson(data: {[key: string]: any}): CompileProviderMetadata {
|
static fromJson(data: {[key: string]: any}): CompileProviderMetadata {
|
||||||
return new CompileProviderMetadata({
|
return new CompileProviderMetadata({
|
||||||
token: objFromJson(data['token'], CompileIdentifierMetadata.fromJson),
|
token: objFromJson(data['token'], CompileIdentifierMetadata.fromJson),
|
||||||
useClass: objFromJson(data['useClass'], CompileTypeMetadata.fromJson),
|
useClass: objFromJson(data['useClass'], CompileTypeMetadata.fromJson)
|
||||||
useExisting: objFromJson(data['useExisting'], CompileIdentifierMetadata.fromJson),
|
|
||||||
useValue: objFromJson(data['useValue'], CompileIdentifierMetadata.fromJson),
|
|
||||||
useFactory: objFromJson(data['useFactory'], CompileFactoryMetadata.fromJson)
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,10 +185,7 @@ export class CompileProviderMetadata {
|
||||||
return {
|
return {
|
||||||
// Note: Runtime type can't be serialized...
|
// Note: Runtime type can't be serialized...
|
||||||
'token': objToJson(this.token),
|
'token': objToJson(this.token),
|
||||||
'useClass': objToJson(this.useClass),
|
'useClass': objToJson(this.useClass)
|
||||||
'useExisting': objToJson(this.useExisting),
|
|
||||||
'useValue': objToJson(this.useValue),
|
|
||||||
'useFactory': objToJson(this.useFactory)
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -204,17 +198,15 @@ export class CompileFactoryMetadata implements CompileIdentifierMetadata {
|
||||||
constConstructor: boolean;
|
constConstructor: boolean;
|
||||||
diDeps: CompileDiDependencyMetadata[];
|
diDeps: CompileDiDependencyMetadata[];
|
||||||
|
|
||||||
constructor({runtime, name, moduleUrl, prefix, constConstructor, diDeps}: {
|
constructor({runtime, name, moduleUrl, constConstructor, diDeps}: {
|
||||||
runtime?: Function,
|
runtime?: Function,
|
||||||
name?: string,
|
name?: string,
|
||||||
prefix?: string,
|
|
||||||
moduleUrl?: string,
|
moduleUrl?: string,
|
||||||
constConstructor?: boolean,
|
constConstructor?: boolean,
|
||||||
diDeps?: CompileDiDependencyMetadata[]
|
diDeps?: CompileDiDependencyMetadata[]
|
||||||
}) {
|
}) {
|
||||||
this.runtime = runtime;
|
this.runtime = runtime;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.prefix = prefix;
|
|
||||||
this.moduleUrl = moduleUrl;
|
this.moduleUrl = moduleUrl;
|
||||||
this.diDeps = diDeps;
|
this.diDeps = diDeps;
|
||||||
this.constConstructor = constConstructor;
|
this.constConstructor = constConstructor;
|
||||||
|
@ -222,25 +214,7 @@ export class CompileFactoryMetadata implements CompileIdentifierMetadata {
|
||||||
|
|
||||||
get identifier(): CompileIdentifierMetadata { return this; }
|
get identifier(): CompileIdentifierMetadata { return this; }
|
||||||
|
|
||||||
static fromJson(data: {[key: string]: any}): CompileFactoryMetadata {
|
toJson() { return null; }
|
||||||
return new CompileFactoryMetadata({
|
|
||||||
name: data['name'],
|
|
||||||
prefix: data['prefix'],
|
|
||||||
moduleUrl: data['moduleUrl'],
|
|
||||||
constConstructor: data['constConstructor'],
|
|
||||||
diDeps: arrayFromJson(data['diDeps'], CompileDiDependencyMetadata.fromJson)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
toJson(): {[key: string]: any} {
|
|
||||||
return {
|
|
||||||
'name': this.name,
|
|
||||||
'prefix': this.prefix,
|
|
||||||
'moduleUrl': this.moduleUrl,
|
|
||||||
'constConstructor': this.constConstructor,
|
|
||||||
'diDeps': arrayToJson(this.diDeps)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -18,9 +18,7 @@ import {
|
||||||
CompileTemplateMetadata,
|
CompileTemplateMetadata,
|
||||||
CompileProviderMetadata,
|
CompileProviderMetadata,
|
||||||
CompileDiDependencyMetadata,
|
CompileDiDependencyMetadata,
|
||||||
CompileQueryMetadata,
|
CompileQueryMetadata
|
||||||
CompileIdentifierMetadata,
|
|
||||||
CompileFactoryMetadata
|
|
||||||
} from 'angular2/src/compiler/directive_metadata';
|
} from 'angular2/src/compiler/directive_metadata';
|
||||||
import {ViewEncapsulation} from 'angular2/src/core/metadata/view';
|
import {ViewEncapsulation} from 'angular2/src/core/metadata/view';
|
||||||
import {ChangeDetectionStrategy} from 'angular2/src/core/change_detection';
|
import {ChangeDetectionStrategy} from 'angular2/src/core/change_detection';
|
||||||
|
@ -33,7 +31,12 @@ export function main() {
|
||||||
var fullDirectiveMeta: CompileDirectiveMetadata;
|
var fullDirectiveMeta: CompileDirectiveMetadata;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
var diDep = new CompileDiDependencyMetadata({
|
fullTypeMeta = new CompileTypeMetadata({
|
||||||
|
name: 'SomeType',
|
||||||
|
moduleUrl: 'someUrl',
|
||||||
|
isHost: true,
|
||||||
|
diDeps: [
|
||||||
|
new CompileDiDependencyMetadata({
|
||||||
isAttribute: true,
|
isAttribute: true,
|
||||||
isSelf: true,
|
isSelf: true,
|
||||||
isHost: true,
|
isHost: true,
|
||||||
|
@ -44,10 +47,9 @@ export function main() {
|
||||||
{selectors: ['one'], descendants: true, first: true, propertyName: 'one'}),
|
{selectors: ['one'], descendants: true, first: true, propertyName: 'one'}),
|
||||||
viewQuery: new CompileQueryMetadata(
|
viewQuery: new CompileQueryMetadata(
|
||||||
{selectors: ['one'], descendants: true, first: true, propertyName: 'one'})
|
{selectors: ['one'], descendants: true, first: true, propertyName: 'one'})
|
||||||
|
})
|
||||||
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
fullTypeMeta = new CompileTypeMetadata(
|
|
||||||
{name: 'SomeType', moduleUrl: 'someUrl', isHost: true, diDeps: [diDep]});
|
|
||||||
fullTemplateMeta = new CompileTemplateMetadata({
|
fullTemplateMeta = new CompileTemplateMetadata({
|
||||||
encapsulation: ViewEncapsulation.Emulated,
|
encapsulation: ViewEncapsulation.Emulated,
|
||||||
template: '<a></a>',
|
template: '<a></a>',
|
||||||
|
@ -67,15 +69,7 @@ export function main() {
|
||||||
outputs: ['someEvent'],
|
outputs: ['someEvent'],
|
||||||
host: {'(event1)': 'handler1', '[prop1]': 'expr1', 'attr1': 'attrValue2'},
|
host: {'(event1)': 'handler1', '[prop1]': 'expr1', 'attr1': 'attrValue2'},
|
||||||
lifecycleHooks: [LifecycleHooks.OnChanges],
|
lifecycleHooks: [LifecycleHooks.OnChanges],
|
||||||
providers: [
|
providers: [new CompileProviderMetadata({token: 'token', useClass: fullTypeMeta})]
|
||||||
new CompileProviderMetadata({
|
|
||||||
token: 'token',
|
|
||||||
useClass: fullTypeMeta,
|
|
||||||
useExisting: new CompileIdentifierMetadata({name: 'someName'}),
|
|
||||||
useFactory: new CompileFactoryMetadata({name: 'someName', diDeps: [diDep]}),
|
|
||||||
useValue: 'someValue',
|
|
||||||
})
|
|
||||||
]
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -431,38 +431,14 @@ class _DirectiveMetadataVisitor extends Object
|
||||||
) {
|
) {
|
||||||
final token = el.argumentList.arguments.first;
|
final token = el.argumentList.arguments.first;
|
||||||
|
|
||||||
var useClass, useExisting, useValue, factoryId, useFactory, deps;
|
var useClass;
|
||||||
el.argumentList.arguments.skip(1).forEach((arg) {
|
el.argumentList.arguments.skip(1).forEach((arg) {
|
||||||
if (arg.name.toString() == "useClass:") {
|
if (arg.name.toString() == "useClass:") {
|
||||||
final id = _readIdentifier(arg.expression);
|
final id = _readIdentifier(arg.expression);
|
||||||
useClass = new CompileTypeMetadata(prefix: id.prefix, name: id.name);
|
useClass = new CompileTypeMetadata(prefix: id.prefix, name: id.name);
|
||||||
} else if (arg.name.toString() == "toClass:") {
|
|
||||||
final id = _readIdentifier(arg.expression);
|
|
||||||
useClass = new CompileTypeMetadata(prefix: id.prefix, name: id.name);
|
|
||||||
|
|
||||||
} else if (arg.name.toString() == "useExisting:") {
|
|
||||||
useExisting = _readIdentifier(arg.expression);
|
|
||||||
} else if (arg.name.toString() == "toAlias:") {
|
|
||||||
useExisting = _readIdentifier(arg.expression);
|
|
||||||
|
|
||||||
} else if (arg.name.toString() == "useValue:") {
|
|
||||||
useValue = _readIdentifier(arg.expression);
|
|
||||||
} else if (arg.name.toString() == "toValue:") {
|
|
||||||
useValue = _readIdentifier(arg.expression);
|
|
||||||
|
|
||||||
} else if (arg.name.toString() == "useFactory:") {
|
|
||||||
factoryId = _readIdentifier(arg.expression);
|
|
||||||
} else if (arg.name.toString() == "toFactory:") {
|
|
||||||
factoryId = _readIdentifier(arg.expression);
|
|
||||||
|
|
||||||
} else if (arg.name.toString() == "deps:") {
|
|
||||||
deps = _readDeps(arg.expression);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (factoryId != null) {
|
return new CompileProviderMetadata(token: _readIdentifier(token), useClass: useClass);
|
||||||
useFactory = new CompileFactoryMetadata(name: factoryId.name, prefix: factoryId.prefix);
|
|
||||||
}
|
|
||||||
return new CompileProviderMetadata(token: _readIdentifier(token), useClass: useClass, useExisting: useExisting, useValue: useValue, useFactory: useFactory, deps: deps);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
throw new ArgumentError(
|
throw new ArgumentError(
|
||||||
|
@ -475,29 +451,6 @@ class _DirectiveMetadataVisitor extends Object
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<CompileDiDependencyMetadata> _readDeps(ListLiteral deps) {
|
|
||||||
return deps.elements.map((p) {
|
|
||||||
final list = p is ListLiteral ? p.elements : [p];
|
|
||||||
final first = list.first;
|
|
||||||
|
|
||||||
var token;
|
|
||||||
if (first is InstanceCreationExpression && first.constructorName.toString() == "Inject") {
|
|
||||||
token = _readIdentifier(first.argumentList.arguments[0]);
|
|
||||||
} else {
|
|
||||||
token = _readIdentifier(first);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new CompileDiDependencyMetadata(
|
|
||||||
token: token,
|
|
||||||
isSelf: _hasConst(list, "Self"),
|
|
||||||
isHost: _hasConst(list, "Host"),
|
|
||||||
isSkipSelf: _hasConst(list, "SkipSelf"),
|
|
||||||
isOptional: _hasConst(list, "Optional"));
|
|
||||||
}).toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool _hasConst(List list, String name) => list.where((m) => m is InstanceCreationExpression && m.constructorName.toString() == name).isNotEmpty;
|
|
||||||
|
|
||||||
//TODO Use AnnotationMatcher instead of string matching
|
//TODO Use AnnotationMatcher instead of string matching
|
||||||
bool _isAnnotation(Annotation node, String annotationName) {
|
bool _isAnnotation(Annotation node, String annotationName) {
|
||||||
var id = node.name;
|
var id = node.name;
|
||||||
|
|
|
@ -162,17 +162,6 @@ class _CompileDataCreator {
|
||||||
if (provider.useClass != null) {
|
if (provider.useClass != null) {
|
||||||
provider.useClass = _resolveIdentifier(ngMetaMap, neededBy, provider.useClass);
|
provider.useClass = _resolveIdentifier(ngMetaMap, neededBy, provider.useClass);
|
||||||
}
|
}
|
||||||
if (provider.useExisting != null) {
|
|
||||||
provider.useExisting = _resolveIdentifier(ngMetaMap, neededBy, provider.useExisting);
|
|
||||||
}
|
|
||||||
if (provider.useValue != null) {
|
|
||||||
provider.useValue = _resolveIdentifier(ngMetaMap, neededBy, provider.useValue);
|
|
||||||
}
|
|
||||||
if (provider.useFactory != null) {
|
|
||||||
final resolved = _resolveIdentifier(ngMetaMap, neededBy, provider.useFactory);
|
|
||||||
provider.useFactory.moduleUrl = resolved.moduleUrl;
|
|
||||||
_resolveDiDependencyMetadata(ngMetaMap, neededBy, provider.useFactory.diDeps);
|
|
||||||
}
|
|
||||||
resolvedProviders.add(provider);
|
resolvedProviders.add(provider);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -671,160 +671,6 @@ void allTests() {
|
||||||
expect(useClass.name).toEqual("ServiceDep");
|
expect(useClass.name).toEqual("ServiceDep");
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should populate `providers` using toClass.',
|
|
||||||
() async {
|
|
||||||
var cmp =
|
|
||||||
(await _testCreateModel('directives_files/components.dart')).identifiers['ComponentWithProvidersToClass'];
|
|
||||||
|
|
||||||
expect(cmp).toBeNotNull();
|
|
||||||
expect(cmp.providers).toBeNotNull();
|
|
||||||
expect(cmp.providers.length).toEqual(1);
|
|
||||||
|
|
||||||
var token = cmp.providers.first.token;
|
|
||||||
var useExisting = cmp.providers.first.useClass;
|
|
||||||
|
|
||||||
expect(useExisting.prefix).toEqual(null);
|
|
||||||
expect(useExisting.name).toEqual("ServiceDep");
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should populate `providers` using useExisting.',
|
|
||||||
() async {
|
|
||||||
var cmp =
|
|
||||||
(await _testCreateModel('directives_files/components.dart')).identifiers['ComponentWithProvidersUseExisting'];
|
|
||||||
|
|
||||||
expect(cmp).toBeNotNull();
|
|
||||||
expect(cmp.providers).toBeNotNull();
|
|
||||||
expect(cmp.providers.length).toEqual(1);
|
|
||||||
|
|
||||||
var token = cmp.providers.first.token;
|
|
||||||
var useExisting = cmp.providers.first.useExisting;
|
|
||||||
|
|
||||||
expect(useExisting.prefix).toEqual(null);
|
|
||||||
expect(useExisting.name).toEqual("ServiceDep");
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should populate `providers` using toAlias.',
|
|
||||||
() async {
|
|
||||||
var cmp =
|
|
||||||
(await _testCreateModel('directives_files/components.dart')).identifiers['ComponentWithProvidersToAlias'];
|
|
||||||
|
|
||||||
expect(cmp).toBeNotNull();
|
|
||||||
expect(cmp.providers).toBeNotNull();
|
|
||||||
expect(cmp.providers.length).toEqual(1);
|
|
||||||
|
|
||||||
var token = cmp.providers.first.token;
|
|
||||||
var useExisting = cmp.providers.first.useExisting;
|
|
||||||
|
|
||||||
expect(useExisting.prefix).toEqual(null);
|
|
||||||
expect(useExisting.name).toEqual("ServiceDep");
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should populate `providers` using useExisting (string token).',
|
|
||||||
() async {
|
|
||||||
var cmp =
|
|
||||||
(await _testCreateModel('directives_files/components.dart')).identifiers['ComponentWithProvidersUseExistingStr'];
|
|
||||||
|
|
||||||
expect(cmp).toBeNotNull();
|
|
||||||
expect(cmp.providers).toBeNotNull();
|
|
||||||
expect(cmp.providers.length).toEqual(1);
|
|
||||||
|
|
||||||
var token = cmp.providers.first.token;
|
|
||||||
var useExisting = cmp.providers.first.useExisting;
|
|
||||||
|
|
||||||
expect(useExisting).toEqual("StrToken");
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should populate `providers` using useValue.',
|
|
||||||
() async {
|
|
||||||
var cmp =
|
|
||||||
(await _testCreateModel('directives_files/components.dart')).identifiers['ComponentWithProvidersUseValue'];
|
|
||||||
|
|
||||||
expect(cmp).toBeNotNull();
|
|
||||||
expect(cmp.providers).toBeNotNull();
|
|
||||||
expect(cmp.providers.length).toEqual(1);
|
|
||||||
|
|
||||||
var token = cmp.providers.first.token;
|
|
||||||
var useValue = cmp.providers.first.useValue;
|
|
||||||
|
|
||||||
expect(useValue.prefix).toEqual(null);
|
|
||||||
expect(useValue.name).toEqual("ServiceDep");
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should populate `providers` using toValue.',
|
|
||||||
() async {
|
|
||||||
var cmp =
|
|
||||||
(await _testCreateModel('directives_files/components.dart')).identifiers['ComponentWithProvidersToValue'];
|
|
||||||
|
|
||||||
expect(cmp).toBeNotNull();
|
|
||||||
expect(cmp.providers).toBeNotNull();
|
|
||||||
expect(cmp.providers.length).toEqual(1);
|
|
||||||
|
|
||||||
var token = cmp.providers.first.token;
|
|
||||||
var useValue = cmp.providers.first.useValue;
|
|
||||||
|
|
||||||
expect(useValue.prefix).toEqual(null);
|
|
||||||
expect(useValue.name).toEqual("ServiceDep");
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should populate `providers` using useValue (string token).',
|
|
||||||
() async {
|
|
||||||
var cmp =
|
|
||||||
(await _testCreateModel('directives_files/components.dart')).identifiers['ComponentWithProvidersUseValueStr'];
|
|
||||||
|
|
||||||
expect(cmp).toBeNotNull();
|
|
||||||
expect(cmp.providers).toBeNotNull();
|
|
||||||
expect(cmp.providers.length).toEqual(1);
|
|
||||||
|
|
||||||
var token = cmp.providers.first.token;
|
|
||||||
var useValue = cmp.providers.first.useValue;
|
|
||||||
|
|
||||||
expect(useValue).toEqual("StrToken");
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should populate `providers` using useFactory.',
|
|
||||||
() async {
|
|
||||||
var cmp =
|
|
||||||
(await _testCreateModel('directives_files/components.dart')).identifiers['ComponentWithProvidersUseFactory'];
|
|
||||||
|
|
||||||
expect(cmp).toBeNotNull();
|
|
||||||
expect(cmp.providers).toBeNotNull();
|
|
||||||
expect(cmp.providers.length).toEqual(1);
|
|
||||||
|
|
||||||
var token = cmp.providers.first.token;
|
|
||||||
var useFactory = cmp.providers.first.useFactory;
|
|
||||||
var deps = cmp.providers.first.deps;
|
|
||||||
|
|
||||||
expect(useFactory.prefix).toEqual(null);
|
|
||||||
expect(useFactory.name).toEqual("funcDep");
|
|
||||||
|
|
||||||
expect(deps[0].token.name).toEqual("ServiceDep");
|
|
||||||
expect(deps[1].token).toEqual("Str");
|
|
||||||
expect(deps[2].token.name).toEqual("ServiceDep");
|
|
||||||
expect(deps[3].token.name).toEqual("ServiceDep");
|
|
||||||
expect(deps[3].isSelf).toEqual(true);
|
|
||||||
expect(deps[4].token.name).toEqual("ServiceDep");
|
|
||||||
expect(deps[4].isSkipSelf).toEqual(true);
|
|
||||||
expect(deps[5].token.name).toEqual("ServiceDep");
|
|
||||||
expect(deps[5].isOptional).toEqual(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should populate `providers` using toFactory.',
|
|
||||||
() async {
|
|
||||||
var cmp =
|
|
||||||
(await _testCreateModel('directives_files/components.dart')).identifiers['ComponentWithProvidersToFactory'];
|
|
||||||
|
|
||||||
expect(cmp).toBeNotNull();
|
|
||||||
expect(cmp.providers).toBeNotNull();
|
|
||||||
expect(cmp.providers.length).toEqual(1);
|
|
||||||
|
|
||||||
var token = cmp.providers.first.token;
|
|
||||||
var useFactory = cmp.providers.first.useFactory;
|
|
||||||
var deps = cmp.providers.first.deps;
|
|
||||||
|
|
||||||
expect(useFactory.prefix).toEqual(null);
|
|
||||||
expect(useFactory.name).toEqual("funcDep");
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should populate `providers` using a string token.',
|
it('should populate `providers` using a string token.',
|
||||||
() async {
|
() async {
|
||||||
var cmp =
|
var cmp =
|
||||||
|
|
|
@ -127,82 +127,9 @@ class ComponentWithDiDeps {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component(
|
|
||||||
selector: 'component-with-providers-use-class',
|
|
||||||
template: '',
|
|
||||||
providers: [const Provider(ServiceDep, useClass: ServiceDep)])
|
|
||||||
class ComponentWithProvidersUseClass {}
|
|
||||||
|
|
||||||
@Component(
|
|
||||||
selector: 'component-with-providers-to-class',
|
|
||||||
template: '',
|
|
||||||
providers: [const Binding(ServiceDep, toClass: ServiceDep)])
|
|
||||||
class ComponentWithProvidersToClass{}
|
|
||||||
|
|
||||||
|
|
||||||
@Component(
|
|
||||||
selector: 'component-with-providers-use-existing',
|
|
||||||
template: '',
|
|
||||||
providers: [const Provider(ServiceDep, useExisting: ServiceDep)])
|
|
||||||
class ComponentWithProvidersUseExisting{}
|
|
||||||
|
|
||||||
@Component(
|
|
||||||
selector: 'component-with-providers-to-alias',
|
|
||||||
template: '',
|
|
||||||
providers: [const Binding(ServiceDep, toAlias: ServiceDep)])
|
|
||||||
class ComponentWithProvidersToAlias{}
|
|
||||||
|
|
||||||
@Component(
|
|
||||||
selector: 'component-with-providers-use-existing-string',
|
|
||||||
template: '',
|
|
||||||
providers: [const Provider(ServiceDep, useExisting: 'StrToken')])
|
|
||||||
class ComponentWithProvidersUseExistingStr{}
|
|
||||||
|
|
||||||
|
|
||||||
@Component(
|
|
||||||
selector: 'component-with-providers-use-value',
|
|
||||||
template: '',
|
|
||||||
providers: [const Provider(ServiceDep, useValue: ServiceDep)])
|
|
||||||
class ComponentWithProvidersUseValue{}
|
|
||||||
|
|
||||||
@Component(
|
|
||||||
selector: 'component-with-providers-to-value',
|
|
||||||
template: '',
|
|
||||||
providers: [const Binding(ServiceDep, toValue: ServiceDep)])
|
|
||||||
class ComponentWithProvidersToValue{}
|
|
||||||
|
|
||||||
@Component(
|
|
||||||
selector: 'component-with-providers-use-value-string',
|
|
||||||
template: '',
|
|
||||||
providers: [const Provider(ServiceDep, useValue: 'StrToken')])
|
|
||||||
class ComponentWithProvidersUseValueStr{}
|
|
||||||
|
|
||||||
|
|
||||||
@Component(
|
|
||||||
selector: 'component-with-providers-use-factory',
|
|
||||||
template: '',
|
|
||||||
providers: [const Provider(ServiceDep, useFactory: funcDep, deps:
|
|
||||||
const [
|
|
||||||
ServiceDep,
|
|
||||||
"Str",
|
|
||||||
[const Inject(ServiceDep)],
|
|
||||||
[ServiceDep, const Self()],
|
|
||||||
[ServiceDep, const SkipSelf()],
|
|
||||||
[ServiceDep, const Optional()]
|
|
||||||
])])
|
|
||||||
class ComponentWithProvidersUseFactory{}
|
|
||||||
|
|
||||||
@Component(
|
|
||||||
selector: 'component-with-providers-to-factory',
|
|
||||||
template: '',
|
|
||||||
providers: [const Binding(ServiceDep, toFactory: funcDep)])
|
|
||||||
class ComponentWithProvidersToFactory{}
|
|
||||||
|
|
||||||
@Component(
|
@Component(
|
||||||
selector: 'component-with-di-deps-string-token',
|
selector: 'component-with-di-deps-string-token',
|
||||||
template: '')
|
template: '')
|
||||||
class ComponentWithDiDepsStrToken {
|
class ComponentWithDiDepsStrToken {
|
||||||
ComponentWithDiDepsStrToken(@Inject("StringDep") arg1);
|
ComponentWithDiDepsStrToken(@Inject("StringDep") arg1);
|
||||||
}
|
}
|
||||||
|
|
||||||
funcDep(){}
|
|
||||||
|
|
|
@ -217,17 +217,8 @@ void allTests() {
|
||||||
barNgMeta.identifiers['Service2'] = new CompileTypeMetadata(name: 'Service2', moduleUrl: 'moduleUrl');
|
barNgMeta.identifiers['Service2'] = new CompileTypeMetadata(name: 'Service2', moduleUrl: 'moduleUrl');
|
||||||
|
|
||||||
fooComponentMeta.template = new CompileTemplateMetadata(template: "import 'bar.dart';");
|
fooComponentMeta.template = new CompileTemplateMetadata(template: "import 'bar.dart';");
|
||||||
fooComponentMeta.providers = [
|
fooComponentMeta.providers = [new CompileProviderMetadata(token: new CompileIdentifierMetadata(name: 'Service1'), useClass:
|
||||||
new CompileProviderMetadata(token: new CompileIdentifierMetadata(name: 'Service1'), useClass: new CompileTypeMetadata(name: 'Service2')),
|
new CompileTypeMetadata(name: 'Service2'))];
|
||||||
new CompileProviderMetadata(token: new CompileIdentifierMetadata(name: 'Service1'), useExisting: new CompileIdentifierMetadata(name: 'Service2')),
|
|
||||||
new CompileProviderMetadata(token: new CompileIdentifierMetadata(name: 'Service1'), useValue: new CompileIdentifierMetadata(name: 'Service2')),
|
|
||||||
new CompileProviderMetadata(token: new CompileIdentifierMetadata(name: 'Service1'), useFactory:
|
|
||||||
new CompileFactoryMetadata(
|
|
||||||
name: 'Service2',
|
|
||||||
diDeps: [new CompileDiDependencyMetadata(token: new CompileIdentifierMetadata(name: 'Service2'))]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
];
|
|
||||||
|
|
||||||
final viewAnnotation = new AnnotationModel()..name = 'View'..isView = true;
|
final viewAnnotation = new AnnotationModel()..name = 'View'..isView = true;
|
||||||
final reflectable = fooNgMeta.ngDeps.reflectables.first;
|
final reflectable = fooNgMeta.ngDeps.reflectables.first;
|
||||||
|
@ -239,29 +230,12 @@ void allTests() {
|
||||||
final viewDefResults = await createCompileData(reader, fooAssetId, [], [], {});
|
final viewDefResults = await createCompileData(reader, fooAssetId, [], [], {});
|
||||||
final cmp = viewDefResults.viewDefinitions.values.first.component;
|
final cmp = viewDefResults.viewDefinitions.values.first.component;
|
||||||
|
|
||||||
expect(cmp.providers.length).toEqual(4);
|
expect(cmp.providers.length).toEqual(1);
|
||||||
|
|
||||||
expect(cmp.providers[0].token.name).toEqual("Service1");
|
expect(cmp.providers[0].token.name).toEqual("Service1");
|
||||||
expect(cmp.providers[0].token.moduleUrl).toEqual("moduleUrl");
|
expect(cmp.providers[0].token.moduleUrl).toEqual("moduleUrl");
|
||||||
expect(cmp.providers[0].useClass.name).toEqual("Service2");
|
expect(cmp.providers[0].useClass.name).toEqual("Service2");
|
||||||
expect(cmp.providers[0].useClass.moduleUrl).toEqual("moduleUrl");
|
expect(cmp.providers[0].useClass.moduleUrl).toEqual("moduleUrl");
|
||||||
|
|
||||||
expect(cmp.providers[1].token.name).toEqual("Service1");
|
|
||||||
expect(cmp.providers[1].token.moduleUrl).toEqual("moduleUrl");
|
|
||||||
expect(cmp.providers[1].useExisting.name).toEqual("Service2");
|
|
||||||
expect(cmp.providers[1].useExisting.moduleUrl).toEqual("moduleUrl");
|
|
||||||
|
|
||||||
expect(cmp.providers[2].token.name).toEqual("Service1");
|
|
||||||
expect(cmp.providers[2].token.moduleUrl).toEqual("moduleUrl");
|
|
||||||
expect(cmp.providers[2].useValue.name).toEqual("Service2");
|
|
||||||
expect(cmp.providers[2].useValue.moduleUrl).toEqual("moduleUrl");
|
|
||||||
|
|
||||||
expect(cmp.providers[3].token.name).toEqual("Service1");
|
|
||||||
expect(cmp.providers[3].token.moduleUrl).toEqual("moduleUrl");
|
|
||||||
expect(cmp.providers[3].useFactory.name).toEqual("Service2");
|
|
||||||
expect(cmp.providers[3].useFactory.moduleUrl).toEqual("moduleUrl");
|
|
||||||
expect(cmp.providers[3].useFactory.diDeps[0].token.name).toEqual("Service2");
|
|
||||||
expect(cmp.providers[3].useFactory.diDeps[0].token.moduleUrl).toEqual("moduleUrl");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should generate providers from Provider objects (literals).', () async {
|
it('should generate providers from Provider objects (literals).', () async {
|
||||||
|
|
Loading…
Reference in New Issue