less 3.10.0-beta.2 → 3.10.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/.DS_Store +0 -0
  2. package/bin/lessc +6652 -5505
  3. package/dist/less.cjs.js +6593 -5448
  4. package/dist/less.js +10 -6
  5. package/dist/less.min.js +2 -2
  6. package/dist/less.min.js.map +1 -1
  7. package/lib/less/constants.js +13 -0
  8. package/lib/less/contexts.js +164 -0
  9. package/lib/less/data/colors.js +150 -0
  10. package/lib/less/data/index.js +4 -0
  11. package/lib/less/data/unit-conversions.js +21 -0
  12. package/lib/less/default-options.js +68 -0
  13. package/lib/less/environment/abstract-file-manager.js +127 -0
  14. package/lib/less/environment/abstract-plugin-loader.js +187 -0
  15. package/lib/less/environment/environment-api.js +25 -0
  16. package/lib/less/environment/environment.js +59 -0
  17. package/lib/less/environment/file-manager-api.js +103 -0
  18. package/lib/less/functions/boolean.js +13 -0
  19. package/lib/less/functions/color-blending.js +84 -0
  20. package/lib/less/functions/color.js +417 -0
  21. package/lib/less/functions/data-uri.js +74 -0
  22. package/lib/less/functions/default.js +25 -0
  23. package/lib/less/functions/function-caller.js +49 -0
  24. package/lib/less/functions/function-registry.js +35 -0
  25. package/lib/less/functions/index.js +33 -0
  26. package/lib/less/functions/list.js +143 -0
  27. package/lib/less/functions/math-helper.js +15 -0
  28. package/lib/less/functions/math.js +28 -0
  29. package/lib/less/functions/number.js +89 -0
  30. package/lib/less/functions/string.js +36 -0
  31. package/lib/less/functions/svg.js +87 -0
  32. package/lib/less/functions/types.js +70 -0
  33. package/lib/less/import-manager.js +169 -0
  34. package/lib/less/index.js +92 -0
  35. package/lib/less/less-error.js +140 -0
  36. package/lib/less/logger.js +34 -0
  37. package/lib/less/parse-tree.js +66 -0
  38. package/lib/less/parse.js +89 -0
  39. package/lib/less/parser/chunker.js +122 -0
  40. package/lib/less/parser/parser-input.js +390 -0
  41. package/lib/less/parser/parser.js +2418 -0
  42. package/lib/less/plugin-manager.js +168 -0
  43. package/lib/less/render.js +42 -0
  44. package/lib/less/source-map-builder.js +77 -0
  45. package/lib/less/source-map-output.js +149 -0
  46. package/lib/less/transform-tree.js +96 -0
  47. package/lib/less/tree/anonymous.js +37 -0
  48. package/lib/less/tree/assignment.js +33 -0
  49. package/lib/less/tree/atrule.js +165 -0
  50. package/lib/less/tree/attribute.js +34 -0
  51. package/lib/less/tree/call.js +105 -0
  52. package/lib/less/tree/color.js +246 -0
  53. package/lib/less/tree/combinator.js +29 -0
  54. package/lib/less/tree/comment.js +29 -0
  55. package/lib/less/tree/condition.js +43 -0
  56. package/lib/less/tree/debug-info.js +34 -0
  57. package/lib/less/tree/declaration.js +115 -0
  58. package/lib/less/tree/detached-ruleset.js +30 -0
  59. package/lib/less/tree/dimension.js +179 -0
  60. package/lib/less/tree/element.js +73 -0
  61. package/lib/less/tree/expression.js +74 -0
  62. package/lib/less/tree/extend.js +66 -0
  63. package/lib/less/tree/import.js +184 -0
  64. package/lib/less/tree/index.js +54 -0
  65. package/lib/less/tree/javascript.js +33 -0
  66. package/lib/less/tree/js-eval-node.js +58 -0
  67. package/lib/less/tree/keyword.js +21 -0
  68. package/lib/less/tree/media.js +154 -0
  69. package/lib/less/tree/mixin-call.js +215 -0
  70. package/lib/less/tree/mixin-definition.js +229 -0
  71. package/lib/less/tree/namespace-value.js +87 -0
  72. package/lib/less/tree/negative.js +26 -0
  73. package/lib/less/tree/node.js +178 -0
  74. package/lib/less/tree/operation.js +62 -0
  75. package/lib/less/tree/paren.js +22 -0
  76. package/lib/less/tree/property.js +77 -0
  77. package/lib/less/tree/quoted.js +70 -0
  78. package/lib/less/tree/ruleset.js +867 -0
  79. package/lib/less/tree/selector.js +146 -0
  80. package/lib/less/tree/unicode-descriptor.js +13 -0
  81. package/lib/less/tree/unit.js +141 -0
  82. package/lib/less/tree/url.js +65 -0
  83. package/lib/less/tree/value.js +44 -0
  84. package/lib/less/tree/variable-call.js +46 -0
  85. package/lib/less/tree/variable.js +67 -0
  86. package/lib/less/utils.js +122 -0
  87. package/lib/less/visitors/extend-visitor.js +505 -0
  88. package/lib/less/visitors/import-sequencer.js +58 -0
  89. package/lib/less/visitors/import-visitor.js +189 -0
  90. package/lib/less/visitors/index.js +15 -0
  91. package/lib/less/visitors/join-selector-visitor.js +57 -0
  92. package/lib/less/visitors/set-tree-visibility-visitor.js +45 -0
  93. package/lib/less/visitors/to-css-visitor.js +363 -0
  94. package/lib/less/visitors/visitor.js +163 -0
  95. package/lib/less-browser/add-default-options.js +49 -0
  96. package/lib/less-browser/bootstrap.js +69 -0
  97. package/lib/less-browser/browser.js +65 -0
  98. package/lib/less-browser/cache.js +43 -0
  99. package/lib/less-browser/error-reporting.js +170 -0
  100. package/lib/less-browser/file-manager.js +113 -0
  101. package/lib/less-browser/image-size.js +28 -0
  102. package/lib/less-browser/index.js +285 -0
  103. package/lib/less-browser/log-listener.js +42 -0
  104. package/lib/less-browser/plugin-loader.js +26 -0
  105. package/lib/less-browser/utils.js +24 -0
  106. package/lib/less-node/environment.js +16 -0
  107. package/lib/less-node/file-manager.js +177 -0
  108. package/lib/less-node/fs.js +10 -0
  109. package/lib/less-node/image-size.js +58 -0
  110. package/lib/less-node/index.js +27 -0
  111. package/lib/less-node/lessc-helper.js +89 -0
  112. package/lib/less-node/plugin-loader.js +53 -0
  113. package/lib/less-node/url-file-manager.js +49 -0
  114. package/lib/lessc.js +557 -0
  115. package/lib/source-map/source-map-0.1.31.js +1933 -0
  116. package/lib/source-map/source-map-footer.js +4 -0
  117. package/lib/source-map/source-map-header.js +3 -0
  118. package/package.json +1 -1
  119. package/test/.DS_Store +0 -0
  120. package/test/browser/less.min.js +11 -0
  121. package/test/browser/less.min.js.map +1 -0
  122. package/test/css/css-escapes.css +1 -0
  123. package/test/less/css-escapes.less +3 -1
  124. package/.git/index +0 -0
@@ -0,0 +1,505 @@
1
+ import tree from '../tree';
2
+ import Visitor from './visitor';
3
+ import logger from '../logger';
4
+ import * as utils from '../utils';
5
+
6
+ /* jshint loopfunc:true */
7
+
8
+ class ExtendFinderVisitor {
9
+ constructor() {
10
+ this._visitor = new Visitor(this);
11
+ this.contexts = [];
12
+ this.allExtendsStack = [[]];
13
+ }
14
+
15
+ run(root) {
16
+ root = this._visitor.visit(root);
17
+ root.allExtends = this.allExtendsStack[0];
18
+ return root;
19
+ }
20
+
21
+ visitDeclaration(declNode, visitArgs) {
22
+ visitArgs.visitDeeper = false;
23
+ }
24
+
25
+ visitMixinDefinition(mixinDefinitionNode, visitArgs) {
26
+ visitArgs.visitDeeper = false;
27
+ }
28
+
29
+ visitRuleset(rulesetNode, visitArgs) {
30
+ if (rulesetNode.root) {
31
+ return;
32
+ }
33
+
34
+ let i;
35
+ let j;
36
+ let extend;
37
+ const allSelectorsExtendList = [];
38
+ let extendList;
39
+
40
+ // get &:extend(.a); rules which apply to all selectors in this ruleset
41
+ const rules = rulesetNode.rules;
42
+
43
+ const ruleCnt = rules ? rules.length : 0;
44
+ for (i = 0; i < ruleCnt; i++) {
45
+ if (rulesetNode.rules[i] instanceof tree.Extend) {
46
+ allSelectorsExtendList.push(rules[i]);
47
+ rulesetNode.extendOnEveryPath = true;
48
+ }
49
+ }
50
+
51
+ // now find every selector and apply the extends that apply to all extends
52
+ // and the ones which apply to an individual extend
53
+ const paths = rulesetNode.paths;
54
+ for (i = 0; i < paths.length; i++) {
55
+ const selectorPath = paths[i];
56
+ const selector = selectorPath[selectorPath.length - 1];
57
+ const selExtendList = selector.extendList;
58
+
59
+ extendList = selExtendList ? utils.copyArray(selExtendList).concat(allSelectorsExtendList)
60
+ : allSelectorsExtendList;
61
+
62
+ if (extendList) {
63
+ extendList = extendList.map(allSelectorsExtend => allSelectorsExtend.clone());
64
+ }
65
+
66
+ for (j = 0; j < extendList.length; j++) {
67
+ this.foundExtends = true;
68
+ extend = extendList[j];
69
+ extend.findSelfSelectors(selectorPath);
70
+ extend.ruleset = rulesetNode;
71
+ if (j === 0) { extend.firstExtendOnThisSelectorPath = true; }
72
+ this.allExtendsStack[this.allExtendsStack.length - 1].push(extend);
73
+ }
74
+ }
75
+
76
+ this.contexts.push(rulesetNode.selectors);
77
+ }
78
+
79
+ visitRulesetOut(rulesetNode) {
80
+ if (!rulesetNode.root) {
81
+ this.contexts.length = this.contexts.length - 1;
82
+ }
83
+ }
84
+
85
+ visitMedia(mediaNode, visitArgs) {
86
+ mediaNode.allExtends = [];
87
+ this.allExtendsStack.push(mediaNode.allExtends);
88
+ }
89
+
90
+ visitMediaOut(mediaNode) {
91
+ this.allExtendsStack.length = this.allExtendsStack.length - 1;
92
+ }
93
+
94
+ visitAtRule(atRuleNode, visitArgs) {
95
+ atRuleNode.allExtends = [];
96
+ this.allExtendsStack.push(atRuleNode.allExtends);
97
+ }
98
+
99
+ visitAtRuleOut(atRuleNode) {
100
+ this.allExtendsStack.length = this.allExtendsStack.length - 1;
101
+ }
102
+ }
103
+
104
+ class ProcessExtendsVisitor {
105
+ constructor() {
106
+ this._visitor = new Visitor(this);
107
+ }
108
+
109
+ run(root) {
110
+ const extendFinder = new ExtendFinderVisitor();
111
+ this.extendIndices = {};
112
+ extendFinder.run(root);
113
+ if (!extendFinder.foundExtends) { return root; }
114
+ root.allExtends = root.allExtends.concat(this.doExtendChaining(root.allExtends, root.allExtends));
115
+ this.allExtendsStack = [root.allExtends];
116
+ const newRoot = this._visitor.visit(root);
117
+ this.checkExtendsForNonMatched(root.allExtends);
118
+ return newRoot;
119
+ }
120
+
121
+ checkExtendsForNonMatched(extendList) {
122
+ const indices = this.extendIndices;
123
+ extendList.filter(extend => !extend.hasFoundMatches && extend.parent_ids.length == 1).forEach(extend => {
124
+ let selector = '_unknown_';
125
+ try {
126
+ selector = extend.selector.toCSS({});
127
+ }
128
+ catch (_) {}
129
+
130
+ if (!indices[`${extend.index} ${selector}`]) {
131
+ indices[`${extend.index} ${selector}`] = true;
132
+ logger.warn(`extend '${selector}' has no matches`);
133
+ }
134
+ });
135
+ }
136
+
137
+ doExtendChaining(extendsList, extendsListTarget, iterationCount) {
138
+ //
139
+ // chaining is different from normal extension.. if we extend an extend then we are not just copying, altering
140
+ // and pasting the selector we would do normally, but we are also adding an extend with the same target selector
141
+ // this means this new extend can then go and alter other extends
142
+ //
143
+ // this method deals with all the chaining work - without it, extend is flat and doesn't work on other extend selectors
144
+ // this is also the most expensive.. and a match on one selector can cause an extension of a selector we had already
145
+ // processed if we look at each selector at a time, as is done in visitRuleset
146
+
147
+ let extendIndex;
148
+
149
+ let targetExtendIndex;
150
+ let matches;
151
+ const extendsToAdd = [];
152
+ let newSelector;
153
+ const extendVisitor = this;
154
+ let selectorPath;
155
+ let extend;
156
+ let targetExtend;
157
+ let newExtend;
158
+
159
+ iterationCount = iterationCount || 0;
160
+
161
+ // loop through comparing every extend with every target extend.
162
+ // a target extend is the one on the ruleset we are looking at copy/edit/pasting in place
163
+ // e.g. .a:extend(.b) {} and .b:extend(.c) {} then the first extend extends the second one
164
+ // and the second is the target.
165
+ // the separation into two lists allows us to process a subset of chains with a bigger set, as is the
166
+ // case when processing media queries
167
+ for (extendIndex = 0; extendIndex < extendsList.length; extendIndex++) {
168
+ for (targetExtendIndex = 0; targetExtendIndex < extendsListTarget.length; targetExtendIndex++) {
169
+
170
+ extend = extendsList[extendIndex];
171
+ targetExtend = extendsListTarget[targetExtendIndex];
172
+
173
+ // look for circular references
174
+ if ( extend.parent_ids.indexOf( targetExtend.object_id ) >= 0 ) { continue; }
175
+
176
+ // find a match in the target extends self selector (the bit before :extend)
177
+ selectorPath = [targetExtend.selfSelectors[0]];
178
+ matches = extendVisitor.findMatch(extend, selectorPath);
179
+
180
+ if (matches.length) {
181
+ extend.hasFoundMatches = true;
182
+
183
+ // we found a match, so for each self selector..
184
+ extend.selfSelectors.forEach(selfSelector => {
185
+ const info = targetExtend.visibilityInfo();
186
+
187
+ // process the extend as usual
188
+ newSelector = extendVisitor.extendSelector(matches, selectorPath, selfSelector, extend.isVisible());
189
+
190
+ // but now we create a new extend from it
191
+ newExtend = new(tree.Extend)(targetExtend.selector, targetExtend.option, 0, targetExtend.fileInfo(), info);
192
+ newExtend.selfSelectors = newSelector;
193
+
194
+ // add the extend onto the list of extends for that selector
195
+ newSelector[newSelector.length - 1].extendList = [newExtend];
196
+
197
+ // record that we need to add it.
198
+ extendsToAdd.push(newExtend);
199
+ newExtend.ruleset = targetExtend.ruleset;
200
+
201
+ // remember its parents for circular references
202
+ newExtend.parent_ids = newExtend.parent_ids.concat(targetExtend.parent_ids, extend.parent_ids);
203
+
204
+ // only process the selector once.. if we have :extend(.a,.b) then multiple
205
+ // extends will look at the same selector path, so when extending
206
+ // we know that any others will be duplicates in terms of what is added to the css
207
+ if (targetExtend.firstExtendOnThisSelectorPath) {
208
+ newExtend.firstExtendOnThisSelectorPath = true;
209
+ targetExtend.ruleset.paths.push(newSelector);
210
+ }
211
+ });
212
+ }
213
+ }
214
+ }
215
+
216
+ if (extendsToAdd.length) {
217
+ // try to detect circular references to stop a stack overflow.
218
+ // may no longer be needed.
219
+ this.extendChainCount++;
220
+ if (iterationCount > 100) {
221
+ let selectorOne = '{unable to calculate}';
222
+ let selectorTwo = '{unable to calculate}';
223
+ try {
224
+ selectorOne = extendsToAdd[0].selfSelectors[0].toCSS();
225
+ selectorTwo = extendsToAdd[0].selector.toCSS();
226
+ }
227
+ catch (e) {}
228
+ throw { message: `extend circular reference detected. One of the circular extends is currently:${selectorOne}:extend(${selectorTwo})`};
229
+ }
230
+
231
+ // now process the new extends on the existing rules so that we can handle a extending b extending c extending
232
+ // d extending e...
233
+ return extendsToAdd.concat(extendVisitor.doExtendChaining(extendsToAdd, extendsListTarget, iterationCount + 1));
234
+ } else {
235
+ return extendsToAdd;
236
+ }
237
+ }
238
+
239
+ visitDeclaration(ruleNode, visitArgs) {
240
+ visitArgs.visitDeeper = false;
241
+ }
242
+
243
+ visitMixinDefinition(mixinDefinitionNode, visitArgs) {
244
+ visitArgs.visitDeeper = false;
245
+ }
246
+
247
+ visitSelector(selectorNode, visitArgs) {
248
+ visitArgs.visitDeeper = false;
249
+ }
250
+
251
+ visitRuleset(rulesetNode, visitArgs) {
252
+ if (rulesetNode.root) {
253
+ return;
254
+ }
255
+ let matches;
256
+ let pathIndex;
257
+ let extendIndex;
258
+ const allExtends = this.allExtendsStack[this.allExtendsStack.length - 1];
259
+ const selectorsToAdd = [];
260
+ const extendVisitor = this;
261
+ let selectorPath;
262
+
263
+ // look at each selector path in the ruleset, find any extend matches and then copy, find and replace
264
+
265
+ for (extendIndex = 0; extendIndex < allExtends.length; extendIndex++) {
266
+ for (pathIndex = 0; pathIndex < rulesetNode.paths.length; pathIndex++) {
267
+ selectorPath = rulesetNode.paths[pathIndex];
268
+
269
+ // extending extends happens initially, before the main pass
270
+ if (rulesetNode.extendOnEveryPath) { continue; }
271
+ const extendList = selectorPath[selectorPath.length - 1].extendList;
272
+ if (extendList && extendList.length) { continue; }
273
+
274
+ matches = this.findMatch(allExtends[extendIndex], selectorPath);
275
+
276
+ if (matches.length) {
277
+ allExtends[extendIndex].hasFoundMatches = true;
278
+
279
+ allExtends[extendIndex].selfSelectors.forEach(selfSelector => {
280
+ let extendedSelectors;
281
+ extendedSelectors = extendVisitor.extendSelector(matches, selectorPath, selfSelector, allExtends[extendIndex].isVisible());
282
+ selectorsToAdd.push(extendedSelectors);
283
+ });
284
+ }
285
+ }
286
+ }
287
+ rulesetNode.paths = rulesetNode.paths.concat(selectorsToAdd);
288
+ }
289
+
290
+ findMatch(extend, haystackSelectorPath) {
291
+ //
292
+ // look through the haystack selector path to try and find the needle - extend.selector
293
+ // returns an array of selector matches that can then be replaced
294
+ //
295
+ let haystackSelectorIndex;
296
+
297
+ let hackstackSelector;
298
+ let hackstackElementIndex;
299
+ let haystackElement;
300
+ let targetCombinator;
301
+ let i;
302
+ const extendVisitor = this;
303
+ const needleElements = extend.selector.elements;
304
+ const potentialMatches = [];
305
+ let potentialMatch;
306
+ const matches = [];
307
+
308
+ // loop through the haystack elements
309
+ for (haystackSelectorIndex = 0; haystackSelectorIndex < haystackSelectorPath.length; haystackSelectorIndex++) {
310
+ hackstackSelector = haystackSelectorPath[haystackSelectorIndex];
311
+
312
+ for (hackstackElementIndex = 0; hackstackElementIndex < hackstackSelector.elements.length; hackstackElementIndex++) {
313
+
314
+ haystackElement = hackstackSelector.elements[hackstackElementIndex];
315
+
316
+ // if we allow elements before our match we can add a potential match every time. otherwise only at the first element.
317
+ if (extend.allowBefore || (haystackSelectorIndex === 0 && hackstackElementIndex === 0)) {
318
+ potentialMatches.push({pathIndex: haystackSelectorIndex, index: hackstackElementIndex, matched: 0,
319
+ initialCombinator: haystackElement.combinator});
320
+ }
321
+
322
+ for (i = 0; i < potentialMatches.length; i++) {
323
+ potentialMatch = potentialMatches[i];
324
+
325
+ // selectors add " " onto the first element. When we use & it joins the selectors together, but if we don't
326
+ // then each selector in haystackSelectorPath has a space before it added in the toCSS phase. so we need to
327
+ // work out what the resulting combinator will be
328
+ targetCombinator = haystackElement.combinator.value;
329
+ if (targetCombinator === '' && hackstackElementIndex === 0) {
330
+ targetCombinator = ' ';
331
+ }
332
+
333
+ // if we don't match, null our match to indicate failure
334
+ if (!extendVisitor.isElementValuesEqual(needleElements[potentialMatch.matched].value, haystackElement.value) ||
335
+ (potentialMatch.matched > 0 && needleElements[potentialMatch.matched].combinator.value !== targetCombinator)) {
336
+ potentialMatch = null;
337
+ } else {
338
+ potentialMatch.matched++;
339
+ }
340
+
341
+ // if we are still valid and have finished, test whether we have elements after and whether these are allowed
342
+ if (potentialMatch) {
343
+ potentialMatch.finished = potentialMatch.matched === needleElements.length;
344
+ if (potentialMatch.finished &&
345
+ (!extend.allowAfter &&
346
+ (hackstackElementIndex + 1 < hackstackSelector.elements.length || haystackSelectorIndex + 1 < haystackSelectorPath.length))) {
347
+ potentialMatch = null;
348
+ }
349
+ }
350
+ // if null we remove, if not, we are still valid, so either push as a valid match or continue
351
+ if (potentialMatch) {
352
+ if (potentialMatch.finished) {
353
+ potentialMatch.length = needleElements.length;
354
+ potentialMatch.endPathIndex = haystackSelectorIndex;
355
+ potentialMatch.endPathElementIndex = hackstackElementIndex + 1; // index after end of match
356
+ potentialMatches.length = 0; // we don't allow matches to overlap, so start matching again
357
+ matches.push(potentialMatch);
358
+ }
359
+ } else {
360
+ potentialMatches.splice(i, 1);
361
+ i--;
362
+ }
363
+ }
364
+ }
365
+ }
366
+ return matches;
367
+ }
368
+
369
+ isElementValuesEqual(elementValue1, elementValue2) {
370
+ if (typeof elementValue1 === 'string' || typeof elementValue2 === 'string') {
371
+ return elementValue1 === elementValue2;
372
+ }
373
+ if (elementValue1 instanceof tree.Attribute) {
374
+ if (elementValue1.op !== elementValue2.op || elementValue1.key !== elementValue2.key) {
375
+ return false;
376
+ }
377
+ if (!elementValue1.value || !elementValue2.value) {
378
+ if (elementValue1.value || elementValue2.value) {
379
+ return false;
380
+ }
381
+ return true;
382
+ }
383
+ elementValue1 = elementValue1.value.value || elementValue1.value;
384
+ elementValue2 = elementValue2.value.value || elementValue2.value;
385
+ return elementValue1 === elementValue2;
386
+ }
387
+ elementValue1 = elementValue1.value;
388
+ elementValue2 = elementValue2.value;
389
+ if (elementValue1 instanceof tree.Selector) {
390
+ if (!(elementValue2 instanceof tree.Selector) || elementValue1.elements.length !== elementValue2.elements.length) {
391
+ return false;
392
+ }
393
+ for (let i = 0; i < elementValue1.elements.length; i++) {
394
+ if (elementValue1.elements[i].combinator.value !== elementValue2.elements[i].combinator.value) {
395
+ if (i !== 0 || (elementValue1.elements[i].combinator.value || ' ') !== (elementValue2.elements[i].combinator.value || ' ')) {
396
+ return false;
397
+ }
398
+ }
399
+ if (!this.isElementValuesEqual(elementValue1.elements[i].value, elementValue2.elements[i].value)) {
400
+ return false;
401
+ }
402
+ }
403
+ return true;
404
+ }
405
+ return false;
406
+ }
407
+
408
+ extendSelector(matches, selectorPath, replacementSelector, isVisible) {
409
+ // for a set of matches, replace each match with the replacement selector
410
+
411
+ let currentSelectorPathIndex = 0;
412
+
413
+ let currentSelectorPathElementIndex = 0;
414
+ let path = [];
415
+ let matchIndex;
416
+ let selector;
417
+ let firstElement;
418
+ let match;
419
+ let newElements;
420
+
421
+ for (matchIndex = 0; matchIndex < matches.length; matchIndex++) {
422
+ match = matches[matchIndex];
423
+ selector = selectorPath[match.pathIndex];
424
+ firstElement = new tree.Element(
425
+ match.initialCombinator,
426
+ replacementSelector.elements[0].value,
427
+ replacementSelector.elements[0].isVariable,
428
+ replacementSelector.elements[0].getIndex(),
429
+ replacementSelector.elements[0].fileInfo()
430
+ );
431
+
432
+ if (match.pathIndex > currentSelectorPathIndex && currentSelectorPathElementIndex > 0) {
433
+ path[path.length - 1].elements = path[path.length - 1]
434
+ .elements.concat(selectorPath[currentSelectorPathIndex].elements.slice(currentSelectorPathElementIndex));
435
+ currentSelectorPathElementIndex = 0;
436
+ currentSelectorPathIndex++;
437
+ }
438
+
439
+ newElements = selector.elements
440
+ .slice(currentSelectorPathElementIndex, match.index)
441
+ .concat([firstElement])
442
+ .concat(replacementSelector.elements.slice(1));
443
+
444
+ if (currentSelectorPathIndex === match.pathIndex && matchIndex > 0) {
445
+ path[path.length - 1].elements =
446
+ path[path.length - 1].elements.concat(newElements);
447
+ } else {
448
+ path = path.concat(selectorPath.slice(currentSelectorPathIndex, match.pathIndex));
449
+
450
+ path.push(new tree.Selector(
451
+ newElements
452
+ ));
453
+ }
454
+ currentSelectorPathIndex = match.endPathIndex;
455
+ currentSelectorPathElementIndex = match.endPathElementIndex;
456
+ if (currentSelectorPathElementIndex >= selectorPath[currentSelectorPathIndex].elements.length) {
457
+ currentSelectorPathElementIndex = 0;
458
+ currentSelectorPathIndex++;
459
+ }
460
+ }
461
+
462
+ if (currentSelectorPathIndex < selectorPath.length && currentSelectorPathElementIndex > 0) {
463
+ path[path.length - 1].elements = path[path.length - 1]
464
+ .elements.concat(selectorPath[currentSelectorPathIndex].elements.slice(currentSelectorPathElementIndex));
465
+ currentSelectorPathIndex++;
466
+ }
467
+
468
+ path = path.concat(selectorPath.slice(currentSelectorPathIndex, selectorPath.length));
469
+ path = path.map(currentValue => {
470
+ // we can re-use elements here, because the visibility property matters only for selectors
471
+ const derived = currentValue.createDerived(currentValue.elements);
472
+ if (isVisible) {
473
+ derived.ensureVisibility();
474
+ } else {
475
+ derived.ensureInvisibility();
476
+ }
477
+ return derived;
478
+ });
479
+ return path;
480
+ }
481
+
482
+ visitMedia(mediaNode, visitArgs) {
483
+ let newAllExtends = mediaNode.allExtends.concat(this.allExtendsStack[this.allExtendsStack.length - 1]);
484
+ newAllExtends = newAllExtends.concat(this.doExtendChaining(newAllExtends, mediaNode.allExtends));
485
+ this.allExtendsStack.push(newAllExtends);
486
+ }
487
+
488
+ visitMediaOut(mediaNode) {
489
+ const lastIndex = this.allExtendsStack.length - 1;
490
+ this.allExtendsStack.length = lastIndex;
491
+ }
492
+
493
+ visitAtRule(atRuleNode, visitArgs) {
494
+ let newAllExtends = atRuleNode.allExtends.concat(this.allExtendsStack[this.allExtendsStack.length - 1]);
495
+ newAllExtends = newAllExtends.concat(this.doExtendChaining(newAllExtends, atRuleNode.allExtends));
496
+ this.allExtendsStack.push(newAllExtends);
497
+ }
498
+
499
+ visitAtRuleOut(atRuleNode) {
500
+ const lastIndex = this.allExtendsStack.length - 1;
501
+ this.allExtendsStack.length = lastIndex;
502
+ }
503
+ }
504
+
505
+ export default ProcessExtendsVisitor;
@@ -0,0 +1,58 @@
1
+ class ImportSequencer {
2
+ constructor(onSequencerEmpty) {
3
+ this.imports = [];
4
+ this.variableImports = [];
5
+ this._onSequencerEmpty = onSequencerEmpty;
6
+ this._currentDepth = 0;
7
+ }
8
+
9
+ addImport(callback) {
10
+ const importSequencer = this;
11
+
12
+ const importItem = {
13
+ callback,
14
+ args: null,
15
+ isReady: false
16
+ };
17
+
18
+ this.imports.push(importItem);
19
+ return function(...args) {
20
+ importItem.args = Array.prototype.slice.call(args, 0);
21
+ importItem.isReady = true;
22
+ importSequencer.tryRun();
23
+ };
24
+ }
25
+
26
+ addVariableImport(callback) {
27
+ this.variableImports.push(callback);
28
+ }
29
+
30
+ tryRun() {
31
+ this._currentDepth++;
32
+ try {
33
+ while (true) {
34
+ while (this.imports.length > 0) {
35
+ const importItem = this.imports[0];
36
+ if (!importItem.isReady) {
37
+ return;
38
+ }
39
+ this.imports = this.imports.slice(1);
40
+ importItem.callback.apply(null, importItem.args);
41
+ }
42
+ if (this.variableImports.length === 0) {
43
+ break;
44
+ }
45
+ const variableImport = this.variableImports[0];
46
+ this.variableImports = this.variableImports.slice(1);
47
+ variableImport();
48
+ }
49
+ } finally {
50
+ this._currentDepth--;
51
+ }
52
+ if (this._currentDepth === 0 && this._onSequencerEmpty) {
53
+ this._onSequencerEmpty();
54
+ }
55
+ }
56
+ }
57
+
58
+ export default ImportSequencer;