|
100 | 100 | for(k = 0; k < allExtends.length; k++) {
|
101 | 101 | for(i = 0; i < rulesetNode.paths.length; i++) {
|
102 | 102 | selectorPath = rulesetNode.paths[i];
|
103 |
| - var match = this.findMatch(allExtends[k], selectorPath); |
104 |
| - if (match) { |
105 |
| - selector = selectorPath[match.pathIndex]; |
| 103 | + var matches = this.findMatch(allExtends[k], selectorPath); |
| 104 | + if (matches.length) { |
106 | 105 | allExtends[k].selfSelectors.forEach(function(selfSelector) {
|
107 |
| - var path = selectorPath.slice(0, match.pathIndex), |
108 |
| - firstElement = new tree.Element( |
109 |
| - match.initialCombinator, |
110 |
| - selfSelector.elements[0].value, |
111 |
| - selfSelector.elements[0].index |
112 |
| - ); |
113 |
| - path.push(new tree.Selector( |
114 |
| - selector.elements |
115 |
| - .slice(0, match.index) |
116 |
| - .concat([firstElement]) |
117 |
| - .concat(selfSelector.elements.slice(1)) |
118 |
| - .concat(selector.elements.slice(match.index + match.length)) |
119 |
| - )); |
120 |
| - path = path.concat(selectorPath.slice(match.endPathIndex + 1, selectorPath.length)); |
| 106 | + var currentSelectorPathIndex = 0, |
| 107 | + currentSelectorPathElementIndex = 0, |
| 108 | + path = []; |
| 109 | + for(j = 0; j < matches.length; j++) { |
| 110 | + match = matches[j]; |
| 111 | + var selector = selectorPath[match.pathIndex], |
| 112 | + firstElement = new tree.Element( |
| 113 | + match.initialCombinator, |
| 114 | + selfSelector.elements[0].value, |
| 115 | + selfSelector.elements[0].index |
| 116 | + ); |
| 117 | + |
| 118 | + if (match.pathIndex > currentSelectorPathIndex && currentSelectorPathElementIndex > 0) { |
| 119 | + path[path.length-1].elements = path[path.length-1].elements.concat(selectorPath[currentSelectorPathIndex].elements.slice(currentSelectorPathElementIndex)); |
| 120 | + currentSelectorPathElementIndex = 0; |
| 121 | + currentSelectorPathIndex++; |
| 122 | + } |
| 123 | + |
| 124 | + path = path.concat(selectorPath.slice(currentSelectorPathIndex, match.pathIndex)); |
| 125 | + |
| 126 | + path.push(new tree.Selector( |
| 127 | + selector.elements |
| 128 | + .slice(currentSelectorPathElementIndex, match.index) |
| 129 | + .concat([firstElement]) |
| 130 | + .concat(selfSelector.elements.slice(1)) |
| 131 | + )); |
| 132 | + currentSelectorPathIndex = match.endPathIndex; |
| 133 | + currentSelectorPathElementIndex = match.endPathElementIndex; |
| 134 | + if (currentSelectorPathElementIndex >= selector.elements.length) { |
| 135 | + currentSelectorPathElementIndex = 0; |
| 136 | + currentSelectorPathIndex++; |
| 137 | + } |
| 138 | + } |
| 139 | + |
| 140 | + if (currentSelectorPathIndex < selectorPath.length && currentSelectorPathElementIndex > 0) { |
| 141 | + path[path.length-1].elements = path[path.length-1].elements.concat(selectorPath[currentSelectorPathIndex].elements.slice(currentSelectorPathElementIndex)); |
| 142 | + currentSelectorPathElementIndex = 0; |
| 143 | + currentSelectorPathIndex++; |
| 144 | + } |
| 145 | + |
| 146 | + path = path.concat(selectorPath.slice(currentSelectorPathIndex, selectorPath.length)); |
| 147 | + |
121 | 148 | selectorsToAdd.push(path);
|
122 | 149 | });
|
123 | 150 | }
|
|
148 | 175 | potentialMatch.initialCombinator = selector.elements[i].combinator;
|
149 | 176 | potentialMatch.length = extend.selector.elements.length;
|
150 | 177 | potentialMatch.endPathIndex = k;
|
151 |
| - return potentialMatch; |
| 178 | + potentialMatch.endPathElementIndex = targetElementIndex; // index after end of match |
152 | 179 | potentialMatches.length = 0;
|
153 | 180 | matches.push(potentialMatch);
|
154 | 181 | break;
|
|
160 | 187 | }
|
161 | 188 | }
|
162 | 189 | }
|
163 |
| - return null; |
164 | 190 | return matches;
|
165 | 191 | },
|
166 | 192 | visitRulesetOut: function (rulesetNode) {
|
|
0 commit comments