Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes import by reference inlines source's inline imports - 2620 #2642

Merged
merged 2 commits into from
Sep 9, 2015
Merged
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
12 changes: 10 additions & 2 deletions lib/less/tree/anonymous.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
var Node = require("./node");

var Anonymous = function (value, index, currentFileInfo, mapLines, rulesetLike) {
var Anonymous = function (value, index, currentFileInfo, mapLines, rulesetLike, referenced) {
this.value = value;
this.index = index;
this.mapLines = mapLines;
this.currentFileInfo = currentFileInfo;
this.rulesetLike = (typeof rulesetLike === 'undefined') ? false : rulesetLike;
this.isReferenced = referenced || false;
};
Anonymous.prototype = new Node();
Anonymous.prototype.type = "Anonymous";
Anonymous.prototype.eval = function () {
return new Anonymous(this.value, this.index, this.currentFileInfo, this.mapLines, this.rulesetLike);
return new Anonymous(this.value, this.index, this.currentFileInfo, this.mapLines, this.rulesetLike, this.isReferenced);
};
Anonymous.prototype.compare = function (other) {
return other.toCSS && this.toCSS() === other.toCSS() ? 0 : undefined;
Expand All @@ -21,4 +22,11 @@ Anonymous.prototype.isRulesetLike = function() {
Anonymous.prototype.genCSS = function (context, output) {
output.add(this.value, this.currentFileInfo, this.index, this.mapLines);
};
Anonymous.prototype.markReferenced = function () {
this.isReferenced = true;
};
Anonymous.prototype.getIsReferenced = function () {
return !this.currentFileInfo || !this.currentFileInfo.reference || this.isReferenced;
};

module.exports = Anonymous;
2 changes: 1 addition & 1 deletion lib/less/tree/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ Import.prototype.eval = function (context) {
}

if (this.options.inline) {
var contents = new Anonymous(this.root, 0, {filename: this.importedFilename}, true, true);
var contents = new Anonymous(this.root, 0, {filename: this.importedFilename, reference: this.path.currentFileInfo.reference}, true, true, false);
return this.features ? new Media([contents], this.features.value) : [contents];
} else if (this.css) {
var newImport = new Import(this.evalPath(context), features, this.options, this.index);
Expand Down
9 changes: 9 additions & 0 deletions lib/less/visitors/to-css-visitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,15 @@ ToCSSVisitor.prototype = {
rule.value = toValue(spacedGroups);
}
});
},

visitAnonymous: function(anonymousNode, visitArgs) {
if (!anonymousNode.getIsReferenced()) {
return ;
}

anonymousNode.accept(this._visitor);
return anonymousNode;
}
};

Expand Down
4 changes: 4 additions & 0 deletions test/css/import-reference.css
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,7 @@ div#id.class[a=1][b=2].class:not(1) {
color: red;
}
}
div {
this isn't very valid CSS.
}
this isn't very valid CSS.
2 changes: 2 additions & 0 deletions test/less/import-reference.less
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@
}
.mixin-with-nested-selectors();
.mixin-with-directives(some-name);

.print-referenced-import-inline();
1 change: 1 addition & 0 deletions test/less/import/import-inline-invalid-css.less
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import (inline) "invalid-css.less";
9 changes: 9 additions & 0 deletions test/less/import/import-reference.less
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,13 @@
}
@rules1: {property: value;};
@rules2: {property: value;};
}

@import (inline, multiple) "invalid-css.less";
@import "import-inline-invalid-css.less";
.print-referenced-import-inline() {
div {
@import (inline, multiple) "invalid-css.less";
}
@import (inline, multiple) "invalid-css.less";
}