less 3.9.0 → 3.10.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 (511) hide show
  1. package/.DS_Store +0 -0
  2. package/.eslintignore +4 -1
  3. package/.eslintrc.json +69 -87
  4. package/CHANGELOG.md +7 -0
  5. package/Gruntfile.js +336 -330
  6. package/bin/lessc +13110 -481
  7. package/dist/less.cjs.js +12571 -0
  8. package/dist/less.js +12878 -11507
  9. package/dist/less.min.js +7 -14
  10. package/dist/less.min.js.map +1 -0
  11. package/index.js +1 -1
  12. package/lib/less/constants.js +12 -12
  13. package/lib/less/contexts.js +93 -95
  14. package/lib/less/data/colors.js +1 -1
  15. package/lib/less/data/index.js +4 -4
  16. package/lib/less/data/unit-conversions.js +1 -1
  17. package/lib/less/default-options.js +53 -58
  18. package/lib/less/environment/abstract-file-manager.js +114 -110
  19. package/lib/less/environment/abstract-plugin-loader.js +139 -141
  20. package/lib/less/environment/environment-api.js +1 -1
  21. package/lib/less/environment/environment.js +44 -41
  22. package/lib/less/environment/file-manager-api.js +1 -1
  23. package/lib/less/functions/boolean.js +10 -12
  24. package/lib/less/functions/color-blending.js +20 -10
  25. package/lib/less/functions/color.js +63 -49
  26. package/lib/less/functions/data-uri.js +25 -39
  27. package/lib/less/functions/default.js +5 -7
  28. package/lib/less/functions/function-caller.js +42 -39
  29. package/lib/less/functions/function-registry.js +3 -3
  30. package/lib/less/functions/index.js +28 -16
  31. package/lib/less/functions/list.js +34 -28
  32. package/lib/less/functions/math-helper.js +4 -5
  33. package/lib/less/functions/math.js +8 -9
  34. package/lib/less/functions/number.js +26 -18
  35. package/lib/less/functions/string.js +13 -13
  36. package/lib/less/functions/svg.js +25 -25
  37. package/lib/less/functions/types.js +23 -27
  38. package/lib/less/import-manager.js +140 -138
  39. package/lib/less/index.js +72 -35
  40. package/lib/less/less-error.js +29 -30
  41. package/lib/less/logger.js +4 -4
  42. package/lib/less/parse-tree.js +53 -47
  43. package/lib/less/parse.js +23 -25
  44. package/lib/less/parser/chunker.js +17 -7
  45. package/lib/less/parser/parser-input.js +100 -93
  46. package/lib/less/parser/parser.js +310 -170
  47. package/lib/less/plugin-manager.js +146 -133
  48. package/lib/less/render.js +10 -13
  49. package/lib/less/source-map-builder.js +62 -57
  50. package/lib/less/source-map-output.js +118 -112
  51. package/lib/less/transform-tree.js +21 -18
  52. package/lib/less/tree/anonymous.js +35 -27
  53. package/lib/less/tree/assignment.js +29 -23
  54. package/lib/less/tree/atrule.js +150 -121
  55. package/lib/less/tree/attribute.js +32 -25
  56. package/lib/less/tree/call.js +87 -79
  57. package/lib/less/tree/color.js +202 -185
  58. package/lib/less/tree/combinator.js +25 -19
  59. package/lib/less/tree/comment.js +27 -21
  60. package/lib/less/tree/condition.js +41 -35
  61. package/lib/less/tree/debug-info.js +13 -17
  62. package/lib/less/tree/declaration.js +101 -88
  63. package/lib/less/tree/detached-ruleset.js +27 -20
  64. package/lib/less/tree/dimension.js +142 -124
  65. package/lib/less/tree/element.js +67 -58
  66. package/lib/less/tree/expression.js +66 -57
  67. package/lib/less/tree/extend.js +61 -53
  68. package/lib/less/tree/import.js +144 -141
  69. package/lib/less/tree/index.js +52 -40
  70. package/lib/less/tree/javascript.js +29 -25
  71. package/lib/less/tree/js-eval-node.js +50 -53
  72. package/lib/less/tree/keyword.js +15 -8
  73. package/lib/less/tree/media.js +137 -124
  74. package/lib/less/tree/mixin-call.js +178 -149
  75. package/lib/less/tree/mixin-definition.js +198 -178
  76. package/lib/less/tree/namespace-value.js +75 -67
  77. package/lib/less/tree/negative.js +24 -18
  78. package/lib/less/tree/node.js +138 -117
  79. package/lib/less/tree/operation.js +57 -49
  80. package/lib/less/tree/paren.js +20 -14
  81. package/lib/less/tree/property.js +65 -58
  82. package/lib/less/tree/quoted.js +62 -53
  83. package/lib/less/tree/ruleset.js +739 -680
  84. package/lib/less/tree/selector.js +129 -114
  85. package/lib/less/tree/unicode-descriptor.js +10 -6
  86. package/lib/less/tree/unit.js +117 -97
  87. package/lib/less/tree/url.js +54 -47
  88. package/lib/less/tree/value.js +38 -33
  89. package/lib/less/tree/variable-call.js +41 -34
  90. package/lib/less/tree/variable.js +58 -51
  91. package/lib/less/utils.js +110 -108
  92. package/lib/less/visitors/extend-visitor.js +157 -114
  93. package/lib/less/visitors/import-sequencer.js +47 -43
  94. package/lib/less/visitors/import-visitor.js +22 -23
  95. package/lib/less/visitors/index.js +14 -9
  96. package/lib/less/visitors/join-selector-visitor.js +32 -26
  97. package/lib/less/visitors/set-tree-visibility-visitor.js +37 -30
  98. package/lib/less/visitors/to-css-visitor.js +60 -57
  99. package/lib/less/visitors/visitor.js +44 -35
  100. package/lib/less-browser/add-default-options.js +4 -4
  101. package/lib/less-browser/bootstrap.js +11 -9
  102. package/lib/less-browser/browser.js +13 -12
  103. package/lib/less-browser/cache.js +9 -9
  104. package/lib/less-browser/error-reporting.js +27 -27
  105. package/lib/less-browser/file-manager.js +37 -35
  106. package/lib/less-browser/image-size.js +3 -3
  107. package/lib/less-browser/index.js +78 -73
  108. package/lib/less-browser/log-listener.js +6 -7
  109. package/lib/less-browser/plugin-loader.js +15 -13
  110. package/lib/less-browser/utils.js +20 -20
  111. package/lib/less-node/environment.js +4 -2
  112. package/lib/less-node/file-manager.js +128 -127
  113. package/lib/less-node/fs.js +2 -2
  114. package/lib/less-node/image-size.js +19 -18
  115. package/lib/less-node/index.js +16 -12
  116. package/lib/less-node/lessc-helper.js +4 -5
  117. package/lib/less-node/plugin-loader.js +41 -40
  118. package/lib/less-node/url-file-manager.js +41 -48
  119. package/lib/lessc.js +557 -0
  120. package/package.json +21 -11
  121. package/test/.DS_Store +0 -0
  122. package/test/browser/common.js +34 -30
  123. package/test/browser/css/urls.css +0 -3
  124. package/test/browser/less/plugin/plugin.js +4 -7
  125. package/test/browser/less/urls.less +0 -3
  126. package/test/browser/less.min.js +11 -0
  127. package/test/browser/less.min.js.map +1 -0
  128. package/test/browser/onload.js +13 -0
  129. package/test/browser/runner-browser-options.js +0 -5
  130. package/test/browser/test-runner-template.tmpl +39 -52
  131. package/test/browser/vendor/boot.js +148 -0
  132. package/test/browser/{jasmine-jsreporter.js → vendor/jasmine-jsreporter.js} +0 -0
  133. package/test/copy-bom.js +2 -1
  134. package/test/css/.DS_Store +0 -0
  135. package/test/css/functions-each.css +10 -0
  136. package/test/css/math/.DS_Store +0 -0
  137. package/test/css/namespacing/namespacing-1.css +4 -0
  138. package/test/css/urls.css +0 -1
  139. package/test/index.js +2 -5
  140. package/test/less/.DS_Store +0 -0
  141. package/test/less/colors.less +1 -1
  142. package/test/less/errors/color-func-invalid-color-2.less +2 -0
  143. package/test/less/errors/color-func-invalid-color-2.txt +3 -0
  144. package/test/less/functions-each.less +32 -0
  145. package/test/less/math/.DS_Store +0 -0
  146. package/test/less/namespacing/namespacing-1.less +10 -0
  147. package/test/less/urls.less +0 -1
  148. package/test/less-test.js +20 -11
  149. package/test/modify-vars.js +11 -2
  150. package/.travis.yml +0 -33
  151. package/appveyor.yml +0 -32
  152. package/browser.js +0 -1
  153. package/test/browser/less.js +0 -12956
  154. package/test/less-bom/3rd-party/bootstrap4.less +0 -1
  155. package/test/less-bom/3rd-party/uikit.less +0 -1
  156. package/test/less-bom/calc.less +0 -30
  157. package/test/less-bom/charsets.less +0 -3
  158. package/test/less-bom/colors.less +0 -116
  159. package/test/less-bom/comments.less +0 -102
  160. package/test/less-bom/comments2.less +0 -31
  161. package/test/less-bom/compression/compression.less +0 -36
  162. package/test/less-bom/css-3.less +0 -153
  163. package/test/less-bom/css-escapes.less +0 -42
  164. package/test/less-bom/css-grid.less +0 -30
  165. package/test/less-bom/css-guards.less +0 -103
  166. package/test/less-bom/debug/import/test.less +0 -25
  167. package/test/less-bom/debug/linenumbers.less +0 -33
  168. package/test/less-bom/detached-rulesets.less +0 -112
  169. package/test/less-bom/directives-bubling.less +0 -142
  170. package/test/less-bom/empty.less +0 -1
  171. package/test/less-bom/errors/add-mixed-units.less +0 -3
  172. package/test/less-bom/errors/add-mixed-units.txt +0 -4
  173. package/test/less-bom/errors/add-mixed-units2.less +0 -3
  174. package/test/less-bom/errors/add-mixed-units2.txt +0 -4
  175. package/test/less-bom/errors/at-rules-undefined-var.less +0 -4
  176. package/test/less-bom/errors/at-rules-undefined-var.txt +0 -4
  177. package/test/less-bom/errors/at-rules-unmatching-block.less +0 -4
  178. package/test/less-bom/errors/at-rules-unmatching-block.txt +0 -3
  179. package/test/less-bom/errors/bad-variable-declaration1.less +0 -1
  180. package/test/less-bom/errors/bad-variable-declaration1.txt +0 -2
  181. package/test/less-bom/errors/color-func-invalid-color.less +0 -3
  182. package/test/less-bom/errors/color-func-invalid-color.txt +0 -4
  183. package/test/less-bom/errors/css-guard-default-func.less +0 -4
  184. package/test/less-bom/errors/css-guard-default-func.txt +0 -4
  185. package/test/less-bom/errors/custom-property-unmatched-block-1.less +0 -6
  186. package/test/less-bom/errors/custom-property-unmatched-block-1.txt +0 -4
  187. package/test/less-bom/errors/custom-property-unmatched-block-2.less +0 -6
  188. package/test/less-bom/errors/custom-property-unmatched-block-2.txt +0 -4
  189. package/test/less-bom/errors/custom-property-unmatched-block-3.less +0 -6
  190. package/test/less-bom/errors/custom-property-unmatched-block-3.txt +0 -4
  191. package/test/less-bom/errors/detached-ruleset-1.less +0 -6
  192. package/test/less-bom/errors/detached-ruleset-1.txt +0 -4
  193. package/test/less-bom/errors/detached-ruleset-2.less +0 -6
  194. package/test/less-bom/errors/detached-ruleset-2.txt +0 -4
  195. package/test/less-bom/errors/detached-ruleset-3.less +0 -4
  196. package/test/less-bom/errors/detached-ruleset-3.txt +0 -4
  197. package/test/less-bom/errors/detached-ruleset-5.less +0 -4
  198. package/test/less-bom/errors/detached-ruleset-5.txt +0 -3
  199. package/test/less-bom/errors/detached-ruleset-6.less +0 -5
  200. package/test/less-bom/errors/detached-ruleset-6.txt +0 -4
  201. package/test/less-bom/errors/divide-mixed-units.less +0 -3
  202. package/test/less-bom/errors/divide-mixed-units.txt +0 -4
  203. package/test/less-bom/errors/extend-no-selector.less +0 -3
  204. package/test/less-bom/errors/extend-no-selector.txt +0 -3
  205. package/test/less-bom/errors/extend-not-at-end.less +0 -3
  206. package/test/less-bom/errors/extend-not-at-end.txt +0 -3
  207. package/test/less-bom/errors/functions-1.less +0 -2
  208. package/test/less-bom/errors/functions-1.txt +0 -3
  209. package/test/less-bom/errors/functions-10-keyword.less +0 -2
  210. package/test/less-bom/errors/functions-10-keyword.txt +0 -3
  211. package/test/less-bom/errors/functions-11-operation.less +0 -2
  212. package/test/less-bom/errors/functions-11-operation.txt +0 -3
  213. package/test/less-bom/errors/functions-12-quoted.less +0 -2
  214. package/test/less-bom/errors/functions-12-quoted.txt +0 -3
  215. package/test/less-bom/errors/functions-13-selector.less +0 -2
  216. package/test/less-bom/errors/functions-13-selector.txt +0 -3
  217. package/test/less-bom/errors/functions-14-url.less +0 -2
  218. package/test/less-bom/errors/functions-14-url.txt +0 -3
  219. package/test/less-bom/errors/functions-15-value.less +0 -2
  220. package/test/less-bom/errors/functions-15-value.txt +0 -3
  221. package/test/less-bom/errors/functions-3-assignment.less +0 -2
  222. package/test/less-bom/errors/functions-3-assignment.txt +0 -3
  223. package/test/less-bom/errors/functions-4-call.less +0 -2
  224. package/test/less-bom/errors/functions-4-call.txt +0 -3
  225. package/test/less-bom/errors/functions-5-color-2.less +0 -1
  226. package/test/less-bom/errors/functions-5-color-2.txt +0 -2
  227. package/test/less-bom/errors/functions-5-color.less +0 -2
  228. package/test/less-bom/errors/functions-5-color.txt +0 -3
  229. package/test/less-bom/errors/functions-6-condition.less +0 -2
  230. package/test/less-bom/errors/functions-6-condition.txt +0 -3
  231. package/test/less-bom/errors/functions-7-dimension.less +0 -2
  232. package/test/less-bom/errors/functions-7-dimension.txt +0 -3
  233. package/test/less-bom/errors/functions-8-element.less +0 -2
  234. package/test/less-bom/errors/functions-8-element.txt +0 -3
  235. package/test/less-bom/errors/functions-9-expression.less +0 -2
  236. package/test/less-bom/errors/functions-9-expression.txt +0 -3
  237. package/test/less-bom/errors/import-malformed.less +0 -1
  238. package/test/less-bom/errors/import-malformed.txt +0 -3
  239. package/test/less-bom/errors/import-missing.less +0 -6
  240. package/test/less-bom/errors/import-missing.txt +0 -3
  241. package/test/less-bom/errors/import-no-semi.less +0 -1
  242. package/test/less-bom/errors/import-no-semi.txt +0 -2
  243. package/test/less-bom/errors/import-subfolder1.less +0 -1
  244. package/test/less-bom/errors/import-subfolder1.txt +0 -3
  245. package/test/less-bom/errors/import-subfolder2.less +0 -1
  246. package/test/less-bom/errors/import-subfolder2.txt +0 -4
  247. package/test/less-bom/errors/imports/import-subfolder1.less +0 -1
  248. package/test/less-bom/errors/imports/import-subfolder2.less +0 -1
  249. package/test/less-bom/errors/imports/import-test.less +0 -4
  250. package/test/less-bom/errors/imports/subfolder/mixin-not-defined.less +0 -1
  251. package/test/less-bom/errors/imports/subfolder/parse-error-curly-bracket.less +0 -1
  252. package/test/less-bom/errors/javascript-error.less +0 -3
  253. package/test/less-bom/errors/javascript-error.txt +0 -4
  254. package/test/less-bom/errors/javascript-undefined-var.less +0 -3
  255. package/test/less-bom/errors/javascript-undefined-var.txt +0 -4
  256. package/test/less-bom/errors/mixed-mixin-definition-args-1.less +0 -6
  257. package/test/less-bom/errors/mixed-mixin-definition-args-1.txt +0 -4
  258. package/test/less-bom/errors/mixed-mixin-definition-args-2.less +0 -6
  259. package/test/less-bom/errors/mixed-mixin-definition-args-2.txt +0 -4
  260. package/test/less-bom/errors/mixin-not-defined-2.less +0 -7
  261. package/test/less-bom/errors/mixin-not-defined-2.txt +0 -4
  262. package/test/less-bom/errors/mixin-not-defined.less +0 -11
  263. package/test/less-bom/errors/mixin-not-defined.txt +0 -3
  264. package/test/less-bom/errors/mixin-not-matched.less +0 -6
  265. package/test/less-bom/errors/mixin-not-matched.txt +0 -3
  266. package/test/less-bom/errors/mixin-not-matched2.less +0 -6
  267. package/test/less-bom/errors/mixin-not-matched2.txt +0 -3
  268. package/test/less-bom/errors/mixin-not-visible-in-scope-1.less +0 -9
  269. package/test/less-bom/errors/mixin-not-visible-in-scope-1.txt +0 -4
  270. package/test/less-bom/errors/mixins-guards-cond-expected.less +0 -5
  271. package/test/less-bom/errors/mixins-guards-cond-expected.txt +0 -3
  272. package/test/less-bom/errors/mixins-guards-default-func-1.less +0 -9
  273. package/test/less-bom/errors/mixins-guards-default-func-1.txt +0 -4
  274. package/test/less-bom/errors/mixins-guards-default-func-2.less +0 -9
  275. package/test/less-bom/errors/mixins-guards-default-func-2.txt +0 -4
  276. package/test/less-bom/errors/mixins-guards-default-func-3.less +0 -9
  277. package/test/less-bom/errors/mixins-guards-default-func-3.txt +0 -4
  278. package/test/less-bom/errors/multiple-guards-on-css-selectors.less +0 -4
  279. package/test/less-bom/errors/multiple-guards-on-css-selectors.txt +0 -4
  280. package/test/less-bom/errors/multiple-guards-on-css-selectors2.less +0 -4
  281. package/test/less-bom/errors/multiple-guards-on-css-selectors2.txt +0 -4
  282. package/test/less-bom/errors/multiply-mixed-units.less +0 -7
  283. package/test/less-bom/errors/multiply-mixed-units.txt +0 -4
  284. package/test/less-bom/errors/namespacing-2.less +0 -7
  285. package/test/less-bom/errors/namespacing-2.txt +0 -4
  286. package/test/less-bom/errors/namespacing-3.less +0 -8
  287. package/test/less-bom/errors/namespacing-3.txt +0 -4
  288. package/test/less-bom/errors/namespacing-4.less +0 -7
  289. package/test/less-bom/errors/namespacing-4.txt +0 -4
  290. package/test/less-bom/errors/parens-error-1.less +0 -3
  291. package/test/less-bom/errors/parens-error-1.txt +0 -4
  292. package/test/less-bom/errors/parens-error-2.less +0 -3
  293. package/test/less-bom/errors/parens-error-2.txt +0 -4
  294. package/test/less-bom/errors/parens-error-3.less +0 -3
  295. package/test/less-bom/errors/parens-error-3.txt +0 -4
  296. package/test/less-bom/errors/parse-error-curly-bracket.less +0 -4
  297. package/test/less-bom/errors/parse-error-curly-bracket.txt +0 -4
  298. package/test/less-bom/errors/parse-error-media-no-block-1.less +0 -5
  299. package/test/less-bom/errors/parse-error-media-no-block-1.txt +0 -3
  300. package/test/less-bom/errors/parse-error-media-no-block-2.less +0 -1
  301. package/test/less-bom/errors/parse-error-media-no-block-2.txt +0 -2
  302. package/test/less-bom/errors/parse-error-media-no-block-3.less +0 -4
  303. package/test/less-bom/errors/parse-error-media-no-block-3.txt +0 -3
  304. package/test/less-bom/errors/parse-error-missing-bracket.less +0 -2
  305. package/test/less-bom/errors/parse-error-missing-bracket.txt +0 -3
  306. package/test/less-bom/errors/parse-error-missing-parens.less +0 -5
  307. package/test/less-bom/errors/parse-error-missing-parens.txt +0 -3
  308. package/test/less-bom/errors/parse-error-with-import.less +0 -13
  309. package/test/less-bom/errors/parse-error-with-import.txt +0 -4
  310. package/test/less-bom/errors/percentage-missing-space.less +0 -3
  311. package/test/less-bom/errors/percentage-missing-space.txt +0 -4
  312. package/test/less-bom/errors/percentage-non-number-argument.less +0 -3
  313. package/test/less-bom/errors/percentage-non-number-argument.txt +0 -4
  314. package/test/less-bom/errors/plugin/plugin-error-2.js +0 -5
  315. package/test/less-bom/errors/plugin/plugin-error-3.js +0 -5
  316. package/test/less-bom/errors/plugin/plugin-error.js +0 -1
  317. package/test/less-bom/errors/plugin-1.less +0 -1
  318. package/test/less-bom/errors/plugin-1.txt +0 -2
  319. package/test/less-bom/errors/plugin-2.less +0 -1
  320. package/test/less-bom/errors/plugin-2.txt +0 -5
  321. package/test/less-bom/errors/plugin-3.less +0 -1
  322. package/test/less-bom/errors/plugin-3.txt +0 -5
  323. package/test/less-bom/errors/property-asterisk-only-name.less +0 -3
  324. package/test/less-bom/errors/property-asterisk-only-name.txt +0 -4
  325. package/test/less-bom/errors/property-ie5-hack.less +0 -3
  326. package/test/less-bom/errors/property-ie5-hack.txt +0 -3
  327. package/test/less-bom/errors/property-in-root.less +0 -4
  328. package/test/less-bom/errors/property-in-root.txt +0 -4
  329. package/test/less-bom/errors/property-in-root2.less +0 -1
  330. package/test/less-bom/errors/property-in-root2.txt +0 -4
  331. package/test/less-bom/errors/property-in-root3.less +0 -4
  332. package/test/less-bom/errors/property-in-root3.txt +0 -3
  333. package/test/less-bom/errors/property-interp-not-defined.less +0 -1
  334. package/test/less-bom/errors/property-interp-not-defined.txt +0 -2
  335. package/test/less-bom/errors/recursive-variable.less +0 -1
  336. package/test/less-bom/errors/recursive-variable.txt +0 -2
  337. package/test/less-bom/errors/root-func-undefined-1.less +0 -1
  338. package/test/less-bom/errors/root-func-undefined-1.txt +0 -2
  339. package/test/less-bom/errors/root-func-undefined-2.less +0 -2
  340. package/test/less-bom/errors/root-func-undefined-2.txt +0 -3
  341. package/test/less-bom/errors/single-character.less +0 -1
  342. package/test/less-bom/errors/single-character.txt +0 -2
  343. package/test/less-bom/errors/svg-gradient1.less +0 -3
  344. package/test/less-bom/errors/svg-gradient1.txt +0 -4
  345. package/test/less-bom/errors/svg-gradient2.less +0 -3
  346. package/test/less-bom/errors/svg-gradient2.txt +0 -4
  347. package/test/less-bom/errors/svg-gradient3.less +0 -3
  348. package/test/less-bom/errors/svg-gradient3.txt +0 -4
  349. package/test/less-bom/errors/svg-gradient4.less +0 -4
  350. package/test/less-bom/errors/svg-gradient4.txt +0 -4
  351. package/test/less-bom/errors/svg-gradient5.less +0 -4
  352. package/test/less-bom/errors/svg-gradient5.txt +0 -4
  353. package/test/less-bom/errors/svg-gradient6.less +0 -4
  354. package/test/less-bom/errors/svg-gradient6.txt +0 -4
  355. package/test/less-bom/errors/unit-function.less +0 -3
  356. package/test/less-bom/errors/unit-function.txt +0 -4
  357. package/test/less-bom/extend-chaining.less +0 -91
  358. package/test/less-bom/extend-clearfix.less +0 -19
  359. package/test/less-bom/extend-exact.less +0 -46
  360. package/test/less-bom/extend-media.less +0 -24
  361. package/test/less-bom/extend-nest.less +0 -65
  362. package/test/less-bom/extend-selector.less +0 -110
  363. package/test/less-bom/extend.less +0 -81
  364. package/test/less-bom/extract-and-length.less +0 -146
  365. package/test/less-bom/filemanagerPlugin/colors.test +0 -1
  366. package/test/less-bom/filemanagerPlugin/filemanager.less +0 -4
  367. package/test/less-bom/functions-each.less +0 -131
  368. package/test/less-bom/functions.less +0 -279
  369. package/test/less-bom/globalVars/extended.json +0 -5
  370. package/test/less-bom/globalVars/extended.less +0 -10
  371. package/test/less-bom/globalVars/simple.json +0 -3
  372. package/test/less-bom/globalVars/simple.less +0 -3
  373. package/test/less-bom/ie-filters.less +0 -15
  374. package/test/less-bom/import/css-import.less +0 -1
  375. package/test/less-bom/import/deeper/deeper-2/url-import-2.less +0 -3
  376. package/test/less-bom/import/deeper/deeper-2/url-import.less +0 -1
  377. package/test/less-bom/import/deeper/import-once-test-a.less +0 -1
  378. package/test/less-bom/import/deeper/url-import.less +0 -1
  379. package/test/less-bom/import/import-and-relative-paths-test.less +0 -17
  380. package/test/less-bom/import/import-charset-test.less +0 -1
  381. package/test/less-bom/import/import-inline-invalid-css.less +0 -1
  382. package/test/less-bom/import/import-interpolation.less +0 -2
  383. package/test/less-bom/import/import-interpolation2.less +0 -5
  384. package/test/less-bom/import/import-once-test-c.less +0 -6
  385. package/test/less-bom/import/import-reference.less +0 -98
  386. package/test/less-bom/import/import-test-a.less +0 -5
  387. package/test/less-bom/import/import-test-b.less +0 -8
  388. package/test/less-bom/import/import-test-c.less +0 -6
  389. package/test/less-bom/import/import-test-d.css +0 -1
  390. package/test/less-bom/import/import-test-e.less +0 -2
  391. package/test/less-bom/import/import-test-f.less +0 -5
  392. package/test/less-bom/import/imports/font.less +0 -8
  393. package/test/less-bom/import/imports/logo.less +0 -6
  394. package/test/less-bom/import/interpolation-vars.less +0 -6
  395. package/test/less-bom/import/invalid-css.less +0 -1
  396. package/test/less-bom/import/urls.less +0 -1
  397. package/test/less-bom/import-inline.less +0 -3
  398. package/test/less-bom/import-interpolation.less +0 -8
  399. package/test/less-bom/import-module.less +0 -3
  400. package/test/less-bom/import-once.less +0 -6
  401. package/test/less-bom/import-reference-issues/appender-reference-1968.less +0 -6
  402. package/test/less-bom/import-reference-issues/global-scope-import.less +0 -13
  403. package/test/less-bom/import-reference-issues/global-scope-nested.less +0 -3
  404. package/test/less-bom/import-reference-issues/mixin-1968.less +0 -8
  405. package/test/less-bom/import-reference-issues/multiple-import-nested.less +0 -12
  406. package/test/less-bom/import-reference-issues/multiple-import.less +0 -10
  407. package/test/less-bom/import-reference-issues/simple-mixin.css +0 -3
  408. package/test/less-bom/import-reference-issues/simple-ruleset-2162.less +0 -3
  409. package/test/less-bom/import-reference-issues.less +0 -50
  410. package/test/less-bom/import-reference.less +0 -26
  411. package/test/less-bom/import.less +0 -29
  412. package/test/less-bom/include-path/include-path.less +0 -8
  413. package/test/less-bom/include-path-string/include-path-string.less +0 -3
  414. package/test/less-bom/javascript.less +0 -39
  415. package/test/less-bom/lazy-eval.less +0 -6
  416. package/test/less-bom/legacy/legacy.less +0 -21
  417. package/test/less-bom/math/parens-division/media-math.less +0 -9
  418. package/test/less-bom/math/parens-division/mixins-args.less +0 -264
  419. package/test/less-bom/math/parens-division/new-division.less +0 -17
  420. package/test/less-bom/math/parens-division/parens.less +0 -46
  421. package/test/less-bom/math/strict/css.less +0 -108
  422. package/test/less-bom/math/strict/media-math.less +0 -9
  423. package/test/less-bom/math/strict/mixins-args.less +0 -264
  424. package/test/less-bom/math/strict/parens.less +0 -46
  425. package/test/less-bom/math/strict-legacy/css.less +0 -108
  426. package/test/less-bom/math/strict-legacy/media-math.less +0 -9
  427. package/test/less-bom/math/strict-legacy/mixins-args.less +0 -263
  428. package/test/less-bom/math/strict-legacy/parens.less +0 -50
  429. package/test/less-bom/media.less +0 -241
  430. package/test/less-bom/merge.less +0 -81
  431. package/test/less-bom/mixins-closure.less +0 -26
  432. package/test/less-bom/mixins-guards-default-func.less +0 -195
  433. package/test/less-bom/mixins-guards.less +0 -358
  434. package/test/less-bom/mixins-important.less +0 -53
  435. package/test/less-bom/mixins-interpolated.less +0 -75
  436. package/test/less-bom/mixins-named-args.less +0 -36
  437. package/test/less-bom/mixins-nested.less +0 -22
  438. package/test/less-bom/mixins-pattern.less +0 -102
  439. package/test/less-bom/mixins.less +0 -145
  440. package/test/less-bom/modifyVars/extended.json +0 -5
  441. package/test/less-bom/modifyVars/extended.less +0 -11
  442. package/test/less-bom/namespacing/imports/a-better-bootstrap.less +0 -13
  443. package/test/less-bom/namespacing/imports/library.less +0 -14
  444. package/test/less-bom/namespacing/namespacing-1.less +0 -42
  445. package/test/less-bom/namespacing/namespacing-2.less +0 -27
  446. package/test/less-bom/namespacing/namespacing-3.less +0 -28
  447. package/test/less-bom/namespacing/namespacing-4.less +0 -33
  448. package/test/less-bom/namespacing/namespacing-5.less +0 -32
  449. package/test/less-bom/namespacing/namespacing-6.less +0 -26
  450. package/test/less-bom/namespacing/namespacing-7.less +0 -48
  451. package/test/less-bom/namespacing/namespacing-functions.less +0 -11
  452. package/test/less-bom/namespacing/namespacing-media.less +0 -26
  453. package/test/less-bom/namespacing/namespacing-operations.less +0 -15
  454. package/test/less-bom/nested-gradient-with-svg-gradient/mixin-consumer.less +0 -5
  455. package/test/less-bom/nested-gradient-with-svg-gradient/svg-gradient-mixin.less +0 -15
  456. package/test/less-bom/no-js-errors/no-js-errors.less +0 -3
  457. package/test/less-bom/no-js-errors/no-js-errors.txt +0 -4
  458. package/test/less-bom/no-output.less +0 -2
  459. package/test/less-bom/no-strict-math/mixins-guards.less +0 -25
  460. package/test/less-bom/no-strict-math/no-sm-operations.less +0 -16
  461. package/test/less-bom/operations.less +0 -63
  462. package/test/less-bom/parse-interpolation.less +0 -53
  463. package/test/less-bom/permissive-parse.less +0 -50
  464. package/test/less-bom/plugin/plugin-collection.js +0 -9
  465. package/test/less-bom/plugin/plugin-global.js +0 -9
  466. package/test/less-bom/plugin/plugin-local.js +0 -14
  467. package/test/less-bom/plugin/plugin-preeval.js +0 -27
  468. package/test/less-bom/plugin/plugin-scope1.js +0 -3
  469. package/test/less-bom/plugin/plugin-scope2.js +0 -3
  470. package/test/less-bom/plugin/plugin-set-options-v2.js +0 -33
  471. package/test/less-bom/plugin/plugin-set-options-v3.js +0 -31
  472. package/test/less-bom/plugin/plugin-set-options.js +0 -32
  473. package/test/less-bom/plugin/plugin-simple.js +0 -7
  474. package/test/less-bom/plugin/plugin-transitive.js +0 -6
  475. package/test/less-bom/plugin/plugin-transitive.less +0 -5
  476. package/test/less-bom/plugin/plugin-tree-nodes.js +0 -82
  477. package/test/less-bom/plugin-module.less +0 -7
  478. package/test/less-bom/plugin-preeval.less +0 -15
  479. package/test/less-bom/plugin.less +0 -142
  480. package/test/less-bom/postProcessorPlugin/postProcessor.less +0 -4
  481. package/test/less-bom/preProcessorPlugin/preProcessor.less +0 -3
  482. package/test/less-bom/property-accessors.less +0 -67
  483. package/test/less-bom/property-name-interp.less +0 -56
  484. package/test/less-bom/rewrite-urls-all/folder/file.less +0 -8
  485. package/test/less-bom/rewrite-urls-all/rewrite-urls-all.less +0 -11
  486. package/test/less-bom/rewrite-urls-local/folder/file.less +0 -8
  487. package/test/less-bom/rewrite-urls-local/rewrite-urls-local.less +0 -11
  488. package/test/less-bom/root-registry/file.less +0 -1
  489. package/test/less-bom/root-registry/root.less +0 -3
  490. package/test/less-bom/rootpath-rewrite-urls-all/folder/file.less +0 -8
  491. package/test/less-bom/rootpath-rewrite-urls-all/rootpath-rewrite-urls-all.less +0 -11
  492. package/test/less-bom/rootpath-rewrite-urls-local/folder/file.less +0 -8
  493. package/test/less-bom/rootpath-rewrite-urls-local/rootpath-rewrite-urls-local.less +0 -11
  494. package/test/less-bom/rulesets.less +0 -30
  495. package/test/less-bom/scope.less +0 -104
  496. package/test/less-bom/selectors.less +0 -184
  497. package/test/less-bom/sourcemaps/basic.json +0 -3
  498. package/test/less-bom/sourcemaps/basic.less +0 -27
  499. package/test/less-bom/sourcemaps/custom-props.less +0 -8
  500. package/test/less-bom/sourcemaps/imported.css +0 -7
  501. package/test/less-bom/sourcemaps-empty/empty.less +0 -1
  502. package/test/less-bom/sourcemaps-empty/var-defs.less +0 -1
  503. package/test/less-bom/static-urls/urls.less +0 -33
  504. package/test/less-bom/strict-units/strict-units.less +0 -4
  505. package/test/less-bom/strings.less +0 -73
  506. package/test/less-bom/url-args/urls.less +0 -63
  507. package/test/less-bom/urls.less +0 -94
  508. package/test/less-bom/variables-in-at-rules.less +0 -20
  509. package/test/less-bom/variables.less +0 -127
  510. package/test/less-bom/visitorPlugin/visitor.less +0 -4
  511. package/test/less-bom/whitespace.less +0 -44
@@ -1,12 +1,10 @@
1
- var contexts = require('./contexts'),
2
- Parser = require('./parser/parser'),
3
- LessError = require('./less-error'),
4
- utils = require('./utils'),
5
- PromiseConstructor = typeof Promise === 'undefined' ? require('promise') : Promise,
6
- logger = require('./logger');
7
-
8
- module.exports = function(environment) {
1
+ import contexts from './contexts';
2
+ import Parser from './parser/parser';
3
+ import LessError from './less-error';
4
+ import * as utils from './utils';
5
+ import logger from './logger';
9
6
 
7
+ export default environment => {
10
8
  // FileInfo = {
11
9
  // 'rewriteUrls' - option - whether to adjust URL's to be relative
12
10
  // 'filename' - full resolved filename of current file
@@ -16,152 +14,156 @@ module.exports = function(environment) {
16
14
  // 'entryPath' - absolute path to the entry file
17
15
  // 'reference' - whether the file should not be output and only output parts that are referenced
18
16
 
19
- var ImportManager = function(less, context, rootFileInfo) {
20
- this.less = less;
21
- this.rootFilename = rootFileInfo.filename;
22
- this.paths = context.paths || []; // Search paths, when importing
23
- this.contents = {}; // map - filename to contents of all the files
24
- this.contentsIgnoredChars = {}; // map - filename to lines at the beginning of each file to ignore
25
- this.mime = context.mime;
26
- this.error = null;
27
- this.context = context;
28
- // Deprecated? Unused outside of here, could be useful.
29
- this.queue = []; // Files which haven't been imported yet
30
- this.files = {}; // Holds the imported parse trees.
31
- };
32
-
33
- /**
34
- * Add an import to be imported
35
- * @param path - the raw path
36
- * @param tryAppendExtension - whether to try appending a file extension (.less or .js if the path has no extension)
37
- * @param currentFileInfo - the current file info (used for instance to work out relative paths)
38
- * @param importOptions - import options
39
- * @param callback - callback for when it is imported
40
- */
41
- ImportManager.prototype.push = function (path, tryAppendExtension, currentFileInfo, importOptions, callback) {
42
- var importManager = this,
43
- pluginLoader = this.context.pluginManager.Loader;
44
-
45
- this.queue.push(path);
46
-
47
- var fileParsedFunc = function (e, root, fullPath) {
48
- importManager.queue.splice(importManager.queue.indexOf(path), 1); // Remove the path from the queue
49
-
50
- var importedEqualsRoot = fullPath === importManager.rootFilename;
51
- if (importOptions.optional && e) {
52
- callback(null, {rules:[]}, false, null);
53
- logger.info('The file ' + fullPath + ' was skipped because it was not found and the import was marked optional.');
54
- }
55
- else {
56
- // Inline imports aren't cached here.
57
- // If we start to cache them, please make sure they won't conflict with non-inline imports of the
58
- // same name as they used to do before this comment and the condition below have been added.
59
- if (!importManager.files[fullPath] && !importOptions.inline) {
60
- importManager.files[fullPath] = { root: root, options: importOptions };
61
- }
62
- if (e && !importManager.error) { importManager.error = e; }
63
- callback(e, root, importedEqualsRoot, fullPath);
64
- }
65
- };
66
-
67
- var newFileInfo = {
68
- rewriteUrls: this.context.rewriteUrls,
69
- entryPath: currentFileInfo.entryPath,
70
- rootpath: currentFileInfo.rootpath,
71
- rootFilename: currentFileInfo.rootFilename
72
- };
73
-
74
- var fileManager = environment.getFileManager(path, currentFileInfo.currentDirectory, this.context, environment);
75
-
76
- if (!fileManager) {
77
- fileParsedFunc({ message: 'Could not find a file-manager for ' + path });
78
- return;
17
+ class ImportManager {
18
+ constructor(less, context, rootFileInfo) {
19
+ this.less = less;
20
+ this.rootFilename = rootFileInfo.filename;
21
+ this.paths = context.paths || []; // Search paths, when importing
22
+ this.contents = {}; // map - filename to contents of all the files
23
+ this.contentsIgnoredChars = {}; // map - filename to lines at the beginning of each file to ignore
24
+ this.mime = context.mime;
25
+ this.error = null;
26
+ this.context = context;
27
+ // Deprecated? Unused outside of here, could be useful.
28
+ this.queue = []; // Files which haven't been imported yet
29
+ this.files = {}; // Holds the imported parse trees.
79
30
  }
80
31
 
81
- var loadFileCallback = function(loadedFile) {
82
- var plugin,
83
- resolvedFilename = loadedFile.filename,
84
- contents = loadedFile.contents.replace(/^\uFEFF/, '');
85
-
86
- // Pass on an updated rootpath if path of imported file is relative and file
87
- // is in a (sub|sup) directory
88
- //
89
- // Examples:
90
- // - If path of imported file is 'module/nav/nav.less' and rootpath is 'less/',
91
- // then rootpath should become 'less/module/nav/'
92
- // - If path of imported file is '../mixins.less' and rootpath is 'less/',
93
- // then rootpath should become 'less/../'
94
- newFileInfo.currentDirectory = fileManager.getPath(resolvedFilename);
95
- if (newFileInfo.rewriteUrls) {
96
- newFileInfo.rootpath = fileManager.join(
97
- (importManager.context.rootpath || ''),
98
- fileManager.pathDiff(newFileInfo.currentDirectory, newFileInfo.entryPath));
99
-
100
- if (!fileManager.isPathAbsolute(newFileInfo.rootpath) && fileManager.alwaysMakePathsAbsolute()) {
101
- newFileInfo.rootpath = fileManager.join(newFileInfo.entryPath, newFileInfo.rootpath);
32
+ /**
33
+ * Add an import to be imported
34
+ * @param path - the raw path
35
+ * @param tryAppendExtension - whether to try appending a file extension (.less or .js if the path has no extension)
36
+ * @param currentFileInfo - the current file info (used for instance to work out relative paths)
37
+ * @param importOptions - import options
38
+ * @param callback - callback for when it is imported
39
+ */
40
+ push(path, tryAppendExtension, currentFileInfo, importOptions, callback) {
41
+ const importManager = this;
42
+ const pluginLoader = this.context.pluginManager.Loader;
43
+
44
+ this.queue.push(path);
45
+
46
+ const fileParsedFunc = (e, root, fullPath) => {
47
+ importManager.queue.splice(importManager.queue.indexOf(path), 1); // Remove the path from the queue
48
+
49
+ const importedEqualsRoot = fullPath === importManager.rootFilename;
50
+ if (importOptions.optional && e) {
51
+ callback(null, {rules:[]}, false, null);
52
+ logger.info(`The file ${fullPath} was skipped because it was not found and the import was marked optional.`);
102
53
  }
103
- }
104
- newFileInfo.filename = resolvedFilename;
54
+ else {
55
+ // Inline imports aren't cached here.
56
+ // If we start to cache them, please make sure they won't conflict with non-inline imports of the
57
+ // same name as they used to do before this comment and the condition below have been added.
58
+ if (!importManager.files[fullPath] && !importOptions.inline) {
59
+ importManager.files[fullPath] = { root, options: importOptions };
60
+ }
61
+ if (e && !importManager.error) { importManager.error = e; }
62
+ callback(e, root, importedEqualsRoot, fullPath);
63
+ }
64
+ };
105
65
 
106
- var newEnv = new contexts.Parse(importManager.context);
66
+ const newFileInfo = {
67
+ rewriteUrls: this.context.rewriteUrls,
68
+ entryPath: currentFileInfo.entryPath,
69
+ rootpath: currentFileInfo.rootpath,
70
+ rootFilename: currentFileInfo.rootFilename
71
+ };
107
72
 
108
- newEnv.processImports = false;
109
- importManager.contents[resolvedFilename] = contents;
73
+ const fileManager = environment.getFileManager(path, currentFileInfo.currentDirectory, this.context, environment);
110
74
 
111
- if (currentFileInfo.reference || importOptions.reference) {
112
- newFileInfo.reference = true;
75
+ if (!fileManager) {
76
+ fileParsedFunc({ message: `Could not find a file-manager for ${path}` });
77
+ return;
113
78
  }
114
79
 
115
- if (importOptions.isPlugin) {
116
- plugin = pluginLoader.evalPlugin(contents, newEnv, importManager, importOptions.pluginArgs, newFileInfo);
117
- if (plugin instanceof LessError) {
118
- fileParsedFunc(plugin, null, resolvedFilename);
119
- }
120
- else {
121
- fileParsedFunc(null, plugin, resolvedFilename);
80
+ const loadFileCallback = loadedFile => {
81
+ let plugin;
82
+ const resolvedFilename = loadedFile.filename;
83
+ const contents = loadedFile.contents.replace(/^\uFEFF/, '');
84
+
85
+ // Pass on an updated rootpath if path of imported file is relative and file
86
+ // is in a (sub|sup) directory
87
+ //
88
+ // Examples:
89
+ // - If path of imported file is 'module/nav/nav.less' and rootpath is 'less/',
90
+ // then rootpath should become 'less/module/nav/'
91
+ // - If path of imported file is '../mixins.less' and rootpath is 'less/',
92
+ // then rootpath should become 'less/../'
93
+ newFileInfo.currentDirectory = fileManager.getPath(resolvedFilename);
94
+ if (newFileInfo.rewriteUrls) {
95
+ newFileInfo.rootpath = fileManager.join(
96
+ (importManager.context.rootpath || ''),
97
+ fileManager.pathDiff(newFileInfo.currentDirectory, newFileInfo.entryPath));
98
+
99
+ if (!fileManager.isPathAbsolute(newFileInfo.rootpath) && fileManager.alwaysMakePathsAbsolute()) {
100
+ newFileInfo.rootpath = fileManager.join(newFileInfo.entryPath, newFileInfo.rootpath);
101
+ }
122
102
  }
123
- } else if (importOptions.inline) {
124
- fileParsedFunc(null, contents, resolvedFilename);
125
- } else {
103
+ newFileInfo.filename = resolvedFilename;
126
104
 
127
- // import (multiple) parse trees apparently get altered and can't be cached.
128
- // TODO: investigate why this is
129
- if (importManager.files[resolvedFilename]
130
- && !importManager.files[resolvedFilename].options.multiple
131
- && !importOptions.multiple) {
105
+ const newEnv = new contexts.Parse(importManager.context);
132
106
 
133
- fileParsedFunc(null, importManager.files[resolvedFilename].root, resolvedFilename);
134
- }
135
- else {
136
- new Parser(newEnv, importManager, newFileInfo).parse(contents, function (e, root) {
137
- fileParsedFunc(e, root, resolvedFilename);
138
- });
107
+ newEnv.processImports = false;
108
+ importManager.contents[resolvedFilename] = contents;
109
+
110
+ if (currentFileInfo.reference || importOptions.reference) {
111
+ newFileInfo.reference = true;
139
112
  }
140
- }
141
- };
142
- var promise, context = utils.clone(this.context);
143
113
 
144
- if (tryAppendExtension) {
145
- context.ext = importOptions.isPlugin ? '.js' : '.less';
146
- }
114
+ if (importOptions.isPlugin) {
115
+ plugin = pluginLoader.evalPlugin(contents, newEnv, importManager, importOptions.pluginArgs, newFileInfo);
116
+ if (plugin instanceof LessError) {
117
+ fileParsedFunc(plugin, null, resolvedFilename);
118
+ }
119
+ else {
120
+ fileParsedFunc(null, plugin, resolvedFilename);
121
+ }
122
+ } else if (importOptions.inline) {
123
+ fileParsedFunc(null, contents, resolvedFilename);
124
+ } else {
147
125
 
148
- if (importOptions.isPlugin) {
149
- promise = pluginLoader.loadPlugin(path, currentFileInfo.currentDirectory, context, environment, fileManager);
150
- }
151
- else {
152
- promise = fileManager.loadFile(path, currentFileInfo.currentDirectory, context, environment,
153
- function(err, loadedFile) {
154
- if (err) {
155
- fileParsedFunc(err);
156
- } else {
157
- loadFileCallback(loadedFile);
126
+ // import (multiple) parse trees apparently get altered and can't be cached.
127
+ // TODO: investigate why this is
128
+ if (importManager.files[resolvedFilename]
129
+ && !importManager.files[resolvedFilename].options.multiple
130
+ && !importOptions.multiple) {
131
+
132
+ fileParsedFunc(null, importManager.files[resolvedFilename].root, resolvedFilename);
158
133
  }
159
- });
160
- }
161
- if (promise) {
162
- promise.then(loadFileCallback, fileParsedFunc);
134
+ else {
135
+ new Parser(newEnv, importManager, newFileInfo).parse(contents, (e, root) => {
136
+ fileParsedFunc(e, root, resolvedFilename);
137
+ });
138
+ }
139
+ }
140
+ };
141
+ let promise;
142
+ const context = utils.clone(this.context);
143
+
144
+ if (tryAppendExtension) {
145
+ context.ext = importOptions.isPlugin ? '.js' : '.less';
146
+ }
147
+
148
+ if (importOptions.isPlugin) {
149
+ context.mime = 'application/javascript';
150
+ promise = pluginLoader.loadPlugin(path, currentFileInfo.currentDirectory, context, environment, fileManager);
151
+ }
152
+ else {
153
+ promise = fileManager.loadFile(path, currentFileInfo.currentDirectory, context, environment,
154
+ (err, loadedFile) => {
155
+ if (err) {
156
+ fileParsedFunc(err);
157
+ } else {
158
+ loadFileCallback(loadedFile);
159
+ }
160
+ });
161
+ }
162
+ if (promise) {
163
+ promise.then(loadFileCallback, fileParsedFunc);
164
+ }
163
165
  }
166
+ }
164
167
 
165
- };
166
168
  return ImportManager;
167
169
  };
package/lib/less/index.js CHANGED
@@ -1,42 +1,79 @@
1
- module.exports = function(environment, fileManagers) {
2
- var SourceMapOutput, SourceMapBuilder, ParseTree, ImportManager, Environment;
1
+ import data from './data';
2
+ import tree from './tree';
3
+ import Environment from './environment/environment';
4
+ import AbstractFileManager from './environment/abstract-file-manager';
5
+ import AbstractPluginLoader from './environment/abstract-plugin-loader';
6
+ import visitors from './visitors';
7
+ import Parser from './parser/parser';
8
+ import Functions from './functions';
9
+ import contexts from './contexts';
10
+ import sourceMapOutput from './source-map-output';
11
+ import sourceMapBuilder from './source-map-builder';
12
+ import parseTree from './parse-tree';
13
+ import importManager from './import-manager';
14
+ import Render from './render';
15
+ import Parse from './parse';
16
+ import LessError from './less-error';
17
+ import transformTree from './transform-tree';
18
+ import * as utils from './utils';
19
+ import PluginManager from './plugin-manager';
20
+ import logger from './logger';
3
21
 
4
- var initial = {
5
- version: [3, 9, 0],
6
- data: require('./data'),
7
- tree: require('./tree'),
8
- Environment: (Environment = require('./environment/environment')),
9
- AbstractFileManager: require('./environment/abstract-file-manager'),
10
- AbstractPluginLoader: require('./environment/abstract-plugin-loader'),
11
- environment: (environment = new Environment(environment, fileManagers)),
12
- visitors: require('./visitors'),
13
- Parser: require('./parser/parser'),
14
- functions: require('./functions')(environment),
15
- contexts: require('./contexts'),
16
- SourceMapOutput: (SourceMapOutput = require('./source-map-output')(environment)),
17
- SourceMapBuilder: (SourceMapBuilder = require('./source-map-builder')(SourceMapOutput, environment)),
18
- ParseTree: (ParseTree = require('./parse-tree')(SourceMapBuilder)),
19
- ImportManager: (ImportManager = require('./import-manager')(environment)),
20
- render: require('./render')(environment, ParseTree, ImportManager),
21
- parse: require('./parse')(environment, ParseTree, ImportManager),
22
- LessError: require('./less-error'),
23
- transformTree: require('./transform-tree'),
24
- utils: require('./utils'),
25
- PluginManager: require('./plugin-manager'),
26
- logger: require('./logger')
22
+ export default (environment, fileManagers) => {
23
+ /**
24
+ * @todo
25
+ * This original code could be improved quite a bit.
26
+ * Many classes / modules currently add side-effects / mutations to passed in objects,
27
+ * which makes it hard to refactor and reason about.
28
+ */
29
+ environment = new Environment(environment, fileManagers);
30
+
31
+ const SourceMapOutput = sourceMapOutput(environment);
32
+ const SourceMapBuilder = sourceMapBuilder(SourceMapOutput, environment);
33
+ const ParseTree = parseTree(SourceMapBuilder);
34
+ const ImportManager = importManager(environment);
35
+ const render = Render(environment, ParseTree, ImportManager);
36
+ const parse = Parse(environment, ParseTree, ImportManager);
37
+ const functions = Functions(environment);
38
+
39
+ /**
40
+ * @todo
41
+ * This root properties / methods need to be organized.
42
+ * It's not clear what should / must be public and why.
43
+ */
44
+ const initial = {
45
+ version: [3, 10, 1],
46
+ data,
47
+ tree,
48
+ Environment,
49
+ AbstractFileManager,
50
+ AbstractPluginLoader,
51
+ environment,
52
+ visitors,
53
+ Parser,
54
+ functions,
55
+ contexts,
56
+ SourceMapOutput,
57
+ SourceMapBuilder,
58
+ ParseTree,
59
+ ImportManager,
60
+ render,
61
+ parse,
62
+ LessError,
63
+ transformTree,
64
+ utils,
65
+ PluginManager,
66
+ logger
27
67
  };
28
68
 
29
69
  // Create a public API
30
-
31
- var ctor = function(t) {
32
- return function() {
33
- var obj = Object.create(t.prototype);
34
- t.apply(obj, Array.prototype.slice.call(arguments, 0));
35
- return obj;
36
- };
70
+ const ctor = t => function (...args) {
71
+ return new t(...args);
37
72
  };
38
- var t, api = Object.create(initial);
39
- for (var n in initial.tree) {
73
+
74
+ let t;
75
+ const api = Object.create(initial);
76
+ for (const n in initial.tree) {
40
77
  /* eslint guard-for-in: 0 */
41
78
  t = initial.tree[n];
42
79
  if (typeof t === 'function') {
@@ -44,7 +81,7 @@ module.exports = function(environment, fileManagers) {
44
81
  }
45
82
  else {
46
83
  api[n] = Object.create(null);
47
- for (var o in t) {
84
+ for (const o in t) {
48
85
  /* eslint guard-for-in: 0 */
49
86
  api[n][o.toLowerCase()] = ctor(t[o]);
50
87
  }
@@ -1,4 +1,4 @@
1
- var utils = require('./utils');
1
+ import * as utils from './utils';
2
2
  /**
3
3
  * This is a centralized class of any error that could be thrown internally (mostly by the parser).
4
4
  * Besides standard .message it keeps some additional data like a path to the file where the error
@@ -21,21 +21,21 @@ var utils = require('./utils');
21
21
  * @param {Object} fileContentMap - An object with file contents in 'contents' property (like importManager) @todo - move to fileManager?
22
22
  * @param {string} [currentFilename]
23
23
  */
24
- var LessError = module.exports = function LessError(e, fileContentMap, currentFilename) {
24
+ const LessError = function LessError(e, fileContentMap, currentFilename) {
25
25
  Error.call(this);
26
26
 
27
- var filename = e.filename || currentFilename;
27
+ const filename = e.filename || currentFilename;
28
28
 
29
29
  this.message = e.message;
30
30
  this.stack = e.stack;
31
31
 
32
32
  if (fileContentMap && filename) {
33
- var input = fileContentMap.contents[filename],
34
- loc = utils.getLocation(e.index, input),
35
- line = loc.line,
36
- col = loc.column,
37
- callLine = e.call && utils.getLocation(e.call, input).line,
38
- lines = input ? input.split('\n') : '';
33
+ const input = fileContentMap.contents[filename];
34
+ const loc = utils.getLocation(e.index, input);
35
+ const line = loc.line;
36
+ const col = loc.column;
37
+ const callLine = e.call && utils.getLocation(e.call, input).line;
38
+ const lines = input ? input.split('\n') : '';
39
39
 
40
40
  this.type = e.type || 'Syntax';
41
41
  this.filename = filename;
@@ -44,7 +44,7 @@ var LessError = module.exports = function LessError(e, fileContentMap, currentFi
44
44
  this.column = col;
45
45
 
46
46
  if (!this.line && this.stack) {
47
- var found = this.stack.match(/(<anonymous>|Function):(\d+):(\d+)/);
47
+ const found = this.stack.match(/(<anonymous>|Function):(\d+):(\d+)/);
48
48
 
49
49
  if (found) {
50
50
  if (found[2]) {
@@ -64,13 +64,12 @@ var LessError = module.exports = function LessError(e, fileContentMap, currentFi
64
64
  lines[this.line - 1],
65
65
  lines[this.line]
66
66
  ];
67
-
68
67
  }
69
68
 
70
69
  };
71
70
 
72
71
  if (typeof Object.create === 'undefined') {
73
- var F = function () {};
72
+ const F = () => {};
74
73
  F.prototype = Error.prototype;
75
74
  LessError.prototype = new F();
76
75
  } else {
@@ -86,28 +85,26 @@ LessError.prototype.constructor = LessError;
86
85
  * @param {Object} options
87
86
  * @returns {string}
88
87
  */
89
- LessError.prototype.toString = function(options) {
90
- options = options || {};
91
-
92
- var message = '';
93
- var extract = this.extract || [];
94
- var error = [];
95
- var stylize = function (str) { return str; };
88
+ LessError.prototype.toString = function(options = {}) {
89
+ let message = '';
90
+ const extract = this.extract || [];
91
+ let error = [];
92
+ let stylize = str => str;
96
93
  if (options.stylize) {
97
- var type = typeof options.stylize;
94
+ const type = typeof options.stylize;
98
95
  if (type !== 'function') {
99
- throw Error('options.stylize should be a function, got a ' + type + '!');
96
+ throw Error(`options.stylize should be a function, got a ${type}!`);
100
97
  }
101
98
  stylize = options.stylize;
102
99
  }
103
100
 
104
101
  if (this.line !== null) {
105
102
  if (typeof extract[0] === 'string') {
106
- error.push(stylize((this.line - 1) + ' ' + extract[0], 'grey'));
103
+ error.push(stylize(`${this.line - 1} ${extract[0]}`, 'grey'));
107
104
  }
108
105
 
109
106
  if (typeof extract[1] === 'string') {
110
- var errorTxt = this.line + ' ';
107
+ let errorTxt = `${this.line} `;
111
108
  if (extract[1]) {
112
109
  errorTxt += extract[1].slice(0, this.column) +
113
110
  stylize(stylize(stylize(extract[1].substr(this.column, 1), 'bold') +
@@ -117,25 +114,27 @@ LessError.prototype.toString = function(options) {
117
114
  }
118
115
 
119
116
  if (typeof extract[2] === 'string') {
120
- error.push(stylize((this.line + 1) + ' ' + extract[2], 'grey'));
117
+ error.push(stylize(`${this.line + 1} ${extract[2]}`, 'grey'));
121
118
  }
122
- error = error.join('\n') + stylize('', 'reset') + '\n';
119
+ error = `${error.join('\n') + stylize('', 'reset')}\n`;
123
120
  }
124
121
 
125
- message += stylize(this.type + 'Error: ' + this.message, 'red');
122
+ message += stylize(`${this.type}Error: ${this.message}`, 'red');
126
123
  if (this.filename) {
127
124
  message += stylize(' in ', 'red') + this.filename;
128
125
  }
129
126
  if (this.line) {
130
- message += stylize(' on line ' + this.line + ', column ' + (this.column + 1) + ':', 'grey');
127
+ message += stylize(` on line ${this.line}, column ${this.column + 1}:`, 'grey');
131
128
  }
132
129
 
133
- message += '\n' + error;
130
+ message += `\n${error}`;
134
131
 
135
132
  if (this.callLine) {
136
- message += stylize('from ', 'red') + (this.filename || '') + '/n';
137
- message += stylize(this.callLine, 'grey') + ' ' + this.callExtract + '/n';
133
+ message += `${stylize('from ', 'red') + (this.filename || '')}/n`;
134
+ message += `${stylize(this.callLine, 'grey')} ${this.callExtract}/n`;
138
135
  }
139
136
 
140
137
  return message;
141
138
  };
139
+
140
+ export default LessError;
@@ -1,4 +1,4 @@
1
- module.exports = {
1
+ export default {
2
2
  error: function(msg) {
3
3
  this._fireEvent('error', msg);
4
4
  },
@@ -15,7 +15,7 @@ module.exports = {
15
15
  this._listeners.push(listener);
16
16
  },
17
17
  removeListener: function(listener) {
18
- for (var i = 0; i < this._listeners.length; i++) {
18
+ for (let i = 0; i < this._listeners.length; i++) {
19
19
  if (this._listeners[i] === listener) {
20
20
  this._listeners.splice(i, 1);
21
21
  return;
@@ -23,8 +23,8 @@ module.exports = {
23
23
  }
24
24
  },
25
25
  _fireEvent: function(type, msg) {
26
- for (var i = 0; i < this._listeners.length; i++) {
27
- var logFunction = this._listeners[i][type];
26
+ for (let i = 0; i < this._listeners.length; i++) {
27
+ const logFunction = this._listeners[i][type];
28
28
  if (logFunction) {
29
29
  logFunction(msg);
30
30
  }