Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ function unwrapValue(value) {
}

var Compile = {
fromString: function(value) {
fromString: function(value, useRules) {
var wrappedValue = wrapValue(value);
var s = sass.renderSync({ data: wrappedValue });
var s = sass.renderSync({ data: useRules.join(';\n') + ';\n' + wrappedValue });
var compiled = String(s.css);
var minifiedCompiled = cssmin(compiled);
return unwrapValue(minifiedCompiled);
Expand Down
2 changes: 1 addition & 1 deletion src/declaration.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Declaration.prototype = {
var replacedValue = declarationStore.replaceVariables(assignedValue);

this.variable = new Variable(assignedVariable);
this.value = new Value(replacedValue);
this.value = new Value(replacedValue, declarationStore.useRules);
this.global = hasGlobalFlag(replacedValue);

declarationStore.addDeclaration(this);
Expand Down
5 changes: 5 additions & 0 deletions src/declarationStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@

function DeclarationStore() {
this.declarations = [];
this.useRules = [];
}

DeclarationStore.prototype = {
addDeclaration: function(declaration) {
this.declarations.push(declaration);
},

addUseRule: function(useRule) {
this.useRules.push(useRule);
},

replaceVariables: function(scssString) {
var replacedString = scssString;

Expand Down
13 changes: 10 additions & 3 deletions src/processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ function makeObject(declarations, options) {

function filterLines(line) {
return EMPTY_LINES.every(function(lineValue) {
return line !== lineValue && line.slice(0, 2) !== COMMENT_DELIMETER && line.indexOf('@import') < 0;
return line !== lineValue && line.slice(0, 2) !== COMMENT_DELIMETER
&& line.indexOf('@import') < 0 && line.indexOf('@use') < 0;
});
}

Expand Down Expand Up @@ -93,8 +94,14 @@ function declarationsFromString(path, declarationStore, options) {
data = extractScope(data, options.scope);
}

var lines = String(data).split(LINE_DELIMITER).map(normalizeLines).filter(filterLines);
return lines.map(function(line) {
var lines = String(data).split(LINE_DELIMITER).map(normalizeLines);
var useRules = lines.filter(function(line) { return line.match(/^@use .+/); });

useRules.forEach(function(useRule) {
declarationStore.addUseRule(useRule);
});

return lines.filter(filterLines).map(function(line) {
return new Declaration(line, declarationStore);
});
}
Expand Down
8 changes: 4 additions & 4 deletions src/value.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ function transforms(value) {
return utilities.removeInlineComments(utilities.removeFlags(value));
}

function Value(scssString) {
this._parse(scssString);
function Value(scssString, useRules) {
this._parse(scssString, useRules);
}

Value.prototype = {
_parse: function(scssString) {
_parse: function(scssString, useRules) {
var transformed = transforms(scssString);
var compiled = compile.fromString(transformed);
var compiled = compile.fromString(transformed, useRules);
this.value = compiled.trim();
}
};
Expand Down