From 52cb01f5f666b690d359b0916c63b0a84264eb77 Mon Sep 17 00:00:00 2001 From: Dzmitry Shylovich Date: Wed, 29 Mar 2017 20:26:48 +0300 Subject: [PATCH] fix(compiler): throw when a component defines both template and templateUrl (#15572) Closes #15566 --- packages/compiler/src/directive_normalizer.ts | 4 ++++ packages/compiler/test/directive_normalizer_spec.ts | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/packages/compiler/src/directive_normalizer.ts b/packages/compiler/src/directive_normalizer.ts index 2b7ec4b1754c0..ddc998fd5ee63 100644 --- a/packages/compiler/src/directive_normalizer.ts +++ b/packages/compiler/src/directive_normalizer.ts @@ -65,6 +65,10 @@ export class DirectiveNormalizer { let normalizedTemplateSync: CompileTemplateMetadata = null; let normalizedTemplateAsync: Promise; 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`); diff --git a/packages/compiler/test/directive_normalizer_spec.ts b/packages/compiler/test/directive_normalizer_spec.ts index 58129dc917ce7..fa82051361f4b 100644 --- a/packages/compiler/test/directive_normalizer_spec.ts +++ b/packages/compiler/test/directive_normalizer_spec.ts @@ -51,6 +51,16 @@ export function main() { templateUrl: {} })).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', () => {