Skip to content

Commit

Permalink
Reference inline comments.
Browse files Browse the repository at this point in the history
As described in #2675 in-value comments are not preserved in referenced rules.

This patch adds reference marking to nodes below rules and expressions if markReferenced is available.
  • Loading branch information
betaorbust committed Aug 31, 2015
1 parent ff5e5a0 commit 74ef1eb
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*~
.#*
.idea
*.iml
*.sublime-*

# npm
Expand Down
5 changes: 5 additions & 0 deletions lib/less/tree/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,9 @@ Expression.prototype.throwAwayComments = function () {
return !(v instanceof Comment);
});
};
Expression.prototype.markReferenced = function () {
this.value.forEach(function (value) {
if (value.markReferenced) { value.markReferenced(); }
});
};
module.exports = Expression;
20 changes: 19 additions & 1 deletion lib/less/tree/rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,22 @@ Rule.prototype.makeImportant = function () {
this.index, this.currentFileInfo, this.inline);
};

module.exports = Rule;
// Recursive marking for rules
var mark = function(value) {
if (!Array.isArray(value)) {
if (value.markReferenced) {
value.markReferenced();
}
} else {
value.forEach(function (ar) {
mark(ar);
});
}
};
Rule.prototype.markReferenced = function () {
if (this.value) {
mark(this.value);
}
};

module.exports = Rule;
2 changes: 1 addition & 1 deletion test/css/import-reference.css
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ div#id.class[a=1][b=2].class:not(1) {
color: green;
}
.y {
pulled-in: yes;
pulled-in: yes /* inline comment survives */;
}
/* comment pulled in */
.visible {
Expand Down
2 changes: 1 addition & 1 deletion test/less/import/import-reference.less
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

.zz {
.y {
pulled-in: yes;
pulled-in: yes /* inline comment survives */;
}
/* comment pulled in */
}
Expand Down

0 comments on commit 74ef1eb

Please sign in to comment.