fix(compiler): throw when a component defines both template and templateUrl (#15572)
Closes #15566
This commit is contained in:
parent
d58a242fe7
commit
9c77a7cdaf
|
@ -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`);
|
||||
|
|
|
@ -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', () => {
|
||||
|
|
Loading…
Reference in New Issue