[Pkg-javascript-commits] [less.js] 09/14: Reviews changes: spacing and commented code. Bug fixed: fixed handling of multi level nesting.
Jonas Smedegaard
dr at jones.dk
Mon Oct 26 23:29:17 UTC 2015
This is an automated email from the git hooks/post-receive script.
js pushed a commit to annotated tag v2.3.1
in repository less.js.
commit 964b991423478e6b85bce25a3aeec084b3986836
Author: jurcovicovam <meri at meri.org>
Date: Wed Jan 28 09:50:44 2015 +0100
Reviews changes: spacing and commented code.
Bug fixed: fixed handling of multi level nesting.
---
lib/less/parser/parser.js | 1 -
lib/less/tree/ruleset.js | 38 ++++++++++++++++++++++++++++++--------
test/css/selectors.css | 2 +-
test/less/selectors.less | 20 +++++++++++---------
4 files changed, 42 insertions(+), 19 deletions(-)
diff --git a/lib/less/parser/parser.js b/lib/less/parser/parser.js
index 61a1d4f..6863979 100644
--- a/lib/less/parser/parser.js
+++ b/lib/less/parser/parser.js
@@ -859,7 +859,6 @@ var Parser = function Parser(context, imports, fileInfo) {
e = parserInput.$re(/^(?:\d+\.\d+|\d+)%/) || parserInput.$re(/^(?:[.#]?|:*)(?:[\w-]|[^\x00-\x9f]|\\(?:[A-Fa-f0-9]{1,6} ?|[^A-Fa-f0-9]))+/) ||
parserInput.$char('*') || parserInput.$char('&') || this.attribute() || parserInput.$re(/^\([^&()@]+\)/) || parserInput.$re(/^[\.#](?=@)/) ||
- //parserInput.$char('*') || parserInput.$char('&') || this.attribute() || parserInput.$re(/^\([^()@]+\)/) || parserInput.$re(/^[\.#](?=@)/) ||
this.entities.variableCurly();
diff --git a/lib/less/tree/ruleset.js b/lib/less/tree/ruleset.js
index 0d46593..49b3d78 100644
--- a/lib/less/tree/ruleset.js
+++ b/lib/less/tree/ruleset.js
@@ -429,6 +429,28 @@ Ruleset.prototype.joinSelectors = function (paths, context, selectors) {
};
Ruleset.prototype.joinSelector = function (paths, context, selector) {
+
+ function createParenthesis(elementsToPak, originalElement) {
+ var replacementParen, j;
+ if (elementsToPak.length === 0) {
+ replacementParen = new Paren(elementsToPak[0]);
+ } else {
+ var insideParent = [];
+ for (j = 0; j < elementsToPak.length; j++) {
+ insideParent.push(new Element(null, elementsToPak[j], originalElement.index, originalElement.currentFileInfo));
+ }
+ replacementParen = new Paren(new Selector(insideParent));
+ }
+ return replacementParen;
+ }
+
+ function createSelector(containedElement, originalElement) {
+ var element, selector;
+ element = new Element(null, containedElement, originalElement.index, originalElement.currentFileInfo);
+ selector = new Selector([element]);
+ return selector;
+ }
+
// replace all parent selectors inside `inSelector` by content of `context` array
// resulting selectors are returned inside `paths` array
// returns true if `inSelector` contained at least one parent selector
@@ -475,15 +497,15 @@ Ruleset.prototype.joinSelector = function (paths, context, selector) {
// on to the current list of selectors to add
mergeElementsOnToSelectors(currentElements, newSelectors);
- var nestedPaths = [], replaced;
+ var nestedPaths = [], replaced, replacedNewSelectors = [];
replaced = replaceParentSelector(nestedPaths, context, nestedSelector);
hadParentSelector = hadParentSelector || replaced;
+ //the nestedPaths array should have only one member - replaceParentSelector does not multiply selectors
for (k = 0; k < nestedPaths.length; k++) {
- var replacementParen = new Paren(nestedPaths[0][0]);
- var replacementElement = new Element(null, replacementParen, el.index, el.currentFileInfo);
- var replacementSelector = new Selector([replacementElement]);
- newSelectors = addAllReplacementsIntoPath(newSelectors, [replacementSelector], el, inSelector);
+ var replacementSelector = createSelector(createParenthesis(nestedPaths[k], el), el);
+ addAllReplacementsIntoPath(newSelectors, [replacementSelector], el, inSelector, replacedNewSelectors);
}
+ newSelectors = replacedNewSelectors;
currentElements = [];
} else {
@@ -591,8 +613,8 @@ Ruleset.prototype.joinSelector = function (paths, context, selector) {
// joins selector path from `beginningPath` with every selector path in `addPaths` array
// `replacedElement` contains element that is being replaced by `addPath`
// returns array with all concatenated paths
- function addAllReplacementsIntoPath( beginningPath, addPaths, replacedElement, originalSelector) {
- var j, result = [];
+ function addAllReplacementsIntoPath( beginningPath, addPaths, replacedElement, originalSelector, result) {
+ var j;
for (j = 0; j < beginningPath.length; j++) {
var newSelectorPath = addReplacementIntoPath(beginningPath[j], addPaths, replacedElement, originalSelector);
result.push(newSelectorPath);
@@ -647,4 +669,4 @@ Ruleset.prototype.joinSelector = function (paths, context, selector) {
}
};
-module.exports = Ruleset;
+module.exports = Ruleset;
\ No newline at end of file
diff --git a/test/css/selectors.css b/test/css/selectors.css
index b114b62..46acb40 100644
--- a/test/css/selectors.css
+++ b/test/css/selectors.css
@@ -154,7 +154,7 @@ blank blank blank blank blank blank blank blank blank blank blank blank blank bl
.blood {
color: red;
}
-.foo:not(.tst.only-nested:hover) {
+.foo:not(.tst.only-nested .level2:hover) {
test: only-nested;
}
.foo.nestend-and-non-nested:not(.tst.nestend-and-non-nested:hover) {
diff --git a/test/less/selectors.less b/test/less/selectors.less
index b98fca2..51e3d08 100644
--- a/test/less/selectors.less
+++ b/test/less/selectors.less
@@ -123,15 +123,15 @@ a {
}
@num: 3;
:nth-child(@{num}) {
- selector: interpolated;
+ selector: interpolated;
}
.test {
- &:nth-child(@{num}) {
- selector: interpolated;
- }
- &:nth-child(odd):not(:nth-child(3)) {
- color: #ff0000;
- }
+ &:nth-child(@{num}) {
+ selector: interpolated;
+ }
+ &:nth-child(odd):not(:nth-child(3)) {
+ color: #ff0000;
+ }
}
[prop],
[prop=10%],
@@ -158,8 +158,10 @@ blank blank blank blank blank blank blank blank blank blank blank blank blank bl
color: red;
}
.only-nested {
- .foo:not(.tst&:hover) {
- test: only-nested;
+ .level2 {
+ .foo:not(.tst&:hover) {
+ test: only-nested;
+ }
}
}
.nestend-and-non-nested {
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/less.js.git
More information about the Pkg-javascript-commits
mailing list