Skip to content

Commit 1fbb1a6

Browse files
committed
[FIX] Variables: handle variables in the proper order
1 parent 6217f5a commit 1fbb1a6

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

lib/plugin/css-variables-collector.js

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,20 @@ CSSVariablesCollectorPlugin.prototype = {
150150
},
151151

152152
visitRule(node, visitArgs) {
153+
// check rule for being a variable declaration
154+
const isVarDeclaration = typeof node.name === "string" && node.name.startsWith("@");
155+
if (!this._isInMixinOrParen() && isVarDeclaration) {
156+
// add the variable declaration to the list of vars
157+
const varName = node.name.substr(1);
158+
const isVarInLib = this._isVarInLibrary({
159+
varName,
160+
filename: node.currentFileInfo.filename
161+
});
162+
this.vars[varName] = {
163+
css: this._getCSS(node.value),
164+
export: isVarInLib
165+
};
166+
}
153167
// store the rule context for the call variable extraction
154168
this.ruleStack.push(node);
155169
return node;
@@ -185,24 +199,6 @@ CSSVariablesCollectorPlugin.prototype = {
185199
return node;
186200
},
187201

188-
visitRuleset(node, visitArgs) {
189-
node.rules.forEach((value) => {
190-
const isVarDeclaration = value instanceof less.tree.Rule && typeof value.name === "string" && value.name.startsWith("@");
191-
if (!this._isInMixinOrParen() && isVarDeclaration) {
192-
// add the variable declaration to the list of vars
193-
const varName = value.name.substr(1);
194-
this.vars[varName] = {
195-
css: this._getCSS(value.value),
196-
export: this._isVarInLibrary({
197-
varName,
198-
filename: value.currentFileInfo.filename
199-
})
200-
};
201-
}
202-
});
203-
return node;
204-
},
205-
206202
visitUrl(node, visitArgs) {
207203
// we mark the less variables which should be updated after eval
208204
// => strangewise less variables with "none" values are also urls

0 commit comments

Comments
 (0)