Merge remote-tracking branch 'origin/extend-warnings'

This commit is contained in:
Luke Page
2015-01-13 16:55:22 +00:00

View File

@@ -1,5 +1,6 @@
var tree = require("../tree"),
Visitor = require("./visitor");
Visitor = require("./visitor"),
logger = require("../logger");
/*jshint loopfunc:true */
@@ -94,11 +95,30 @@ var ProcessExtendsVisitor = function() {
ProcessExtendsVisitor.prototype = {
run: function(root) {
var extendFinder = new ExtendFinderVisitor();
this.extendIndicies = {};
extendFinder.run(root);
if (!extendFinder.foundExtends) { return root; }
root.allExtends = root.allExtends.concat(this.doExtendChaining(root.allExtends, root.allExtends));
this.allExtendsStack = [root.allExtends];
return this._visitor.visit(root);
var newRoot = this._visitor.visit(root);
this.checkExtendsForNonMatched(root.allExtends);
return newRoot;
},
checkExtendsForNonMatched: function(extendList) {
var indicies = this.extendIndicies;
extendList.filter(function(extend) {
return !extend.hasFoundMatches && extend.parent_ids.length == 1;
}).forEach(function(extend) {
var selector = "_unknown_";
try {
selector = extend.selector.toCSS({});
}catch(_){}
if(!indicies[extend.index + ' ' + selector]) {
indicies[extend.index + ' ' + selector] = true;
logger.warn("extend '"+selector+"' has no matches");
}
});
},
doExtendChaining: function (extendsList, extendsListTarget, iterationCount) {
//
@@ -135,6 +155,8 @@ ProcessExtendsVisitor.prototype = {
if (matches.length) {
extend.hasFoundMatches = true;
// we found a match, so for each self selector..
extend.selfSelectors.forEach(function(selfSelector) {
@@ -218,6 +240,7 @@ ProcessExtendsVisitor.prototype = {
matches = this.findMatch(allExtends[extendIndex], selectorPath);
if (matches.length) {
allExtends[extendIndex].hasFoundMatches = true;
allExtends[extendIndex].selfSelectors.forEach(function(selfSelector) {
selectorsToAdd.push(extendVisitor.extendSelector(matches, selectorPath, selfSelector));
@@ -403,7 +426,9 @@ ProcessExtendsVisitor.prototype = {
this.allExtendsStack.push(newAllExtends);
},
visitMediaOut: function (mediaNode) {
this.allExtendsStack.length = this.allExtendsStack.length - 1;
var lastIndex = this.allExtendsStack.length - 1;
this.checkExtendsForNonMatched(this.allExtendsStack[lastIndex]);
this.allExtendsStack.length = lastIndex;
},
visitDirective: function (directiveNode, visitArgs) {
var newAllExtends = directiveNode.allExtends.concat(this.allExtendsStack[this.allExtendsStack.length-1]);
@@ -411,7 +436,9 @@ ProcessExtendsVisitor.prototype = {
this.allExtendsStack.push(newAllExtends);
},
visitDirectiveOut: function (directiveNode) {
this.allExtendsStack.length = this.allExtendsStack.length - 1;
var lastIndex = this.allExtendsStack.length - 1;
this.checkExtendsForNonMatched(this.allExtendsStack[lastIndex]);
this.allExtendsStack.length = lastIndex;
}
};