Skip to content

Commit

Permalink
fix(coreDirectives): Added an Error Message for invalid selectors on …
Browse files Browse the repository at this point in the history
…component annotation

If the component selector is an empty string or not a string an error will be thrown.

Closes angular#3464
  • Loading branch information
Daniel Rasmuson committed Sep 1, 2015
1 parent 12a8064 commit ac0cd3e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
5 changes: 4 additions & 1 deletion modules/angular2/src/core/metadata/directives.ts
@@ -1,4 +1,4 @@
import {CONST, CONST_EXPR} from 'angular2/src/core/facade/lang';
import {CONST, CONST_EXPR, isString, isBlank, makeTypeError} from 'angular2/src/core/facade/lang';
import {InjectableMetadata} from 'angular2/src/core/di/metadata';
import {ChangeDetectionStrategy} from 'angular2/change_detection';

Expand Down Expand Up @@ -831,6 +831,9 @@ export class ComponentMetadata extends DirectiveMetadata {
viewBindings?: any[],
changeDetection?: ChangeDetectionStrategy,
} = {}) {
if (!isBlank(selector) && !(isString(selector) && selector.length > 0)) {
throw makeTypeError('The component annotation requires a string selector.');
}
super({
selector: selector,
properties: properties,
Expand Down
15 changes: 14 additions & 1 deletion modules/angular2/test/core/compiler/element_injector_spec.ts
Expand Up @@ -479,7 +479,20 @@ export function main() {
expect(pei.getBindingAtIndex(i).key.token).toBe(i);
}
});
});

it('should not error if selector is undefined', () => {
expect(function(){
new ComponentMetadata();
}).not.toThrow()
});

it('should throw an error if the selector is an empty string', () => {
expect(function(){
new ComponentMetadata({selector: ''});
}).toThrowError("The component annotation requires a string selector.")
});

);
});

describe("ElementInjector", () => {
Expand Down

0 comments on commit ac0cd3e

Please sign in to comment.