less 2.3.1 → 2.4.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 (301) hide show
  1. package/.idea/workspace.xml +277 -237
  2. package/.jscsrc +36 -1
  3. package/.travis.yml +1 -0
  4. package/CHANGELOG.md +14 -0
  5. package/Gruntfile.js +1 -1
  6. package/appveyor.yml +5 -0
  7. package/bin/lessc +8 -5
  8. package/bower.json +1 -1
  9. package/dist/less.js +909 -814
  10. package/dist/less.min.js +6 -6
  11. package/lib/less/contexts.js +2 -2
  12. package/lib/less/environment/abstract-file-manager.js +6 -6
  13. package/lib/less/environment/environment.js +2 -2
  14. package/lib/less/functions/color.js +13 -5
  15. package/lib/less/functions/math.js +1 -1
  16. package/lib/less/functions/number.js +2 -2
  17. package/lib/less/functions/types.js +18 -8
  18. package/lib/less/import-manager.js +5 -5
  19. package/lib/less/index.js +1 -1
  20. package/lib/less/less-error.js +1 -1
  21. package/lib/less/logger.js +2 -2
  22. package/lib/less/parse-tree.js +45 -45
  23. package/lib/less/parse.js +5 -2
  24. package/lib/less/parser/parser-input.js +3 -3
  25. package/lib/less/parser/parser.js +52 -18
  26. package/lib/less/plugin-manager.js +30 -3
  27. package/lib/less/render.js +5 -2
  28. package/lib/less/source-map-builder.js +4 -0
  29. package/lib/less/source-map-output.js +3 -3
  30. package/lib/less/transform-tree.js +4 -4
  31. package/lib/less/tree/anonymous.js +1 -1
  32. package/lib/less/tree/call.js +1 -1
  33. package/lib/less/tree/color.js +2 -2
  34. package/lib/less/tree/condition.js +8 -4
  35. package/lib/less/tree/dimension.js +4 -4
  36. package/lib/less/tree/element.js +1 -1
  37. package/lib/less/tree/expression.js +1 -1
  38. package/lib/less/tree/extend.js +3 -3
  39. package/lib/less/tree/javascript.js +2 -2
  40. package/lib/less/tree/media.js +20 -20
  41. package/lib/less/tree/mixin-call.js +2 -2
  42. package/lib/less/tree/mixin-definition.js +29 -8
  43. package/lib/less/tree/quoted.js +3 -3
  44. package/lib/less/tree/rule.js +1 -1
  45. package/lib/less/tree/ruleset.js +35 -28
  46. package/lib/less/tree/selector.js +1 -1
  47. package/lib/less/tree/unit.js +2 -0
  48. package/lib/less/tree/value.js +1 -1
  49. package/lib/less/visitors/extend-visitor.js +15 -14
  50. package/lib/less/visitors/import-sequencer.js +2 -2
  51. package/lib/less/visitors/import-visitor.js +2 -2
  52. package/lib/less/visitors/to-css-visitor.js +5 -5
  53. package/lib/less-browser/cache.js +2 -2
  54. package/lib/less-browser/file-manager.js +96 -96
  55. package/lib/less-browser/index.js +205 -205
  56. package/lib/less-browser/log-listener.js +2 -2
  57. package/lib/less-browser/utils.js +6 -6
  58. package/lib/less-node/file-manager.js +9 -4
  59. package/lib/less-node/index.js +3 -3
  60. package/lib/less-node/plugin-loader.js +3 -3
  61. package/lib/less-node/url-file-manager.js +5 -2
  62. package/lib/less-rhino/index.js +13 -9
  63. package/lib/source-map/source-map-0.1.31.js +1 -1
  64. package/package.json +1 -1
  65. package/test/browser/css/relative-urls/urls.css +1 -0
  66. package/test/browser/less/relative-urls/urls.less +1 -0
  67. package/test/browser/runner-browser-options.js +23 -23
  68. package/test/browser/runner-errors-spec.js +1 -1
  69. package/test/browser/runner-global-vars-spec.js +1 -1
  70. package/test/browser/runner-main-options.js +5 -5
  71. package/test/browser/runner-main-spec.js +1 -1
  72. package/test/copy-bom.js +35 -35
  73. package/test/css/functions.css +8 -0
  74. package/test/css/import-interpolation.css +1 -0
  75. package/test/css/mixins-important.css +6 -0
  76. package/test/css/selectors.css +5 -0
  77. package/test/css/static-urls/urls.css +1 -0
  78. package/test/css/urls.css +1 -0
  79. package/test/index.js +2 -1
  80. package/test/less/functions.less +13 -0
  81. package/test/less/import/imports/logo.less +1 -0
  82. package/test/less/mixins-important.less +17 -1
  83. package/test/less/selectors.less +10 -0
  84. package/test/less/sourcemaps-empty/empty.less +0 -0
  85. package/test/less/sourcemaps-empty/var-defs.less +1 -0
  86. package/test/less/urls.less +1 -1
  87. package/test/less-test.js +49 -27
  88. package/test/modify-vars.js +13 -13
  89. package/test/browser/less.js +0 -29
  90. package/test/less-bom/charsets.less +0 -3
  91. package/test/less-bom/colors.less +0 -98
  92. package/test/less-bom/comments.less +0 -102
  93. package/test/less-bom/comments2.less +0 -20
  94. package/test/less-bom/compression/compression.less +0 -36
  95. package/test/less-bom/css-3.less +0 -154
  96. package/test/less-bom/css-escapes.less +0 -33
  97. package/test/less-bom/css-guards.less +0 -103
  98. package/test/less-bom/css.less +0 -108
  99. package/test/less-bom/debug/import/test.less +0 -25
  100. package/test/less-bom/debug/linenumbers.less +0 -33
  101. package/test/less-bom/detached-rulesets.less +0 -103
  102. package/test/less-bom/empty.less +0 -1
  103. package/test/less-bom/errors/add-mixed-units.less +0 -3
  104. package/test/less-bom/errors/add-mixed-units.txt +0 -4
  105. package/test/less-bom/errors/add-mixed-units2.less +0 -3
  106. package/test/less-bom/errors/add-mixed-units2.txt +0 -4
  107. package/test/less-bom/errors/at-rules-undefined-var.less +0 -4
  108. package/test/less-bom/errors/at-rules-undefined-var.txt +0 -4
  109. package/test/less-bom/errors/bad-variable-declaration1.less +0 -1
  110. package/test/less-bom/errors/bad-variable-declaration1.txt +0 -2
  111. package/test/less-bom/errors/color-func-invalid-color.less +0 -3
  112. package/test/less-bom/errors/color-func-invalid-color.txt +0 -4
  113. package/test/less-bom/errors/color-invalid-hex-code.less +0 -3
  114. package/test/less-bom/errors/color-invalid-hex-code.txt +0 -4
  115. package/test/less-bom/errors/color-invalid-hex-code2.less +0 -3
  116. package/test/less-bom/errors/color-invalid-hex-code2.txt +0 -4
  117. package/test/less-bom/errors/css-guard-default-func.less +0 -4
  118. package/test/less-bom/errors/css-guard-default-func.txt +0 -4
  119. package/test/less-bom/errors/detached-ruleset-1.less +0 -6
  120. package/test/less-bom/errors/detached-ruleset-1.txt +0 -4
  121. package/test/less-bom/errors/detached-ruleset-2.less +0 -6
  122. package/test/less-bom/errors/detached-ruleset-2.txt +0 -4
  123. package/test/less-bom/errors/detached-ruleset-3.less +0 -4
  124. package/test/less-bom/errors/detached-ruleset-3.txt +0 -4
  125. package/test/less-bom/errors/detached-ruleset-4.less +0 -5
  126. package/test/less-bom/errors/detached-ruleset-4.txt +0 -4
  127. package/test/less-bom/errors/detached-ruleset-5.less +0 -4
  128. package/test/less-bom/errors/detached-ruleset-5.txt +0 -3
  129. package/test/less-bom/errors/detached-ruleset-6.less +0 -5
  130. package/test/less-bom/errors/detached-ruleset-6.txt +0 -4
  131. package/test/less-bom/errors/divide-mixed-units.less +0 -3
  132. package/test/less-bom/errors/divide-mixed-units.txt +0 -4
  133. package/test/less-bom/errors/extend-no-selector.less +0 -3
  134. package/test/less-bom/errors/extend-no-selector.txt +0 -3
  135. package/test/less-bom/errors/extend-not-at-end.less +0 -3
  136. package/test/less-bom/errors/extend-not-at-end.txt +0 -3
  137. package/test/less-bom/errors/import-malformed.less +0 -1
  138. package/test/less-bom/errors/import-malformed.txt +0 -3
  139. package/test/less-bom/errors/import-missing.less +0 -6
  140. package/test/less-bom/errors/import-missing.txt +0 -3
  141. package/test/less-bom/errors/import-no-semi.less +0 -1
  142. package/test/less-bom/errors/import-no-semi.txt +0 -2
  143. package/test/less-bom/errors/import-subfolder1.less +0 -1
  144. package/test/less-bom/errors/import-subfolder1.txt +0 -3
  145. package/test/less-bom/errors/import-subfolder2.less +0 -1
  146. package/test/less-bom/errors/import-subfolder2.txt +0 -4
  147. package/test/less-bom/errors/imports/import-subfolder1.less +0 -1
  148. package/test/less-bom/errors/imports/import-subfolder2.less +0 -1
  149. package/test/less-bom/errors/imports/import-test.less +0 -4
  150. package/test/less-bom/errors/imports/subfolder/mixin-not-defined.less +0 -1
  151. package/test/less-bom/errors/imports/subfolder/parse-error-curly-bracket.less +0 -1
  152. package/test/less-bom/errors/javascript-error.less +0 -3
  153. package/test/less-bom/errors/javascript-error.txt +0 -4
  154. package/test/less-bom/errors/javascript-undefined-var.less +0 -3
  155. package/test/less-bom/errors/javascript-undefined-var.txt +0 -4
  156. package/test/less-bom/errors/mixed-mixin-definition-args-1.less +0 -6
  157. package/test/less-bom/errors/mixed-mixin-definition-args-1.txt +0 -4
  158. package/test/less-bom/errors/mixed-mixin-definition-args-2.less +0 -6
  159. package/test/less-bom/errors/mixed-mixin-definition-args-2.txt +0 -4
  160. package/test/less-bom/errors/mixin-not-defined.less +0 -11
  161. package/test/less-bom/errors/mixin-not-defined.txt +0 -3
  162. package/test/less-bom/errors/mixin-not-matched.less +0 -6
  163. package/test/less-bom/errors/mixin-not-matched.txt +0 -3
  164. package/test/less-bom/errors/mixin-not-matched2.less +0 -6
  165. package/test/less-bom/errors/mixin-not-matched2.txt +0 -3
  166. package/test/less-bom/errors/mixin-not-visible-in-scope-1.less +0 -9
  167. package/test/less-bom/errors/mixin-not-visible-in-scope-1.txt +0 -4
  168. package/test/less-bom/errors/mixins-guards-default-func-1.less +0 -9
  169. package/test/less-bom/errors/mixins-guards-default-func-1.txt +0 -4
  170. package/test/less-bom/errors/mixins-guards-default-func-2.less +0 -9
  171. package/test/less-bom/errors/mixins-guards-default-func-2.txt +0 -4
  172. package/test/less-bom/errors/mixins-guards-default-func-3.less +0 -9
  173. package/test/less-bom/errors/mixins-guards-default-func-3.txt +0 -4
  174. package/test/less-bom/errors/multiple-guards-on-css-selectors.less +0 -4
  175. package/test/less-bom/errors/multiple-guards-on-css-selectors.txt +0 -4
  176. package/test/less-bom/errors/multiple-guards-on-css-selectors2.less +0 -4
  177. package/test/less-bom/errors/multiple-guards-on-css-selectors2.txt +0 -4
  178. package/test/less-bom/errors/multiply-mixed-units.less +0 -7
  179. package/test/less-bom/errors/multiply-mixed-units.txt +0 -4
  180. package/test/less-bom/errors/parens-error-1.less +0 -3
  181. package/test/less-bom/errors/parens-error-1.txt +0 -4
  182. package/test/less-bom/errors/parens-error-2.less +0 -3
  183. package/test/less-bom/errors/parens-error-2.txt +0 -4
  184. package/test/less-bom/errors/parens-error-3.less +0 -3
  185. package/test/less-bom/errors/parens-error-3.txt +0 -4
  186. package/test/less-bom/errors/parse-error-curly-bracket.less +0 -4
  187. package/test/less-bom/errors/parse-error-curly-bracket.txt +0 -4
  188. package/test/less-bom/errors/parse-error-extra-parens.less +0 -5
  189. package/test/less-bom/errors/parse-error-extra-parens.txt +0 -3
  190. package/test/less-bom/errors/parse-error-missing-bracket.less +0 -2
  191. package/test/less-bom/errors/parse-error-missing-bracket.txt +0 -3
  192. package/test/less-bom/errors/parse-error-missing-parens.less +0 -5
  193. package/test/less-bom/errors/parse-error-missing-parens.txt +0 -3
  194. package/test/less-bom/errors/parse-error-with-import.less +0 -13
  195. package/test/less-bom/errors/parse-error-with-import.txt +0 -4
  196. package/test/less-bom/errors/percentage-missing-space.less +0 -3
  197. package/test/less-bom/errors/percentage-missing-space.txt +0 -4
  198. package/test/less-bom/errors/property-asterisk-only-name.less +0 -3
  199. package/test/less-bom/errors/property-asterisk-only-name.txt +0 -4
  200. package/test/less-bom/errors/property-ie5-hack.less +0 -3
  201. package/test/less-bom/errors/property-ie5-hack.txt +0 -3
  202. package/test/less-bom/errors/property-in-root.less +0 -4
  203. package/test/less-bom/errors/property-in-root.txt +0 -4
  204. package/test/less-bom/errors/property-in-root2.less +0 -1
  205. package/test/less-bom/errors/property-in-root2.txt +0 -4
  206. package/test/less-bom/errors/property-in-root3.less +0 -4
  207. package/test/less-bom/errors/property-in-root3.txt +0 -3
  208. package/test/less-bom/errors/property-interp-not-defined.less +0 -1
  209. package/test/less-bom/errors/property-interp-not-defined.txt +0 -2
  210. package/test/less-bom/errors/recursive-variable.less +0 -1
  211. package/test/less-bom/errors/recursive-variable.txt +0 -2
  212. package/test/less-bom/errors/single-character.less +0 -1
  213. package/test/less-bom/errors/single-character.txt +0 -2
  214. package/test/less-bom/errors/svg-gradient1.less +0 -3
  215. package/test/less-bom/errors/svg-gradient1.txt +0 -4
  216. package/test/less-bom/errors/svg-gradient2.less +0 -3
  217. package/test/less-bom/errors/svg-gradient2.txt +0 -4
  218. package/test/less-bom/errors/svg-gradient3.less +0 -3
  219. package/test/less-bom/errors/svg-gradient3.txt +0 -4
  220. package/test/less-bom/errors/unit-function.less +0 -3
  221. package/test/less-bom/errors/unit-function.txt +0 -4
  222. package/test/less-bom/extend-chaining.less +0 -91
  223. package/test/less-bom/extend-clearfix.less +0 -19
  224. package/test/less-bom/extend-exact.less +0 -46
  225. package/test/less-bom/extend-media.less +0 -24
  226. package/test/less-bom/extend-nest.less +0 -65
  227. package/test/less-bom/extend-selector.less +0 -99
  228. package/test/less-bom/extend.less +0 -81
  229. package/test/less-bom/extract-and-length.less +0 -133
  230. package/test/less-bom/functions.less +0 -201
  231. package/test/less-bom/globalVars/extended.json +0 -5
  232. package/test/less-bom/globalVars/extended.less +0 -10
  233. package/test/less-bom/globalVars/simple.json +0 -3
  234. package/test/less-bom/globalVars/simple.less +0 -3
  235. package/test/less-bom/ie-filters.less +0 -15
  236. package/test/less-bom/import/deeper/deeper-2/url-import-2.less +0 -3
  237. package/test/less-bom/import/deeper/deeper-2/url-import.less +0 -1
  238. package/test/less-bom/import/deeper/import-once-test-a.less +0 -1
  239. package/test/less-bom/import/deeper/url-import.less +0 -1
  240. package/test/less-bom/import/import-and-relative-paths-test.less +0 -17
  241. package/test/less-bom/import/import-charset-test.less +0 -1
  242. package/test/less-bom/import/import-interpolation.less +0 -2
  243. package/test/less-bom/import/import-interpolation2.less +0 -5
  244. package/test/less-bom/import/import-once-test-c.less +0 -6
  245. package/test/less-bom/import/import-reference.less +0 -89
  246. package/test/less-bom/import/import-test-a.less +0 -4
  247. package/test/less-bom/import/import-test-b.less +0 -8
  248. package/test/less-bom/import/import-test-c.less +0 -6
  249. package/test/less-bom/import/import-test-d.css +0 -1
  250. package/test/less-bom/import/import-test-e.less +0 -2
  251. package/test/less-bom/import/import-test-f.less +0 -5
  252. package/test/less-bom/import/imports/font.less +0 -8
  253. package/test/less-bom/import/imports/logo.less +0 -5
  254. package/test/less-bom/import/interpolation-vars.less +0 -6
  255. package/test/less-bom/import/invalid-css.less +0 -1
  256. package/test/less-bom/import/urls.less +0 -1
  257. package/test/less-bom/import-inline.less +0 -3
  258. package/test/less-bom/import-interpolation.less +0 -8
  259. package/test/less-bom/import-once.less +0 -6
  260. package/test/less-bom/import-reference.less +0 -23
  261. package/test/less-bom/import.less +0 -30
  262. package/test/less-bom/include-path/include-path.less +0 -6
  263. package/test/less-bom/javascript.less +0 -38
  264. package/test/less-bom/lazy-eval.less +0 -6
  265. package/test/less-bom/legacy/legacy.less +0 -7
  266. package/test/less-bom/media.less +0 -234
  267. package/test/less-bom/merge.less +0 -78
  268. package/test/less-bom/mixins-args.less +0 -215
  269. package/test/less-bom/mixins-closure.less +0 -26
  270. package/test/less-bom/mixins-guards-default-func.less +0 -195
  271. package/test/less-bom/mixins-guards.less +0 -271
  272. package/test/less-bom/mixins-important.less +0 -37
  273. package/test/less-bom/mixins-interpolated.less +0 -75
  274. package/test/less-bom/mixins-named-args.less +0 -36
  275. package/test/less-bom/mixins-nested.less +0 -22
  276. package/test/less-bom/mixins-pattern.less +0 -102
  277. package/test/less-bom/mixins.less +0 -145
  278. package/test/less-bom/modifyVars/extended.json +0 -5
  279. package/test/less-bom/modifyVars/extended.less +0 -11
  280. package/test/less-bom/nested-gradient-with-svg-gradient/mixin-consumer.less +0 -5
  281. package/test/less-bom/nested-gradient-with-svg-gradient/svg-gradient-mixin.less +0 -15
  282. package/test/less-bom/no-js-errors/no-js-errors.less +0 -3
  283. package/test/less-bom/no-js-errors/no-js-errors.txt +0 -4
  284. package/test/less-bom/no-output.less +0 -2
  285. package/test/less-bom/operations.less +0 -62
  286. package/test/less-bom/parens.less +0 -45
  287. package/test/less-bom/property-name-interp.less +0 -56
  288. package/test/less-bom/rulesets.less +0 -30
  289. package/test/less-bom/scope.less +0 -104
  290. package/test/less-bom/selectors.less +0 -174
  291. package/test/less-bom/sourcemaps/basic.json +0 -3
  292. package/test/less-bom/sourcemaps/basic.less +0 -27
  293. package/test/less-bom/sourcemaps/imported.css +0 -7
  294. package/test/less-bom/static-urls/urls.less +0 -33
  295. package/test/less-bom/strict-units/strict-units.less +0 -4
  296. package/test/less-bom/strings.less +0 -73
  297. package/test/less-bom/url-args/urls.less +0 -63
  298. package/test/less-bom/urls.less +0 -94
  299. package/test/less-bom/variables-in-at-rules.less +0 -20
  300. package/test/less-bom/variables.less +0 -119
  301. package/test/less-bom/whitespace.less +0 -44
@@ -6,251 +6,251 @@ var addDataAttr = require("./utils").addDataAttr,
6
6
  browser = require("./browser");
7
7
 
8
8
  module.exports = function(window, options) {
9
- var document = window.document;
10
- var less = require('../less')();
11
- module.exports = less;
12
- less.options = options;
13
- var environment = less.environment,
14
- FileManager = require("./file-manager")(options, less.logger),
15
- fileManager = new FileManager();
16
- environment.addFileManager(fileManager);
17
- less.FileManager = FileManager;
18
-
19
- require("./log-listener")(less, options);
20
- var errors = require("./error-reporting")(window, less, options);
21
- var cache = less.cache = options.cache || require("./cache")(window, options, less.logger);
22
-
23
- //Setup user functions
24
- if (options.functions) {
25
- less.functions.functionRegistry.addMultiple(options.functions);
26
- }
27
-
28
- var typePattern = /^text\/(x-)?less$/;
29
-
30
- function postProcessCSS(styles) {
31
- if (options.postProcessor && typeof options.postProcessor === 'function') {
32
- styles = options.postProcessor.call(styles, styles) || styles;
9
+ var document = window.document;
10
+ var less = require('../less')();
11
+ //module.exports = less;
12
+ less.options = options;
13
+ var environment = less.environment,
14
+ FileManager = require("./file-manager")(options, less.logger),
15
+ fileManager = new FileManager();
16
+ environment.addFileManager(fileManager);
17
+ less.FileManager = FileManager;
18
+
19
+ require("./log-listener")(less, options);
20
+ var errors = require("./error-reporting")(window, less, options);
21
+ var cache = less.cache = options.cache || require("./cache")(window, options, less.logger);
22
+
23
+ //Setup user functions
24
+ if (options.functions) {
25
+ less.functions.functionRegistry.addMultiple(options.functions);
33
26
  }
34
- return styles;
35
- }
36
-
37
- function clone(obj) {
38
- var cloned = {};
39
- for(var prop in obj) {
40
- if (obj.hasOwnProperty(prop)) {
41
- cloned[prop] = obj[prop];
27
+
28
+ var typePattern = /^text\/(x-)?less$/;
29
+
30
+ function postProcessCSS(styles) {
31
+ if (options.postProcessor && typeof options.postProcessor === 'function') {
32
+ styles = options.postProcessor.call(styles, styles) || styles;
42
33
  }
34
+ return styles;
43
35
  }
44
- return cloned;
45
- }
46
-
47
- // only really needed for phantom
48
- function bind(func, thisArg) {
49
- var curryArgs = Array.prototype.slice.call(arguments, 2);
50
- return function() {
51
- var args = curryArgs.concat(Array.prototype.slice.call(arguments, 0));
52
- return func.apply(thisArg, args);
53
- };
54
- }
55
36
 
56
- function loadStyles(modifyVars) {
57
- var styles = document.getElementsByTagName('style'),
58
- style;
37
+ function clone(obj) {
38
+ var cloned = {};
39
+ for (var prop in obj) {
40
+ if (obj.hasOwnProperty(prop)) {
41
+ cloned[prop] = obj[prop];
42
+ }
43
+ }
44
+ return cloned;
45
+ }
59
46
 
60
- for (var i = 0; i < styles.length; i++) {
61
- style = styles[i];
62
- if (style.type.match(typePattern)) {
63
- var instanceOptions = clone(options);
64
- instanceOptions.modifyVars = modifyVars;
65
- var lessText = style.innerHTML || '';
66
- instanceOptions.filename = document.location.href.replace(/#.*$/, '');
47
+ // only really needed for phantom
48
+ function bind(func, thisArg) {
49
+ var curryArgs = Array.prototype.slice.call(arguments, 2);
50
+ return function() {
51
+ var args = curryArgs.concat(Array.prototype.slice.call(arguments, 0));
52
+ return func.apply(thisArg, args);
53
+ };
54
+ }
67
55
 
68
- /*jshint loopfunc:true */
69
- // use closure to store current style
70
- less.render(lessText, instanceOptions,
71
- bind(function(style, e, result) {
72
- if (e) {
73
- errors.add(e, "inline");
74
- } else {
75
- style.type = 'text/css';
76
- if (style.styleSheet) {
77
- style.styleSheet.cssText = result.css;
56
+ function loadStyles(modifyVars) {
57
+ var styles = document.getElementsByTagName('style'),
58
+ style;
59
+
60
+ for (var i = 0; i < styles.length; i++) {
61
+ style = styles[i];
62
+ if (style.type.match(typePattern)) {
63
+ var instanceOptions = clone(options);
64
+ instanceOptions.modifyVars = modifyVars;
65
+ var lessText = style.innerHTML || '';
66
+ instanceOptions.filename = document.location.href.replace(/#.*$/, '');
67
+
68
+ /*jshint loopfunc:true */
69
+ // use closure to store current style
70
+ less.render(lessText, instanceOptions,
71
+ bind(function(style, e, result) {
72
+ if (e) {
73
+ errors.add(e, "inline");
78
74
  } else {
79
- style.innerHTML = result.css;
75
+ style.type = 'text/css';
76
+ if (style.styleSheet) {
77
+ style.styleSheet.cssText = result.css;
78
+ } else {
79
+ style.innerHTML = result.css;
80
+ }
80
81
  }
81
- }
82
- }, null, style));
82
+ }, null, style));
83
+ }
83
84
  }
84
85
  }
85
- }
86
86
 
87
- function loadStyleSheet(sheet, callback, reload, remaining, modifyVars) {
87
+ function loadStyleSheet(sheet, callback, reload, remaining, modifyVars) {
88
88
 
89
- var instanceOptions = clone(options);
90
- addDataAttr(instanceOptions, sheet);
91
- instanceOptions.mime = sheet.type;
89
+ var instanceOptions = clone(options);
90
+ addDataAttr(instanceOptions, sheet);
91
+ instanceOptions.mime = sheet.type;
92
92
 
93
- if (modifyVars) {
94
- instanceOptions.modifyVars = modifyVars;
95
- }
93
+ if (modifyVars) {
94
+ instanceOptions.modifyVars = modifyVars;
95
+ }
96
96
 
97
- function loadInitialFileCallback(loadedFile) {
97
+ function loadInitialFileCallback(loadedFile) {
98
98
 
99
- var data = loadedFile.contents,
100
- path = loadedFile.filename,
101
- webInfo = loadedFile.webInfo;
99
+ var data = loadedFile.contents,
100
+ path = loadedFile.filename,
101
+ webInfo = loadedFile.webInfo;
102
102
 
103
- var newFileInfo = {
104
- currentDirectory: fileManager.getPath(path),
105
- filename: path,
106
- rootFilename: path,
107
- relativeUrls: instanceOptions.relativeUrls};
103
+ var newFileInfo = {
104
+ currentDirectory: fileManager.getPath(path),
105
+ filename: path,
106
+ rootFilename: path,
107
+ relativeUrls: instanceOptions.relativeUrls};
108
108
 
109
- newFileInfo.entryPath = newFileInfo.currentDirectory;
110
- newFileInfo.rootpath = instanceOptions.rootpath || newFileInfo.currentDirectory;
109
+ newFileInfo.entryPath = newFileInfo.currentDirectory;
110
+ newFileInfo.rootpath = instanceOptions.rootpath || newFileInfo.currentDirectory;
111
111
 
112
- if (webInfo) {
113
- webInfo.remaining = remaining;
112
+ if (webInfo) {
113
+ webInfo.remaining = remaining;
114
114
 
115
- if (!instanceOptions.modifyVars) {
116
- var css = cache.getCSS(path, webInfo);
117
- if (!reload && css) {
118
- webInfo.local = true;
119
- callback(null, css, data, sheet, webInfo, path);
120
- return;
115
+ if (!instanceOptions.modifyVars) {
116
+ var css = cache.getCSS(path, webInfo);
117
+ if (!reload && css) {
118
+ webInfo.local = true;
119
+ callback(null, css, data, sheet, webInfo, path);
120
+ return;
121
+ }
121
122
  }
122
123
  }
123
- }
124
124
 
125
- //TODO add tests around how this behaves when reloading
126
- errors.remove(path);
125
+ //TODO add tests around how this behaves when reloading
126
+ errors.remove(path);
127
+
128
+ instanceOptions.rootFileInfo = newFileInfo;
129
+ less.render(data, instanceOptions, function(e, result) {
130
+ if (e) {
131
+ e.href = path;
132
+ callback(e);
133
+ } else {
134
+ result.css = postProcessCSS(result.css);
135
+ if (!instanceOptions.modifyVars) {
136
+ cache.setCSS(sheet.href, webInfo.lastModified, result.css);
137
+ }
138
+ callback(null, result.css, data, sheet, webInfo, path);
139
+ }
140
+ });
141
+ }
127
142
 
128
- instanceOptions.rootFileInfo = newFileInfo;
129
- less.render(data, instanceOptions, function(e, result) {
143
+ fileManager.loadFile(sheet.href, null, instanceOptions, environment, function(e, loadedFile) {
130
144
  if (e) {
131
- e.href = path;
132
145
  callback(e);
133
- } else {
134
- result.css = postProcessCSS(result.css);
135
- if (!instanceOptions.modifyVars) {
136
- cache.setCSS(sheet.href, webInfo.lastModified, result.css);
137
- }
138
- callback(null, result.css, data, sheet, webInfo, path);
146
+ return;
139
147
  }
148
+ loadInitialFileCallback(loadedFile);
140
149
  });
141
150
  }
142
151
 
143
- fileManager.loadFile(sheet.href, null, instanceOptions, environment, function(e, loadedFile) {
144
- if (e) {
145
- callback(e);
146
- return;
152
+ function loadStyleSheets(callback, reload, modifyVars) {
153
+ for (var i = 0; i < less.sheets.length; i++) {
154
+ loadStyleSheet(less.sheets[i], callback, reload, less.sheets.length - (i + 1), modifyVars);
147
155
  }
148
- loadInitialFileCallback(loadedFile);
149
- });
150
- }
151
-
152
- function loadStyleSheets(callback, reload, modifyVars) {
153
- for (var i = 0; i < less.sheets.length; i++) {
154
- loadStyleSheet(less.sheets[i], callback, reload, less.sheets.length - (i + 1), modifyVars);
155
156
  }
156
- }
157
-
158
- function initRunningMode(){
159
- if (less.env === 'development') {
160
- less.watchTimer = setInterval(function () {
161
- if (less.watchMode) {
162
- fileManager.clearFileCache();
163
- loadStyleSheets(function (e, css, _, sheet, webInfo) {
164
- if (e) {
165
- errors.add(e, e.href || sheet.href);
166
- } else if (css) {
167
- browser.createCSS(window.document, css, sheet);
168
- }
169
- });
170
- }
171
- }, options.poll);
172
- }
173
- }
174
157
 
175
- //
176
- // Watch mode
177
- //
178
- less.watch = function () {
179
- if (!less.watchMode ){
180
- less.env = 'development';
181
- initRunningMode();
158
+ function initRunningMode() {
159
+ if (less.env === 'development') {
160
+ less.watchTimer = setInterval(function () {
161
+ if (less.watchMode) {
162
+ fileManager.clearFileCache();
163
+ loadStyleSheets(function (e, css, _, sheet, webInfo) {
164
+ if (e) {
165
+ errors.add(e, e.href || sheet.href);
166
+ } else if (css) {
167
+ browser.createCSS(window.document, css, sheet);
168
+ }
169
+ });
170
+ }
171
+ }, options.poll);
172
+ }
182
173
  }
183
- this.watchMode = true;
184
- return true;
185
- };
186
174
 
187
- less.unwatch = function () {clearInterval(less.watchTimer); this.watchMode = false; return false; };
188
-
189
- //
190
- // Get all <link> tags with the 'rel' attribute set to "stylesheet/less"
191
- //
192
- less.registerStylesheets = function() {
193
- return new Promise(function(resolve, reject) {
194
- var links = document.getElementsByTagName('link');
195
- less.sheets = [];
196
-
197
- for (var i = 0; i < links.length; i++) {
198
- if (links[i].rel === 'stylesheet/less' || (links[i].rel.match(/stylesheet/) &&
199
- (links[i].type.match(typePattern)))) {
200
- less.sheets.push(links[i]);
201
- }
175
+ //
176
+ // Watch mode
177
+ //
178
+ less.watch = function () {
179
+ if (!less.watchMode ) {
180
+ less.env = 'development';
181
+ initRunningMode();
202
182
  }
183
+ this.watchMode = true;
184
+ return true;
185
+ };
203
186
 
204
- resolve();
205
- });
206
- };
207
-
208
- //
209
- // With this function, it's possible to alter variables and re-render
210
- // CSS without reloading less-files
211
- //
212
- less.modifyVars = function(record) {
213
- return less.refresh(true, record, false);
214
- };
187
+ less.unwatch = function () {clearInterval(less.watchTimer); this.watchMode = false; return false; };
215
188
 
216
- less.refresh = function (reload, modifyVars, clearFileCache) {
217
- if ((reload || clearFileCache) && clearFileCache !== false) {
218
- fileManager.clearFileCache();
219
- }
220
- return new Promise(function (resolve, reject) {
221
- var startTime, endTime, totalMilliseconds;
222
- startTime = endTime = new Date();
189
+ //
190
+ // Get all <link> tags with the 'rel' attribute set to "stylesheet/less"
191
+ //
192
+ less.registerStylesheets = function() {
193
+ return new Promise(function(resolve, reject) {
194
+ var links = document.getElementsByTagName('link');
195
+ less.sheets = [];
223
196
 
224
- loadStyleSheets(function (e, css, _, sheet, webInfo) {
225
- if (e) {
226
- errors.add(e, e.href || sheet.href);
227
- reject(e);
228
- return;
229
- }
230
- if (webInfo.local) {
231
- less.logger.info("loading " + sheet.href + " from cache.");
232
- } else {
233
- less.logger.info("rendered " + sheet.href + " successfully.");
234
- }
235
- browser.createCSS(window.document, css, sheet);
236
- less.logger.info("css for " + sheet.href + " generated in " + (new Date() - endTime) + 'ms');
237
- if (webInfo.remaining === 0) {
238
- totalMilliseconds = new Date() - startTime;
239
- less.logger.info("less has finished. css generated in " + totalMilliseconds + 'ms');
240
- resolve({
241
- startTime: startTime,
242
- endTime: endTime,
243
- totalMilliseconds: totalMilliseconds,
244
- sheets: less.sheets.length
245
- });
197
+ for (var i = 0; i < links.length; i++) {
198
+ if (links[i].rel === 'stylesheet/less' || (links[i].rel.match(/stylesheet/) &&
199
+ (links[i].type.match(typePattern)))) {
200
+ less.sheets.push(links[i]);
201
+ }
246
202
  }
247
- endTime = new Date();
248
- }, reload, modifyVars);
249
203
 
250
- loadStyles(modifyVars);
251
- });
252
- };
204
+ resolve();
205
+ });
206
+ };
207
+
208
+ //
209
+ // With this function, it's possible to alter variables and re-render
210
+ // CSS without reloading less-files
211
+ //
212
+ less.modifyVars = function(record) {
213
+ return less.refresh(true, record, false);
214
+ };
215
+
216
+ less.refresh = function (reload, modifyVars, clearFileCache) {
217
+ if ((reload || clearFileCache) && clearFileCache !== false) {
218
+ fileManager.clearFileCache();
219
+ }
220
+ return new Promise(function (resolve, reject) {
221
+ var startTime, endTime, totalMilliseconds;
222
+ startTime = endTime = new Date();
223
+
224
+ loadStyleSheets(function (e, css, _, sheet, webInfo) {
225
+ if (e) {
226
+ errors.add(e, e.href || sheet.href);
227
+ reject(e);
228
+ return;
229
+ }
230
+ if (webInfo.local) {
231
+ less.logger.info("loading " + sheet.href + " from cache.");
232
+ } else {
233
+ less.logger.info("rendered " + sheet.href + " successfully.");
234
+ }
235
+ browser.createCSS(window.document, css, sheet);
236
+ less.logger.info("css for " + sheet.href + " generated in " + (new Date() - endTime) + 'ms');
237
+ if (webInfo.remaining === 0) {
238
+ totalMilliseconds = new Date() - startTime;
239
+ less.logger.info("less has finished. css generated in " + totalMilliseconds + 'ms');
240
+ resolve({
241
+ startTime: startTime,
242
+ endTime: endTime,
243
+ totalMilliseconds: totalMilliseconds,
244
+ sheets: less.sheets.length
245
+ });
246
+ }
247
+ endTime = new Date();
248
+ }, reload, modifyVars);
249
+
250
+ loadStyles(modifyVars);
251
+ });
252
+ };
253
253
 
254
- less.refreshStyles = loadStyles;
254
+ less.refreshStyles = loadStyles;
255
255
  return less;
256
256
  };
@@ -11,7 +11,7 @@ module.exports = function(less, options) {
11
11
  // 1 - Errors
12
12
  // 0 - None
13
13
  // Defaults to 2
14
- options.logLevel = typeof(options.logLevel) !== 'undefined' ? options.logLevel : (options.env === 'development' ? logLevel_info : logLevel_error);
14
+ options.logLevel = typeof options.logLevel !== 'undefined' ? options.logLevel : (options.env === 'development' ? logLevel_info : logLevel_error);
15
15
 
16
16
  if (!options.loggers) {
17
17
  options.loggers = [{
@@ -37,7 +37,7 @@ module.exports = function(less, options) {
37
37
  }
38
38
  }];
39
39
  }
40
- for(var i = 0; i < options.loggers.length; i++) {
40
+ for (var i = 0; i < options.loggers.length; i++) {
41
41
  less.logger.addListener(options.loggers[i]);
42
42
  }
43
43
  };
@@ -1,11 +1,11 @@
1
1
  module.exports = {
2
2
  extractId: function(href) {
3
- return href.replace(/^[a-z-]+:\/+?[^\/]+/, '' ) // Remove protocol & domain
4
- .replace(/[\?\&]livereload=\w+/, '' ) // Remove LiveReload cachebuster
5
- .replace(/^\//, '' ) // Remove root /
6
- .replace(/\.[a-zA-Z]+$/, '' ) // Remove simple extension
7
- .replace(/[^\.\w-]+/g, '-') // Replace illegal characters
8
- .replace(/\./g, ':'); // Replace dots with colons(for valid id)
3
+ return href.replace(/^[a-z-]+:\/+?[^\/]+/, '') // Remove protocol & domain
4
+ .replace(/[\?\&]livereload=\w+/, '') // Remove LiveReload cachebuster
5
+ .replace(/^\//, '') // Remove root /
6
+ .replace(/\.[a-zA-Z]+$/, '') // Remove simple extension
7
+ .replace(/[^\.\w-]+/g, '-') // Replace illegal characters
8
+ .replace(/\./g, ':'); // Replace dots with colons(for valid id)
9
9
  },
10
10
  addDataAttr: function(options, tag) {
11
11
  for (var opt in tag.dataset) {
@@ -1,8 +1,13 @@
1
1
  var path = require('path'),
2
2
  fs = require('./fs'),
3
- PromiseConstructor = typeof Promise === 'undefined' ? require('promise') : Promise,
3
+ PromiseConstructor,
4
4
  AbstractFileManager = require("../less/environment/abstract-file-manager.js");
5
5
 
6
+ try {
7
+ PromiseConstructor = typeof Promise === 'undefined' ? require('promise') : Promise;
8
+ } catch(e) {
9
+ }
10
+
6
11
  var FileManager = function() {
7
12
  };
8
13
 
@@ -23,7 +28,7 @@ FileManager.prototype.loadFile = function(filename, currentDirectory, options, e
23
28
 
24
29
  options = options || {};
25
30
 
26
- if (options.syncImport) {
31
+ if (options.syncImport || !PromiseConstructor) {
27
32
  data = this.loadFileSync(filename, currentDirectory, options, environment, 'utf-8');
28
33
  callback(data.error, data);
29
34
  return;
@@ -79,7 +84,7 @@ FileManager.prototype.loadFileSync = function(filename, currentDirectory, option
79
84
  try {
80
85
  fullFilename = filename;
81
86
  if (paths[i]) {
82
- fullFilename = path.join(paths[i], fullFilename);
87
+ fullFilename = path.join(paths[i], fullFilename);
83
88
  }
84
89
  filenamesTried.push(fullFilename);
85
90
  fs.statSync(fullFilename);
@@ -95,7 +100,7 @@ FileManager.prototype.loadFileSync = function(filename, currentDirectory, option
95
100
  } else {
96
101
  data = fs.readFileSync(fullFilename, encoding);
97
102
  result = { contents: data, filename: fullFilename};
98
- }
103
+ }
99
104
 
100
105
  return result;
101
106
  };
@@ -27,11 +27,11 @@ less.formatError = function(ctx, options) {
27
27
  return ctx.stack || ctx.message;
28
28
  }
29
29
 
30
- if (typeof(extract[0]) === 'string') {
30
+ if (typeof extract[0] === 'string') {
31
31
  error.push(stylize((ctx.line - 1) + ' ' + extract[0], 'grey'));
32
32
  }
33
33
 
34
- if (typeof(extract[1]) === 'string') {
34
+ if (typeof extract[1] === 'string') {
35
35
  var errorTxt = ctx.line + ' ';
36
36
  if (extract[1]) {
37
37
  errorTxt += extract[1].slice(0, ctx.column) +
@@ -41,7 +41,7 @@ less.formatError = function(ctx, options) {
41
41
  error.push(errorTxt);
42
42
  }
43
43
 
44
- if (typeof(extract[2]) === 'string') {
44
+ if (typeof extract[2] === 'string') {
45
45
  error.push(stylize((ctx.line + 1) + ' ' + extract[2], 'grey'));
46
46
  }
47
47
  error = error.join('\n') + stylize('', 'reset') + '\n';
@@ -38,7 +38,7 @@ PluginLoader.prototype.tryLoadPlugin = function(name, argument) {
38
38
  return null;
39
39
  };
40
40
  PluginLoader.prototype.compareVersion = function(aVersion, bVersion) {
41
- for(var i = 0; i < aVersion.length; i++) {
41
+ for (var i = 0; i < aVersion.length; i++) {
42
42
  if (aVersion[i] !== bVersion[i]) {
43
43
  return parseInt(aVersion[i]) > parseInt(bVersion[i]) ? -1 : 1;
44
44
  }
@@ -47,7 +47,7 @@ PluginLoader.prototype.compareVersion = function(aVersion, bVersion) {
47
47
  };
48
48
  PluginLoader.prototype.versionToString = function(version) {
49
49
  var versionString = "";
50
- for(var i = 0; i < version.length; i++) {
50
+ for (var i = 0; i < version.length; i++) {
51
51
  versionString += (versionString ? "." : "") + version[i];
52
52
  }
53
53
  return versionString;
@@ -81,7 +81,7 @@ PluginLoader.prototype.tryRequirePlugin = function(name) {
81
81
  }
82
82
  };
83
83
  PluginLoader.prototype.printUsage = function(plugins) {
84
- for(var i = 0; i < plugins.length; i++) {
84
+ for (var i = 0; i < plugins.length; i++) {
85
85
  var plugin = plugins[i];
86
86
  if (plugin.printUsage) {
87
87
  plugin.printUsage();
@@ -1,7 +1,7 @@
1
1
  var isUrlRe = /^(?:https?:)?\/\//i,
2
2
  url = require('url'),
3
3
  request,
4
- PromiseConstructor = typeof Promise === 'undefined' ? require('promise') : Promise,
4
+ PromiseConstructor,
5
5
  AbstractFileManager = require("../less/environment/abstract-file-manager.js"),
6
6
  logger = require("../less/logger");
7
7
 
@@ -15,6 +15,9 @@ UrlFileManager.prototype.supports = function(filename, currentDirectory, options
15
15
  };
16
16
 
17
17
  UrlFileManager.prototype.loadFile = function(filename, currentDirectory, options, environment) {
18
+ if (!PromiseConstructor) {
19
+ PromiseConstructor = typeof Promise === 'undefined' ? require('promise') : Promise;
20
+ }
18
21
  return new PromiseConstructor(function(fulfill, reject) {
19
22
  if (request === undefined) {
20
23
  try { request = require('request'); }
@@ -43,7 +46,7 @@ UrlFileManager.prototype.loadFile = function(filename, currentDirectory, options
43
46
  return;
44
47
  }
45
48
  if (!body) {
46
- logger.warn('Warning: Empty body (HTTP '+ res.statusCode + ') returned by "' + urlStr + '"');
49
+ logger.warn('Warning: Empty body (HTTP ' + res.statusCode + ') returned by "' + urlStr + '"');
47
50
  }
48
51
  fulfill({ contents: body, filename: urlStr });
49
52
  });