[Pkg-javascript-commits] [less.js] 40/58: Extend looses @supports imported by reference
Jonas Smedegaard
dr at jones.dk
Mon Oct 26 23:28:30 UTC 2015
This is an automated email from the git hooks/post-receive script.
js pushed a commit to annotated tag v2.3.0
in repository less.js.
commit 8f1c35a8149c2e95fafd5b1675f0253b70b8608b
Author: jurcovicovam <meri at meri.org>
Date: Fri Jan 23 17:48:26 2015 +0100
Extend looses @supports imported by reference
New logic: directive with body that contains something referenced (for
example by extend) will be shown in output too. @Media works with the same
logic - it shows up in output if it contains something visible.
Related to: #2359
---
lib/less/tree/directive.js | 3 +++
lib/less/tree/ruleset.js | 39 ++++++++++++++++++++++++++++++----
lib/less/visitors/to-css-visitor.js | 37 +++++++++++++++++++++++++++++---
test/css/import-reference.css | 8 +++++++
test/less/import-reference.less | 2 +-
test/less/import/import-reference.less | 16 +++++++++++++-
6 files changed, 96 insertions(+), 9 deletions(-)
diff --git a/lib/less/tree/directive.js b/lib/less/tree/directive.js
index e189128..5a22abc 100644
--- a/lib/less/tree/directive.js
+++ b/lib/less/tree/directive.js
@@ -73,6 +73,9 @@ Directive.prototype.markReferenced = function () {
}
}
};
+Directive.prototype.getIsReferenced = function () {
+ return !this.currentFileInfo || !this.currentFileInfo.reference || this.isReferenced;
+};
Directive.prototype.outputRuleset = function (context, output, rules) {
var ruleCnt = rules.length, i;
context.tabLevel = (context.tabLevel | 0) + 1;
diff --git a/lib/less/tree/ruleset.js b/lib/less/tree/ruleset.js
index aa86214..ce3cb54 100644
--- a/lib/less/tree/ruleset.js
+++ b/lib/less/tree/ruleset.js
@@ -414,13 +414,44 @@ Ruleset.prototype.genCSS = function (context, output) {
}
};
Ruleset.prototype.markReferenced = function () {
- if (!this.selectors) {
- return;
+ var s;
+ if (this.selectors) {
+ for (s = 0; s < this.selectors.length; s++) {
+ this.selectors[s].markReferenced();
+ }
+ }
+
+ if (this.rules) {
+ for (s = 0; s < this.rules.length; s++) {
+ if (this.rules[s].markReferenced)
+ this.rules[s].markReferenced();
+ }
+ }
+};
+Ruleset.prototype.getIsReferenced = function() {
+ var i, j, path, selector;
+
+ if (this.paths) {
+ for (i=0; i<this.paths.length; i++) {
+ path = this.paths[i];
+ for (j=0; j<path.length; j++) {
+ if (path[j].getIsReferenced && path[j].getIsReferenced())
+ return true;
+ }
+ }
}
- for (var s = 0; s < this.selectors.length; s++) {
- this.selectors[s].markReferenced();
+
+ if (this.selectors) {
+ for (i=0;i<this.selectors.length;i++) {
+ selector = this.selectors[i];
+ if (selector.getIsReferenced && selector.getIsReferenced())
+ return true;
+ }
}
+ return false;
};
+
+
Ruleset.prototype.joinSelectors = function (paths, context, selectors) {
for (var s = 0; s < selectors.length; s++) {
this.joinSelector(paths, context, selectors[s]);
diff --git a/lib/less/visitors/to-css-visitor.js b/lib/less/visitors/to-css-visitor.js
index 3e26f88..93cb6d6 100644
--- a/lib/less/visitors/to-css-visitor.js
+++ b/lib/less/visitors/to-css-visitor.js
@@ -46,10 +46,10 @@ ToCSSVisitor.prototype = {
},
visitDirective: function(directiveNode, visitArgs) {
- if (directiveNode.currentFileInfo.reference && !directiveNode.isReferenced) {
- return;
- }
if (directiveNode.name === "@charset") {
+ if (!directiveNode.getIsReferenced()) {
+ return;
+ }
// Only output the debug info together with subsequent @charset definitions
// a comment (or @media statement) before the actual @charset directive would
// be considered illegal css as it has to be on the first line
@@ -65,6 +65,37 @@ ToCSSVisitor.prototype = {
}
if (directiveNode.rules && directiveNode.rules.rules) {
this._mergeRules(directiveNode.rules.rules);
+ //process childs
+ directiveNode.accept(this._visitor);
+ visitArgs.visitDeeper = false;
+
+ // the directive was directly referenced and therefore needs to be shown in the output
+ if (directiveNode.getIsReferenced()) {
+ return directiveNode;
+ }
+
+ if (!directiveNode.rules.rules) {
+ return ;
+ }
+
+ //the directive was not directly referenced
+ for (var r = 0; r<directiveNode.rules.rules.length; r++) {
+ var rule = directiveNode.rules.rules[r];
+ if (rule.getIsReferenced && rule.getIsReferenced()) {
+ //the directive contains something that was referenced (likely by extend)
+ //therefore it needs to be shown in output too
+
+ //marking as referenced in case the directive is stored inside another directive
+ directiveNode.markReferenced();
+ return directiveNode;
+ }
+ }
+ //The directive was not directly referenced and does not contain anything that
+ //was referenced. Therefore it must not be shown in output.
+ return ;
+ } else {
+ if (!directiveNode.getIsReferenced())
+ return;
}
return directiveNode;
},
diff --git a/test/css/import-reference.css b/test/css/import-reference.css
index f25f4b1..4dc5490 100644
--- a/test/css/import-reference.css
+++ b/test/css/import-reference.css
@@ -34,6 +34,14 @@ div#id.class[a=1][b=2].class:not(1) {
.visible + .visible .sub {
color: green;
}
+ at supports (something: else) {
+ .class {
+ something: else;
+ }
+ .nestedToo .class {
+ something: else;
+ }
+}
.b {
color: red;
color: green;
diff --git a/test/less/import-reference.less b/test/less/import-reference.less
index 93160ab..e1477c5 100644
--- a/test/less/import-reference.less
+++ b/test/less/import-reference.less
@@ -18,4 +18,4 @@
}
.class:extend(.class all) {
-}
\ No newline at end of file
+}
diff --git a/test/less/import/import-reference.less b/test/less/import/import-reference.less
index c77f692..f8f9642 100644
--- a/test/less/import/import-reference.less
+++ b/test/less/import/import-reference.less
@@ -48,4 +48,18 @@
@media (max-size: @max-size) {
color: red;
}
-}
\ No newline at end of file
+}
+
+ at supports (something: else) {
+ .class {
+ something: else;
+ }
+ .nestedToo {
+ .class {
+ something: else;
+ }
+ }
+ .invisible {
+ something: else;
+ }
+}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/less.js.git
More information about the Pkg-javascript-commits
mailing list