Allow replacing visitors to return undefined. Fixes #2252

This commit is contained in:
Luke Page
2014-11-01 17:31:50 +00:00
parent 9ddd81fc07
commit 8faa5b83d9
2 changed files with 12 additions and 7 deletions

View File

@@ -14,7 +14,7 @@ ToCSSVisitor.prototype = {
visitRule: function (ruleNode, visitArgs) {
if (ruleNode.variable) {
return [];
return;
}
return ruleNode;
},
@@ -23,16 +23,14 @@ ToCSSVisitor.prototype = {
// mixin definitions do not get eval'd - this means they keep state
// so we have to clear that state here so it isn't used if toCSS is called twice
mixinNode.frames = [];
return [];
},
visitExtend: function (extendNode, visitArgs) {
return [];
},
visitComment: function (commentNode, visitArgs) {
if (commentNode.isSilent(this._context)) {
return [];
return;
}
return commentNode;
},
@@ -42,14 +40,14 @@ ToCSSVisitor.prototype = {
visitArgs.visitDeeper = false;
if (!mediaNode.rules.length) {
return [];
return;
}
return mediaNode;
},
visitDirective: function(directiveNode, visitArgs) {
if (directiveNode.currentFileInfo.reference && !directiveNode.isReferenced) {
return [];
return;
}
if (directiveNode.name === "@charset") {
// Only output the debug info together with subsequent @charset definitions
@@ -61,7 +59,7 @@ ToCSSVisitor.prototype = {
comment.debugInfo = directiveNode.debugInfo;
return this._visitor.visit(comment);
}
return [];
return;
}
this.charset = true;
}

View File

@@ -106,6 +106,7 @@ Visitor.prototype = {
var out = [];
for (i = 0; i < cnt; i++) {
var evald = this.visit(nodes[i]);
if (evald === undefined) { continue; }
if (!evald.splice) {
out.push(evald);
} else if (evald.length) {
@@ -124,6 +125,9 @@ Visitor.prototype = {
for (i = 0, cnt = arr.length; i < cnt; i++) {
item = arr[i];
if (item === undefined) {
continue;
}
if (!item.splice) {
out.push(item);
continue;
@@ -131,6 +135,9 @@ Visitor.prototype = {
for (j = 0, nestedCnt = item.length; j < nestedCnt; j++) {
nestedItem = item[j];
if (nestedItem === undefined) {
continue;
}
if (!nestedItem.splice) {
out.push(nestedItem);
} else if (nestedItem.length) {