less 4.4.2 → 4.6.0

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 (333) hide show
  1. package/bin/lessc +67 -58
  2. package/dist/less.js +14496 -11811
  3. package/dist/less.min.js +4 -4
  4. package/dist/less.min.js.map +1 -1
  5. package/lib/less/constants.js +5 -7
  6. package/lib/less/contexts.js +71 -56
  7. package/lib/less/data/colors.js +150 -153
  8. package/lib/less/data/index.js +4 -7
  9. package/lib/less/data/unit-conversions.js +2 -5
  10. package/lib/less/default-options.js +52 -23
  11. package/lib/less/deprecation.js +67 -0
  12. package/lib/less/environment/abstract-file-manager.js +62 -50
  13. package/lib/less/environment/abstract-plugin-loader.js +69 -46
  14. package/lib/less/environment/environment-api.ts +21 -0
  15. package/lib/less/environment/environment.js +34 -30
  16. package/lib/less/environment/file-manager-api.ts +77 -0
  17. package/lib/less/functions/boolean.js +13 -13
  18. package/lib/less/functions/color-blending.js +39 -31
  19. package/lib/less/functions/color.js +153 -137
  20. package/lib/less/functions/data-uri.js +73 -64
  21. package/lib/less/functions/default.js +9 -11
  22. package/lib/less/functions/function-caller.js +35 -34
  23. package/lib/less/functions/function-registry.js +16 -17
  24. package/lib/less/functions/index.js +33 -33
  25. package/lib/less/functions/list.js +88 -75
  26. package/lib/less/functions/math-helper.js +8 -11
  27. package/lib/less/functions/math.js +21 -21
  28. package/lib/less/functions/number.js +42 -53
  29. package/lib/less/functions/string.js +18 -22
  30. package/lib/less/functions/style.js +21 -20
  31. package/lib/less/functions/svg.js +83 -82
  32. package/lib/less/functions/types.js +28 -32
  33. package/lib/less/import-manager.js +73 -64
  34. package/lib/less/index.js +65 -65
  35. package/lib/less/less-error.js +65 -46
  36. package/lib/less/logger.js +11 -14
  37. package/lib/less/parse-tree.js +94 -38
  38. package/lib/less/parse.js +44 -44
  39. package/lib/less/parser/parser-input.js +152 -131
  40. package/lib/less/parser/parser.js +866 -672
  41. package/lib/less/plugin-manager.js +57 -46
  42. package/lib/less/render.js +17 -23
  43. package/lib/less/source-map-builder.js +52 -43
  44. package/lib/less/source-map-output.js +57 -44
  45. package/lib/less/transform-tree.js +40 -30
  46. package/lib/less/tree/anonymous.js +52 -28
  47. package/lib/less/tree/assignment.js +44 -27
  48. package/lib/less/tree/atrule-syntax.js +4 -6
  49. package/lib/less/tree/atrule.js +247 -140
  50. package/lib/less/tree/attribute.js +55 -24
  51. package/lib/less/tree/call.js +70 -42
  52. package/lib/less/tree/color.js +194 -145
  53. package/lib/less/tree/combinator.js +31 -21
  54. package/lib/less/tree/comment.js +44 -23
  55. package/lib/less/tree/condition.js +61 -36
  56. package/lib/less/tree/container.js +90 -34
  57. package/lib/less/tree/debug-info.js +53 -11
  58. package/lib/less/tree/declaration.js +97 -52
  59. package/lib/less/tree/detached-ruleset.js +42 -24
  60. package/lib/less/tree/dimension.js +127 -71
  61. package/lib/less/tree/element.js +82 -52
  62. package/lib/less/tree/expression.js +75 -50
  63. package/lib/less/tree/extend.js +71 -42
  64. package/lib/less/tree/import.js +184 -110
  65. package/lib/less/tree/index.js +52 -81
  66. package/lib/less/tree/javascript.js +43 -32
  67. package/lib/less/tree/js-eval-node.js +46 -32
  68. package/lib/less/tree/keyword.js +25 -17
  69. package/lib/less/tree/media.js +77 -35
  70. package/lib/less/tree/merge-rules.js +47 -0
  71. package/lib/less/tree/mixin-call.js +181 -98
  72. package/lib/less/tree/mixin-definition.js +211 -117
  73. package/lib/less/tree/namespace-value.js +63 -44
  74. package/lib/less/tree/negative.js +34 -21
  75. package/lib/less/tree/nested-at-rule.js +149 -66
  76. package/lib/less/tree/node.js +225 -90
  77. package/lib/less/tree/operation.js +59 -34
  78. package/lib/less/tree/paren.js +34 -17
  79. package/lib/less/tree/property.js +66 -35
  80. package/lib/less/tree/query-in-parens.js +52 -60
  81. package/lib/less/tree/quoted.js +93 -44
  82. package/lib/less/tree/ruleset.js +632 -318
  83. package/lib/less/tree/selector.js +151 -77
  84. package/lib/less/tree/unicode-descriptor.js +14 -12
  85. package/lib/less/tree/unit.js +111 -63
  86. package/lib/less/tree/url.js +62 -38
  87. package/lib/less/tree/value.js +50 -34
  88. package/lib/less/tree/variable-call.js +47 -30
  89. package/lib/less/tree/variable.js +53 -31
  90. package/lib/less/utils.js +44 -47
  91. package/lib/less/visitors/extend-visitor.js +233 -172
  92. package/lib/less/visitors/import-sequencer.js +24 -24
  93. package/lib/less/visitors/import-visitor.js +62 -52
  94. package/lib/less/visitors/index.js +14 -17
  95. package/lib/less/visitors/join-selector-visitor.js +40 -37
  96. package/lib/less/visitors/set-tree-visibility-visitor.js +32 -18
  97. package/lib/less/visitors/to-css-visitor.js +135 -128
  98. package/lib/less/visitors/visitor.js +60 -45
  99. package/lib/less-browser/add-default-options.js +23 -13
  100. package/lib/less-browser/bootstrap.js +23 -17
  101. package/lib/less-browser/browser.js +24 -21
  102. package/lib/less-browser/cache.js +17 -19
  103. package/lib/less-browser/error-reporting.js +52 -44
  104. package/lib/less-browser/file-manager.js +52 -42
  105. package/lib/less-browser/image-size.js +12 -12
  106. package/lib/less-browser/index.js +131 -105
  107. package/lib/less-browser/log-listener.js +30 -31
  108. package/lib/less-browser/plugin-loader.js +10 -10
  109. package/lib/less-browser/utils.js +19 -21
  110. package/lib/less-node/environment.js +32 -8
  111. package/lib/less-node/file-manager.js +62 -45
  112. package/lib/less-node/fs.js +11 -8
  113. package/lib/less-node/image-size.js +40 -31
  114. package/lib/less-node/index.js +28 -19
  115. package/lib/less-node/lessc-helper.js +28 -28
  116. package/lib/less-node/plugin-loader.js +35 -27
  117. package/lib/less-node/url-file-manager.js +33 -31
  118. package/package.json +31 -19
  119. package/.eslintignore +0 -6
  120. package/.eslintrc.js +0 -63
  121. package/Gruntfile.js +0 -404
  122. package/bower.json +0 -22
  123. package/lib/less/constants.js.map +0 -1
  124. package/lib/less/contexts.js.map +0 -1
  125. package/lib/less/data/colors.js.map +0 -1
  126. package/lib/less/data/index.js.map +0 -1
  127. package/lib/less/data/unit-conversions.js.map +0 -1
  128. package/lib/less/default-options.js.map +0 -1
  129. package/lib/less/environment/abstract-file-manager.js.map +0 -1
  130. package/lib/less/environment/abstract-plugin-loader.js.map +0 -1
  131. package/lib/less/environment/environment-api.js +0 -3
  132. package/lib/less/environment/environment-api.js.map +0 -1
  133. package/lib/less/environment/environment.js.map +0 -1
  134. package/lib/less/environment/file-manager-api.js +0 -3
  135. package/lib/less/environment/file-manager-api.js.map +0 -1
  136. package/lib/less/functions/boolean.js.map +0 -1
  137. package/lib/less/functions/color-blending.js.map +0 -1
  138. package/lib/less/functions/color.js.map +0 -1
  139. package/lib/less/functions/data-uri.js.map +0 -1
  140. package/lib/less/functions/default.js.map +0 -1
  141. package/lib/less/functions/function-caller.js.map +0 -1
  142. package/lib/less/functions/function-registry.js.map +0 -1
  143. package/lib/less/functions/index.js.map +0 -1
  144. package/lib/less/functions/list.js.map +0 -1
  145. package/lib/less/functions/math-helper.js.map +0 -1
  146. package/lib/less/functions/math.js.map +0 -1
  147. package/lib/less/functions/number.js.map +0 -1
  148. package/lib/less/functions/string.js.map +0 -1
  149. package/lib/less/functions/style.js.map +0 -1
  150. package/lib/less/functions/svg.js.map +0 -1
  151. package/lib/less/functions/types.js.map +0 -1
  152. package/lib/less/import-manager.js.map +0 -1
  153. package/lib/less/index.js.map +0 -1
  154. package/lib/less/less-error.js.map +0 -1
  155. package/lib/less/logger.js.map +0 -1
  156. package/lib/less/parse-tree.js.map +0 -1
  157. package/lib/less/parse.js.map +0 -1
  158. package/lib/less/parser/chunker.js +0 -148
  159. package/lib/less/parser/chunker.js.map +0 -1
  160. package/lib/less/parser/parser-input.js.map +0 -1
  161. package/lib/less/parser/parser.js.map +0 -1
  162. package/lib/less/plugin-manager.js.map +0 -1
  163. package/lib/less/render.js.map +0 -1
  164. package/lib/less/source-map-builder.js.map +0 -1
  165. package/lib/less/source-map-output.js.map +0 -1
  166. package/lib/less/transform-tree.js.map +0 -1
  167. package/lib/less/tree/anonymous.js.map +0 -1
  168. package/lib/less/tree/assignment.js.map +0 -1
  169. package/lib/less/tree/atrule-syntax.js.map +0 -1
  170. package/lib/less/tree/atrule.js.map +0 -1
  171. package/lib/less/tree/attribute.js.map +0 -1
  172. package/lib/less/tree/call.js.map +0 -1
  173. package/lib/less/tree/color.js.map +0 -1
  174. package/lib/less/tree/combinator.js.map +0 -1
  175. package/lib/less/tree/comment.js.map +0 -1
  176. package/lib/less/tree/condition.js.map +0 -1
  177. package/lib/less/tree/container.js.map +0 -1
  178. package/lib/less/tree/debug-info.js.map +0 -1
  179. package/lib/less/tree/declaration.js.map +0 -1
  180. package/lib/less/tree/detached-ruleset.js.map +0 -1
  181. package/lib/less/tree/dimension.js.map +0 -1
  182. package/lib/less/tree/element.js.map +0 -1
  183. package/lib/less/tree/expression.js.map +0 -1
  184. package/lib/less/tree/extend.js.map +0 -1
  185. package/lib/less/tree/import.js.map +0 -1
  186. package/lib/less/tree/index.js.map +0 -1
  187. package/lib/less/tree/javascript.js.map +0 -1
  188. package/lib/less/tree/js-eval-node.js.map +0 -1
  189. package/lib/less/tree/keyword.js.map +0 -1
  190. package/lib/less/tree/media.js.map +0 -1
  191. package/lib/less/tree/mixin-call.js.map +0 -1
  192. package/lib/less/tree/mixin-definition.js.map +0 -1
  193. package/lib/less/tree/namespace-value.js.map +0 -1
  194. package/lib/less/tree/negative.js.map +0 -1
  195. package/lib/less/tree/nested-at-rule.js.map +0 -1
  196. package/lib/less/tree/node.js.map +0 -1
  197. package/lib/less/tree/operation.js.map +0 -1
  198. package/lib/less/tree/paren.js.map +0 -1
  199. package/lib/less/tree/property.js.map +0 -1
  200. package/lib/less/tree/query-in-parens.js.map +0 -1
  201. package/lib/less/tree/quoted.js.map +0 -1
  202. package/lib/less/tree/ruleset.js.map +0 -1
  203. package/lib/less/tree/selector.js.map +0 -1
  204. package/lib/less/tree/unicode-descriptor.js.map +0 -1
  205. package/lib/less/tree/unit.js.map +0 -1
  206. package/lib/less/tree/url.js.map +0 -1
  207. package/lib/less/tree/value.js.map +0 -1
  208. package/lib/less/tree/variable-call.js.map +0 -1
  209. package/lib/less/tree/variable.js.map +0 -1
  210. package/lib/less/utils.js.map +0 -1
  211. package/lib/less/visitors/extend-visitor.js.map +0 -1
  212. package/lib/less/visitors/import-sequencer.js.map +0 -1
  213. package/lib/less/visitors/import-visitor.js.map +0 -1
  214. package/lib/less/visitors/index.js.map +0 -1
  215. package/lib/less/visitors/join-selector-visitor.js.map +0 -1
  216. package/lib/less/visitors/set-tree-visibility-visitor.js.map +0 -1
  217. package/lib/less/visitors/to-css-visitor.js.map +0 -1
  218. package/lib/less/visitors/visitor.js.map +0 -1
  219. package/lib/less-browser/add-default-options.js.map +0 -1
  220. package/lib/less-browser/bootstrap.js.map +0 -1
  221. package/lib/less-browser/browser.js.map +0 -1
  222. package/lib/less-browser/cache.js.map +0 -1
  223. package/lib/less-browser/error-reporting.js.map +0 -1
  224. package/lib/less-browser/file-manager.js.map +0 -1
  225. package/lib/less-browser/image-size.js.map +0 -1
  226. package/lib/less-browser/index.js.map +0 -1
  227. package/lib/less-browser/log-listener.js.map +0 -1
  228. package/lib/less-browser/plugin-loader.js.map +0 -1
  229. package/lib/less-browser/utils.js.map +0 -1
  230. package/lib/less-node/environment.js.map +0 -1
  231. package/lib/less-node/file-manager.js.map +0 -1
  232. package/lib/less-node/fs.js.map +0 -1
  233. package/lib/less-node/image-size.js.map +0 -1
  234. package/lib/less-node/index.js.map +0 -1
  235. package/lib/less-node/lessc-helper.js.map +0 -1
  236. package/lib/less-node/plugin-loader.js.map +0 -1
  237. package/lib/less-node/url-file-manager.js.map +0 -1
  238. package/test/.eslintrc.json +0 -9
  239. package/test/README.md +0 -3
  240. package/test/browser/common.js +0 -230
  241. package/test/browser/css/global-vars/simple.css +0 -3
  242. package/test/browser/css/modify-vars/simple.css +0 -8
  243. package/test/browser/css/plugin/plugin.css +0 -3
  244. package/test/browser/css/postProcessor/postProcessor.css +0 -4
  245. package/test/browser/css/relative-urls/urls.css +0 -36
  246. package/test/browser/css/rewrite-urls/urls.css +0 -36
  247. package/test/browser/css/rootpath/urls.css +0 -35
  248. package/test/browser/css/rootpath-relative/urls.css +0 -35
  249. package/test/browser/css/rootpath-rewrite-urls/urls.css +0 -35
  250. package/test/browser/css/urls.css +0 -54
  251. package/test/browser/generator/benchmark.config.js +0 -50
  252. package/test/browser/generator/generate.js +0 -78
  253. package/test/browser/generator/runner.config.js +0 -188
  254. package/test/browser/generator/runner.js +0 -2
  255. package/test/browser/generator/template.js +0 -93
  256. package/test/browser/generator/utils.js +0 -14
  257. package/test/browser/less/console-errors/test-error.less +0 -3
  258. package/test/browser/less/console-errors/test-error.txt +0 -2
  259. package/test/browser/less/errors/image-height-error.less +0 -3
  260. package/test/browser/less/errors/image-height-error.txt +0 -4
  261. package/test/browser/less/errors/image-size-error.less +0 -3
  262. package/test/browser/less/errors/image-size-error.txt +0 -4
  263. package/test/browser/less/errors/image-width-error.less +0 -3
  264. package/test/browser/less/errors/image-width-error.txt +0 -4
  265. package/test/browser/less/global-vars/simple.less +0 -3
  266. package/test/browser/less/imports/urls.less +0 -4
  267. package/test/browser/less/imports/urls2.less +0 -4
  268. package/test/browser/less/modify-vars/imports/simple2.less +0 -4
  269. package/test/browser/less/modify-vars/simple.less +0 -8
  270. package/test/browser/less/nested-gradient-with-svg-gradient/mixin-consumer.less +0 -5
  271. package/test/browser/less/nested-gradient-with-svg-gradient/svg-gradient-mixin.less +0 -15
  272. package/test/browser/less/plugin/plugin.js +0 -4
  273. package/test/browser/less/plugin/plugin.less +0 -4
  274. package/test/browser/less/postProcessor/postProcessor.less +0 -4
  275. package/test/browser/less/relative-urls/urls.less +0 -34
  276. package/test/browser/less/rewrite-urls/urls.less +0 -34
  277. package/test/browser/less/rootpath/urls.less +0 -33
  278. package/test/browser/less/rootpath-relative/urls.less +0 -33
  279. package/test/browser/less/rootpath-rewrite-urls/urls.less +0 -33
  280. package/test/browser/less/urls.less +0 -62
  281. package/test/browser/runner-VisitorPlugin-options.js +0 -3
  282. package/test/browser/runner-VisitorPlugin.js +0 -3
  283. package/test/browser/runner-browser-options.js +0 -51
  284. package/test/browser/runner-browser-spec.js +0 -12
  285. package/test/browser/runner-console-errors.js +0 -5
  286. package/test/browser/runner-errors-options.js +0 -6
  287. package/test/browser/runner-errors-spec.js +0 -3
  288. package/test/browser/runner-filemanagerPlugin-options.js +0 -5
  289. package/test/browser/runner-filemanagerPlugin.js +0 -3
  290. package/test/browser/runner-global-vars-options.js +0 -7
  291. package/test/browser/runner-global-vars-spec.js +0 -3
  292. package/test/browser/runner-legacy-options.js +0 -6
  293. package/test/browser/runner-legacy-spec.js +0 -3
  294. package/test/browser/runner-main-options.js +0 -17
  295. package/test/browser/runner-main-spec.js +0 -7
  296. package/test/browser/runner-modify-vars-options.js +0 -5
  297. package/test/browser/runner-modify-vars-spec.js +0 -33
  298. package/test/browser/runner-no-js-errors-options.js +0 -4
  299. package/test/browser/runner-no-js-errors-spec.js +0 -3
  300. package/test/browser/runner-postProcessorPlugin-options.js +0 -3
  301. package/test/browser/runner-postProcessorPlugin.js +0 -3
  302. package/test/browser/runner-preProcessorPlugin-options.js +0 -3
  303. package/test/browser/runner-preProcessorPlugin.js +0 -3
  304. package/test/browser/runner-production-options.js +0 -3
  305. package/test/browser/runner-production-spec.js +0 -5
  306. package/test/browser/runner-relative-urls-options.js +0 -3
  307. package/test/browser/runner-relative-urls-spec.js +0 -3
  308. package/test/browser/runner-rewrite-urls-options.js +0 -3
  309. package/test/browser/runner-rewrite-urls-spec.js +0 -3
  310. package/test/browser/runner-rootpath-options.js +0 -3
  311. package/test/browser/runner-rootpath-relative-options.js +0 -4
  312. package/test/browser/runner-rootpath-relative-spec.js +0 -3
  313. package/test/browser/runner-rootpath-rewrite-urls-options.js +0 -4
  314. package/test/browser/runner-rootpath-rewrite-urls-spec.js +0 -3
  315. package/test/browser/runner-rootpath-spec.js +0 -3
  316. package/test/browser/runner-strict-units-options.js +0 -5
  317. package/test/browser/runner-strict-units-spec.js +0 -3
  318. package/test/index.js +0 -112
  319. package/test/less-test.js +0 -625
  320. package/test/mocha-playwright/runner.js +0 -210
  321. package/test/modify-vars.js +0 -28
  322. package/test/plugins/filemanager/index.js +0 -19
  323. package/test/plugins/postprocess/index.js +0 -14
  324. package/test/plugins/preprocess/index.js +0 -19
  325. package/test/plugins/visitor/index.js +0 -24
  326. package/test/sourcemaps/basic.json +0 -1
  327. package/test/sourcemaps/custom-props.json +0 -1
  328. package/test/sourcemaps/index.html +0 -17
  329. package/test/sourcemaps-disable-annotation/basic.json +0 -1
  330. package/test/sourcemaps-variable-selector/basic.json +0 -1
  331. package/test/test-es6.ts +0 -17
  332. package/tsconfig.build.json +0 -7
  333. package/tsconfig.json +0 -21
@@ -1,46 +1,71 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var tslib_1 = require("tslib");
4
- var node_1 = tslib_1.__importDefault(require("./node"));
5
- var color_1 = tslib_1.__importDefault(require("./color"));
6
- var dimension_1 = tslib_1.__importDefault(require("./dimension"));
7
- var Constants = tslib_1.__importStar(require("../constants"));
8
- var MATH = Constants.Math;
9
- var Operation = function (op, operands, isSpaced) {
10
- this.op = op.trim();
11
- this.operands = operands;
12
- this.isSpaced = isSpaced;
13
- };
14
- Operation.prototype = Object.assign(new node_1.default(), {
15
- type: 'Operation',
16
- accept: function (visitor) {
1
+ // @ts-check
2
+ /** @import { EvalContext, CSSOutput, TreeVisitor } from './node.js' */
3
+ import Node from './node.js';
4
+ import Color from './color.js';
5
+ import Dimension from './dimension.js';
6
+ import * as Constants from '../constants.js';
7
+ const MATH = Constants.Math;
8
+
9
+ class Operation extends Node {
10
+ get type() { return 'Operation'; }
11
+
12
+ /**
13
+ * @param {string} op
14
+ * @param {Node[]} operands
15
+ * @param {boolean} isSpaced
16
+ */
17
+ constructor(op, operands, isSpaced) {
18
+ super();
19
+ this.op = op.trim();
20
+ this.operands = operands;
21
+ this.isSpaced = isSpaced;
22
+ }
23
+
24
+ /** @param {TreeVisitor} visitor */
25
+ accept(visitor) {
17
26
  this.operands = visitor.visitArray(this.operands);
18
- },
19
- eval: function (context) {
20
- var a = this.operands[0].eval(context), b = this.operands[1].eval(context), op;
27
+ }
28
+
29
+ /**
30
+ * @param {EvalContext} context
31
+ * @returns {Node}
32
+ */
33
+ eval(context) {
34
+ let a = this.operands[0].eval(context), b = this.operands[1].eval(context), op;
35
+
21
36
  if (context.isMathOn(this.op)) {
22
37
  op = this.op === './' ? '/' : this.op;
23
- if (a instanceof dimension_1.default && b instanceof color_1.default) {
24
- a = a.toColor();
38
+ if (a instanceof Dimension && b instanceof Color) {
39
+ a = /** @type {Dimension} */ (a).toColor();
25
40
  }
26
- if (b instanceof dimension_1.default && a instanceof color_1.default) {
27
- b = b.toColor();
41
+ if (b instanceof Dimension && a instanceof Color) {
42
+ b = /** @type {Dimension} */ (b).toColor();
28
43
  }
29
- if (!a.operate || !b.operate) {
30
- if ((a instanceof Operation || b instanceof Operation)
31
- && a.op === '/' && context.math === MATH.PARENS_DIVISION) {
44
+ if (!/** @type {Dimension | Color} */ (a).operate || !/** @type {Dimension | Color} */ (b).operate) {
45
+ if (
46
+ (a instanceof Operation || b instanceof Operation)
47
+ && /** @type {Operation} */ (a).op === '/' && context.math === MATH.PARENS_DIVISION
48
+ ) {
32
49
  return new Operation(this.op, [a, b], this.isSpaced);
33
50
  }
34
51
  throw { type: 'Operation',
35
52
  message: 'Operation on an invalid type' };
36
53
  }
37
- return a.operate(context, op, b);
38
- }
39
- else {
54
+
55
+ if (a instanceof Dimension) {
56
+ return a.operate(context, op, /** @type {Dimension} */ (b));
57
+ }
58
+ return /** @type {Color} */ (a).operate(context, op, /** @type {Color} */ (b));
59
+ } else {
40
60
  return new Operation(this.op, [a, b], this.isSpaced);
41
61
  }
42
- },
43
- genCSS: function (context, output) {
62
+ }
63
+
64
+ /**
65
+ * @param {EvalContext} context
66
+ * @param {CSSOutput} output
67
+ */
68
+ genCSS(context, output) {
44
69
  this.operands[0].genCSS(context, output);
45
70
  if (this.isSpaced) {
46
71
  output.add(' ');
@@ -51,6 +76,6 @@ Operation.prototype = Object.assign(new node_1.default(), {
51
76
  }
52
77
  this.operands[1].genCSS(context, output);
53
78
  }
54
- });
55
- exports.default = Operation;
56
- //# sourceMappingURL=operation.js.map
79
+ }
80
+
81
+ export default Operation;
@@ -1,24 +1,41 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var tslib_1 = require("tslib");
4
- var node_1 = tslib_1.__importDefault(require("./node"));
5
- var Paren = function (node) {
6
- this.value = node;
7
- };
8
- Paren.prototype = Object.assign(new node_1.default(), {
9
- type: 'Paren',
10
- genCSS: function (context, output) {
1
+ // @ts-check
2
+ /** @import { EvalContext, CSSOutput } from './node.js' */
3
+ import Node from './node.js';
4
+
5
+ class Paren extends Node {
6
+ get type() { return 'Paren'; }
7
+
8
+ /** @param {Node} node */
9
+ constructor(node) {
10
+ super();
11
+ this.value = node;
12
+ /** @type {boolean | undefined} */
13
+ this.noSpacing = undefined;
14
+ }
15
+
16
+ /**
17
+ * @param {EvalContext} context
18
+ * @param {CSSOutput} output
19
+ */
20
+ genCSS(context, output) {
11
21
  output.add('(');
12
- this.value.genCSS(context, output);
22
+ /** @type {Node} */ (this.value).genCSS(context, output);
13
23
  output.add(')');
14
- },
15
- eval: function (context) {
16
- var paren = new Paren(this.value.eval(context));
24
+ }
25
+
26
+ /**
27
+ * @param {EvalContext} context
28
+ * @returns {Paren}
29
+ */
30
+ eval(context) {
31
+ const paren = new Paren(/** @type {Node} */ (this.value).eval(context));
32
+
17
33
  if (this.noSpacing) {
18
34
  paren.noSpacing = true;
19
35
  }
36
+
20
37
  return paren;
21
38
  }
22
- });
23
- exports.default = Paren;
24
- //# sourceMappingURL=paren.js.map
39
+ }
40
+
41
+ export default Paren;
@@ -1,39 +1,67 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var tslib_1 = require("tslib");
4
- var node_1 = tslib_1.__importDefault(require("./node"));
5
- var declaration_1 = tslib_1.__importDefault(require("./declaration"));
6
- var Property = function (name, index, currentFileInfo) {
7
- this.name = name;
8
- this._index = index;
9
- this._fileInfo = currentFileInfo;
10
- };
11
- Property.prototype = Object.assign(new node_1.default(), {
12
- type: 'Property',
13
- eval: function (context) {
14
- var property;
15
- var name = this.name;
1
+ // @ts-check
2
+ /** @import { EvalContext, FileInfo } from './node.js' */
3
+ import Node from './node.js';
4
+ import Declaration from './declaration.js';
5
+ import Ruleset from './ruleset.js';
6
+
7
+ class Property extends Node {
8
+ get type() { return 'Property'; }
9
+
10
+ /**
11
+ * @param {string} name
12
+ * @param {number} index
13
+ * @param {FileInfo} currentFileInfo
14
+ */
15
+ constructor(name, index, currentFileInfo) {
16
+ super();
17
+ this.name = name;
18
+ this._index = index;
19
+ this._fileInfo = currentFileInfo;
20
+ /** @type {boolean | undefined} */
21
+ this.evaluating = undefined;
22
+ }
23
+
24
+ /**
25
+ * @param {EvalContext} context
26
+ * @returns {Node}
27
+ */
28
+ eval(context) {
29
+ let property;
30
+ const name = this.name;
16
31
  // TODO: shorten this reference
17
- var mergeRules = context.pluginManager.less.visitors.ToCSSVisitor.prototype._mergeRules;
32
+ const mergeRules = /** @type {{ less: { visitors: { ToCSSVisitor: { prototype: { _mergeRules: (rules: Declaration[]) => void } } } } }} */ (context.pluginManager).less.visitors.ToCSSVisitor.prototype._mergeRules;
33
+
18
34
  if (this.evaluating) {
19
35
  throw { type: 'Name',
20
- message: "Recursive property reference for ".concat(name),
36
+ message: `Recursive property reference for ${name}`,
21
37
  filename: this.fileInfo().filename,
22
38
  index: this.getIndex() };
23
39
  }
40
+
24
41
  this.evaluating = true;
25
- property = this.find(context.frames, function (frame) {
26
- var v;
27
- var vArr = frame.property(name);
42
+
43
+ property = this.find(context.frames, function (/** @type {Node} */ frame) {
44
+ let v;
45
+ const vArr = /** @type {Ruleset} */ (frame).property(name);
28
46
  if (vArr) {
29
- for (var i = 0; i < vArr.length; i++) {
47
+ for (let i = 0; i < vArr.length; i++) {
30
48
  v = vArr[i];
31
- vArr[i] = new declaration_1.default(v.name, v.value, v.important, v.merge, v.index, v.currentFileInfo, v.inline, v.variable);
49
+
50
+ vArr[i] = new Declaration(v.name,
51
+ v.value,
52
+ v.important,
53
+ v.merge,
54
+ v.index,
55
+ v.currentFileInfo,
56
+ v.inline,
57
+ v.variable
58
+ );
32
59
  }
33
60
  mergeRules(vArr);
61
+
34
62
  v = vArr[vArr.length - 1];
35
63
  if (v.important) {
36
- var importantScope = context.importantScope[context.importantScope.length - 1];
64
+ const importantScope = context.importantScope[context.importantScope.length - 1];
37
65
  importantScope.important = v.important;
38
66
  }
39
67
  v = v.value.eval(context);
@@ -43,23 +71,26 @@ Property.prototype = Object.assign(new node_1.default(), {
43
71
  if (property) {
44
72
  this.evaluating = false;
45
73
  return property;
46
- }
47
- else {
74
+ } else {
48
75
  throw { type: 'Name',
49
- message: "Property '".concat(name, "' is undefined"),
76
+ message: `Property '${name}' is undefined`,
50
77
  filename: this.currentFileInfo.filename,
51
78
  index: this.index };
52
79
  }
53
- },
54
- find: function (obj, fun) {
55
- for (var i = 0, r = void 0; i < obj.length; i++) {
80
+ }
81
+
82
+ /**
83
+ * @param {Node[]} obj
84
+ * @param {(frame: Node) => Node | undefined} fun
85
+ * @returns {Node | null}
86
+ */
87
+ find(obj, fun) {
88
+ for (let i = 0, r; i < obj.length; i++) {
56
89
  r = fun.call(obj, obj[i]);
57
- if (r) {
58
- return r;
59
- }
90
+ if (r) { return r; }
60
91
  }
61
92
  return null;
62
93
  }
63
- });
64
- exports.default = Property;
65
- //# sourceMappingURL=property.js.map
94
+ }
95
+
96
+ export default Property;
@@ -1,72 +1,64 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var tslib_1 = require("tslib");
4
- var copy_anything_1 = require("copy-anything");
5
- var declaration_1 = tslib_1.__importDefault(require("./declaration"));
6
- var node_1 = tslib_1.__importDefault(require("./node"));
7
- var QueryInParens = function (op, l, m, op2, r, i) {
8
- this.op = op.trim();
9
- this.lvalue = l;
10
- this.mvalue = m;
11
- this.op2 = op2 ? op2.trim() : null;
12
- this.rvalue = r;
13
- this._index = i;
14
- this.mvalues = [];
15
- };
16
- QueryInParens.prototype = Object.assign(new node_1.default(), {
17
- type: 'QueryInParens',
18
- accept: function (visitor) {
1
+ // @ts-check
2
+ /** @import { EvalContext, CSSOutput, TreeVisitor } from './node.js' */
3
+ import Node from './node.js';
4
+
5
+ class QueryInParens extends Node {
6
+ get type() { return 'QueryInParens'; }
7
+
8
+ /**
9
+ * @param {string} op
10
+ * @param {Node} l
11
+ * @param {Node} m
12
+ * @param {string | null} op2
13
+ * @param {Node | null} r
14
+ * @param {number} i
15
+ */
16
+ constructor(op, l, m, op2, r, i) {
17
+ super();
18
+ this.op = op.trim();
19
+ this.lvalue = l;
20
+ this.mvalue = m;
21
+ this.op2 = op2 ? op2.trim() : null;
22
+ /** @type {Node | null} */
23
+ this.rvalue = r;
24
+ this._index = i;
25
+ }
26
+
27
+ /** @param {TreeVisitor} visitor */
28
+ accept(visitor) {
19
29
  this.lvalue = visitor.visit(this.lvalue);
20
30
  this.mvalue = visitor.visit(this.mvalue);
21
31
  if (this.rvalue) {
22
32
  this.rvalue = visitor.visit(this.rvalue);
23
33
  }
24
- },
25
- eval: function (context) {
26
- this.lvalue = this.lvalue.eval(context);
27
- var variableDeclaration;
28
- var rule;
29
- for (var i = 0; (rule = context.frames[i]); i++) {
30
- if (rule.type === 'Ruleset') {
31
- variableDeclaration = rule.rules.find(function (r) {
32
- if ((r instanceof declaration_1.default) && r.variable) {
33
- return true;
34
- }
35
- return false;
36
- });
37
- if (variableDeclaration) {
38
- break;
39
- }
40
- }
41
- }
42
- if (!this.mvalueCopy) {
43
- this.mvalueCopy = (0, copy_anything_1.copy)(this.mvalue);
44
- }
45
- if (variableDeclaration) {
46
- this.mvalue = this.mvalueCopy;
47
- this.mvalue = this.mvalue.eval(context);
48
- this.mvalues.push(this.mvalue);
49
- }
50
- else {
51
- this.mvalue = this.mvalue.eval(context);
52
- }
53
- if (this.rvalue) {
54
- this.rvalue = this.rvalue.eval(context);
55
- }
56
- return this;
57
- },
58
- genCSS: function (context, output) {
34
+ }
35
+
36
+ /** @param {EvalContext} context */
37
+ eval(context) {
38
+ const node = new QueryInParens(
39
+ this.op,
40
+ this.lvalue.eval(context),
41
+ this.mvalue.eval(context),
42
+ this.op2,
43
+ this.rvalue ? this.rvalue.eval(context) : null,
44
+ this._index || 0
45
+ );
46
+ return node;
47
+ }
48
+
49
+ /**
50
+ * @param {EvalContext} context
51
+ * @param {CSSOutput} output
52
+ */
53
+ genCSS(context, output) {
59
54
  this.lvalue.genCSS(context, output);
60
55
  output.add(' ' + this.op + ' ');
61
- if (this.mvalues.length > 0) {
62
- this.mvalue = this.mvalues.shift();
63
- }
64
56
  this.mvalue.genCSS(context, output);
65
57
  if (this.rvalue) {
66
58
  output.add(' ' + this.op2 + ' ');
67
59
  this.rvalue.genCSS(context, output);
68
60
  }
69
- },
70
- });
71
- exports.default = QueryInParens;
72
- //# sourceMappingURL=query-in-parens.js.map
61
+ }
62
+ }
63
+
64
+ export default QueryInParens;
@@ -1,46 +1,88 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var tslib_1 = require("tslib");
4
- var node_1 = tslib_1.__importDefault(require("./node"));
5
- var variable_1 = tslib_1.__importDefault(require("./variable"));
6
- var property_1 = tslib_1.__importDefault(require("./property"));
7
- var Quoted = function (str, content, escaped, index, currentFileInfo) {
8
- this.escaped = (escaped === undefined) ? true : escaped;
9
- this.value = content || '';
10
- this.quote = str.charAt(0);
11
- this._index = index;
12
- this._fileInfo = currentFileInfo;
13
- this.variableRegex = /@\{([\w-]+)\}/g;
14
- this.propRegex = /\$\{([\w-]+)\}/g;
15
- this.allowRoot = escaped;
16
- };
17
- Quoted.prototype = Object.assign(new node_1.default(), {
18
- type: 'Quoted',
19
- genCSS: function (context, output) {
1
+ // @ts-check
2
+ /** @import { EvalContext, CSSOutput, FileInfo } from './node.js' */
3
+ import Node from './node.js';
4
+ import Variable from './variable.js';
5
+ import Property from './property.js';
6
+
7
+ class Quoted extends Node {
8
+ get type() { return 'Quoted'; }
9
+
10
+ /**
11
+ * @param {string} str
12
+ * @param {string} [content]
13
+ * @param {boolean} [escaped]
14
+ * @param {number} [index]
15
+ * @param {FileInfo} [currentFileInfo]
16
+ */
17
+ constructor(str, content, escaped, index, currentFileInfo) {
18
+ super();
19
+ /** @type {boolean} */
20
+ this.escaped = (escaped === undefined) ? true : escaped;
21
+ /** @type {string} */
22
+ this.value = content || '';
23
+ /** @type {string} */
24
+ this.quote = str.charAt(0);
25
+ this._index = index;
26
+ this._fileInfo = currentFileInfo;
27
+ /** @type {RegExp} */
28
+ this.variableRegex = /@\{([\w-]+)\}/g;
29
+ /** @type {RegExp} */
30
+ this.propRegex = /\$\{([\w-]+)\}/g;
31
+ /** @type {boolean | undefined} */
32
+ this.allowRoot = escaped;
33
+ }
34
+
35
+ /**
36
+ * @param {EvalContext} context
37
+ * @param {CSSOutput} output
38
+ */
39
+ genCSS(context, output) {
20
40
  if (!this.escaped) {
21
41
  output.add(this.quote, this.fileInfo(), this.getIndex());
22
42
  }
23
- output.add(this.value);
43
+ output.add(/** @type {string} */ (this.value));
24
44
  if (!this.escaped) {
25
45
  output.add(this.quote);
26
46
  }
27
- },
28
- containsVariables: function () {
29
- return this.value.match(this.variableRegex);
30
- },
31
- eval: function (context) {
32
- var that = this;
33
- var value = this.value;
34
- var variableReplacement = function (_, name1, name2) {
35
- var v = new variable_1.default("@".concat(name1 !== null && name1 !== void 0 ? name1 : name2), that.getIndex(), that.fileInfo()).eval(context, true);
36
- return (v instanceof Quoted) ? v.value : v.toCSS();
47
+ }
48
+
49
+ /** @returns {RegExpMatchArray | null} */
50
+ containsVariables() {
51
+ return /** @type {string} */ (this.value).match(this.variableRegex);
52
+ }
53
+
54
+ /** @param {EvalContext} context */
55
+ eval(context) {
56
+ const that = this;
57
+ let value = /** @type {string} */ (this.value);
58
+ /**
59
+ * @param {string} _
60
+ * @param {string} name1
61
+ * @param {string} name2
62
+ * @returns {string}
63
+ */
64
+ const variableReplacement = function (_, name1, name2) {
65
+ const v = new Variable(`@${name1 ?? name2}`, that.getIndex(), that.fileInfo()).eval(context);
66
+ return (v instanceof Quoted) ? /** @type {string} */ (v.value) : v.toCSS(context);
37
67
  };
38
- var propertyReplacement = function (_, name1, name2) {
39
- var v = new property_1.default("$".concat(name1 !== null && name1 !== void 0 ? name1 : name2), that.getIndex(), that.fileInfo()).eval(context, true);
40
- return (v instanceof Quoted) ? v.value : v.toCSS();
68
+ /**
69
+ * @param {string} _
70
+ * @param {string} name1
71
+ * @param {string} name2
72
+ * @returns {string}
73
+ */
74
+ const propertyReplacement = function (_, name1, name2) {
75
+ const v = new Property(`$${name1 ?? name2}`, that.getIndex(), that.fileInfo()).eval(context);
76
+ return (v instanceof Quoted) ? /** @type {string} */ (v.value) : v.toCSS(context);
41
77
  };
78
+ /**
79
+ * @param {string} value
80
+ * @param {RegExp} regexp
81
+ * @param {(substring: string, ...args: string[]) => string} replacementFnc
82
+ * @returns {string}
83
+ */
42
84
  function iterativeReplace(value, regexp, replacementFnc) {
43
- var evaluatedValue = value;
85
+ let evaluatedValue = value;
44
86
  do {
45
87
  value = evaluatedValue.toString();
46
88
  evaluatedValue = value.replace(regexp, replacementFnc);
@@ -50,16 +92,23 @@ Quoted.prototype = Object.assign(new node_1.default(), {
50
92
  value = iterativeReplace(value, this.variableRegex, variableReplacement);
51
93
  value = iterativeReplace(value, this.propRegex, propertyReplacement);
52
94
  return new Quoted(this.quote + value + this.quote, value, this.escaped, this.getIndex(), this.fileInfo());
53
- },
54
- compare: function (other) {
95
+ }
96
+
97
+ /**
98
+ * @param {Node} other
99
+ * @returns {number | undefined}
100
+ */
101
+ compare(other) {
55
102
  // when comparing quoted strings allow the quote to differ
56
- if (other.type === 'Quoted' && !this.escaped && !other.escaped) {
57
- return node_1.default.numericCompare(this.value, other.value);
58
- }
59
- else {
60
- return other.toCSS && this.toCSS() === other.toCSS() ? 0 : undefined;
103
+ if (other.type === 'Quoted' && !this.escaped && !/** @type {Quoted} */ (other).escaped) {
104
+ return Node.numericCompare(
105
+ /** @type {string} */ (this.value),
106
+ /** @type {string} */ (other.value)
107
+ );
108
+ } else {
109
+ return other.toCSS && this.toCSS(/** @type {EvalContext} */ ({})) === other.toCSS(/** @type {EvalContext} */ ({})) ? 0 : undefined;
61
110
  }
62
111
  }
63
- });
64
- exports.default = Quoted;
65
- //# sourceMappingURL=quoted.js.map
112
+ }
113
+
114
+ export default Quoted;