fix(compiler): disable non-components as an entry component (#14335)

PR Close #14335
This commit is contained in:
Bowen Ni
2017-02-06 17:55:58 -08:00
committed by Miško Hevery
parent 56b3b3cbed
commit 44bb337acc
3 changed files with 71 additions and 13 deletions

View File

@ -930,7 +930,7 @@ export class CompileMetadataResolver {
extractIdentifiers(provider.useValue, collectedIdentifiers);
collectedIdentifiers.forEach((identifier) => {
const entry = this._getEntryComponentMetadata(identifier.reference);
const entry = this._getEntryComponentMetadata(identifier.reference, false);
if (entry) {
components.push(entry);
}
@ -938,17 +938,22 @@ export class CompileMetadataResolver {
return components;
}
private _getEntryComponentMetadata(dirType: any): cpl.CompileEntryComponentMetadata {
private _getEntryComponentMetadata(dirType: any, throwIfNotFound = true):
cpl.CompileEntryComponentMetadata {
const dirMeta = this.getNonNormalizedDirectiveMetadata(dirType);
if (dirMeta) {
if (dirMeta && dirMeta.metadata.isComponent) {
return {componentType: dirType, componentFactory: dirMeta.metadata.componentFactory};
} else {
const dirSummary =
<cpl.CompileDirectiveSummary>this._loadSummary(dirType, cpl.CompileSummaryKind.Directive);
if (dirSummary) {
if (dirSummary && dirSummary.isComponent) {
return {componentType: dirType, componentFactory: dirSummary.componentFactory};
}
}
if (throwIfNotFound) {
throw syntaxError(`${dirType.name} cannot be used as an entry component.`);
}
}
getProviderMetadata(provider: cpl.ProviderMeta): cpl.CompileProviderMetadata {
@ -1109,4 +1114,4 @@ function componentStillLoadingError(compType: Type<any>) {
Error(`Can't compile synchronously as ${stringify(compType)} is still being loaded!`);
(error as any)[ERROR_COMPONENT_TYPE] = compType;
return error;
}
}