less 4.8.1 → 5.0.0-alpha.1

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 (129) hide show
  1. package/README.md +19 -5
  2. package/bin/lessc +190 -630
  3. package/dist/less-node.cjs +398 -14282
  4. package/index.cjs +5 -2
  5. package/lib/index.js +164 -0
  6. package/lib/lessc-helper.js +52 -0
  7. package/lib/logger.js +76 -0
  8. package/lib/options.d.ts +46 -0
  9. package/lib/options.js +145 -0
  10. package/lib/types.js +20 -0
  11. package/lib/version.js +19 -0
  12. package/package.json +33 -40
  13. package/dist/less.cjs +0 -14929
  14. package/dist/less.js +0 -14929
  15. package/dist/less.min.js +0 -11
  16. package/dist/less.min.js.map +0 -1
  17. package/lib/less/constants.js +0 -13
  18. package/lib/less/contexts.js +0 -165
  19. package/lib/less/data/colors.js +0 -150
  20. package/lib/less/data/index.js +0 -4
  21. package/lib/less/data/unit-conversions.js +0 -21
  22. package/lib/less/default-options.js +0 -89
  23. package/lib/less/deprecation.js +0 -82
  24. package/lib/less/environment/abstract-file-manager.js +0 -140
  25. package/lib/less/environment/abstract-plugin-loader.js +0 -185
  26. package/lib/less/environment/environment-api.ts +0 -21
  27. package/lib/less/environment/environment.js +0 -59
  28. package/lib/less/environment/file-manager-api.ts +0 -77
  29. package/lib/less/functions/boolean.js +0 -29
  30. package/lib/less/functions/color-blending.js +0 -85
  31. package/lib/less/functions/color.js +0 -452
  32. package/lib/less/functions/data-uri.js +0 -74
  33. package/lib/less/functions/default.js +0 -26
  34. package/lib/less/functions/function-caller.js +0 -55
  35. package/lib/less/functions/function-registry.js +0 -36
  36. package/lib/less/functions/index.js +0 -35
  37. package/lib/less/functions/list.js +0 -158
  38. package/lib/less/functions/math-helper.js +0 -22
  39. package/lib/less/functions/math.js +0 -30
  40. package/lib/less/functions/number.js +0 -95
  41. package/lib/less/functions/string.js +0 -36
  42. package/lib/less/functions/style.js +0 -29
  43. package/lib/less/functions/svg.js +0 -87
  44. package/lib/less/functions/types.js +0 -70
  45. package/lib/less/import-manager.js +0 -183
  46. package/lib/less/index.js +0 -95
  47. package/lib/less/less-error.js +0 -166
  48. package/lib/less/logger.js +0 -34
  49. package/lib/less/parse-tree.js +0 -124
  50. package/lib/less/parse.js +0 -87
  51. package/lib/less/parser/parser-input.js +0 -400
  52. package/lib/less/parser/parser.js +0 -2894
  53. package/lib/less/plugin-manager.js +0 -168
  54. package/lib/less/render.js +0 -41
  55. package/lib/less/source-map-builder.js +0 -82
  56. package/lib/less/source-map-output.js +0 -151
  57. package/lib/less/transform-tree.js +0 -102
  58. package/lib/less/tree/anonymous.js +0 -57
  59. package/lib/less/tree/assignment.js +0 -48
  60. package/lib/less/tree/atrule-syntax.js +0 -8
  61. package/lib/less/tree/atrule.js +0 -340
  62. package/lib/less/tree/attribute.js +0 -63
  63. package/lib/less/tree/call.js +0 -132
  64. package/lib/less/tree/color.js +0 -285
  65. package/lib/less/tree/combinator.js +0 -38
  66. package/lib/less/tree/comment.js +0 -48
  67. package/lib/less/tree/condition.js +0 -65
  68. package/lib/less/tree/container.js +0 -104
  69. package/lib/less/tree/debug-info.js +0 -80
  70. package/lib/less/tree/declaration.js +0 -139
  71. package/lib/less/tree/detached-ruleset.js +0 -45
  72. package/lib/less/tree/dimension.js +0 -215
  73. package/lib/less/tree/element.js +0 -93
  74. package/lib/less/tree/expression.js +0 -100
  75. package/lib/less/tree/extend.js +0 -88
  76. package/lib/less/tree/import.js +0 -299
  77. package/lib/less/tree/index.js +0 -56
  78. package/lib/less/tree/javascript.js +0 -45
  79. package/lib/less/tree/js-eval-node.js +0 -74
  80. package/lib/less/tree/keyword.js +0 -28
  81. package/lib/less/tree/media.js +0 -90
  82. package/lib/less/tree/merge-rules.js +0 -47
  83. package/lib/less/tree/mixin-call.js +0 -283
  84. package/lib/less/tree/mixin-definition.js +0 -319
  85. package/lib/less/tree/namespace-value.js +0 -95
  86. package/lib/less/tree/negative.js +0 -37
  87. package/lib/less/tree/nested-at-rule.js +0 -198
  88. package/lib/less/tree/node.js +0 -310
  89. package/lib/less/tree/operation.js +0 -81
  90. package/lib/less/tree/paren.js +0 -41
  91. package/lib/less/tree/property.js +0 -96
  92. package/lib/less/tree/query-in-parens.js +0 -64
  93. package/lib/less/tree/quoted.js +0 -114
  94. package/lib/less/tree/ruleset.js +0 -1066
  95. package/lib/less/tree/selector.js +0 -201
  96. package/lib/less/tree/unicode-descriptor.js +0 -14
  97. package/lib/less/tree/unit.js +0 -170
  98. package/lib/less/tree/url.js +0 -83
  99. package/lib/less/tree/value.js +0 -60
  100. package/lib/less/tree/variable-call.js +0 -60
  101. package/lib/less/tree/variable.js +0 -85
  102. package/lib/less/utils.js +0 -126
  103. package/lib/less/visitors/extend-visitor.js +0 -505
  104. package/lib/less/visitors/import-sequencer.js +0 -56
  105. package/lib/less/visitors/import-visitor.js +0 -203
  106. package/lib/less/visitors/index.js +0 -15
  107. package/lib/less/visitors/join-selector-visitor.js +0 -65
  108. package/lib/less/visitors/set-tree-visibility-visitor.js +0 -57
  109. package/lib/less/visitors/to-css-visitor.js +0 -332
  110. package/lib/less/visitors/visitor.js +0 -165
  111. package/lib/less-browser/add-default-options.js +0 -53
  112. package/lib/less-browser/bootstrap.js +0 -67
  113. package/lib/less-browser/browser.js +0 -65
  114. package/lib/less-browser/cache.js +0 -43
  115. package/lib/less-browser/error-reporting.js +0 -170
  116. package/lib/less-browser/file-manager.js +0 -112
  117. package/lib/less-browser/image-size.js +0 -28
  118. package/lib/less-browser/index.js +0 -284
  119. package/lib/less-browser/log-listener.js +0 -42
  120. package/lib/less-browser/plugin-loader.js +0 -24
  121. package/lib/less-browser/utils.js +0 -30
  122. package/lib/less-node/environment.js +0 -43
  123. package/lib/less-node/file-manager.js +0 -156
  124. package/lib/less-node/fs.js +0 -14
  125. package/lib/less-node/image-size.js +0 -78
  126. package/lib/less-node/index.js +0 -31
  127. package/lib/less-node/lessc-helper.js +0 -95
  128. package/lib/less-node/plugin-loader.js +0 -62
  129. package/lib/less-node/url-file-manager.js +0 -60
@@ -1,400 +0,0 @@
1
- export default () => {
2
- let // Less input string
3
- input;
4
-
5
- let // current chunk
6
- j;
7
-
8
- const // holds state for backtracking
9
- saveStack = [];
10
-
11
- let // furthest index the parser has gone to
12
- furthest;
13
-
14
- let // if this is furthest we got to, this is the probably cause
15
- furthestPossibleErrorMessage;
16
-
17
- let // chunkified input
18
- chunks;
19
-
20
- let // current chunk
21
- current;
22
-
23
- let // index of current chunk, in `input`
24
- currentPos;
25
-
26
- const parserInput = {};
27
- const CHARCODE_SPACE = 32;
28
- const CHARCODE_TAB = 9;
29
- const CHARCODE_LF = 10;
30
- const CHARCODE_CR = 13;
31
- const CHARCODE_PLUS = 43;
32
- const CHARCODE_COMMA = 44;
33
- const CHARCODE_FORWARD_SLASH = 47;
34
- const CHARCODE_9 = 57;
35
-
36
- function skipWhitespace(length) {
37
- const oldi = parserInput.i;
38
- const oldj = j;
39
- const curr = parserInput.i - currentPos;
40
- const endIndex = parserInput.i + current.length - curr;
41
- const mem = (parserInput.i += length);
42
- const inp = input;
43
- let c;
44
- let nextChar;
45
- let comment;
46
-
47
- for (; parserInput.i < endIndex; parserInput.i++) {
48
- c = inp.charCodeAt(parserInput.i);
49
-
50
- if (parserInput.autoCommentAbsorb && c === CHARCODE_FORWARD_SLASH) {
51
- nextChar = inp.charAt(parserInput.i + 1);
52
- if (nextChar === '/') {
53
- comment = {index: parserInput.i, isLineComment: true};
54
- let nextNewLine = inp.indexOf('\n', parserInput.i + 2);
55
- if (nextNewLine < 0) {
56
- nextNewLine = endIndex;
57
- }
58
- parserInput.i = nextNewLine;
59
- comment.text = inp.slice(comment.index, parserInput.i);
60
- parserInput.commentStore.push(comment);
61
- continue;
62
- } else if (nextChar === '*') {
63
- const nextStarSlash = inp.indexOf('*/', parserInput.i + 2);
64
- if (nextStarSlash >= 0) {
65
- comment = {
66
- index: parserInput.i,
67
- text: inp.slice(parserInput.i, nextStarSlash + 2),
68
- isLineComment: false
69
- };
70
- parserInput.i += comment.text.length - 1;
71
- parserInput.commentStore.push(comment);
72
- continue;
73
- }
74
- }
75
- break;
76
- }
77
-
78
- if ((c !== CHARCODE_SPACE) && (c !== CHARCODE_LF) && (c !== CHARCODE_TAB) && (c !== CHARCODE_CR)) {
79
- break;
80
- }
81
- }
82
-
83
- current = current.slice(length + parserInput.i - mem + curr);
84
- currentPos = parserInput.i;
85
-
86
- if (!current.length) {
87
- if (j < chunks.length - 1) {
88
- current = chunks[++j];
89
- skipWhitespace(0); // skip space at the beginning of a chunk
90
- return true; // things changed
91
- }
92
- parserInput.finished = true;
93
- }
94
-
95
- return oldi !== parserInput.i || oldj !== j;
96
- }
97
-
98
- parserInput.save = () => {
99
- currentPos = parserInput.i;
100
- saveStack.push( { current, i: parserInput.i, j });
101
- };
102
- parserInput.restore = possibleErrorMessage => {
103
-
104
- if (parserInput.i > furthest || (parserInput.i === furthest && possibleErrorMessage && !furthestPossibleErrorMessage)) {
105
- furthest = parserInput.i;
106
- furthestPossibleErrorMessage = possibleErrorMessage;
107
- }
108
- const state = saveStack.pop();
109
- current = state.current;
110
- currentPos = parserInput.i = state.i;
111
- j = state.j;
112
- };
113
- parserInput.forget = () => {
114
- saveStack.pop();
115
- };
116
- parserInput.isWhitespace = offset => {
117
- const pos = parserInput.i + (offset || 0);
118
- const code = input.charCodeAt(pos);
119
- return (code === CHARCODE_SPACE || code === CHARCODE_CR || code === CHARCODE_TAB || code === CHARCODE_LF);
120
- };
121
-
122
- // Specialization of $(tok)
123
- parserInput.$re = tok => {
124
- if (parserInput.i > currentPos) {
125
- current = current.slice(parserInput.i - currentPos);
126
- currentPos = parserInput.i;
127
- }
128
-
129
- const m = tok.exec(current);
130
- if (!m) {
131
- return null;
132
- }
133
-
134
- skipWhitespace(m[0].length);
135
- if (typeof m === 'string') {
136
- return m;
137
- }
138
-
139
- return m.length === 1 ? m[0] : m;
140
- };
141
-
142
- parserInput.$char = tok => {
143
- if (input.charAt(parserInput.i) !== tok) {
144
- return null;
145
- }
146
- skipWhitespace(1);
147
- return tok;
148
- };
149
-
150
- parserInput.$peekChar = tok => {
151
- if (input.charAt(parserInput.i) !== tok) {
152
- return null;
153
- }
154
- return tok;
155
- };
156
-
157
- parserInput.$str = tok => {
158
- const tokLength = tok.length;
159
-
160
- // https://jsperf.com/string-startswith/21
161
- for (let i = 0; i < tokLength; i++) {
162
- if (input.charAt(parserInput.i + i) !== tok.charAt(i)) {
163
- return null;
164
- }
165
- }
166
-
167
- skipWhitespace(tokLength);
168
- return tok;
169
- };
170
-
171
- parserInput.$quoted = loc => {
172
- const pos = loc || parserInput.i;
173
- const startChar = input.charAt(pos);
174
-
175
- if (startChar !== '\'' && startChar !== '"') {
176
- return;
177
- }
178
- const length = input.length;
179
- const currentPosition = pos;
180
-
181
- for (let i = 1; i + currentPosition < length; i++) {
182
- const nextChar = input.charAt(i + currentPosition);
183
- switch (nextChar) {
184
- case '\\':
185
- i++;
186
- continue;
187
- case '\r':
188
- case '\n':
189
- break;
190
- case startChar: {
191
- const str = input.slice(currentPosition, currentPosition + i + 1);
192
- if (!loc && loc !== 0) {
193
- skipWhitespace(i + 1);
194
- return str
195
- }
196
- return [startChar, str];
197
- }
198
- default:
199
- }
200
- }
201
- return null;
202
- };
203
-
204
- /**
205
- * Permissive parsing. Ignores everything except matching {} [] () and quotes
206
- * until matching token (outside of blocks)
207
- *
208
- * @param {string|RegExp} tok - stop token
209
- * @param {boolean} [detectBareVar] - when set, also record the position of the
210
- * first bare `@variable` reference (not `@{interpolation}`) that appears at
211
- * PAREN depth 0 — i.e. a structural reference, not a declaration value inside
212
- * `(...)`. Reuses this single pass (which already skips strings/comments) so
213
- * callers don't re-scan the text. Exposed as `.bareVarIndex` on the returned
214
- * group array (or null). `[...]`/`{...}` do NOT shield a reference — only
215
- * `(...)` (a declaration-value group) does.
216
- */
217
- parserInput.$parseUntil = (tok, detectBareVar) => {
218
- let quote = '';
219
- let returnVal = null;
220
- let inComment = false;
221
- let blockDepth = 0;
222
- let parenDepth = 0;
223
- let bareVarIndex = null;
224
- const blockStack = [];
225
- const parseGroups = [];
226
- const length = input.length;
227
- const startPos = parserInput.i;
228
- let lastPos = parserInput.i;
229
- let i = parserInput.i;
230
- let loop = true;
231
- let testChar;
232
-
233
- if (typeof tok === 'string') {
234
- testChar = char => char === tok
235
- } else {
236
- testChar = char => tok.test(char)
237
- }
238
-
239
- do {
240
- let nextChar = input.charAt(i);
241
- if (blockDepth === 0 && testChar(nextChar)) {
242
- returnVal = input.slice(lastPos, i);
243
- if (returnVal) {
244
- parseGroups.push(returnVal);
245
- }
246
- else {
247
- parseGroups.push(' ');
248
- }
249
- returnVal = parseGroups;
250
- skipWhitespace(i - startPos);
251
- loop = false
252
- } else {
253
- if (inComment) {
254
- if (nextChar === '*' &&
255
- input.charAt(i + 1) === '/') {
256
- i++;
257
- blockDepth--;
258
- inComment = false;
259
- }
260
- i++;
261
- continue;
262
- }
263
- if (detectBareVar && bareVarIndex === null && nextChar === '@' && parenDepth === 0) {
264
- // A bare `@ident` (not `@{interpolation}`) outside any `(...)` —
265
- // a structural reference. Strings/comments are already skipped above.
266
- const after = input.charAt(i + 1);
267
- if (after && /[-\w]/.test(after)) { bareVarIndex = i; }
268
- }
269
- switch (nextChar) {
270
- case '\\':
271
- i++;
272
- nextChar = input.charAt(i);
273
- parseGroups.push(input.slice(lastPos, i + 1));
274
- lastPos = i + 1;
275
- break;
276
- case '/':
277
- if (input.charAt(i + 1) === '*') {
278
- i++;
279
- inComment = true;
280
- blockDepth++;
281
- }
282
- break;
283
- case '\'':
284
- case '"':
285
- quote = parserInput.$quoted(i);
286
- if (quote) {
287
- parseGroups.push(input.slice(lastPos, i), quote);
288
- i += quote[1].length - 1;
289
- lastPos = i + 1;
290
- }
291
- else {
292
- skipWhitespace(i - startPos);
293
- returnVal = nextChar;
294
- loop = false;
295
- }
296
- break;
297
- case '{':
298
- blockStack.push('}');
299
- blockDepth++;
300
- break;
301
- case '(':
302
- blockStack.push(')');
303
- blockDepth++;
304
- parenDepth++;
305
- break;
306
- case '[':
307
- blockStack.push(']');
308
- blockDepth++;
309
- break;
310
- case '}':
311
- case ')':
312
- case ']': {
313
- const expected = blockStack.pop();
314
- if (nextChar === expected) {
315
- blockDepth--;
316
- if (nextChar === ')' && parenDepth > 0) { parenDepth--; }
317
- } else {
318
- // move the parser to the error and return expected
319
- skipWhitespace(i - startPos);
320
- returnVal = expected;
321
- loop = false;
322
- }
323
- }
324
- }
325
- i++;
326
- if (i > length) {
327
- loop = false;
328
- }
329
- }
330
- } while (loop);
331
-
332
- if (Array.isArray(returnVal)) { returnVal.bareVarIndex = bareVarIndex; }
333
- return returnVal ? returnVal : null;
334
- }
335
-
336
- parserInput.autoCommentAbsorb = true;
337
- parserInput.commentStore = [];
338
- parserInput.finished = false;
339
-
340
- // Same as $(), but don't change the state of the parser,
341
- // just return the match.
342
- parserInput.peek = tok => {
343
- if (typeof tok === 'string') {
344
- // https://jsperf.com/string-startswith/21
345
- for (let i = 0; i < tok.length; i++) {
346
- if (input.charAt(parserInput.i + i) !== tok.charAt(i)) {
347
- return false;
348
- }
349
- }
350
- return true;
351
- } else {
352
- return tok.test(current);
353
- }
354
- };
355
-
356
- // Specialization of peek()
357
- // TODO remove or change some currentChar calls to peekChar
358
- parserInput.peekChar = tok => input.charAt(parserInput.i) === tok;
359
-
360
- parserInput.currentChar = () => input.charAt(parserInput.i);
361
-
362
- parserInput.prevChar = () => input.charAt(parserInput.i - 1);
363
-
364
- parserInput.getInput = () => input;
365
-
366
- parserInput.peekNotNumeric = () => {
367
- const c = input.charCodeAt(parserInput.i);
368
- // Is the first char of the dimension 0-9, '.', '+' or '-'
369
- return (c > CHARCODE_9 || c < CHARCODE_PLUS) || c === CHARCODE_FORWARD_SLASH || c === CHARCODE_COMMA;
370
- };
371
-
372
- parserInput.start = (str) => {
373
- input = str;
374
- parserInput.i = j = currentPos = furthest = 0;
375
-
376
- chunks = [str];
377
- current = chunks[0];
378
-
379
- skipWhitespace(0);
380
- };
381
-
382
- parserInput.end = () => {
383
- let message;
384
- const isFinished = parserInput.i >= input.length;
385
-
386
- if (parserInput.i < furthest) {
387
- message = furthestPossibleErrorMessage;
388
- parserInput.i = furthest;
389
- }
390
- return {
391
- isFinished,
392
- furthest: parserInput.i,
393
- furthestPossibleErrorMessage: message,
394
- furthestReachedEnd: parserInput.i >= input.length - 1,
395
- furthestChar: input[parserInput.i]
396
- };
397
- };
398
-
399
- return parserInput;
400
- };