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

Fix selectors folding into directives #2512

Merged
merged 1 commit into from
Mar 19, 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
13 changes: 10 additions & 3 deletions lib/less/parser/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1346,7 +1346,7 @@ var Parser = function Parser(context, imports, fileInfo) {
//
directive: function () {
var index = parserInput.i, name, value, rules, nonVendorSpecificName,
hasIdentifier, hasExpression, hasUnknown, hasBlock = true;
hasIdentifier, hasExpression, hasUnknown, hasBlock = true, isRooted = true;

if (parserInput.currentChar() !== '@') { return; }

Expand Down Expand Up @@ -1387,6 +1387,7 @@ var Parser = function Parser(context, imports, fileInfo) {
case "@right-middle":
case "@right-bottom":
hasBlock = true;
isRooted = true;
break;
*/
case "@counter-style":
Expand All @@ -1406,9 +1407,12 @@ var Parser = function Parser(context, imports, fileInfo) {
break;
case "@host":
case "@page":
hasUnknown = true;
break;
case "@document":
case "@supports":
hasUnknown = true;
isRooted = false;
break;
}

Expand Down Expand Up @@ -1437,8 +1441,11 @@ var Parser = function Parser(context, imports, fileInfo) {

if (rules || (!hasBlock && value && parserInput.$char(';'))) {
parserInput.forget();
return new(tree.Directive)(name, value, rules, index, fileInfo,
context.dumpLineNumbers ? getDebugInfo(index) : null);
return new (tree.Directive)(name, value, rules, index, fileInfo,
context.dumpLineNumbers ? getDebugInfo(index) : null,
false,
isRooted
);
}

parserInput.restore("directive options not recognised");
Expand Down
5 changes: 3 additions & 2 deletions lib/less/tree/directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var Node = require("./node"),
Selector = require("./selector"),
Ruleset = require("./ruleset");

var Directive = function (name, value, rules, index, currentFileInfo, debugInfo, isReferenced) {
var Directive = function (name, value, rules, index, currentFileInfo, debugInfo, isReferenced, isRooted) {
var i;

this.name = name;
Expand All @@ -22,6 +22,7 @@ var Directive = function (name, value, rules, index, currentFileInfo, debugInfo,
this.currentFileInfo = currentFileInfo;
this.debugInfo = debugInfo;
this.isReferenced = isReferenced;
this.isRooted = isRooted || false;
};

Directive.prototype = new Node();
Expand Down Expand Up @@ -78,7 +79,7 @@ Directive.prototype.eval = function (context) {
context.mediaBlocks = mediaBlocksBackup;

return new Directive(this.name, value, rules,
this.index, this.currentFileInfo, this.debugInfo, this.isReferenced);
this.index, this.currentFileInfo, this.debugInfo, this.isReferenced, this.isRooted);
};
Directive.prototype.variable = function (name) {
if (this.rules) {
Expand Down
2 changes: 1 addition & 1 deletion lib/less/visitors/join-selector-visitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ JoinSelectorVisitor.prototype = {
visitDirective: function (directiveNode, visitArgs) {
var context = this.contexts[this.contexts.length - 1];
if (directiveNode.rules && directiveNode.rules.length) {
directiveNode.rules[0].root = (context.length === 0 || null);
directiveNode.rules[0].root = (directiveNode.isRooted || context.length === 0 || null);
}
}
};
Expand Down
16 changes: 16 additions & 0 deletions test/css/directives-bubling.css
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,19 @@ html {
property: value;
}
}
.onTop {
animation: "textscale";
font-family: something;
}
@font-face {
font-family: something;
src: made-up-url;
}
@keyframes "textscale" {
0% {
font-size: 1em;
}
100% {
font-size: 2em;
}
}
28 changes: 21 additions & 7 deletions test/less/directives-bubling.less
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,32 @@

//called from mixin
.nestedSupportsMixin() {
font-weight: 300;
-webkit-font-smoothing: subpixel-antialiased;
@supports not (-webkit-font-smoothing: subpixel-antialiased) {
font-weight: 400;
nested {
property: value;
}
font-weight: 300;
-webkit-font-smoothing: subpixel-antialiased;
@supports not (-webkit-font-smoothing: subpixel-antialiased) {
font-weight: 400;
nested {
property: value;
}
}
}

html {
.nestedSupportsMixin;
}

// selectors should not propagate into all directive types
.onTop {
@font-face {
font-family: something;
src: made-up-url;
}

@keyframes "textscale" {
0% { font-size : 1em; }
100% { font-size : 2em; }
}

animation : "textscale";
font-family : something;
}