Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit 42692a1

Browse files
committed
feat(compiler): Throw a useful error message on a missing NgComponenet selector
1 parent e13d5b5 commit 42692a1

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

lib/core_dom/selector.dart

+3-1
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,13 @@ DirectiveSelector directiveSelectorFactory(DirectiveMap directives) {
214214
_ElementSelector elementSelector = new _ElementSelector('');
215215
List<_ContainsSelector> attrSelector = [];
216216
List<_ContainsSelector> textSelector = [];
217-
218217
directives.forEach((NgAnnotation annotation, Type type) {
219218
var match;
220219
var selector = annotation.selector;
221220
List<_SelectorPart> selectorParts;
221+
if (selector == null) {
222+
throw new ArgumentError('Missing selector annotation for $type');
223+
}
222224

223225
if ((match = _CONTAINS_REGEXP.firstMatch(selector)) != null) {
224226
textSelector.add(new _ContainsSelector(annotation, match.group(1)));

test/core_dom/compiler_spec.dart

+25
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,24 @@ main() => describe('dte.compiler', () {
442442
expect(element.textWithShadow()).toEqual('WORKED');
443443
})));
444444
});
445+
446+
describe('invalid components', () {
447+
beforeEach(module((Module module) {
448+
module
449+
..type(MissingSelector);
450+
return (Injector _injector) {
451+
injector = _injector;
452+
$compile = injector.get(Compiler);
453+
$rootScope = injector.get(Scope);
454+
};
455+
}));
456+
457+
it('should throw a useful error message', () {
458+
expect(() {
459+
inject((Compiler c) { });
460+
}).toThrow('Missing selector annotation for MissingSelector');
461+
});
462+
});
445463
});
446464

447465

@@ -720,3 +738,10 @@ class MyController {
720738
}
721739
}
722740

741+
@NgComponent(
742+
template: 'boo'
743+
)
744+
class MissingSelector {
745+
746+
}
747+

0 commit comments

Comments
 (0)