parent
9146bb0816
commit
3aca5ff9e2
modules/@angular/compiler
@ -260,11 +260,12 @@ export class CompileMetadataResolver {
|
|||||||
|
|
||||||
getDependenciesMetadata(typeOrFunc: Type | Function,
|
getDependenciesMetadata(typeOrFunc: Type | Function,
|
||||||
dependencies: any[]): cpl.CompileDiDependencyMetadata[] {
|
dependencies: any[]): cpl.CompileDiDependencyMetadata[] {
|
||||||
|
let hasUnknownDeps = false;
|
||||||
let params = isPresent(dependencies) ? dependencies : this._reflector.parameters(typeOrFunc);
|
let params = isPresent(dependencies) ? dependencies : this._reflector.parameters(typeOrFunc);
|
||||||
if (isBlank(params)) {
|
if (isBlank(params)) {
|
||||||
params = [];
|
params = [];
|
||||||
}
|
}
|
||||||
return params.map((param) => {
|
let dependenciesMetadata: cpl.CompileDiDependencyMetadata[] = params.map((param) => {
|
||||||
if (isBlank(param)) {
|
if (isBlank(param)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -306,6 +307,7 @@ export class CompileMetadataResolver {
|
|||||||
token = param;
|
token = param;
|
||||||
}
|
}
|
||||||
if (isBlank(token)) {
|
if (isBlank(token)) {
|
||||||
|
hasUnknownDeps = true;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return new cpl.CompileDiDependencyMetadata({
|
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 {
|
getTokenMetadata(token: any): cpl.CompileTokenMetadata {
|
||||||
|
@ -78,6 +78,14 @@ export function main() {
|
|||||||
.toThrowError(`Expected 'styles' to be an array of strings.`);
|
.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', () => {
|
describe('getViewDirectivesMetadata', () => {
|
||||||
@ -148,3 +156,8 @@ class ComponentWithEverything implements OnChanges,
|
|||||||
ngAfterViewInit(): void {}
|
ngAfterViewInit(): void {}
|
||||||
ngAfterViewChecked(): void {}
|
ngAfterViewChecked(): void {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Component({selector: 'my-broken-comp', template: ''})
|
||||||
|
class MyBrokenComp1 {
|
||||||
|
constructor(public dependency: any) {}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user