8000 Allow circular references and ignore them when they become circular · nullstring/less.js@2ff9ae5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2ff9ae5

Browse files
committed
Allow circular references and ignore them when they become circular
1 parent 7170aaf commit 2ff9ae5

File tree

5 files changed

+41
-31
lines changed

5 files changed

+41
-31
lines changed

lib/less/extend-visitor.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
newSelector[newSelector.length-1].extendList = [newExtend];
110110
extendsToAdd.push(newExtend);
111111
newExtend.ruleset = targetExtend.ruleset;
112-
newExtend.parent = targetExtend;
112+
newExtend.parents = [targetExtend, extend];
113113
targetExtend.ruleset.paths.push(newSelector);
114114
});
115115
}
@@ -135,7 +135,18 @@
135135
}
136136
},
137137
inInheritanceChain: function (possibleParent, possibleChild) {
138-
return possibleParent === possibleChild || (possibleChild.parent ? this.inInheritanceChain(possibleParent, possibleChild.parent) : false);
138+
if (possibleParent === possibleChild) {
139+
return true;
140+
}
141+
if (possibleChild.parents) {
142+
if (this.inInheritanceChain(possibleParent, possibleChild.parents[0])) {
143+
return true;
144+
}
145+
if (this.inInheritanceChain(possibleParent, possibleChild.parents[1])) {
146+
return true;
147+
}
148+
}
149+
return false;
139150
},
140151
visitRule: function (ruleNode, visitArgs) {
141152
visitArgs.visitDeeper = false;

test/css/extend-chaining.css

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,18 @@
3636
.v.w.v {
3737
color: black;
3838
}
39+
.x,
40+
.y,
41+
.z {
42+
color: x;
43+
}
44+
.y,
45+
.z,
46+
.x {
47+
color: y;
48+
}
49+
.z,
50+
.x,
51+
.y {
52+
color: z;
53+
}

test/less/errors/extend-circular.less

Lines changed: 0 additions & 26 deletions
This file was deleted.

test/less/errors/extend-circular.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.

test/less/extend-chaining.less

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,16 @@
4545
// circular reference because the new extend product will match the existing extend
4646

4747
.w:extend(.w) {color: black;}
48-
.v.w.v:extend(.w all){}
48+
.v.w.v:extend(.w all){}
49+
50+
// classic circular references
51+
52+
.x:extend(.z) {
53+
color: x;
54+
}
55+
.y:extend(.x) {
56+
color: y;
57+
}
58+
.z:extend(.y) {
59+
color: z;
60+
}

0 commit comments

Comments
 (0)
0