support for deep but exact extend

This commit is contained in:
Luke Page
2013-03-05 10:20:41 +00:00
parent 62cc6cfc0b
commit 7cebd9ca25
6 changed files with 110 additions and 7 deletions

View File

@@ -177,9 +177,9 @@
if (potentialMatch) {
potentialMatch.finished = potentialMatch.matched === extend.selector.elements.length;
if (potentialMatch.finished && (
(!extend.any && i+1 < selector.elements.length) ||
(!extend.deep && k+1 < selectorPath.length))) {
if (potentialMatch.finished &&
(!extend.deep && (i+1 < selector.elements.length ||
k+1 < selectorPath.length))) {
potentialMatch = null;
}
}

View File

@@ -804,10 +804,6 @@ less.Parser = function Parser(env) {
option = option && option[1];
if (option != "all" && option) {
error(":extend only supports the all option at the moment, please specify it after your selector, e.g. :extend(.a all) or specify no option to extend shallow and exact");
}
if (isRule) {
expect(/^;/);
}

49
test/css/extend-deep.css Normal file
View File

@@ -0,0 +1,49 @@
.replace.replace .replace,
.c.replace + .replace .replace,
.replace.replace .c,
.c.replace + .replace .c,
.rep_ace,
.effected.replace + .replace .replace,
.effected.replace + .replace .c {
prop: copy-paste-replace;
}
.replace.replace .replace .d,
.c.replace + .replace .replace .d,
.replace.replace .c .d,
.c.replace + .replace .c .d,
.rep_ace .d,
.effected.replace + .replace .replace .d,
.effected.replace + .replace .c .d {
prop: deep;
}
.a .b .c,
.effected .b .c {
prop: is_effected;
}
.a,
.effected {
prop: is_effected;
}
.a .b,
.effected .b {
prop: is_effected;
}
.a .b.c,
.effected .b.c {
prop: is_effected;
}
.b .a {
prop: not_effected;
}
.a:hover,
.effected:hover {
hover: is_effected;
}
.e.e,
.dbl {
prop: extend-double;
}
.e.e:hover,
.dbl:hover {
hover: up;
}

View File

@@ -32,3 +32,6 @@
.dbl {
prop: extend-double;
}
.e.e:hover {
hover: not-extended;
}

View File

@@ -0,0 +1,52 @@
.replace.replace,
.c.replace + .replace {
.replace,
.c {
prop: copy-paste-replace;
.d {
prop: deep;
}
}
}
.rep_ace:extend(.replace.replace .replace deep) {}
.a .b .c {
prop: is_effected;
}
.a {
prop: is_effected;
.b {
prop: is_effected;
}
.b.c {
prop: is_effected;
}
}
.b {
.a {
prop: not_effected;
}
}
.a {
&:hover {
hover: is_effected;
}
}
.effected {
&:extend(.a deep);
&:extend(.c deep);
}
.e {
&& {
prop: extend-double;
&:hover {
hover: up;
}
}
}
.dbl:extend(.e.e deep) {}

View File

@@ -38,6 +38,9 @@
.e {
&& {
prop: extend-double;
&:hover {
hover: not-extended;
}
}
}
.dbl:extend(.e.e) {}