Browse files

Deal with null nodes, for instance [,,,]

  • Loading branch information...
1 parent 4db5ee4 commit 6df6d2298431d49f292d8626d6b240d14b48ad4e @mbebenita committed Sep 10, 2012
Showing with 14 additions and 3 deletions.
  1. +4 −2 src/compiler.js
  2. +10 −1 src/estransform.js
View
6 src/compiler.js
@@ -383,7 +383,9 @@
function scanList(list, o) {
for (var i = 0, j = list.length; i < j; i++) {
- list[i].scan(o);
+ if (list[i]) {
+ list[i].scan(o);
+ }
}
}
@@ -435,7 +437,7 @@
}
}
return this;
- }
+ };
FunctionExpression.prototype.scan =
FunctionDeclaration.prototype.scan = function (o) {
View
11 src/estransform.js
@@ -372,7 +372,9 @@
if (child instanceof Array) {
arr = this[children[i]] = [];
for (var k = 0, l = child.length; k < l; k++) {
- if (typeof child[k][name] === "function") {
+ if (!child[k]) {
+ arr.push(child[k]);
+ } else if (typeof child[k][name] === "function") {
trans = child[k][name](o);
if (trans !== null) {
arr.push(trans);
@@ -408,6 +410,10 @@
};
exports.lift = function lift(raw) {
+ if (!raw) {
+ return raw;
+ }
+
if (raw instanceof Array) {
return raw.map(function (r) {
return lift(r);
@@ -440,6 +446,9 @@
};
exports.flatten = function flatten(node) {
+ if (!node) {
+ return node;
+ }
if (node instanceof Array) {
return node.map(function (n) {
return flatten(n);

0 comments on commit 6df6d22

Please sign in to comment.