move selector joining into visitor

This commit is contained in:
Luke Page
2013-03-01 17:34:11 +00:00
parent 054beb2ad2
commit 4101ae9bdc
3 changed files with 15 additions and 13 deletions

View File

@@ -1,6 +1,6 @@
(function (tree) {
tree.joinSelectorVisitor = function() {
this.context = [];
this.contexts = [[]];
this._visitor = new tree.visitor(this);
};
@@ -18,16 +18,23 @@
},
visitRuleset: function (rulesetNode, visitArgs) {
var context = this.contexts[this.contexts.length - 1];
var paths = [];
this.contexts.push(paths);
if (! rulesetNode.root) {
rulesetNode.joinSelectors(paths, context, rulesetNode.selectors);
rulesetNode.paths = paths;
}
return rulesetNode;
},
visitMedia: function (rulesetNode, visitArgs) {
return rulesetNode;
visitRulesetOut: function (rulesetNode) {
this.contexts.length = this.contexts.length - 1;
},
visitDirective: function (rulesetNode, visitArgs) {
return rulesetNode;
visitMedia: function (mediaNode, visitArgs) {
var context = this.contexts[this.contexts.length - 1];
mediaNode.ruleset.root = (context.length === 0 || context[0].multiMedia);
return mediaNode;
}
};

View File

@@ -16,7 +16,6 @@ tree.Media.prototype = {
toCSS: function (ctx, env) {
var features = this.features.toCSS(env);
this.ruleset.root = (ctx.length === 0 || ctx[0].multiMedia);
return '@media ' + features + (env.compress ? '{' : ' {\n ') +
this.ruleset.toCSS(ctx, env).trim().replace(/\n/g, '\n ') +
(env.compress ? '}': '\n}\n');

View File

@@ -186,10 +186,6 @@ tree.Ruleset.prototype = {
debugInfo, // Line number debugging
rule;
if (! this.root) {
this.joinSelectors(paths, context, this.selectors);
}
// Compile rules and rulesets
for (var i = 0; i < this.rules.length; i++) {
rule = this.rules[i];
@@ -249,7 +245,7 @@ tree.Ruleset.prototype = {
} else {
if (rules.length > 0) {
debugInfo = tree.debugInfo(env, this);
selector = paths.map(function (p) {
selector = this.paths.map(function (p) {
return p.map(function (s) {
return s.toCSS(env);
}).join('').trim();