parent
9146bb0816
commit
3aca5ff9e2
|
@ -260,11 +260,12 @@ export class CompileMetadataResolver {
|
|||
|
||||
getDependenciesMetadata(typeOrFunc: Type | Function,
|
||||
dependencies: any[]): cpl.CompileDiDependencyMetadata[] {
|
||||
let hasUnknownDeps = false;
|
||||
let params = isPresent(dependencies) ? dependencies : this._reflector.parameters(typeOrFunc);
|
||||
if (isBlank(params)) {
|
||||
params = [];
|
||||
}
|
||||
return params.map((param) => {
|
||||
let dependenciesMetadata: cpl.CompileDiDependencyMetadata[] = params.map((param) => {
|
||||
if (isBlank(param)) {
|
||||
return null;
|
||||
}
|
||||
|
@ -306,6 +307,7 @@ export class CompileMetadataResolver {
|
|||
token = param;
|
||||
}
|
||||
if (isBlank(token)) {
|
||||
hasUnknownDeps = true;
|
||||
return null;
|
||||
}
|
||||
return new cpl.CompileDiDependencyMetadata({
|
||||
|
@ -320,6 +322,15 @@ export class CompileMetadataResolver {
|
|||
});
|
||||
|
||||
});
|
||||
|
||||
if (hasUnknownDeps) {
|
||||
let depsTokens = dependenciesMetadata.map((dep) => {
|
||||
return dep ? stringify(dep.token) : '?';
|
||||
}).join(', ');
|
||||
throw new BaseException(`Can't resolve all parameters for ${stringify(typeOrFunc)}: (${depsTokens}).`);
|
||||
}
|
||||
|
||||
return dependenciesMetadata;
|
||||
}
|
||||
|
||||
getTokenMetadata(token: any): cpl.CompileTokenMetadata {
|
||||
|
|
|
@ -78,6 +78,14 @@ export function main() {
|
|||
.toThrowError(`Expected 'styles' to be an array of strings.`);
|
||||
}
|
||||
}));
|
||||
|
||||
it('should throw with descriptive error message when provider token can not be resolved',
|
||||
inject([CompileMetadataResolver], (resolver: CompileMetadataResolver) => {
|
||||
if (!IS_DART) {
|
||||
expect(() => resolver.getDirectiveMetadata(MyBrokenComp1))
|
||||
.toThrowError(`Can't resolve all parameters for MyBrokenComp1: (?).`);
|
||||
}
|
||||
}));
|
||||
});
|
||||
|
||||
describe('getViewDirectivesMetadata', () => {
|
||||
|
@ -148,3 +156,8 @@ class ComponentWithEverything implements OnChanges,
|
|||
ngAfterViewInit(): void {}
|
||||
ngAfterViewChecked(): void {}
|
||||
}
|
||||
|
||||
@Component({selector: 'my-broken-comp', template: ''})
|
||||
class MyBrokenComp1 {
|
||||
constructor(public dependency: any) {}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue