From 8f1c35a8149c2e95fafd5b1675f0253b70b8608b Mon Sep 17 00:00:00 2001 From: jurcovicovam Date: Fri, 23 Jan 2015 17:48:26 +0100 Subject: [PATCH 1/2] 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 e189128d..5a22abca 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 aa86214d..ce3cb541 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(); + } } - for (var 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 Date: Fri, 23 Jan 2015 18:42:02 +0100 Subject: [PATCH 2/2] Added unit test for referenced parent selectors Name: Parent selectors not working within mixins using (reference) Number: #1979 --- test/css/import-reference.css | 6 ++++++ test/less/import-reference.less | 1 + test/less/import/import-reference.less | 11 ++++++++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/test/css/import-reference.css b/test/css/import-reference.css index 4dc5490b..0d06c2bf 100644 --- a/test/css/import-reference.css +++ b/test/css/import-reference.css @@ -74,3 +74,9 @@ div#id.class[a=1][b=2].class:not(1) { color: red; } } +.test { + color: red; +} +.test:first-child { + color: blue; +} diff --git a/test/less/import-reference.less b/test/less/import-reference.less index e1477c50..77df43ba 100644 --- a/test/less/import-reference.less +++ b/test/less/import-reference.less @@ -19,3 +19,4 @@ .class:extend(.class all) { } +.mixin-with-nested-selectors(); \ No newline at end of file diff --git a/test/less/import/import-reference.less b/test/less/import/import-reference.less index f8f96425..f4c9c74d 100644 --- a/test/less/import/import-reference.less +++ b/test/less/import/import-reference.less @@ -49,7 +49,7 @@ color: red; } } - +//https://github.com/less/less.js/issues/2359 @supports (something: else) { .class { something: else; @@ -63,3 +63,12 @@ something: else; } } +//https://github.com/less/less.js/issues/1979 +.mixin-with-nested-selectors() { + .test { + color: red; + &:first-child { + color: blue; + } + } +} \ No newline at end of file