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

Commit 99eab54

Browse files
committed
feat(compiler): A better error message for invalid selectors
1 parent 42692a1 commit 99eab54

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

lib/core_dom/selector.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ class _ElementSelector {
181181
toString() => 'ElementSelector($name)';
182182
}
183183

184-
List<_SelectorPart> _splitCss(String selector) {
184+
List<_SelectorPart> _splitCss(String selector, Type type) {
185185
List<_SelectorPart> parts = [];
186186
var remainder = selector;
187187
var match;
@@ -199,7 +199,7 @@ List<_SelectorPart> _splitCss(String selector) {
199199
throw "Missmatched RegExp $_SELECTOR_REGEXP on $remainder";
200200
}
201201
} else {
202-
throw "Unknown selector format '$remainder'.";
202+
throw "Unknown selector format '$selector' for $type.";
203203
}
204204
remainder = remainder.substring(match.end);
205205
}
@@ -226,7 +226,7 @@ DirectiveSelector directiveSelectorFactory(DirectiveMap directives) {
226226
textSelector.add(new _ContainsSelector(annotation, match.group(1)));
227227
} else if ((match = _ATTR_CONTAINS_REGEXP.firstMatch(selector)) != null) {
228228
attrSelector.add(new _ContainsSelector(annotation, match[1]));
229-
} else if ((selectorParts = _splitCss(selector)) != null){
229+
} else if ((selectorParts = _splitCss(selector, type)) != null){
230230
elementSelector.addDirective(selectorParts, new _Directive(type, annotation));
231231
} else {
232232
throw new ArgumentError('Unsupported Selector: $selector');

test/core_dom/compiler_spec.dart

+20-16
Original file line numberDiff line numberDiff line change
@@ -444,21 +444,26 @@ main() => describe('dte.compiler', () {
444444
});
445445

446446
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', () {
447+
it('should throw a useful error message for missing selectors', () {
448+
module((Module module) {
449+
module
450+
..type(MissingSelector);
451+
});
458452
expect(() {
459453
inject((Compiler c) { });
460454
}).toThrow('Missing selector annotation for MissingSelector');
461455
});
456+
457+
458+
it('should throw a useful error message for invalid selector', () {
459+
module((Module module) {
460+
module
461+
..type(InvalidSelector);
462+
});
463+
expect(() {
464+
inject((Compiler c) { });
465+
}).toThrow('Unknown selector format \'buttonbar button\' for InvalidSelector');
466+
});
462467
});
463468
});
464469

@@ -738,10 +743,9 @@ class MyController {
738743
}
739744
}
740745

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

746-
}
749+
@NgComponent(selector: 'buttonbar button')
750+
class InvalidSelector {}
747751

0 commit comments

Comments
 (0)