fix(compiler): throw when a component defines both template and templateUrl (#15572)

Closes #15566
This commit is contained in:
Dzmitry Shylovich 2017-03-29 20:26:48 +03:00 committed by Victor Berchet
parent d58a242fe7
commit 9c77a7cdaf
2 changed files with 14 additions and 0 deletions

View File

@ -65,6 +65,10 @@ export class DirectiveNormalizer {
let normalizedTemplateSync: CompileTemplateMetadata = null;
let normalizedTemplateAsync: Promise<CompileTemplateMetadata>;
if (prenormData.template != null) {
if (prenormData.templateUrl != null) {
throw syntaxError(
`'${stringify(prenormData.componentType)}' component cannot define both template and templateUrl`);
}
if (typeof prenormData.template !== 'string') {
throw syntaxError(
`The template specified for component ${stringify(prenormData.componentType)} is not a string`);

View File

@ -51,6 +51,16 @@ export function main() {
templateUrl: <any>{}
})).toThrowError('The templateUrl specified for component SomeComp is not a string');
}));
it('should throw if both template and templateUrl are defined',
inject([DirectiveNormalizer], (normalizer: DirectiveNormalizer) => {
expect(() => normalizer.normalizeTemplate({
ngModuleType: null,
componentType: SomeComp,
moduleUrl: SOME_MODULE_URL,
template: '',
templateUrl: '',
})).toThrowError(`'SomeComp' component cannot define both template and templateUrl`);
}));
});
describe('normalizeTemplateSync', () => {