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

Commit

Permalink
feat(compiler): A better error message for invalid selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
jbdeboer committed Jan 8, 2014
1 parent 42692a1 commit 99eab54
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
6 changes: 3 additions & 3 deletions lib/core_dom/selector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class _ElementSelector {
toString() => 'ElementSelector($name)';
}

List<_SelectorPart> _splitCss(String selector) {
List<_SelectorPart> _splitCss(String selector, Type type) {
List<_SelectorPart> parts = [];
var remainder = selector;
var match;
Expand All @@ -199,7 +199,7 @@ List<_SelectorPart> _splitCss(String selector) {
throw "Missmatched RegExp $_SELECTOR_REGEXP on $remainder";
}
} else {
throw "Unknown selector format '$remainder'.";
throw "Unknown selector format '$selector' for $type.";
}
remainder = remainder.substring(match.end);
}
Expand All @@ -226,7 +226,7 @@ DirectiveSelector directiveSelectorFactory(DirectiveMap directives) {
textSelector.add(new _ContainsSelector(annotation, match.group(1)));
} else if ((match = _ATTR_CONTAINS_REGEXP.firstMatch(selector)) != null) {
attrSelector.add(new _ContainsSelector(annotation, match[1]));
} else if ((selectorParts = _splitCss(selector)) != null){
} else if ((selectorParts = _splitCss(selector, type)) != null){
elementSelector.addDirective(selectorParts, new _Directive(type, annotation));
} else {
throw new ArgumentError('Unsupported Selector: $selector');
Expand Down
36 changes: 20 additions & 16 deletions test/core_dom/compiler_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -444,21 +444,26 @@ main() => describe('dte.compiler', () {
});

describe('invalid components', () {
beforeEach(module((Module module) {
module
..type(MissingSelector);
return (Injector _injector) {
injector = _injector;
$compile = injector.get(Compiler);
$rootScope = injector.get(Scope);
};
}));

it('should throw a useful error message', () {
it('should throw a useful error message for missing selectors', () {
module((Module module) {
module
..type(MissingSelector);
});
expect(() {
inject((Compiler c) { });
}).toThrow('Missing selector annotation for MissingSelector');
});


it('should throw a useful error message for invalid selector', () {
module((Module module) {
module
..type(InvalidSelector);
});
expect(() {
inject((Compiler c) { });
}).toThrow('Unknown selector format \'buttonbar button\' for InvalidSelector');
});
});
});

Expand Down Expand Up @@ -738,10 +743,9 @@ class MyController {
}
}

@NgComponent(
template: 'boo'
)
class MissingSelector {
@NgComponent()
class MissingSelector {}

}
@NgComponent(selector: 'buttonbar button')
class InvalidSelector {}

0 comments on commit 99eab54

Please sign in to comment.