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,390 @@
1
+ import chunker from './chunker';
2
+
3
+ export default () => {
4
+ let // Less input string
5
+ input;
6
+
7
+ let // current chunk
8
+ j;
9
+
10
+ const // holds state for backtracking
11
+ saveStack = [];
12
+
13
+ let // furthest index the parser has gone to
14
+ furthest;
15
+
16
+ let // if this is furthest we got to, this is the probably cause
17
+ furthestPossibleErrorMessage;
18
+
19
+ let // chunkified input
20
+ chunks;
21
+
22
+ let // current chunk
23
+ current;
24
+
25
+ let // index of current chunk, in `input`
26
+ currentPos;
27
+
28
+ const parserInput = {};
29
+ const CHARCODE_SPACE = 32;
30
+ const CHARCODE_TAB = 9;
31
+ const CHARCODE_LF = 10;
32
+ const CHARCODE_CR = 13;
33
+ const CHARCODE_PLUS = 43;
34
+ const CHARCODE_COMMA = 44;
35
+ const CHARCODE_FORWARD_SLASH = 47;
36
+ const CHARCODE_9 = 57;
37
+
38
+ function skipWhitespace(length) {
39
+ const oldi = parserInput.i;
40
+ const oldj = j;
41
+ const curr = parserInput.i - currentPos;
42
+ const endIndex = parserInput.i + current.length - curr;
43
+ const mem = (parserInput.i += length);
44
+ const inp = input;
45
+ let c;
46
+ let nextChar;
47
+ let comment;
48
+
49
+ for (; parserInput.i < endIndex; parserInput.i++) {
50
+ c = inp.charCodeAt(parserInput.i);
51
+
52
+ if (parserInput.autoCommentAbsorb && c === CHARCODE_FORWARD_SLASH) {
53
+ nextChar = inp.charAt(parserInput.i + 1);
54
+ if (nextChar === '/') {
55
+ comment = {index: parserInput.i, isLineComment: true};
56
+ let nextNewLine = inp.indexOf('\n', parserInput.i + 2);
57
+ if (nextNewLine < 0) {
58
+ nextNewLine = endIndex;
59
+ }
60
+ parserInput.i = nextNewLine;
61
+ comment.text = inp.substr(comment.index, parserInput.i - comment.index);
62
+ parserInput.commentStore.push(comment);
63
+ continue;
64
+ } else if (nextChar === '*') {
65
+ const nextStarSlash = inp.indexOf('*/', parserInput.i + 2);
66
+ if (nextStarSlash >= 0) {
67
+ comment = {
68
+ index: parserInput.i,
69
+ text: inp.substr(parserInput.i, nextStarSlash + 2 - parserInput.i),
70
+ isLineComment: false
71
+ };
72
+ parserInput.i += comment.text.length - 1;
73
+ parserInput.commentStore.push(comment);
74
+ continue;
75
+ }
76
+ }
77
+ break;
78
+ }
79
+
80
+ if ((c !== CHARCODE_SPACE) && (c !== CHARCODE_LF) && (c !== CHARCODE_TAB) && (c !== CHARCODE_CR)) {
81
+ break;
82
+ }
83
+ }
84
+
85
+ current = current.slice(length + parserInput.i - mem + curr);
86
+ currentPos = parserInput.i;
87
+
88
+ if (!current.length) {
89
+ if (j < chunks.length - 1) {
90
+ current = chunks[++j];
91
+ skipWhitespace(0); // skip space at the beginning of a chunk
92
+ return true; // things changed
93
+ }
94
+ parserInput.finished = true;
95
+ }
96
+
97
+ return oldi !== parserInput.i || oldj !== j;
98
+ }
99
+
100
+ parserInput.save = () => {
101
+ currentPos = parserInput.i;
102
+ saveStack.push( { current, i: parserInput.i, j });
103
+ };
104
+ parserInput.restore = possibleErrorMessage => {
105
+
106
+ if (parserInput.i > furthest || (parserInput.i === furthest && possibleErrorMessage && !furthestPossibleErrorMessage)) {
107
+ furthest = parserInput.i;
108
+ furthestPossibleErrorMessage = possibleErrorMessage;
109
+ }
110
+ const state = saveStack.pop();
111
+ current = state.current;
112
+ currentPos = parserInput.i = state.i;
113
+ j = state.j;
114
+ };
115
+ parserInput.forget = () => {
116
+ saveStack.pop();
117
+ };
118
+ parserInput.isWhitespace = offset => {
119
+ const pos = parserInput.i + (offset || 0);
120
+ const code = input.charCodeAt(pos);
121
+ return (code === CHARCODE_SPACE || code === CHARCODE_CR || code === CHARCODE_TAB || code === CHARCODE_LF);
122
+ };
123
+
124
+ // Specialization of $(tok)
125
+ parserInput.$re = tok => {
126
+ if (parserInput.i > currentPos) {
127
+ current = current.slice(parserInput.i - currentPos);
128
+ currentPos = parserInput.i;
129
+ }
130
+
131
+ const m = tok.exec(current);
132
+ if (!m) {
133
+ return null;
134
+ }
135
+
136
+ skipWhitespace(m[0].length);
137
+ if (typeof m === 'string') {
138
+ return m;
139
+ }
140
+
141
+ return m.length === 1 ? m[0] : m;
142
+ };
143
+
144
+ parserInput.$char = tok => {
145
+ if (input.charAt(parserInput.i) !== tok) {
146
+ return null;
147
+ }
148
+ skipWhitespace(1);
149
+ return tok;
150
+ };
151
+
152
+ parserInput.$str = tok => {
153
+ const tokLength = tok.length;
154
+
155
+ // https://jsperf.com/string-startswith/21
156
+ for (let i = 0; i < tokLength; i++) {
157
+ if (input.charAt(parserInput.i + i) !== tok.charAt(i)) {
158
+ return null;
159
+ }
160
+ }
161
+
162
+ skipWhitespace(tokLength);
163
+ return tok;
164
+ };
165
+
166
+ parserInput.$quoted = loc => {
167
+ const pos = loc || parserInput.i;
168
+ const startChar = input.charAt(pos);
169
+
170
+ if (startChar !== '\'' && startChar !== '"') {
171
+ return;
172
+ }
173
+ const length = input.length;
174
+ const currentPosition = pos;
175
+
176
+ for (let i = 1; i + currentPosition < length; i++) {
177
+ const nextChar = input.charAt(i + currentPosition);
178
+ switch (nextChar) {
179
+ case '\\':
180
+ i++;
181
+ continue;
182
+ case '\r':
183
+ case '\n':
184
+ break;
185
+ case startChar:
186
+ const str = input.substr(currentPosition, i + 1);
187
+ if (!loc && loc !== 0) {
188
+ skipWhitespace(i + 1);
189
+ return str
190
+ }
191
+ return [startChar, str];
192
+ default:
193
+ }
194
+ }
195
+ return null;
196
+ };
197
+
198
+ /**
199
+ * Permissive parsing. Ignores everything except matching {} [] () and quotes
200
+ * until matching token (outside of blocks)
201
+ */
202
+ parserInput.$parseUntil = tok => {
203
+ let quote = '';
204
+ let returnVal = null;
205
+ let inComment = false;
206
+ let blockDepth = 0;
207
+ const blockStack = [];
208
+ const parseGroups = [];
209
+ const length = input.length;
210
+ const startPos = parserInput.i;
211
+ let lastPos = parserInput.i;
212
+ let i = parserInput.i;
213
+ let loop = true;
214
+ let testChar;
215
+
216
+ if (typeof tok === 'string') {
217
+ testChar = char => char === tok
218
+ } else {
219
+ testChar = char => tok.test(char)
220
+ }
221
+
222
+ do {
223
+ let prevChar;
224
+ let nextChar = input.charAt(i);
225
+ if (blockDepth === 0 && testChar(nextChar)) {
226
+ returnVal = input.substr(lastPos, i - lastPos);
227
+ if (returnVal) {
228
+ parseGroups.push(returnVal);
229
+ }
230
+ else {
231
+ parseGroups.push(' ');
232
+ }
233
+ returnVal = parseGroups;
234
+ skipWhitespace(i - startPos);
235
+ loop = false
236
+ } else {
237
+ if (inComment) {
238
+ if (nextChar === '*' &&
239
+ input.charAt(i + 1) === '/') {
240
+ i++;
241
+ blockDepth--;
242
+ inComment = false;
243
+ }
244
+ i++;
245
+ continue;
246
+ }
247
+ switch (nextChar) {
248
+ case '\\':
249
+ i++;
250
+ nextChar = input.charAt(i);
251
+ parseGroups.push(input.substr(lastPos, i - lastPos + 1));
252
+ lastPos = i + 1;
253
+ break;
254
+ case '/':
255
+ if (input.charAt(i + 1) === '*') {
256
+ i++;
257
+ inComment = true;
258
+ blockDepth++;
259
+ }
260
+ break;
261
+ case '\'':
262
+ case '"':
263
+ quote = parserInput.$quoted(i);
264
+ if (quote) {
265
+ parseGroups.push(input.substr(lastPos, i - lastPos), quote);
266
+ i += quote[1].length - 1;
267
+ lastPos = i + 1;
268
+ }
269
+ else {
270
+ skipWhitespace(i - startPos);
271
+ returnVal = nextChar;
272
+ loop = false;
273
+ }
274
+ break;
275
+ case '{':
276
+ blockStack.push('}');
277
+ blockDepth++;
278
+ break;
279
+ case '(':
280
+ blockStack.push(')');
281
+ blockDepth++;
282
+ break;
283
+ case '[':
284
+ blockStack.push(']');
285
+ blockDepth++;
286
+ break;
287
+ case '}':
288
+ case ')':
289
+ case ']':
290
+ const expected = blockStack.pop();
291
+ if (nextChar === expected) {
292
+ blockDepth--;
293
+ } else {
294
+ // move the parser to the error and return expected
295
+ skipWhitespace(i - startPos);
296
+ returnVal = expected;
297
+ loop = false;
298
+ }
299
+ }
300
+ i++;
301
+ if (i > length) {
302
+ loop = false;
303
+ }
304
+ }
305
+ prevChar = nextChar;
306
+ } while (loop);
307
+
308
+ return returnVal ? returnVal : null;
309
+ }
310
+
311
+ parserInput.autoCommentAbsorb = true;
312
+ parserInput.commentStore = [];
313
+ parserInput.finished = false;
314
+
315
+ // Same as $(), but don't change the state of the parser,
316
+ // just return the match.
317
+ parserInput.peek = tok => {
318
+ if (typeof tok === 'string') {
319
+ // https://jsperf.com/string-startswith/21
320
+ for (let i = 0; i < tok.length; i++) {
321
+ if (input.charAt(parserInput.i + i) !== tok.charAt(i)) {
322
+ return false;
323
+ }
324
+ }
325
+ return true;
326
+ } else {
327
+ return tok.test(current);
328
+ }
329
+ };
330
+
331
+ // Specialization of peek()
332
+ // TODO remove or change some currentChar calls to peekChar
333
+ parserInput.peekChar = tok => input.charAt(parserInput.i) === tok;
334
+
335
+ parserInput.currentChar = () => input.charAt(parserInput.i);
336
+
337
+ parserInput.prevChar = () => input.charAt(parserInput.i - 1);
338
+
339
+ parserInput.getInput = () => input;
340
+
341
+ parserInput.peekNotNumeric = () => {
342
+ const c = input.charCodeAt(parserInput.i);
343
+ // Is the first char of the dimension 0-9, '.', '+' or '-'
344
+ return (c > CHARCODE_9 || c < CHARCODE_PLUS) || c === CHARCODE_FORWARD_SLASH || c === CHARCODE_COMMA;
345
+ };
346
+
347
+ parserInput.start = (str, chunkInput, failFunction) => {
348
+ input = str;
349
+ parserInput.i = j = currentPos = furthest = 0;
350
+
351
+ // chunking apparently makes things quicker (but my tests indicate
352
+ // it might actually make things slower in node at least)
353
+ // and it is a non-perfect parse - it can't recognise
354
+ // unquoted urls, meaning it can't distinguish comments
355
+ // meaning comments with quotes or {}() in them get 'counted'
356
+ // and then lead to parse errors.
357
+ // In addition if the chunking chunks in the wrong place we might
358
+ // not be able to parse a parser statement in one go
359
+ // this is officially deprecated but can be switched on via an option
360
+ // in the case it causes too much performance issues.
361
+ if (chunkInput) {
362
+ chunks = chunker(str, failFunction);
363
+ } else {
364
+ chunks = [str];
365
+ }
366
+
367
+ current = chunks[0];
368
+
369
+ skipWhitespace(0);
370
+ };
371
+
372
+ parserInput.end = () => {
373
+ let message;
374
+ const isFinished = parserInput.i >= input.length;
375
+
376
+ if (parserInput.i < furthest) {
377
+ message = furthestPossibleErrorMessage;
378
+ parserInput.i = furthest;
379
+ }
380
+ return {
381
+ isFinished,
382
+ furthest: parserInput.i,
383
+ furthestPossibleErrorMessage: message,
384
+ furthestReachedEnd: parserInput.i >= input.length - 1,
385
+ furthestChar: input[parserInput.i]
386
+ };
387
+ };
388
+
389
+ return parserInput;
390
+ };