Skip to content

Commit

Permalink
Broken attempt to chain XOR
Browse files Browse the repository at this point in the history
This doesn't work because invertCombinator
doesn't pass through to the inner callback.
See less/less.js#2556
  • Loading branch information
SLaks committed Apr 19, 2015
1 parent 33400dc commit 7e60a91
Show file tree
Hide file tree
Showing 4 changed files with 407 additions and 7 deletions.
47 changes: 41 additions & 6 deletions styles/_combinators.less
Original file line number Diff line number Diff line change
@@ -1,27 +1,53 @@

.op(@first, @operation, @second, @content: @content) when (@operation = xor) {
// This overload is called by the outermost operation,
// as opposed to operations passed as detached ruleset
// parameters). It sets @invertCombinator, and passes
// @content as a scoped variable. This is necessary to
// prevent errors from the when() clauses.
.op(@first, @operation, @second, @content) {
@invertCombinator: false;
.op(@first, @operation, @second);
}

.op(@first, @operation, @second) when (@operation = xor) and not (@invertCombinator) {
#private.callInverted(~'', @first, {
#private.call(~' ~ ', @second, @content);
});
#private.call(~'', @first, {
#private.callInverted(~' ~ ', @second, @content);
});
}
.op(@first, @operation, @second) when (@operation = xor) and (@invertCombinator) {
#private.callInverted(~'', @first, {
#private.callInverted(~' ~ ', @second, @content);
});
#private.call(~'', @first, {
#private.call(~' ~ ', @second, @content);
});
}

.op(@first, @operation, @second, @content: @content) when (@operation = or) {
.op(@first, @operation, @second) when (@operation = or) and not (@invertCombinator) {
#private.call(~'', @first, @content);
#private.call(~'', @second, @content);
}
.op(@first, @operation, @second) when (@operation = or) and (@invertCombinator) {
#private.callInverted(~'', @first, {
#private.callInverted(~' ~ ', @second, @content);
});
}

.op(@first, @operation, @second, @content: @content) when (@operation = and) {
.op(@first, @operation, @second) when (@operation = and) and not (@invertCombinator) {
#private.call(~'', @first, {
#private.call(~' ~ ', @second, @content);
});
}
.op(@first, @operation, @second) when (@operation = and) and (@invertCombinator) {
#private.callInverted(~'', @first, @content);
#private.callInverted(~'', @second, @content);
}

// Calls a selector (as a string or a nested ruleset),
// inside the context that this selector was called in
#private {
// Calls a selector (as a string or a nested ruleset),
// inside the context that this selector was called in
.call(@combinator, @selector, @content) when (isString(@selector)), (isKeyword(@selector)) {
&@{combinator}@{selector}:checked { @content(); }
}
Expand All @@ -32,7 +58,16 @@
}
}

// Same as above, but passes @invertCombinator
// to invert the result of the combinator.
.callInverted(@combinator, @selector, @content) when (isString(@selector)), (isKeyword(@selector)) {
&@{combinator}@{selector}:not(:checked) { @content(); }
}

.callInverted(@combinator, @selector, @content) when (default()) { // isruleset(@selector) doesn't work
&@{combinator} {
@invertCombinator: true;
@selector();
}
}
}
Loading

0 comments on commit 7e60a91

Please sign in to comment.