Skip to content

Commit

Permalink
fix(compiler): throw when a component defines both template and templ…
Browse files Browse the repository at this point in the history
…ateUrl (angular#15572)

Closes angular#15566
  • Loading branch information
DzmitryShylovich authored and juleskremer committed Aug 24, 2017
1 parent 1a04378 commit 52cb01f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/compiler/src/directive_normalizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
Expand Down
10 changes: 10 additions & 0 deletions packages/compiler/test/directive_normalizer_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 52cb01f

Please sign in to comment.