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

Commit 472b6c6

Browse files
committed
feat(compiler): gracefully handle empty lists
1 parent 11babbd commit 472b6c6

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

lib/compiler.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class Compiler {
1313
_compileBlock(NodeCursor domCursor, NodeCursor templateCursor,
1414
List<BlockCache> blockCaches,
1515
List<DirectiveRef> useExistingDirectiveRefs) {
16+
if (domCursor.nodeList().length == 0) return null;
17+
1618
var directivePositions = null; // don't pre-create to create spars tree and prevent GC pressure.
1719
var cursorAlreadyAdvanced;
1820

lib/node_cursor.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ class NodeCursor {
3535
}
3636

3737
nodeList() {
38+
if (!isValid()) return []; // or should we return null?
39+
3840
var node = elements[index];
3941
var nodes = [];
4042

test/compiler_spec.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ main() {
2929
expect(element.text()).toEqual('angular');
3030
}));
3131

32+
it('should not throw on an empty list', inject((Compiler $compile) {
33+
$compile([]);
34+
}));
35+
3236
it('should compile a directive in a child', inject((Compiler $compile) {
3337
var element = $('<div><div ng-bind="name"></div></div>');
3438
var template = $compile(element);

0 commit comments

Comments
 (0)