less 4.5.1 → 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 (338) hide show
  1. package/bin/lessc +37 -23
  2. package/dist/less.js +14497 -11745
  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 -55
  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 +36 -26
  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 +63 -45
  36. package/lib/less/logger.js +11 -14
  37. package/lib/less/parse-tree.js +52 -53
  38. package/lib/less/parse.js +44 -44
  39. package/lib/less/parser/parser-input.js +151 -113
  40. package/lib/less/parser/parser.js +864 -658
  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 +56 -43
  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 +28 -15
  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 +20 -21
  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 +25 -18
  119. package/.eslintignore +0 -6
  120. package/.eslintrc.js +0 -63
  121. package/Gruntfile.js +0 -403
  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/parser-input.js.map +0 -1
  159. package/lib/less/parser/parser.js.map +0 -1
  160. package/lib/less/plugin-manager.js.map +0 -1
  161. package/lib/less/render.js.map +0 -1
  162. package/lib/less/source-map-builder.js.map +0 -1
  163. package/lib/less/source-map-output.js.map +0 -1
  164. package/lib/less/transform-tree.js.map +0 -1
  165. package/lib/less/tree/anonymous.js.map +0 -1
  166. package/lib/less/tree/assignment.js.map +0 -1
  167. package/lib/less/tree/atrule-syntax.js.map +0 -1
  168. package/lib/less/tree/atrule.js.map +0 -1
  169. package/lib/less/tree/attribute.js.map +0 -1
  170. package/lib/less/tree/call.js.map +0 -1
  171. package/lib/less/tree/color.js.map +0 -1
  172. package/lib/less/tree/combinator.js.map +0 -1
  173. package/lib/less/tree/comment.js.map +0 -1
  174. package/lib/less/tree/condition.js.map +0 -1
  175. package/lib/less/tree/container.js.map +0 -1
  176. package/lib/less/tree/debug-info.js.map +0 -1
  177. package/lib/less/tree/declaration.js.map +0 -1
  178. package/lib/less/tree/detached-ruleset.js.map +0 -1
  179. package/lib/less/tree/dimension.js.map +0 -1
  180. package/lib/less/tree/element.js.map +0 -1
  181. package/lib/less/tree/expression.js.map +0 -1
  182. package/lib/less/tree/extend.js.map +0 -1
  183. package/lib/less/tree/import.js.map +0 -1
  184. package/lib/less/tree/index.js.map +0 -1
  185. package/lib/less/tree/javascript.js.map +0 -1
  186. package/lib/less/tree/js-eval-node.js.map +0 -1
  187. package/lib/less/tree/keyword.js.map +0 -1
  188. package/lib/less/tree/media.js.map +0 -1
  189. package/lib/less/tree/mixin-call.js.map +0 -1
  190. package/lib/less/tree/mixin-definition.js.map +0 -1
  191. package/lib/less/tree/namespace-value.js.map +0 -1
  192. package/lib/less/tree/negative.js.map +0 -1
  193. package/lib/less/tree/nested-at-rule.js.map +0 -1
  194. package/lib/less/tree/node.js.map +0 -1
  195. package/lib/less/tree/operation.js.map +0 -1
  196. package/lib/less/tree/paren.js.map +0 -1
  197. package/lib/less/tree/property.js.map +0 -1
  198. package/lib/less/tree/query-in-parens.js.map +0 -1
  199. package/lib/less/tree/quoted.js.map +0 -1
  200. package/lib/less/tree/ruleset.js.map +0 -1
  201. package/lib/less/tree/selector.js.map +0 -1
  202. package/lib/less/tree/unicode-descriptor.js.map +0 -1
  203. package/lib/less/tree/unit.js.map +0 -1
  204. package/lib/less/tree/url.js.map +0 -1
  205. package/lib/less/tree/value.js.map +0 -1
  206. package/lib/less/tree/variable-call.js.map +0 -1
  207. package/lib/less/tree/variable.js.map +0 -1
  208. package/lib/less/utils.js.map +0 -1
  209. package/lib/less/visitors/extend-visitor.js.map +0 -1
  210. package/lib/less/visitors/import-sequencer.js.map +0 -1
  211. package/lib/less/visitors/import-visitor.js.map +0 -1
  212. package/lib/less/visitors/index.js.map +0 -1
  213. package/lib/less/visitors/join-selector-visitor.js.map +0 -1
  214. package/lib/less/visitors/set-tree-visibility-visitor.js.map +0 -1
  215. package/lib/less/visitors/to-css-visitor.js.map +0 -1
  216. package/lib/less/visitors/visitor.js.map +0 -1
  217. package/lib/less-browser/add-default-options.js.map +0 -1
  218. package/lib/less-browser/bootstrap.js.map +0 -1
  219. package/lib/less-browser/browser.js.map +0 -1
  220. package/lib/less-browser/cache.js.map +0 -1
  221. package/lib/less-browser/error-reporting.js.map +0 -1
  222. package/lib/less-browser/file-manager.js.map +0 -1
  223. package/lib/less-browser/image-size.js.map +0 -1
  224. package/lib/less-browser/index.js.map +0 -1
  225. package/lib/less-browser/log-listener.js.map +0 -1
  226. package/lib/less-browser/plugin-loader.js.map +0 -1
  227. package/lib/less-browser/utils.js.map +0 -1
  228. package/lib/less-node/environment.js.map +0 -1
  229. package/lib/less-node/file-manager.js.map +0 -1
  230. package/lib/less-node/fs.js.map +0 -1
  231. package/lib/less-node/image-size.js.map +0 -1
  232. package/lib/less-node/index.js.map +0 -1
  233. package/lib/less-node/lessc-helper.js.map +0 -1
  234. package/lib/less-node/plugin-loader.js.map +0 -1
  235. package/lib/less-node/url-file-manager.js.map +0 -1
  236. package/scripts/coverage-lines.js +0 -207
  237. package/scripts/coverage-report.js +0 -158
  238. package/scripts/postinstall.js +0 -61
  239. package/test/.eslintrc.json +0 -9
  240. package/test/README.md +0 -3
  241. package/test/browser/common.js +0 -251
  242. package/test/browser/css/global-vars/simple.css +0 -3
  243. package/test/browser/css/modify-vars/simple.css +0 -8
  244. package/test/browser/css/plugin/plugin.css +0 -3
  245. package/test/browser/css/postProcessor/postProcessor.css +0 -4
  246. package/test/browser/css/relative-urls/urls.css +0 -36
  247. package/test/browser/css/rewrite-urls/urls.css +0 -36
  248. package/test/browser/css/rootpath/urls.css +0 -35
  249. package/test/browser/css/rootpath-relative/urls.css +0 -35
  250. package/test/browser/css/rootpath-rewrite-urls/urls.css +0 -35
  251. package/test/browser/css/urls.css +0 -54
  252. package/test/browser/generator/benchmark.config.js +0 -50
  253. package/test/browser/generator/generate.js +0 -78
  254. package/test/browser/generator/runner.config.js +0 -184
  255. package/test/browser/generator/runner.js +0 -2
  256. package/test/browser/generator/template.js +0 -104
  257. package/test/browser/generator/utils.js +0 -14
  258. package/test/browser/less/console-errors/test-error.less +0 -3
  259. package/test/browser/less/console-errors/test-error.txt +0 -2
  260. package/test/browser/less/errors/image-height-error.less +0 -3
  261. package/test/browser/less/errors/image-height-error.txt +0 -4
  262. package/test/browser/less/errors/image-size-error.less +0 -3
  263. package/test/browser/less/errors/image-size-error.txt +0 -4
  264. package/test/browser/less/errors/image-width-error.less +0 -3
  265. package/test/browser/less/errors/image-width-error.txt +0 -4
  266. package/test/browser/less/global-vars/simple.less +0 -3
  267. package/test/browser/less/imports/urls.less +0 -4
  268. package/test/browser/less/imports/urls2.less +0 -4
  269. package/test/browser/less/modify-vars/imports/simple2.less +0 -4
  270. package/test/browser/less/modify-vars/simple.less +0 -8
  271. package/test/browser/less/nested-gradient-with-svg-gradient/mixin-consumer.less +0 -5
  272. package/test/browser/less/nested-gradient-with-svg-gradient/svg-gradient-mixin.less +0 -15
  273. package/test/browser/less/plugin/plugin.js +0 -4
  274. package/test/browser/less/plugin/plugin.less +0 -4
  275. package/test/browser/less/postProcessor/postProcessor.less +0 -4
  276. package/test/browser/less/relative-urls/urls.less +0 -34
  277. package/test/browser/less/rewrite-urls/urls.less +0 -34
  278. package/test/browser/less/rootpath/urls.less +0 -33
  279. package/test/browser/less/rootpath-relative/urls.less +0 -33
  280. package/test/browser/less/rootpath-rewrite-urls/urls.less +0 -33
  281. package/test/browser/less/urls.less +0 -62
  282. package/test/browser/runner-VisitorPlugin-options.js +0 -3
  283. package/test/browser/runner-VisitorPlugin.js +0 -3
  284. package/test/browser/runner-browser-options.js +0 -51
  285. package/test/browser/runner-browser-spec.js +0 -12
  286. package/test/browser/runner-console-errors.js +0 -5
  287. package/test/browser/runner-errors-options.js +0 -6
  288. package/test/browser/runner-errors-spec.js +0 -3
  289. package/test/browser/runner-filemanagerPlugin-options.js +0 -5
  290. package/test/browser/runner-filemanagerPlugin.js +0 -3
  291. package/test/browser/runner-global-vars-options.js +0 -7
  292. package/test/browser/runner-global-vars-spec.js +0 -3
  293. package/test/browser/runner-main-options.js +0 -17
  294. package/test/browser/runner-main-spec.js +0 -7
  295. package/test/browser/runner-modify-vars-options.js +0 -5
  296. package/test/browser/runner-modify-vars-spec.js +0 -33
  297. package/test/browser/runner-no-js-errors-options.js +0 -4
  298. package/test/browser/runner-no-js-errors-spec.js +0 -3
  299. package/test/browser/runner-postProcessorPlugin-options.js +0 -3
  300. package/test/browser/runner-postProcessorPlugin.js +0 -3
  301. package/test/browser/runner-preProcessorPlugin-options.js +0 -3
  302. package/test/browser/runner-preProcessorPlugin.js +0 -3
  303. package/test/browser/runner-production-options.js +0 -3
  304. package/test/browser/runner-production-spec.js +0 -5
  305. package/test/browser/runner-relative-urls-options.js +0 -3
  306. package/test/browser/runner-relative-urls-spec.js +0 -3
  307. package/test/browser/runner-rewrite-urls-options.js +0 -3
  308. package/test/browser/runner-rewrite-urls-spec.js +0 -3
  309. package/test/browser/runner-rootpath-options.js +0 -3
  310. package/test/browser/runner-rootpath-relative-options.js +0 -4
  311. package/test/browser/runner-rootpath-relative-spec.js +0 -3
  312. package/test/browser/runner-rootpath-rewrite-urls-options.js +0 -4
  313. package/test/browser/runner-rootpath-rewrite-urls-spec.js +0 -3
  314. package/test/browser/runner-rootpath-spec.js +0 -3
  315. package/test/browser/runner-strict-units-options.js +0 -5
  316. package/test/browser/runner-strict-units-spec.js +0 -3
  317. package/test/index.js +0 -307
  318. package/test/less-test.js +0 -984
  319. package/test/mocha-playwright/runner.js +0 -210
  320. package/test/modify-vars.js +0 -28
  321. package/test/plugins/filemanager/index.js +0 -19
  322. package/test/plugins/postprocess/index.js +0 -14
  323. package/test/plugins/preprocess/index.js +0 -19
  324. package/test/plugins/visitor/index.js +0 -24
  325. package/test/sourcemaps/basic.json +0 -1
  326. package/test/sourcemaps/comprehensive.json +0 -1
  327. package/test/sourcemaps/custom-props.json +0 -1
  328. package/test/sourcemaps/index.html +0 -17
  329. package/test/sourcemaps/sourcemaps-basepath.json +0 -1
  330. package/test/sourcemaps/sourcemaps-include-source.json +0 -1
  331. package/test/sourcemaps/sourcemaps-rootpath.json +0 -1
  332. package/test/sourcemaps/sourcemaps-url.json +0 -1
  333. package/test/sourcemaps-disable-annotation/basic.json +0 -1
  334. package/test/sourcemaps-variable-selector/basic.json +0 -1
  335. package/test/test-es6.ts +0 -17
  336. package/test.less +0 -1
  337. package/tsconfig.build.json +0 -7
  338. package/tsconfig.json +0 -21
@@ -1,111 +1,188 @@
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 selector_1 = tslib_1.__importDefault(require("./selector"));
6
- var ruleset_1 = tslib_1.__importDefault(require("./ruleset"));
7
- var anonymous_1 = tslib_1.__importDefault(require("./anonymous"));
8
- var nested_at_rule_1 = tslib_1.__importDefault(require("./nested-at-rule"));
9
- var AtRule = function (name, value, rules, index, currentFileInfo, debugInfo, isRooted, visibilityInfo) {
10
- var _this = this;
11
- var i;
12
- var selectors = (new selector_1.default([], null, null, this._index, this._fileInfo)).createEmptySelectors();
13
- this.name = name;
14
- this.value = (value instanceof node_1.default) ? value : (value ? new anonymous_1.default(value) : value);
15
- if (rules) {
16
- if (Array.isArray(rules)) {
17
- var allDeclarations = this.declarationsBlock(rules);
18
- var allRulesetDeclarations_1 = true;
19
- rules.forEach(function (rule) {
20
- if (rule.type === 'Ruleset' && rule.rules)
21
- allRulesetDeclarations_1 = allRulesetDeclarations_1 && _this.declarationsBlock(rule.rules, true);
22
- });
23
- if (allDeclarations && !isRooted) {
24
- this.simpleBlock = true;
25
- this.declarations = rules;
26
- }
27
- else if (allRulesetDeclarations_1 && rules.length === 1 && !isRooted && !value) {
28
- this.simpleBlock = true;
29
- this.declarations = rules[0].rules ? rules[0].rules : rules;
1
+ // @ts-check
2
+ /** @import { EvalContext, CSSOutput, TreeVisitor, FileInfo, VisibilityInfo } from './node.js' */
3
+ /** @import { FunctionRegistry } from './nested-at-rule.js' */
4
+ import Node from './node.js';
5
+ import Selector from './selector.js';
6
+ import Ruleset from './ruleset.js';
7
+ import Anonymous from './anonymous.js';
8
+ import NestableAtRulePrototype from './nested-at-rule.js';
9
+ import mergeRules from './merge-rules.js';
10
+
11
+ /**
12
+ * @typedef {Node & {
13
+ * rules?: Node[],
14
+ * selectors?: Selector[],
15
+ * root?: boolean,
16
+ * allowImports?: boolean,
17
+ * functionRegistry?: FunctionRegistry,
18
+ * merge?: boolean,
19
+ * debugInfo?: { lineNumber: number, fileName: string },
20
+ * elements?: import('./element.js').default[]
21
+ * }} RulesetLikeNode
22
+ */
23
+
24
+ class AtRule extends Node {
25
+ get type() { return 'AtRule'; }
26
+
27
+ /**
28
+ * @param {string} [name]
29
+ * @param {Node | string} [value]
30
+ * @param {Node[] | Ruleset} [rules]
31
+ * @param {number} [index]
32
+ * @param {FileInfo} [currentFileInfo]
33
+ * @param {{ lineNumber: number, fileName: string }} [debugInfo]
34
+ * @param {boolean} [isRooted]
35
+ * @param {VisibilityInfo} [visibilityInfo]
36
+ */
37
+ constructor(
38
+ name,
39
+ value,
40
+ rules,
41
+ index,
42
+ currentFileInfo,
43
+ debugInfo,
44
+ isRooted,
45
+ visibilityInfo
46
+ ) {
47
+ super();
48
+ let i;
49
+ var selectors = (new Selector([], null, null, index, currentFileInfo)).createEmptySelectors();
50
+
51
+ /** @type {string | undefined} */
52
+ this.name = name;
53
+ this.value = (value instanceof Node) ? value : (value ? new Anonymous(value) : value);
54
+ /** @type {boolean | undefined} */
55
+ this.simpleBlock = undefined;
56
+ /** @type {RulesetLikeNode[] | undefined} */
57
+ this.declarations = undefined;
58
+ /** @type {RulesetLikeNode[] | undefined} */
59
+ this.rules = undefined;
60
+ if (rules) {
61
+ if (Array.isArray(rules)) {
62
+ const allDeclarations = this.declarationsBlock(rules);
63
+
64
+ let allRulesetDeclarations = true;
65
+ rules.forEach(rule => {
66
+ if (rule.type === 'Ruleset' && /** @type {RulesetLikeNode} */ (rule).rules) allRulesetDeclarations = allRulesetDeclarations && this.declarationsBlock(/** @type {Node[]} */ (/** @type {RulesetLikeNode} */ (rule).rules), true);
67
+ });
68
+
69
+ if (allDeclarations && !isRooted) {
70
+ this.simpleBlock = true;
71
+ this.declarations = rules;
72
+ } else if (allRulesetDeclarations && rules.length === 1 && !isRooted && !value) {
73
+ this.simpleBlock = true;
74
+ this.declarations = /** @type {RulesetLikeNode} */ (rules[0]).rules ? /** @type {RulesetLikeNode} */ (rules[0]).rules : rules;
75
+ } else {
76
+ this.rules = rules;
77
+ }
78
+ } else {
79
+ const allDeclarations = this.declarationsBlock(/** @type {Node[]} */ (rules.rules));
80
+
81
+ if (allDeclarations && !isRooted && !value) {
82
+ this.simpleBlock = true;
83
+ this.declarations = rules.rules;
84
+ } else {
85
+ this.rules = [rules];
86
+ /** @type {RulesetLikeNode} */ (this.rules[0]).selectors = (new Selector([], null, null, index, currentFileInfo)).createEmptySelectors();
87
+ }
30
88
  }
31
- else {
32
- this.rules = rules;
89
+ if (!this.simpleBlock) {
90
+ for (i = 0; i < this.rules.length; i++) {
91
+ /** @type {RulesetLikeNode} */ (this.rules[i]).allowImports = true;
92
+ }
33
93
  }
34
- }
35
- else {
36
- var allDeclarations = this.declarationsBlock(rules.rules);
37
- if (allDeclarations && !isRooted && !value) {
38
- this.simpleBlock = true;
39
- this.declarations = rules.rules;
94
+ if (this.declarations) {
95
+ this.setParent(this.declarations, /** @type {Node} */ (/** @type {unknown} */ (this)));
40
96
  }
41
- else {
42
- this.rules = [rules];
43
- this.rules[0].selectors = (new selector_1.default([], null, null, index, currentFileInfo)).createEmptySelectors();
97
+ if (this.rules) {
98
+ this.setParent(this.rules, /** @type {Node} */ (/** @type {unknown} */ (this)));
44
99
  }
45
100
  }
46
- if (!this.simpleBlock) {
47
- for (i = 0; i < this.rules.length; i++) {
48
- this.rules[i].allowImports = true;
49
- }
50
- }
51
- this.setParent(selectors, this);
52
- this.setParent(this.rules, this);
101
+ this._index = index;
102
+ this._fileInfo = currentFileInfo;
103
+ /** @type {{ lineNumber: number, fileName: string } | undefined} */
104
+ this.debugInfo = debugInfo;
105
+ /** @type {boolean} */
106
+ this.isRooted = isRooted || false;
107
+ this.copyVisibilityInfo(visibilityInfo);
108
+ this.allowRoot = true;
53
109
  }
54
- this._index = index;
55
- this._fileInfo = currentFileInfo;
56
- this.debugInfo = debugInfo;
57
- this.isRooted = isRooted || false;
58
- this.copyVisibilityInfo(visibilityInfo);
59
- this.allowRoot = true;
60
- };
61
- AtRule.prototype = Object.assign(new node_1.default(), tslib_1.__assign(tslib_1.__assign({ type: 'AtRule' }, nested_at_rule_1.default), { declarationsBlock: function (rules, mergeable) {
62
- if (mergeable === void 0) { mergeable = false; }
110
+
111
+ /**
112
+ * @param {Node[]} rules
113
+ * @param {boolean} [mergeable]
114
+ * @returns {boolean}
115
+ */
116
+ declarationsBlock(rules, mergeable = false) {
63
117
  if (!mergeable) {
64
- return rules.filter(function (node) { return (node.type === 'Declaration' || node.type === 'Comment') && !node.merge; }).length === rules.length;
65
- }
66
- else {
67
- return rules.filter(function (node) { return (node.type === 'Declaration' || node.type === 'Comment'); }).length === rules.length;
118
+ return rules.filter(function (/** @type {Node & { merge?: boolean }} */ node) { return (node.type === 'Declaration' || node.type === 'Comment') && !node.merge}).length === rules.length;
119
+ } else {
120
+ return rules.filter(function (/** @type {Node} */ node) { return (node.type === 'Declaration' || node.type === 'Comment'); }).length === rules.length;
68
121
  }
69
- }, keywordList: function (rules) {
122
+ }
123
+
124
+ /**
125
+ * @param {Node[]} rules
126
+ * @returns {boolean}
127
+ */
128
+ keywordList(rules) {
70
129
  if (!Array.isArray(rules)) {
71
130
  return false;
131
+ } else {
132
+ return rules.filter(function (/** @type {Node} */ node) { return (node.type === 'Keyword' || node.type === 'Comment'); }).length === rules.length;
72
133
  }
73
- else {
74
- return rules.filter(function (node) { return (node.type === 'Keyword' || node.type === 'Comment'); }).length === rules.length;
75
- }
76
- }, accept: function (visitor) {
77
- var value = this.value, rules = this.rules, declarations = this.declarations;
134
+ }
135
+
136
+ /** @param {TreeVisitor} visitor */
137
+ accept(visitor) {
138
+ const value = this.value, rules = this.rules, declarations = this.declarations;
139
+
78
140
  if (rules) {
79
141
  this.rules = visitor.visitArray(rules);
80
- }
81
- else if (declarations) {
142
+ } else if (declarations) {
82
143
  this.declarations = visitor.visitArray(declarations);
83
144
  }
84
145
  if (value) {
85
- this.value = visitor.visit(value);
146
+ this.value = visitor.visit(/** @type {Node} */ (value));
86
147
  }
87
- }, isRulesetLike: function () {
88
- return this.rules || !this.isCharset();
89
- }, isCharset: function () {
148
+ }
149
+
150
+ /** @override @returns {boolean} */
151
+ isRulesetLike() {
152
+ return /** @type {boolean} */ (/** @type {unknown} */ (this.rules || !this.isCharset()));
153
+ }
154
+
155
+ isCharset() {
90
156
  return '@charset' === this.name;
91
- }, genCSS: function (context, output) {
92
- var value = this.value, rules = this.rules || this.declarations;
93
- output.add(this.name, this.fileInfo(), this.getIndex());
157
+ }
158
+
159
+ /**
160
+ * @param {EvalContext} context
161
+ * @param {CSSOutput} output
162
+ */
163
+ genCSS(context, output) {
164
+ const value = this.value, rules = this.rules || this.declarations;
165
+ output.add(/** @type {string} */ (this.name), this.fileInfo(), this.getIndex());
94
166
  if (value) {
95
167
  output.add(' ');
96
- value.genCSS(context, output);
168
+ /** @type {Node} */ (value).genCSS(context, output);
97
169
  }
98
170
  if (this.simpleBlock) {
99
- this.outputRuleset(context, output, this.declarations);
100
- }
101
- else if (rules) {
171
+ this.outputRuleset(context, output, /** @type {Node[]} */ (this.declarations));
172
+ } else if (rules) {
102
173
  this.outputRuleset(context, output, rules);
103
- }
104
- else {
174
+ } else {
105
175
  output.add(';');
106
176
  }
107
- }, eval: function (context) {
108
- var mediaPathBackup, mediaBlocksBackup, value = this.value, rules = this.rules || this.declarations;
177
+ }
178
+
179
+ /**
180
+ * @param {EvalContext} context
181
+ * @returns {Node}
182
+ */
183
+ eval(context) {
184
+ let mediaPathBackup, mediaBlocksBackup, value = this.value, rules = this.rules || this.declarations;
185
+
109
186
  // media stored inside other atrule should not bubble over it
110
187
  // backpup media bubbling information
111
188
  mediaPathBackup = context.mediaPath;
@@ -113,96 +190,120 @@ AtRule.prototype = Object.assign(new node_1.default(), tslib_1.__assign(tslib_1.
113
190
  // deleted media bubbling information
114
191
  context.mediaPath = [];
115
192
  context.mediaBlocks = [];
193
+
116
194
  if (value) {
117
- value = value.eval(context);
118
- if (value.value && this.keywordList(value.value)) {
119
- value = new anonymous_1.default(value.value.map(function (keyword) { return keyword.value; }).join(', '), this.getIndex(), this.fileInfo());
120
- }
195
+ value = /** @type {Node} */ (value).eval(context);
121
196
  }
197
+
122
198
  if (rules) {
123
199
  rules = this.evalRoot(context, rules);
124
200
  }
125
- if (Array.isArray(rules) && rules[0].rules && Array.isArray(rules[0].rules) && rules[0].rules.length) {
126
- var allMergeableDeclarations = this.declarationsBlock(rules[0].rules, true);
201
+ if (Array.isArray(rules) && /** @type {RulesetLikeNode} */ (rules[0]).rules && Array.isArray(/** @type {RulesetLikeNode} */ (rules[0]).rules) && /** @type {Node[]} */ (/** @type {RulesetLikeNode} */ (rules[0]).rules).length) {
202
+ const allMergeableDeclarations = this.declarationsBlock(/** @type {Node[]} */ (/** @type {RulesetLikeNode} */ (rules[0]).rules), true);
127
203
  if (allMergeableDeclarations && !this.isRooted && !value) {
128
- var mergeRules = context.pluginManager.less.visitors.ToCSSVisitor.prototype._mergeRules;
129
- mergeRules(rules[0].rules);
130
- rules = rules[0].rules;
131
- rules.forEach(function (rule) { return rule.merge = false; });
204
+ mergeRules(/** @type {Node[]} */ (/** @type {RulesetLikeNode} */ (rules[0]).rules));
205
+ rules = /** @type {RulesetLikeNode[]} */ (/** @type {RulesetLikeNode} */ (rules[0]).rules);
206
+ rules.forEach(/** @param {RulesetLikeNode} rule */ rule => { rule.merge = false; });
132
207
  }
133
208
  }
134
209
  if (this.simpleBlock && rules) {
135
- rules[0].functionRegistry = context.frames[0].functionRegistry.inherit();
136
- rules = rules.map(function (rule) { return rule.eval(context); });
210
+ /** @type {RulesetLikeNode} */ (rules[0]).functionRegistry = /** @type {RulesetLikeNode} */ (context.frames[0]).functionRegistry.inherit();
211
+ rules = rules.map(function (/** @type {Node} */ rule) { return rule.eval(context); });
137
212
  }
213
+
138
214
  // restore media bubbling information
139
215
  context.mediaPath = mediaPathBackup;
140
216
  context.mediaBlocks = mediaBlocksBackup;
141
- return new AtRule(this.name, value, rules, this.getIndex(), this.fileInfo(), this.debugInfo, this.isRooted, this.visibilityInfo());
142
- }, evalRoot: function (context, rules) {
143
- var ampersandCount = 0;
144
- var noAmpersandCount = 0;
145
- var noAmpersands = true;
146
- var allAmpersands = false;
217
+ return /** @type {Node} */ (/** @type {unknown} */ (new AtRule(this.name, value, rules, this.getIndex(), this.fileInfo(), this.debugInfo, this.isRooted, this.visibilityInfo())));
218
+ }
219
+
220
+ /**
221
+ * @param {EvalContext} context
222
+ * @param {Node[]} rules
223
+ * @returns {Node[]}
224
+ */
225
+ evalRoot(context, rules) {
226
+ let ampersandCount = 0;
227
+ let noAmpersandCount = 0;
228
+ let noAmpersands = true;
229
+
147
230
  if (!this.simpleBlock) {
148
231
  rules = [rules[0].eval(context)];
149
232
  }
150
- var precedingSelectors = [];
233
+
234
+ /** @type {Selector[]} */
235
+ let precedingSelectors = [];
151
236
  if (context.frames.length > 0) {
152
- var _loop_1 = function (index) {
153
- var frame = context.frames[index];
154
- if (frame.type === 'Ruleset' &&
237
+ for (let index = 0; index < context.frames.length; index++) {
238
+ const frame = /** @type {RulesetLikeNode} */ (context.frames[index]);
239
+ if (
240
+ frame.type === 'Ruleset' &&
155
241
  frame.rules &&
156
- frame.rules.length > 0) {
242
+ frame.rules.length > 0
243
+ ) {
157
244
  if (frame && !frame.root && frame.selectors && frame.selectors.length > 0) {
158
245
  precedingSelectors = precedingSelectors.concat(frame.selectors);
159
246
  }
160
247
  }
161
248
  if (precedingSelectors.length > 0) {
162
- var value_1 = '';
163
- var output = { add: function (s) { value_1 += s; } };
164
- for (var i = 0; i < precedingSelectors.length; i++) {
165
- precedingSelectors[i].genCSS(context, output);
166
- }
167
- if (/^&+$/.test(value_1.replace(/\s+/g, ''))) {
249
+ const allAmpersandElements = precedingSelectors.every(
250
+ sel => sel.elements && sel.elements.length > 0 && sel.elements.every(
251
+ /** @param {import('./element.js').default} el */
252
+ el => el.value === '&'
253
+ )
254
+ );
255
+ if (allAmpersandElements) {
168
256
  noAmpersands = false;
169
257
  noAmpersandCount++;
170
- }
171
- else {
172
- allAmpersands = false;
258
+ } else {
173
259
  ampersandCount++;
174
260
  }
175
261
  }
176
- };
177
- for (var index = 0; index < context.frames.length; index++) {
178
- _loop_1(index);
179
262
  }
180
263
  }
181
- var mixedAmpersands = ampersandCount > 0 && noAmpersandCount > 0 && !allAmpersands && !noAmpersands;
182
- if ((this.isRooted && ampersandCount > 0 && noAmpersandCount === 0 && !allAmpersands && noAmpersands)
183
- || !mixedAmpersands) {
184
- rules[0].root = true;
264
+
265
+ const mixedAmpersands = ampersandCount > 0 && noAmpersandCount > 0 && !noAmpersands;
266
+ if (
267
+ (this.isRooted && ampersandCount > 0 && noAmpersandCount === 0 && noAmpersands)
268
+ || !mixedAmpersands
269
+ ) {
270
+ /** @type {RulesetLikeNode} */ (rules[0]).root = true;
185
271
  }
186
272
  return rules;
187
- }, variable: function (name) {
273
+ }
274
+
275
+ /** @param {string} name */
276
+ variable(name) {
188
277
  if (this.rules) {
189
278
  // assuming that there is only one rule at this point - that is how parser constructs the rule
190
- return ruleset_1.default.prototype.variable.call(this.rules[0], name);
279
+ return Ruleset.prototype.variable.call(this.rules[0], name);
191
280
  }
192
- }, find: function () {
281
+ }
282
+
283
+ find() {
193
284
  if (this.rules) {
194
285
  // assuming that there is only one rule at this point - that is how parser constructs the rule
195
- return ruleset_1.default.prototype.find.apply(this.rules[0], arguments);
286
+ return Ruleset.prototype.find.apply(this.rules[0], arguments);
196
287
  }
197
- }, rulesets: function () {
288
+ }
289
+
290
+ rulesets() {
198
291
  if (this.rules) {
199
292
  // assuming that there is only one rule at this point - that is how parser constructs the rule
200
- return ruleset_1.default.prototype.rulesets.apply(this.rules[0]);
293
+ return Ruleset.prototype.rulesets.apply(this.rules[0]);
201
294
  }
202
- }, outputRuleset: function (context, output, rules) {
203
- var ruleCnt = rules.length;
204
- var i;
295
+ }
296
+
297
+ /**
298
+ * @param {EvalContext} context
299
+ * @param {CSSOutput} output
300
+ * @param {Node[]} rules
301
+ */
302
+ outputRuleset(context, output, rules) {
303
+ const ruleCnt = rules.length;
304
+ let i;
205
305
  context.tabLevel = (context.tabLevel | 0) + 1;
306
+
206
307
  // Compressed
207
308
  if (context.compress) {
208
309
  output.add('{');
@@ -213,21 +314,27 @@ AtRule.prototype = Object.assign(new node_1.default(), tslib_1.__assign(tslib_1.
213
314
  context.tabLevel--;
214
315
  return;
215
316
  }
317
+
216
318
  // Non-compressed
217
- var tabSetStr = "\n".concat(Array(context.tabLevel).join(' ')), tabRuleStr = "".concat(tabSetStr, " ");
319
+ const tabSetStr = `\n${Array(context.tabLevel).join(' ')}`, tabRuleStr = `${tabSetStr} `;
218
320
  if (!ruleCnt) {
219
- output.add(" {".concat(tabSetStr, "}"));
220
- }
221
- else {
222
- output.add(" {".concat(tabRuleStr));
321
+ output.add(` {${tabSetStr}}`);
322
+ } else {
323
+ output.add(` {${tabRuleStr}`);
223
324
  rules[0].genCSS(context, output);
224
325
  for (i = 1; i < ruleCnt; i++) {
225
326
  output.add(tabRuleStr);
226
327
  rules[i].genCSS(context, output);
227
328
  }
228
- output.add("".concat(tabSetStr, "}"));
329
+ output.add(`${tabSetStr}}`);
229
330
  }
331
+
230
332
  context.tabLevel--;
231
- } }));
232
- exports.default = AtRule;
233
- //# sourceMappingURL=atrule.js.map
333
+ }
334
+ }
335
+
336
+ // Apply shared methods from NestableAtRulePrototype that AtRule doesn't override
337
+ const { evalFunction, evalTop, evalNested, permute, bubbleSelectors } = NestableAtRulePrototype;
338
+ Object.assign(AtRule.prototype, { evalFunction, evalTop, evalNested, permute, bubbleSelectors });
339
+
340
+ export default AtRule;
@@ -1,32 +1,63 @@
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 Attribute = function (key, op, value, cif) {
6
- this.key = key;
7
- this.op = op;
8
- this.value = value;
9
- this.cif = cif;
10
- };
11
- Attribute.prototype = Object.assign(new node_1.default(), {
12
- type: 'Attribute',
13
- eval: function (context) {
14
- return new Attribute(this.key.eval ? this.key.eval(context) : this.key, this.op, (this.value && this.value.eval) ? this.value.eval(context) : this.value, this.cif);
15
- },
16
- genCSS: function (context, output) {
1
+ // @ts-check
2
+ /** @import { EvalContext, CSSOutput } from './node.js' */
3
+ import Node from './node.js';
4
+
5
+ class Attribute extends Node {
6
+ get type() { return 'Attribute'; }
7
+
8
+ /**
9
+ * @param {string | Node} key
10
+ * @param {string} op
11
+ * @param {string | Node} value
12
+ * @param {string} cif
13
+ */
14
+ constructor(key, op, value, cif) {
15
+ super();
16
+ this.key = key;
17
+ this.op = op;
18
+ this.value = value;
19
+ this.cif = cif;
20
+ }
21
+
22
+ /**
23
+ * @param {EvalContext} context
24
+ * @returns {Attribute}
25
+ */
26
+ eval(context) {
27
+ return new Attribute(
28
+ /** @type {Node} */ (this.key).eval ? /** @type {Node} */ (this.key).eval(context) : /** @type {string} */ (this.key),
29
+ this.op,
30
+ (this.value && /** @type {Node} */ (this.value).eval) ? /** @type {Node} */ (this.value).eval(context) : this.value,
31
+ this.cif
32
+ );
33
+ }
34
+
35
+ /**
36
+ * @param {EvalContext} context
37
+ * @param {CSSOutput} output
38
+ */
39
+ genCSS(context, output) {
17
40
  output.add(this.toCSS(context));
18
- },
19
- toCSS: function (context) {
20
- var value = this.key.toCSS ? this.key.toCSS(context) : this.key;
41
+ }
42
+
43
+ /**
44
+ * @param {EvalContext} context
45
+ * @returns {string}
46
+ */
47
+ toCSS(context) {
48
+ let value = /** @type {Node} */ (this.key).toCSS ? /** @type {Node} */ (this.key).toCSS(context) : /** @type {string} */ (this.key);
49
+
21
50
  if (this.op) {
22
51
  value += this.op;
23
- value += (this.value.toCSS ? this.value.toCSS(context) : this.value);
52
+ value += (/** @type {Node} */ (this.value).toCSS ? /** @type {Node} */ (this.value).toCSS(context) : /** @type {string} */ (this.value));
24
53
  }
54
+
25
55
  if (this.cif) {
26
56
  value = value + ' ' + this.cif;
27
57
  }
28
- return "[".concat(value, "]");
58
+
59
+ return `[${value}]`;
29
60
  }
30
- });
31
- exports.default = Attribute;
32
- //# sourceMappingURL=attribute.js.map
61
+ }
62
+
63
+ export default Attribute;