less 4.5.1 → 4.6.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 (340) hide show
  1. package/README.md +70 -5
  2. package/bin/lessc +37 -23
  3. package/dist/less.js +14501 -11745
  4. package/dist/less.min.js +4 -4
  5. package/dist/less.min.js.map +1 -1
  6. package/index.cjs +41 -0
  7. package/lib/less/constants.js +5 -7
  8. package/lib/less/contexts.js +71 -55
  9. package/lib/less/data/colors.js +150 -153
  10. package/lib/less/data/index.js +4 -7
  11. package/lib/less/data/unit-conversions.js +2 -5
  12. package/lib/less/default-options.js +36 -26
  13. package/lib/less/deprecation.js +67 -0
  14. package/lib/less/environment/abstract-file-manager.js +62 -50
  15. package/lib/less/environment/abstract-plugin-loader.js +69 -46
  16. package/lib/less/environment/environment-api.ts +21 -0
  17. package/lib/less/environment/environment.js +34 -30
  18. package/lib/less/environment/file-manager-api.ts +77 -0
  19. package/lib/less/functions/boolean.js +13 -13
  20. package/lib/less/functions/color-blending.js +39 -31
  21. package/lib/less/functions/color.js +153 -137
  22. package/lib/less/functions/data-uri.js +73 -64
  23. package/lib/less/functions/default.js +9 -11
  24. package/lib/less/functions/function-caller.js +35 -34
  25. package/lib/less/functions/function-registry.js +16 -17
  26. package/lib/less/functions/index.js +33 -33
  27. package/lib/less/functions/list.js +88 -75
  28. package/lib/less/functions/math-helper.js +8 -11
  29. package/lib/less/functions/math.js +21 -21
  30. package/lib/less/functions/number.js +42 -53
  31. package/lib/less/functions/string.js +18 -22
  32. package/lib/less/functions/style.js +21 -20
  33. package/lib/less/functions/svg.js +83 -82
  34. package/lib/less/functions/types.js +28 -32
  35. package/lib/less/import-manager.js +73 -64
  36. package/lib/less/index.js +65 -65
  37. package/lib/less/less-error.js +63 -45
  38. package/lib/less/logger.js +11 -14
  39. package/lib/less/parse-tree.js +52 -53
  40. package/lib/less/parse.js +44 -44
  41. package/lib/less/parser/parser-input.js +151 -113
  42. package/lib/less/parser/parser.js +864 -658
  43. package/lib/less/plugin-manager.js +57 -46
  44. package/lib/less/render.js +17 -23
  45. package/lib/less/source-map-builder.js +52 -43
  46. package/lib/less/source-map-output.js +56 -43
  47. package/lib/less/transform-tree.js +40 -30
  48. package/lib/less/tree/anonymous.js +52 -28
  49. package/lib/less/tree/assignment.js +44 -27
  50. package/lib/less/tree/atrule-syntax.js +4 -6
  51. package/lib/less/tree/atrule.js +247 -140
  52. package/lib/less/tree/attribute.js +55 -24
  53. package/lib/less/tree/call.js +70 -42
  54. package/lib/less/tree/color.js +194 -145
  55. package/lib/less/tree/combinator.js +31 -21
  56. package/lib/less/tree/comment.js +44 -23
  57. package/lib/less/tree/condition.js +61 -36
  58. package/lib/less/tree/container.js +90 -34
  59. package/lib/less/tree/debug-info.js +28 -15
  60. package/lib/less/tree/declaration.js +97 -52
  61. package/lib/less/tree/detached-ruleset.js +42 -24
  62. package/lib/less/tree/dimension.js +127 -71
  63. package/lib/less/tree/element.js +82 -52
  64. package/lib/less/tree/expression.js +75 -50
  65. package/lib/less/tree/extend.js +71 -42
  66. package/lib/less/tree/import.js +184 -110
  67. package/lib/less/tree/index.js +52 -81
  68. package/lib/less/tree/javascript.js +43 -32
  69. package/lib/less/tree/js-eval-node.js +46 -32
  70. package/lib/less/tree/keyword.js +25 -17
  71. package/lib/less/tree/media.js +77 -35
  72. package/lib/less/tree/merge-rules.js +47 -0
  73. package/lib/less/tree/mixin-call.js +181 -98
  74. package/lib/less/tree/mixin-definition.js +211 -117
  75. package/lib/less/tree/namespace-value.js +63 -44
  76. package/lib/less/tree/negative.js +34 -21
  77. package/lib/less/tree/nested-at-rule.js +149 -66
  78. package/lib/less/tree/node.js +225 -90
  79. package/lib/less/tree/operation.js +59 -34
  80. package/lib/less/tree/paren.js +34 -17
  81. package/lib/less/tree/property.js +66 -35
  82. package/lib/less/tree/query-in-parens.js +52 -60
  83. package/lib/less/tree/quoted.js +93 -44
  84. package/lib/less/tree/ruleset.js +632 -318
  85. package/lib/less/tree/selector.js +151 -77
  86. package/lib/less/tree/unicode-descriptor.js +14 -12
  87. package/lib/less/tree/unit.js +111 -63
  88. package/lib/less/tree/url.js +62 -38
  89. package/lib/less/tree/value.js +50 -34
  90. package/lib/less/tree/variable-call.js +47 -30
  91. package/lib/less/tree/variable.js +53 -31
  92. package/lib/less/utils.js +44 -47
  93. package/lib/less/visitors/extend-visitor.js +233 -172
  94. package/lib/less/visitors/import-sequencer.js +24 -24
  95. package/lib/less/visitors/import-visitor.js +62 -52
  96. package/lib/less/visitors/index.js +14 -17
  97. package/lib/less/visitors/join-selector-visitor.js +40 -37
  98. package/lib/less/visitors/set-tree-visibility-visitor.js +32 -18
  99. package/lib/less/visitors/to-css-visitor.js +135 -128
  100. package/lib/less/visitors/visitor.js +60 -45
  101. package/lib/less-browser/add-default-options.js +23 -13
  102. package/lib/less-browser/bootstrap.js +23 -17
  103. package/lib/less-browser/browser.js +24 -21
  104. package/lib/less-browser/cache.js +17 -19
  105. package/lib/less-browser/error-reporting.js +52 -44
  106. package/lib/less-browser/file-manager.js +52 -42
  107. package/lib/less-browser/image-size.js +12 -12
  108. package/lib/less-browser/index.js +131 -105
  109. package/lib/less-browser/log-listener.js +30 -31
  110. package/lib/less-browser/plugin-loader.js +10 -10
  111. package/lib/less-browser/utils.js +19 -21
  112. package/lib/less-node/environment.js +32 -8
  113. package/lib/less-node/file-manager.js +62 -45
  114. package/lib/less-node/fs.js +11 -8
  115. package/lib/less-node/image-size.js +40 -31
  116. package/lib/less-node/index.js +28 -19
  117. package/lib/less-node/lessc-helper.js +20 -21
  118. package/lib/less-node/plugin-loader.js +35 -27
  119. package/lib/less-node/url-file-manager.js +33 -31
  120. package/package.json +29 -18
  121. package/.eslintignore +0 -6
  122. package/.eslintrc.js +0 -63
  123. package/Gruntfile.js +0 -403
  124. package/bower.json +0 -22
  125. package/lib/less/constants.js.map +0 -1
  126. package/lib/less/contexts.js.map +0 -1
  127. package/lib/less/data/colors.js.map +0 -1
  128. package/lib/less/data/index.js.map +0 -1
  129. package/lib/less/data/unit-conversions.js.map +0 -1
  130. package/lib/less/default-options.js.map +0 -1
  131. package/lib/less/environment/abstract-file-manager.js.map +0 -1
  132. package/lib/less/environment/abstract-plugin-loader.js.map +0 -1
  133. package/lib/less/environment/environment-api.js +0 -3
  134. package/lib/less/environment/environment-api.js.map +0 -1
  135. package/lib/less/environment/environment.js.map +0 -1
  136. package/lib/less/environment/file-manager-api.js +0 -3
  137. package/lib/less/environment/file-manager-api.js.map +0 -1
  138. package/lib/less/functions/boolean.js.map +0 -1
  139. package/lib/less/functions/color-blending.js.map +0 -1
  140. package/lib/less/functions/color.js.map +0 -1
  141. package/lib/less/functions/data-uri.js.map +0 -1
  142. package/lib/less/functions/default.js.map +0 -1
  143. package/lib/less/functions/function-caller.js.map +0 -1
  144. package/lib/less/functions/function-registry.js.map +0 -1
  145. package/lib/less/functions/index.js.map +0 -1
  146. package/lib/less/functions/list.js.map +0 -1
  147. package/lib/less/functions/math-helper.js.map +0 -1
  148. package/lib/less/functions/math.js.map +0 -1
  149. package/lib/less/functions/number.js.map +0 -1
  150. package/lib/less/functions/string.js.map +0 -1
  151. package/lib/less/functions/style.js.map +0 -1
  152. package/lib/less/functions/svg.js.map +0 -1
  153. package/lib/less/functions/types.js.map +0 -1
  154. package/lib/less/import-manager.js.map +0 -1
  155. package/lib/less/index.js.map +0 -1
  156. package/lib/less/less-error.js.map +0 -1
  157. package/lib/less/logger.js.map +0 -1
  158. package/lib/less/parse-tree.js.map +0 -1
  159. package/lib/less/parse.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/scripts/coverage-lines.js +0 -207
  239. package/scripts/coverage-report.js +0 -158
  240. package/scripts/postinstall.js +0 -61
  241. package/test/.eslintrc.json +0 -9
  242. package/test/README.md +0 -3
  243. package/test/browser/common.js +0 -251
  244. package/test/browser/css/global-vars/simple.css +0 -3
  245. package/test/browser/css/modify-vars/simple.css +0 -8
  246. package/test/browser/css/plugin/plugin.css +0 -3
  247. package/test/browser/css/postProcessor/postProcessor.css +0 -4
  248. package/test/browser/css/relative-urls/urls.css +0 -36
  249. package/test/browser/css/rewrite-urls/urls.css +0 -36
  250. package/test/browser/css/rootpath/urls.css +0 -35
  251. package/test/browser/css/rootpath-relative/urls.css +0 -35
  252. package/test/browser/css/rootpath-rewrite-urls/urls.css +0 -35
  253. package/test/browser/css/urls.css +0 -54
  254. package/test/browser/generator/benchmark.config.js +0 -50
  255. package/test/browser/generator/generate.js +0 -78
  256. package/test/browser/generator/runner.config.js +0 -184
  257. package/test/browser/generator/runner.js +0 -2
  258. package/test/browser/generator/template.js +0 -104
  259. package/test/browser/generator/utils.js +0 -14
  260. package/test/browser/less/console-errors/test-error.less +0 -3
  261. package/test/browser/less/console-errors/test-error.txt +0 -2
  262. package/test/browser/less/errors/image-height-error.less +0 -3
  263. package/test/browser/less/errors/image-height-error.txt +0 -4
  264. package/test/browser/less/errors/image-size-error.less +0 -3
  265. package/test/browser/less/errors/image-size-error.txt +0 -4
  266. package/test/browser/less/errors/image-width-error.less +0 -3
  267. package/test/browser/less/errors/image-width-error.txt +0 -4
  268. package/test/browser/less/global-vars/simple.less +0 -3
  269. package/test/browser/less/imports/urls.less +0 -4
  270. package/test/browser/less/imports/urls2.less +0 -4
  271. package/test/browser/less/modify-vars/imports/simple2.less +0 -4
  272. package/test/browser/less/modify-vars/simple.less +0 -8
  273. package/test/browser/less/nested-gradient-with-svg-gradient/mixin-consumer.less +0 -5
  274. package/test/browser/less/nested-gradient-with-svg-gradient/svg-gradient-mixin.less +0 -15
  275. package/test/browser/less/plugin/plugin.js +0 -4
  276. package/test/browser/less/plugin/plugin.less +0 -4
  277. package/test/browser/less/postProcessor/postProcessor.less +0 -4
  278. package/test/browser/less/relative-urls/urls.less +0 -34
  279. package/test/browser/less/rewrite-urls/urls.less +0 -34
  280. package/test/browser/less/rootpath/urls.less +0 -33
  281. package/test/browser/less/rootpath-relative/urls.less +0 -33
  282. package/test/browser/less/rootpath-rewrite-urls/urls.less +0 -33
  283. package/test/browser/less/urls.less +0 -62
  284. package/test/browser/runner-VisitorPlugin-options.js +0 -3
  285. package/test/browser/runner-VisitorPlugin.js +0 -3
  286. package/test/browser/runner-browser-options.js +0 -51
  287. package/test/browser/runner-browser-spec.js +0 -12
  288. package/test/browser/runner-console-errors.js +0 -5
  289. package/test/browser/runner-errors-options.js +0 -6
  290. package/test/browser/runner-errors-spec.js +0 -3
  291. package/test/browser/runner-filemanagerPlugin-options.js +0 -5
  292. package/test/browser/runner-filemanagerPlugin.js +0 -3
  293. package/test/browser/runner-global-vars-options.js +0 -7
  294. package/test/browser/runner-global-vars-spec.js +0 -3
  295. package/test/browser/runner-main-options.js +0 -17
  296. package/test/browser/runner-main-spec.js +0 -7
  297. package/test/browser/runner-modify-vars-options.js +0 -5
  298. package/test/browser/runner-modify-vars-spec.js +0 -33
  299. package/test/browser/runner-no-js-errors-options.js +0 -4
  300. package/test/browser/runner-no-js-errors-spec.js +0 -3
  301. package/test/browser/runner-postProcessorPlugin-options.js +0 -3
  302. package/test/browser/runner-postProcessorPlugin.js +0 -3
  303. package/test/browser/runner-preProcessorPlugin-options.js +0 -3
  304. package/test/browser/runner-preProcessorPlugin.js +0 -3
  305. package/test/browser/runner-production-options.js +0 -3
  306. package/test/browser/runner-production-spec.js +0 -5
  307. package/test/browser/runner-relative-urls-options.js +0 -3
  308. package/test/browser/runner-relative-urls-spec.js +0 -3
  309. package/test/browser/runner-rewrite-urls-options.js +0 -3
  310. package/test/browser/runner-rewrite-urls-spec.js +0 -3
  311. package/test/browser/runner-rootpath-options.js +0 -3
  312. package/test/browser/runner-rootpath-relative-options.js +0 -4
  313. package/test/browser/runner-rootpath-relative-spec.js +0 -3
  314. package/test/browser/runner-rootpath-rewrite-urls-options.js +0 -4
  315. package/test/browser/runner-rootpath-rewrite-urls-spec.js +0 -3
  316. package/test/browser/runner-rootpath-spec.js +0 -3
  317. package/test/browser/runner-strict-units-options.js +0 -5
  318. package/test/browser/runner-strict-units-spec.js +0 -3
  319. package/test/index.js +0 -307
  320. package/test/less-test.js +0 -984
  321. package/test/mocha-playwright/runner.js +0 -210
  322. package/test/modify-vars.js +0 -28
  323. package/test/plugins/filemanager/index.js +0 -19
  324. package/test/plugins/postprocess/index.js +0 -14
  325. package/test/plugins/preprocess/index.js +0 -19
  326. package/test/plugins/visitor/index.js +0 -24
  327. package/test/sourcemaps/basic.json +0 -1
  328. package/test/sourcemaps/comprehensive.json +0 -1
  329. package/test/sourcemaps/custom-props.json +0 -1
  330. package/test/sourcemaps/index.html +0 -17
  331. package/test/sourcemaps/sourcemaps-basepath.json +0 -1
  332. package/test/sourcemaps/sourcemaps-include-source.json +0 -1
  333. package/test/sourcemaps/sourcemaps-rootpath.json +0 -1
  334. package/test/sourcemaps/sourcemaps-url.json +0 -1
  335. package/test/sourcemaps-disable-annotation/basic.json +0 -1
  336. package/test/sourcemaps-variable-selector/basic.json +0 -1
  337. package/test/test-es6.ts +0 -17
  338. package/test.less +0 -1
  339. package/tsconfig.build.json +0 -7
  340. package/tsconfig.json +0 -21
@@ -1,72 +1,140 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var tslib_1 = require("tslib");
4
- var ruleset_1 = tslib_1.__importDefault(require("./ruleset"));
5
- var value_1 = tslib_1.__importDefault(require("./value"));
6
- var selector_1 = tslib_1.__importDefault(require("./selector"));
7
- var anonymous_1 = tslib_1.__importDefault(require("./anonymous"));
8
- var expression_1 = tslib_1.__importDefault(require("./expression"));
9
- var utils = tslib_1.__importStar(require("../utils"));
10
- var NestableAtRulePrototype = {
11
- isRulesetLike: function () {
1
+ // @ts-check
2
+ /** @import { EvalContext, CSSOutput, TreeVisitor, FileInfo, VisibilityInfo } from './node.js' */
3
+ import Ruleset from './ruleset.js';
4
+ import Value from './value.js';
5
+ import Selector from './selector.js';
6
+ import Anonymous from './anonymous.js';
7
+ import Expression from './expression.js';
8
+ import * as utils from '../utils.js';
9
+ import Node from './node.js';
10
+
11
+ /**
12
+ * @typedef {object} FunctionRegistry
13
+ * @property {(name: string, func: Function) => void} add
14
+ * @property {(functions: Object) => void} addMultiple
15
+ * @property {(name: string) => Function} get
16
+ * @property {() => Object} getLocalFunctions
17
+ * @property {() => FunctionRegistry} inherit
18
+ * @property {(base: FunctionRegistry) => FunctionRegistry} create
19
+ */
20
+
21
+ /**
22
+ * @typedef {Node & {
23
+ * features: Value,
24
+ * rules: Ruleset[],
25
+ * type: string,
26
+ * functionRegistry?: FunctionRegistry,
27
+ * multiMedia?: boolean,
28
+ * debugInfo?: { lineNumber: number, fileName: string },
29
+ * allowRoot?: boolean,
30
+ * _evaluated?: boolean,
31
+ * evalFunction: () => void,
32
+ * evalTop: (context: EvalContext) => Node | Ruleset,
33
+ * evalNested: (context: EvalContext) => Node | Ruleset,
34
+ * permute: (arr: Node[][]) => Node[][],
35
+ * bubbleSelectors: (selectors: Selector[] | undefined) => void,
36
+ * outputRuleset: (context: EvalContext, output: CSSOutput, rules: Node[]) => void
37
+ * }} NestableAtRuleThis
38
+ */
39
+
40
+ const NestableAtRulePrototype = {
41
+
42
+ isRulesetLike() {
12
43
  return true;
13
44
  },
14
- accept: function (visitor) {
15
- if (this.features) {
16
- this.features = visitor.visit(this.features);
45
+
46
+ /** @param {TreeVisitor} visitor */
47
+ accept(visitor) {
48
+ /** @type {NestableAtRuleThis} */
49
+ const self = /** @type {NestableAtRuleThis} */ (/** @type {unknown} */ (this));
50
+ if (self.features) {
51
+ self.features = /** @type {Value} */ (visitor.visit(self.features));
17
52
  }
18
- if (this.rules) {
19
- this.rules = visitor.visitArray(this.rules);
53
+ if (self.rules) {
54
+ self.rules = /** @type {Ruleset[]} */ (visitor.visitArray(self.rules));
20
55
  }
21
56
  },
57
+
22
58
  evalFunction: function () {
23
- if (!this.features || !Array.isArray(this.features.value) || this.features.value.length < 1) {
59
+ /** @type {NestableAtRuleThis} */
60
+ const self = /** @type {NestableAtRuleThis} */ (/** @type {unknown} */ (this));
61
+ if (!self.features || !Array.isArray(self.features.value) || self.features.value.length < 1) {
24
62
  return;
25
63
  }
26
- var exprValues = this.features.value;
27
- var expr, paren;
28
- for (var index = 0; index < exprValues.length; ++index) {
64
+
65
+ const exprValues = /** @type {Node[]} */ (self.features.value);
66
+ /** @type {Node | undefined} */
67
+ let expr;
68
+ /** @type {Node | undefined} */
69
+ let paren;
70
+
71
+ for (let index = 0; index < exprValues.length; ++index) {
29
72
  expr = exprValues[index];
30
- if (expr.type === 'Keyword' && index + 1 < exprValues.length && (expr.noSpacing || expr.noSpacing == null)) {
31
- paren = exprValues[index + 1];
32
- if (paren.type === 'Paren' && paren.noSpacing) {
33
- exprValues[index] = new expression_1.default([expr, paren]);
73
+
74
+ if ((expr.type === 'Keyword' || expr.type === 'Variable')
75
+ && index + 1 < exprValues.length
76
+ && (/** @type {Node & { noSpacing?: boolean }} */ (expr).noSpacing || /** @type {Node & { noSpacing?: boolean }} */ (expr).noSpacing == null)) {
77
+ paren = exprValues[index + 1];
78
+
79
+ if (paren.type === 'Paren' && /** @type {Node & { noSpacing?: boolean }} */ (paren).noSpacing) {
80
+ exprValues[index]= new Expression([expr, paren]);
34
81
  exprValues.splice(index + 1, 1);
35
- exprValues[index].noSpacing = true;
82
+ /** @type {Node & { noSpacing?: boolean }} */ (exprValues[index]).noSpacing = true;
36
83
  }
37
84
  }
38
85
  }
39
86
  },
40
- evalTop: function (context) {
41
- this.evalFunction();
42
- var result = this;
87
+
88
+ /** @param {EvalContext} context */
89
+ evalTop(context) {
90
+ /** @type {NestableAtRuleThis} */
91
+ const self = /** @type {NestableAtRuleThis} */ (/** @type {unknown} */ (this));
92
+ self.evalFunction();
93
+
94
+ /** @type {Node | Ruleset} */
95
+ let result = self;
96
+
43
97
  // Render all dependent Media blocks.
44
98
  if (context.mediaBlocks.length > 1) {
45
- var selectors = (new selector_1.default([], null, null, this.getIndex(), this.fileInfo())).createEmptySelectors();
46
- result = new ruleset_1.default(selectors, context.mediaBlocks);
47
- result.multiMedia = true;
48
- result.copyVisibilityInfo(this.visibilityInfo());
49
- this.setParent(result, this);
99
+ const selectors = (new Selector([], null, null, self.getIndex(), self.fileInfo())).createEmptySelectors();
100
+ result = new Ruleset(selectors, context.mediaBlocks);
101
+ /** @type {Ruleset & { multiMedia?: boolean }} */ (result).multiMedia = true;
102
+ result.copyVisibilityInfo(self.visibilityInfo());
103
+ self.setParent(result, self);
50
104
  }
105
+
51
106
  delete context.mediaBlocks;
52
107
  delete context.mediaPath;
108
+
53
109
  return result;
54
110
  },
55
- evalNested: function (context) {
56
- this.evalFunction();
57
- var i;
58
- var value;
59
- var path = context.mediaPath.concat([this]);
111
+
112
+ /** @param {EvalContext} context */
113
+ evalNested(context) {
114
+ /** @type {NestableAtRuleThis} */
115
+ const self = /** @type {NestableAtRuleThis} */ (/** @type {unknown} */ (this));
116
+ self.evalFunction();
117
+
118
+ let i;
119
+ /** @type {Node | Node[]} */
120
+ let value;
121
+ const path = context.mediaPath.concat([self]);
122
+
60
123
  // Extract the media-query conditions separated with `,` (OR).
61
124
  for (i = 0; i < path.length; i++) {
62
- if (path[i].type !== this.type) {
63
- context.mediaBlocks.splice(i, 1);
64
- return this;
125
+ if (path[i].type !== self.type) {
126
+ const blockIndex = context.mediaBlocks.indexOf(self);
127
+ if (blockIndex > -1) {
128
+ context.mediaBlocks.splice(blockIndex, 1);
129
+ }
130
+ return self;
65
131
  }
66
- value = path[i].features instanceof value_1.default ?
67
- path[i].features.value : path[i].features;
68
- path[i] = Array.isArray(value) ? value : [value];
132
+
133
+ value = /** @type {NestableAtRuleThis} */ (path[i]).features instanceof Value ?
134
+ /** @type {Node[]} */ (/** @type {NestableAtRuleThis} */ (path[i]).features.value) : /** @type {NestableAtRuleThis} */ (path[i]).features;
135
+ path[i] = /** @type {Node} */ (/** @type {unknown} */ (Array.isArray(value) ? value : [value]));
69
136
  }
137
+
70
138
  // Trace all permutations to generate the resulting media-query.
71
139
  //
72
140
  // (a, b and c) with nested (d, e) ->
@@ -74,42 +142,57 @@ var NestableAtRulePrototype = {
74
142
  // a and e
75
143
  // b and c and d
76
144
  // b and c and e
77
- this.features = new value_1.default(this.permute(path).map(function (path) {
78
- path = path.map(function (fragment) { return fragment.toCSS ? fragment : new anonymous_1.default(fragment); });
79
- for (i = path.length - 1; i > 0; i--) {
80
- path.splice(i, 0, new anonymous_1.default('and'));
145
+ self.features = new Value(self.permute(/** @type {Node[][]} */ (/** @type {unknown} */ (path))).map(
146
+ /** @param {Node | Node[]} path */
147
+ path => {
148
+ path = /** @type {Node[]} */ (path).map(
149
+ /** @param {Node & { toCSS?: Function }} fragment */
150
+ fragment => fragment.toCSS ? fragment : new Anonymous(/** @type {string} */ (/** @type {unknown} */ (fragment))));
151
+
152
+ for (i = /** @type {Node[]} */ (path).length - 1; i > 0; i--) {
153
+ /** @type {Node[]} */ (path).splice(i, 0, new Anonymous('and'));
81
154
  }
82
- return new expression_1.default(path);
155
+
156
+ return new Expression(/** @type {Node[]} */ (path));
83
157
  }));
84
- this.setParent(this.features, this);
158
+ self.setParent(self.features, self);
159
+
85
160
  // Fake a tree-node that doesn't output anything.
86
- return new ruleset_1.default([], []);
161
+ return new Ruleset([], []);
87
162
  },
88
- permute: function (arr) {
163
+
164
+ /**
165
+ * @param {Node[][]} arr
166
+ * @returns {Node[][]}
167
+ */
168
+ permute(arr) {
89
169
  if (arr.length === 0) {
90
170
  return [];
91
- }
92
- else if (arr.length === 1) {
93
- return arr[0];
94
- }
95
- else {
96
- var result = [];
97
- var rest = this.permute(arr.slice(1));
98
- for (var i = 0; i < rest.length; i++) {
99
- for (var j = 0; j < arr[0].length; j++) {
171
+ } else if (arr.length === 1) {
172
+ return /** @type {Node[][]} */ (/** @type {unknown} */ (arr[0]));
173
+ } else {
174
+ /** @type {Node[][]} */
175
+ const result = [];
176
+ const rest = this.permute(arr.slice(1));
177
+ for (let i = 0; i < rest.length; i++) {
178
+ for (let j = 0; j < arr[0].length; j++) {
100
179
  result.push([arr[0][j]].concat(rest[i]));
101
180
  }
102
181
  }
103
182
  return result;
104
183
  }
105
184
  },
106
- bubbleSelectors: function (selectors) {
185
+
186
+ /** @param {Selector[] | undefined} selectors */
187
+ bubbleSelectors(selectors) {
188
+ /** @type {NestableAtRuleThis} */
189
+ const self = /** @type {NestableAtRuleThis} */ (/** @type {unknown} */ (this));
107
190
  if (!selectors) {
108
191
  return;
109
192
  }
110
- this.rules = [new ruleset_1.default(utils.copyArray(selectors), [this.rules[0]])];
111
- this.setParent(this.rules, this);
193
+ self.rules = [new Ruleset(utils.copyArray(selectors), [self.rules[0]])];
194
+ self.setParent(self.rules, self);
112
195
  }
113
196
  };
114
- exports.default = NestableAtRulePrototype;
115
- //# sourceMappingURL=nested-at-rule.js.map
197
+
198
+ export default NestableAtRulePrototype;
@@ -1,34 +1,108 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ // @ts-check
2
+ /**
3
+ * @typedef {object} FileInfo
4
+ * @property {string} [filename]
5
+ * @property {string} [rootpath]
6
+ * @property {string} [currentDirectory]
7
+ * @property {string} [rootFilename]
8
+ * @property {string} [entryPath]
9
+ * @property {boolean} [reference]
10
+ */
11
+
12
+ /**
13
+ * @typedef {object} VisibilityInfo
14
+ * @property {number} [visibilityBlocks]
15
+ * @property {boolean} [nodeVisible]
16
+ */
17
+
18
+ /**
19
+ * @typedef {object} CSSOutput
20
+ * @property {(chunk: string, fileInfo?: FileInfo, index?: number, mapLines?: boolean) => void} add
21
+ * @property {() => boolean} isEmpty
22
+ */
23
+
24
+ /**
25
+ * @typedef {object} EvalContext
26
+ * @property {number} [numPrecision]
27
+ * @property {(op?: string) => boolean} [isMathOn]
28
+ * @property {number} [math]
29
+ * @property {Node[]} [frames]
30
+ * @property {Array<{important?: string}>} [importantScope]
31
+ * @property {string[]} [paths]
32
+ * @property {boolean} [compress]
33
+ * @property {boolean} [strictUnits]
34
+ * @property {boolean} [sourceMap]
35
+ * @property {boolean} [importMultiple]
36
+ * @property {string} [urlArgs]
37
+ * @property {boolean} [javascriptEnabled]
38
+ * @property {object} [pluginManager]
39
+ * @property {number} [rewriteUrls]
40
+ * @property {boolean} [inCalc]
41
+ * @property {boolean} [mathOn]
42
+ * @property {boolean[]} [calcStack]
43
+ * @property {boolean[]} [parensStack]
44
+ * @property {Node[]} [mediaBlocks]
45
+ * @property {Node[]} [mediaPath]
46
+ * @property {() => void} [inParenthesis]
47
+ * @property {() => void} [outOfParenthesis]
48
+ * @property {() => void} [enterCalc]
49
+ * @property {() => void} [exitCalc]
50
+ * @property {(path: string) => boolean} [pathRequiresRewrite]
51
+ * @property {(path: string, rootpath?: string) => string} [rewritePath]
52
+ * @property {(path: string) => string} [normalizePath]
53
+ * @property {number} [tabLevel]
54
+ * @property {boolean} [lastRule]
55
+ */
56
+
57
+ /**
58
+ * @typedef {object} TreeVisitor
59
+ * @property {(node: Node) => Node} visit
60
+ * @property {(nodes: Node[], nonReplacing?: boolean) => Node[]} visitArray
61
+ */
62
+
3
63
  /**
4
64
  * The reason why Node is a class and other nodes simply do not extend
5
65
  * from Node (since we're transpiling) is due to this issue:
6
66
  *
7
67
  * @see https://github.com/less/less.js/issues/3434
8
68
  */
9
- var Node = /** @class */ (function () {
10
- function Node() {
69
+ class Node {
70
+ get type() { return ''; }
71
+
72
+ constructor() {
73
+ /** @type {Node | null} */
11
74
  this.parent = null;
75
+ /** @type {number | undefined} */
12
76
  this.visibilityBlocks = undefined;
77
+ /** @type {boolean | undefined} */
13
78
  this.nodeVisible = undefined;
79
+ /** @type {Node | null} */
14
80
  this.rootNode = null;
81
+ /** @type {Node | null} */
15
82
  this.parsed = null;
83
+
84
+ /** @type {Node | Node[] | string | number | undefined} */
85
+ this.value = undefined;
86
+ /** @type {number | undefined} */
87
+ this._index = undefined;
88
+ /** @type {FileInfo | undefined} */
89
+ this._fileInfo = undefined;
90
+ }
91
+
92
+ get currentFileInfo() {
93
+ return this.fileInfo();
94
+ }
95
+
96
+ get index() {
97
+ return this.getIndex();
16
98
  }
17
- Object.defineProperty(Node.prototype, "currentFileInfo", {
18
- get: function () {
19
- return this.fileInfo();
20
- },
21
- enumerable: false,
22
- configurable: true
23
- });
24
- Object.defineProperty(Node.prototype, "index", {
25
- get: function () {
26
- return this.getIndex();
27
- },
28
- enumerable: false,
29
- configurable: true
30
- });
31
- Node.prototype.setParent = function (nodes, parent) {
99
+
100
+ /**
101
+ * @param {Node | Node[]} nodes
102
+ * @param {Node} parent
103
+ */
104
+ setParent(nodes, parent) {
105
+ /** @param {Node} node */
32
106
  function set(node) {
33
107
  if (node && node instanceof Node) {
34
108
  node.parent = parent;
@@ -40,20 +114,30 @@ var Node = /** @class */ (function () {
40
114
  else {
41
115
  set(nodes);
42
116
  }
43
- };
44
- Node.prototype.getIndex = function () {
117
+ }
118
+
119
+ /** @returns {number} */
120
+ getIndex() {
45
121
  return this._index || (this.parent && this.parent.getIndex()) || 0;
46
- };
47
- Node.prototype.fileInfo = function () {
122
+ }
123
+
124
+ /** @returns {FileInfo} */
125
+ fileInfo() {
48
126
  return this._fileInfo || (this.parent && this.parent.fileInfo()) || {};
49
- };
50
- Node.prototype.isRulesetLike = function () { return false; };
51
- Node.prototype.toCSS = function (context) {
52
- var strs = [];
127
+ }
128
+
129
+ /** @returns {boolean} */
130
+ isRulesetLike() { return false; }
131
+
132
+ /**
133
+ * @param {EvalContext} context
134
+ * @returns {string}
135
+ */
136
+ toCSS(context) {
137
+ /** @type {string[]} */
138
+ const strs = [];
53
139
  this.genCSS(context, {
54
- // remove when genCSS has JSDoc types
55
- // eslint-disable-next-line no-unused-vars
56
- add: function (chunk, fileInfo, index) {
140
+ add: function(chunk, fileInfo, index) {
57
141
  strs.push(chunk);
58
142
  },
59
143
  isEmpty: function () {
@@ -61,115 +145,166 @@ var Node = /** @class */ (function () {
61
145
  }
62
146
  });
63
147
  return strs.join('');
64
- };
65
- Node.prototype.genCSS = function (context, output) {
66
- output.add(this.value);
67
- };
68
- Node.prototype.accept = function (visitor) {
69
- this.value = visitor.visit(this.value);
70
- };
71
- Node.prototype.eval = function () { return this; };
72
- Node.prototype._operate = function (context, op, a, b) {
148
+ }
149
+
150
+ /**
151
+ * @param {EvalContext} context
152
+ * @param {CSSOutput} output
153
+ */
154
+ genCSS(context, output) {
155
+ output.add(/** @type {string} */ (this.value));
156
+ }
157
+
158
+ /**
159
+ * @param {TreeVisitor} visitor
160
+ */
161
+ accept(visitor) {
162
+ this.value = visitor.visit(/** @type {Node} */ (this.value));
163
+ }
164
+
165
+ /**
166
+ * @param {EvalContext} [context]
167
+ * @returns {Node}
168
+ */
169
+ eval(context) { return this; }
170
+
171
+ /**
172
+ * @param {EvalContext} context
173
+ * @param {string} op
174
+ * @param {number} a
175
+ * @param {number} b
176
+ * @returns {number | undefined}
177
+ */
178
+ _operate(context, op, a, b) {
73
179
  switch (op) {
74
180
  case '+': return a + b;
75
181
  case '-': return a - b;
76
182
  case '*': return a * b;
77
183
  case '/': return a / b;
78
184
  }
79
- };
80
- Node.prototype.fround = function (context, value) {
81
- var precision = context && context.numPrecision;
185
+ }
186
+
187
+ /**
188
+ * @param {EvalContext} context
189
+ * @param {number} value
190
+ * @returns {number}
191
+ */
192
+ fround(context, value) {
193
+ const precision = context && context.numPrecision;
82
194
  // add "epsilon" to ensure numbers like 1.000000005 (represented as 1.000000004999...) are properly rounded:
83
195
  return (precision) ? Number((value + 2e-16).toFixed(precision)) : value;
84
- };
85
- Node.compare = function (a, b) {
196
+ }
197
+
198
+ /**
199
+ * @param {Node & { compare?: (other: Node) => number | undefined }} a
200
+ * @param {Node & { compare?: (other: Node) => number | undefined }} b
201
+ * @returns {number | undefined}
202
+ */
203
+ static compare(a, b) {
86
204
  /* returns:
87
205
  -1: a < b
88
206
  0: a = b
89
207
  1: a > b
90
208
  and *any* other value for a != b (e.g. undefined, NaN, -2 etc.) */
209
+
91
210
  if ((a.compare) &&
92
211
  // for "symmetric results" force toCSS-based comparison
93
212
  // of Quoted or Anonymous if either value is one of those
94
213
  !(b.type === 'Quoted' || b.type === 'Anonymous')) {
95
214
  return a.compare(b);
96
- }
97
- else if (b.compare) {
215
+ } else if (b.compare) {
98
216
  return -b.compare(a);
99
- }
100
- else if (a.type !== b.type) {
217
+ } else if (a.type !== b.type) {
101
218
  return undefined;
102
219
  }
103
- a = a.value;
104
- b = b.value;
105
- if (!Array.isArray(a)) {
106
- return a === b ? 0 : undefined;
220
+
221
+ let aVal = a.value;
222
+ let bVal = b.value;
223
+ if (!Array.isArray(aVal)) {
224
+ return aVal === bVal ? 0 : undefined;
107
225
  }
108
- if (a.length !== b.length) {
226
+ if (!Array.isArray(bVal)) {
109
227
  return undefined;
110
228
  }
111
- for (var i = 0; i < a.length; i++) {
112
- if (Node.compare(a[i], b[i]) !== 0) {
229
+ if (aVal.length !== bVal.length) {
230
+ return undefined;
231
+ }
232
+ for (let i = 0; i < aVal.length; i++) {
233
+ if (Node.compare(aVal[i], bVal[i]) !== 0) {
113
234
  return undefined;
114
235
  }
115
236
  }
116
237
  return 0;
117
- };
118
- Node.numericCompare = function (a, b) {
119
- return a < b ? -1
120
- : a === b ? 0
121
- : a > b ? 1 : undefined;
122
- };
123
- // Returns true if this node represents root of ast imported by reference
124
- Node.prototype.blocksVisibility = function () {
238
+ }
239
+
240
+ /**
241
+ * @param {number | string} a
242
+ * @param {number | string} b
243
+ * @returns {number | undefined}
244
+ */
245
+ static numericCompare(a, b) {
246
+ return a < b ? -1
247
+ : a === b ? 0
248
+ : a > b ? 1 : undefined;
249
+ }
250
+
251
+ /** @returns {boolean} */
252
+ blocksVisibility() {
125
253
  if (this.visibilityBlocks === undefined) {
126
254
  this.visibilityBlocks = 0;
127
255
  }
128
256
  return this.visibilityBlocks !== 0;
129
- };
130
- Node.prototype.addVisibilityBlock = function () {
257
+ }
258
+
259
+ addVisibilityBlock() {
131
260
  if (this.visibilityBlocks === undefined) {
132
261
  this.visibilityBlocks = 0;
133
262
  }
134
263
  this.visibilityBlocks = this.visibilityBlocks + 1;
135
- };
136
- Node.prototype.removeVisibilityBlock = function () {
264
+ }
265
+
266
+ removeVisibilityBlock() {
137
267
  if (this.visibilityBlocks === undefined) {
138
268
  this.visibilityBlocks = 0;
139
269
  }
140
270
  this.visibilityBlocks = this.visibilityBlocks - 1;
141
- };
142
- // Turns on node visibility - if called node will be shown in output regardless
143
- // of whether it comes from import by reference or not
144
- Node.prototype.ensureVisibility = function () {
271
+ }
272
+
273
+ ensureVisibility() {
145
274
  this.nodeVisible = true;
146
- };
147
- // Turns off node visibility - if called node will NOT be shown in output regardless
148
- // of whether it comes from import by reference or not
149
- Node.prototype.ensureInvisibility = function () {
275
+ }
276
+
277
+ ensureInvisibility() {
150
278
  this.nodeVisible = false;
151
- };
152
- // return values:
153
- // false - the node must not be visible
154
- // true - the node must be visible
155
- // undefined or null - the node has the same visibility as its parent
156
- Node.prototype.isVisible = function () {
279
+ }
280
+
281
+ /** @returns {boolean | undefined} */
282
+ isVisible() {
157
283
  return this.nodeVisible;
158
- };
159
- Node.prototype.visibilityInfo = function () {
284
+ }
285
+
286
+ /** @returns {VisibilityInfo} */
287
+ visibilityInfo() {
160
288
  return {
161
289
  visibilityBlocks: this.visibilityBlocks,
162
290
  nodeVisible: this.nodeVisible
163
291
  };
164
- };
165
- Node.prototype.copyVisibilityInfo = function (info) {
292
+ }
293
+
294
+ /** @param {VisibilityInfo} info */
295
+ copyVisibilityInfo(info) {
166
296
  if (!info) {
167
297
  return;
168
298
  }
169
299
  this.visibilityBlocks = info.visibilityBlocks;
170
300
  this.nodeVisible = info.nodeVisible;
171
- };
172
- return Node;
173
- }());
174
- exports.default = Node;
175
- //# sourceMappingURL=node.js.map
301
+ }
302
+ }
303
+
304
+ /**
305
+ * Set by the parser at runtime on Node.prototype.
306
+ * @type {{ context: EvalContext, importManager: object, imports: object } | undefined}
307
+ */
308
+ Node.prototype.parse = undefined;
309
+
310
+ export default Node;