less 2.4.0 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (265) hide show
  1. checksums.yaml +4 -4
  2. data/Changelog.md +4 -0
  3. data/Gemfile +1 -1
  4. data/less.gemspec +1 -1
  5. data/lib/less/defaults.rb +3 -3
  6. data/lib/less/java_script/v8_context.rb +1 -1
  7. data/lib/less/js/.gitattributes +3 -2
  8. data/lib/less/js/.gitignore +18 -2
  9. data/lib/less/js/.jshintrc +11 -0
  10. data/lib/less/js/CHANGELOG.md +87 -2
  11. data/lib/less/js/CONTRIBUTING.md +4 -3
  12. data/lib/less/js/Gruntfile.js +290 -0
  13. data/lib/less/js/README.md +342 -12
  14. data/lib/less/js/benchmark/benchmark.less +194 -194
  15. data/lib/less/js/benchmark/less-benchmark.js +9 -10
  16. data/lib/less/js/bin/lessc +154 -12
  17. data/lib/less/js/bower.json +18 -0
  18. data/lib/less/js/build.gradle +347 -0
  19. data/lib/less/js/build/README.md +350 -0
  20. data/lib/less/js/build/browser-header.js +4 -0
  21. data/lib/less/js/build/build.yml +160 -0
  22. data/lib/less/js/build/require-rhino.js +7 -2
  23. data/lib/less/js/build/rhino-header.js +4 -0
  24. data/lib/less/js/build/rhino-modules.js +131 -0
  25. data/lib/less/js/build/tasks/.gitkeep +1 -0
  26. data/lib/less/js/dist/less-1.5.0.js +6914 -0
  27. data/lib/less/js/dist/less-1.5.0.min.js +13 -0
  28. data/lib/less/js/dist/less-1.5.1.js +6941 -0
  29. data/lib/less/js/dist/less-1.5.1.min.js +13 -0
  30. data/lib/less/js/dist/less-1.6.0.js +7485 -0
  31. data/lib/less/js/dist/less-1.6.0.min.js +16 -0
  32. data/lib/less/js/dist/less-1.6.1.js +7513 -0
  33. data/lib/less/js/dist/less-1.6.1.min.js +16 -0
  34. data/lib/less/js/dist/less-1.6.2.js +7624 -0
  35. data/lib/less/js/dist/less-1.6.2.min.js +16 -0
  36. data/lib/less/js/dist/less-rhino-1.5.1.js +6831 -0
  37. data/lib/less/js/dist/less-rhino-1.6.2.js +9017 -0
  38. data/lib/less/js/dist/lessc-rhino-1.6.2.js +449 -0
  39. data/lib/less/js/gradle/wrapper/gradle-wrapper.jar +0 -0
  40. data/lib/less/js/gradle/wrapper/gradle-wrapper.properties +6 -0
  41. data/lib/less/js/gradlew +164 -0
  42. data/lib/less/js/gradlew.bat +90 -0
  43. data/lib/less/js/lib/less/browser.js +482 -367
  44. data/lib/less/js/lib/less/colors.js +0 -1
  45. data/lib/less/js/lib/less/encoder.js +4 -0
  46. data/lib/less/js/lib/less/env.js +50 -19
  47. data/lib/less/js/lib/less/extend-visitor.js +66 -41
  48. data/lib/less/js/lib/less/functions.js +309 -104
  49. data/lib/less/js/lib/less/import-visitor.js +21 -10
  50. data/lib/less/js/lib/less/index.js +90 -68
  51. data/lib/less/js/lib/less/join-selector-visitor.js +11 -4
  52. data/lib/less/js/lib/less/lessc_helper.js +56 -45
  53. data/lib/less/js/lib/less/parser.js +830 -460
  54. data/lib/less/js/lib/less/rhino.js +380 -58
  55. data/lib/less/js/lib/less/source-map-output.js +141 -0
  56. data/lib/less/js/lib/less/to-css-visitor.js +215 -0
  57. data/lib/less/js/lib/less/tree.js +57 -5
  58. data/lib/less/js/lib/less/tree/alpha.js +13 -5
  59. data/lib/less/js/lib/less/tree/anonymous.js +11 -5
  60. data/lib/less/js/lib/less/tree/assignment.js +11 -5
  61. data/lib/less/js/lib/less/tree/call.js +19 -8
  62. data/lib/less/js/lib/less/tree/color.js +59 -36
  63. data/lib/less/js/lib/less/tree/comment.js +17 -4
  64. data/lib/less/js/lib/less/tree/condition.js +3 -3
  65. data/lib/less/js/lib/less/tree/dimension.js +161 -153
  66. data/lib/less/js/lib/less/tree/directive.js +39 -18
  67. data/lib/less/js/lib/less/tree/element.js +41 -18
  68. data/lib/less/js/lib/less/tree/expression.js +11 -5
  69. data/lib/less/js/lib/less/tree/extend.js +11 -1
  70. data/lib/less/js/lib/less/tree/import.js +34 -20
  71. data/lib/less/js/lib/less/tree/javascript.js +16 -10
  72. data/lib/less/js/lib/less/tree/keyword.js +5 -2
  73. data/lib/less/js/lib/less/tree/media.js +39 -22
  74. data/lib/less/js/lib/less/tree/mixin.js +135 -56
  75. data/lib/less/js/lib/less/tree/negative.js +4 -2
  76. data/lib/less/js/lib/less/tree/operation.js +17 -12
  77. data/lib/less/js/lib/less/tree/paren.js +5 -2
  78. data/lib/less/js/lib/less/tree/quoted.js +9 -6
  79. data/lib/less/js/lib/less/tree/rule.js +39 -21
  80. data/lib/less/js/lib/less/tree/ruleset.js +229 -145
  81. data/lib/less/js/lib/less/tree/selector.js +101 -34
  82. data/lib/less/js/lib/less/tree/unicode-descriptor.js +4 -3
  83. data/lib/less/js/lib/less/tree/url.js +33 -11
  84. data/lib/less/js/lib/less/tree/value.js +13 -6
  85. data/lib/less/js/lib/less/tree/variable.js +13 -8
  86. data/lib/less/js/lib/less/visitor.js +117 -25
  87. data/lib/less/js/lib/source-map/source-map-0.1.31.js +1933 -0
  88. data/lib/less/js/lib/source-map/source-map-footer.js +4 -0
  89. data/lib/less/js/lib/source-map/source-map-header.js +3 -0
  90. data/lib/less/js/package.json +30 -15
  91. data/lib/less/js/test/browser/common.js +131 -56
  92. data/lib/less/js/test/browser/css/global-vars/simple.css +3 -0
  93. data/lib/less/js/test/browser/css/modify-vars/simple.css +8 -0
  94. data/lib/less/js/test/browser/css/relative-urls/urls.css +8 -9
  95. data/lib/less/js/test/browser/css/rootpath-relative/urls.css +0 -1
  96. data/lib/less/js/test/browser/css/rootpath/urls.css +0 -1
  97. data/lib/less/js/test/browser/css/urls.css +18 -14
  98. data/lib/less/js/test/browser/es5.js +27 -0
  99. data/lib/less/js/test/{less/errors/color-operation-error.less → browser/less/console-errors/test-error.less} +0 -0
  100. data/lib/less/js/test/browser/less/console-errors/test-error.txt +2 -0
  101. data/lib/less/js/test/browser/less/global-vars/simple.less +3 -0
  102. data/lib/less/js/test/browser/less/modify-vars/imports/simple2.less +4 -0
  103. data/lib/less/js/test/browser/less/modify-vars/simple.less +8 -0
  104. data/lib/less/js/test/browser/less/relative-urls/urls.less +1 -1
  105. data/lib/less/js/test/browser/less/rootpath-relative/urls.less +1 -1
  106. data/lib/less/js/test/browser/less/rootpath/urls.less +1 -1
  107. data/lib/less/js/test/browser/less/urls.less +9 -1
  108. data/lib/less/js/test/browser/phantom-runner.js +112 -103
  109. data/lib/less/js/test/browser/runner-browser-options.js +42 -0
  110. data/lib/less/js/test/browser/{runner-browser.js → runner-browser-spec.js} +7 -2
  111. data/lib/less/js/test/browser/runner-console-errors.js +5 -0
  112. data/lib/less/js/test/browser/runner-errors-options.js +5 -0
  113. data/lib/less/js/test/browser/runner-errors-spec.js +4 -0
  114. data/lib/less/js/test/browser/runner-global-vars-options.js +4 -0
  115. data/lib/less/js/test/browser/runner-global-vars-spec.js +3 -0
  116. data/lib/less/js/test/browser/runner-legacy-options.js +4 -0
  117. data/lib/less/js/test/browser/{runner-legacy.js → runner-legacy-spec.js} +1 -4
  118. data/lib/less/js/test/browser/runner-main-options.js +15 -0
  119. data/lib/less/js/test/browser/runner-main-spec.js +3 -0
  120. data/lib/less/js/test/browser/runner-modify-vars-options.js +2 -0
  121. data/lib/less/js/test/browser/runner-modify-vars-spec.js +43 -0
  122. data/lib/less/js/test/browser/runner-no-js-errors-options.js +4 -0
  123. data/lib/less/js/test/browser/runner-no-js-errors-spec.js +4 -0
  124. data/lib/less/js/test/browser/runner-production-options.js +3 -0
  125. data/lib/less/js/test/browser/{runner-production.js → runner-production-spec.js} +1 -3
  126. data/lib/less/js/test/browser/runner-relative-urls-options.js +3 -0
  127. data/lib/less/js/test/browser/{runner-relative-urls.js → runner-relative-urls-spec.js} +1 -2
  128. data/lib/less/js/test/browser/runner-rootpath-options.js +3 -0
  129. data/lib/less/js/test/browser/runner-rootpath-relative-options.js +4 -0
  130. data/lib/less/js/test/browser/{runner-rootpath-relative.js → runner-rootpath-relative-spec.js} +1 -3
  131. data/lib/less/js/test/browser/{runner-rootpath.js → runner-rootpath-spec.js} +1 -2
  132. data/lib/less/js/test/browser/test-runner-template.tmpl +47 -0
  133. data/lib/less/js/test/css/colors.css +7 -0
  134. data/lib/less/js/test/css/comments.css +9 -4
  135. data/lib/less/js/test/css/compression/compression.css +3 -2
  136. data/lib/less/js/test/css/css-3.css +17 -5
  137. data/lib/less/js/test/css/css-guards.css +37 -0
  138. data/lib/less/js/test/css/debug/linenumbers-all.css +6 -0
  139. data/lib/less/js/test/css/debug/linenumbers-comments.css +5 -0
  140. data/lib/less/js/test/css/debug/linenumbers-mediaquery.css +5 -0
  141. data/lib/less/js/test/css/empty.css +0 -0
  142. data/lib/less/js/test/css/extend-chaining.css +9 -0
  143. data/lib/less/js/test/css/extend-selector.css +10 -2
  144. data/lib/less/js/test/css/extract-and-length.css +133 -0
  145. data/lib/less/js/test/css/functions.css +23 -10
  146. data/lib/less/js/test/css/globalVars/extended.css +12 -0
  147. data/lib/less/js/test/css/globalVars/simple.css +6 -0
  148. data/lib/less/js/test/css/import-inline.css +5 -0
  149. data/lib/less/js/test/css/import-once.css +12 -0
  150. data/lib/less/js/test/css/import-reference.css +49 -0
  151. data/lib/less/js/test/css/import.css +0 -2
  152. data/lib/less/js/test/css/media.css +21 -5
  153. data/lib/less/js/test/css/merge.css +26 -0
  154. data/lib/less/js/test/css/mixins-guards-default-func.css +129 -0
  155. data/lib/less/js/test/css/mixins-guards.css +6 -0
  156. data/lib/less/js/test/css/mixins-important.css +7 -0
  157. data/lib/less/js/test/css/mixins-interpolated.css +39 -0
  158. data/lib/less/js/test/css/mixins.css +20 -0
  159. data/lib/less/js/test/css/modifyVars/extended.css +9 -0
  160. data/lib/less/js/test/css/no-output.css +0 -0
  161. data/lib/less/js/test/css/parens.css +3 -0
  162. data/lib/less/js/test/css/property-name-interp.css +20 -0
  163. data/lib/less/js/test/css/selectors.css +12 -0
  164. data/lib/less/js/test/css/static-urls/urls.css +7 -4
  165. data/lib/less/js/test/css/strings.css +3 -0
  166. data/lib/less/js/test/css/url-args/urls.css +56 -0
  167. data/lib/less/js/test/css/urls.css +21 -9
  168. data/lib/less/js/test/index.js +45 -0
  169. data/lib/less/js/test/less-test.js +234 -191
  170. data/lib/less/js/test/less/colors.less +6 -0
  171. data/lib/less/js/test/less/comments.less +7 -1
  172. data/lib/less/js/test/less/compression/compression.less +21 -1
  173. data/lib/less/js/test/less/css-3.less +12 -0
  174. data/lib/less/js/test/less/css-guards.less +99 -0
  175. data/lib/less/js/test/less/debug/linenumbers.less +11 -1
  176. data/lib/less/js/test/less/empty.less +0 -0
  177. data/lib/less/js/test/less/errors/add-mixed-units.txt +4 -2
  178. data/lib/less/js/test/less/errors/add-mixed-units2.txt +4 -2
  179. data/lib/less/js/test/less/errors/color-func-invalid-color.less +3 -0
  180. data/lib/less/js/test/less/errors/color-func-invalid-color.txt +4 -0
  181. data/lib/less/js/test/less/errors/css-guard-default-func.less +4 -0
  182. data/lib/less/js/test/less/errors/css-guard-default-func.txt +4 -0
  183. data/lib/less/js/test/less/errors/import-subfolder2.txt +4 -2
  184. data/lib/less/js/test/less/errors/javascript-undefined-var.less +3 -0
  185. data/lib/less/js/test/less/errors/javascript-undefined-var.txt +4 -0
  186. data/lib/less/js/test/less/errors/mixins-guards-default-func-1.less +9 -0
  187. data/lib/less/js/test/less/errors/mixins-guards-default-func-1.txt +4 -0
  188. data/lib/less/js/test/less/errors/mixins-guards-default-func-2.less +9 -0
  189. data/lib/less/js/test/less/errors/mixins-guards-default-func-2.txt +4 -0
  190. data/lib/less/js/test/less/errors/mixins-guards-default-func-3.less +9 -0
  191. data/lib/less/js/test/less/errors/mixins-guards-default-func-3.txt +4 -0
  192. data/lib/less/js/test/less/errors/multiple-guards-on-css-selectors.less +4 -0
  193. data/lib/less/js/test/less/errors/multiple-guards-on-css-selectors.txt +4 -0
  194. data/lib/less/js/test/less/errors/multiple-guards-on-css-selectors2.less +4 -0
  195. data/lib/less/js/test/less/errors/multiple-guards-on-css-selectors2.txt +4 -0
  196. data/lib/less/js/test/less/errors/parse-error-curly-bracket.less +4 -1
  197. data/lib/less/js/test/less/errors/parse-error-curly-bracket.txt +4 -2
  198. data/lib/less/js/test/less/errors/parse-error-extra-parens.less +5 -0
  199. data/lib/less/js/test/less/errors/parse-error-extra-parens.txt +3 -0
  200. data/lib/less/js/test/less/errors/parse-error-missing-bracket.txt +2 -2
  201. data/lib/less/js/test/less/errors/parse-error-missing-parens.less +5 -0
  202. data/lib/less/js/test/less/errors/parse-error-missing-parens.txt +3 -0
  203. data/lib/less/js/test/less/errors/property-asterisk-only-name.less +3 -0
  204. data/lib/less/js/test/less/errors/property-asterisk-only-name.txt +4 -0
  205. data/lib/less/js/test/less/errors/property-interp-not-defined.less +1 -0
  206. data/lib/less/js/test/less/errors/property-interp-not-defined.txt +2 -0
  207. data/lib/less/js/test/less/errors/svg-gradient1.less +3 -0
  208. data/lib/less/js/test/less/errors/svg-gradient1.txt +4 -0
  209. data/lib/less/js/test/less/errors/svg-gradient2.less +3 -0
  210. data/lib/less/js/test/less/errors/svg-gradient2.txt +4 -0
  211. data/lib/less/js/test/less/errors/svg-gradient3.less +3 -0
  212. data/lib/less/js/test/less/errors/svg-gradient3.txt +4 -0
  213. data/lib/less/js/test/less/errors/unit-function.less +3 -0
  214. data/lib/less/js/test/less/errors/unit-function.txt +4 -0
  215. data/lib/less/js/test/less/extend-chaining.less +12 -0
  216. data/lib/less/js/test/less/extend-selector.less +15 -0
  217. data/lib/less/js/test/less/extract-and-length.less +133 -0
  218. data/lib/less/js/test/less/functions.less +15 -2
  219. data/lib/less/js/test/less/globalVars/extended.json +5 -0
  220. data/lib/less/js/test/less/globalVars/extended.less +10 -0
  221. data/lib/less/js/test/less/globalVars/simple.json +3 -0
  222. data/lib/less/js/test/less/globalVars/simple.less +3 -0
  223. data/lib/less/js/test/less/import-inline.less +2 -0
  224. data/lib/less/js/test/less/import-once.less +2 -0
  225. data/lib/less/js/test/less/import-reference.less +18 -0
  226. data/lib/less/js/test/less/import/import-and-relative-paths-test.less +11 -0
  227. data/lib/less/js/test/less/import/import-reference.less +43 -0
  228. data/lib/less/js/test/less/import/import-test-f.less +5 -0
  229. data/lib/less/js/test/less/import/invalid-css.less +1 -0
  230. data/lib/less/js/test/less/media.less +25 -1
  231. data/lib/less/js/test/less/merge.less +59 -0
  232. data/lib/less/js/test/less/mixins-args.less +10 -0
  233. data/lib/less/js/test/less/mixins-guards-default-func.less +195 -0
  234. data/lib/less/js/test/less/mixins-guards.less +16 -0
  235. data/lib/less/js/test/less/mixins-important.less +4 -1
  236. data/lib/less/js/test/less/mixins-interpolated.less +69 -0
  237. data/lib/less/js/test/less/mixins.less +27 -0
  238. data/lib/less/js/test/less/modifyVars/extended.json +5 -0
  239. data/lib/less/js/test/less/modifyVars/extended.less +11 -0
  240. data/lib/less/js/test/less/no-js-errors/no-js-errors.less +3 -0
  241. data/lib/less/js/test/less/no-js-errors/no-js-errors.txt +4 -0
  242. data/lib/less/js/test/less/no-output.less +2 -0
  243. data/lib/less/js/test/less/parens.less +4 -0
  244. data/lib/less/js/test/less/property-name-interp.less +53 -0
  245. data/lib/less/js/test/less/selectors.less +13 -0
  246. data/lib/less/js/test/less/sourcemaps/basic.json +3 -0
  247. data/lib/less/js/test/less/sourcemaps/basic.less +27 -0
  248. data/lib/less/js/test/less/sourcemaps/imported.css +7 -0
  249. data/lib/less/js/test/less/strings.less +6 -0
  250. data/lib/less/js/test/less/url-args/urls.less +63 -0
  251. data/lib/less/js/test/less/urls.less +15 -0
  252. data/lib/less/js/test/rhino/test-header.js +15 -0
  253. data/lib/less/js/test/sourcemaps/basic.json +1 -0
  254. data/lib/less/js/test/sourcemaps/index.html +17 -0
  255. data/lib/less/loader.rb +48 -40
  256. data/lib/less/version.rb +1 -1
  257. data/spec/less/parser_spec.rb +15 -15
  258. metadata +146 -40
  259. data/lib/less/js/Makefile +0 -102
  260. data/lib/less/js/build/header.js +0 -9
  261. data/lib/less/js/test/browser-test-prepare.js +0 -46
  262. data/lib/less/js/test/browser/runner-errors.js +0 -5
  263. data/lib/less/js/test/browser/runner-main.js +0 -15
  264. data/lib/less/js/test/browser/template.htm +0 -10
  265. data/lib/less/js/test/less/errors/color-operation-error.txt +0 -2
@@ -0,0 +1,141 @@
1
+ (function (tree) {
2
+
3
+ tree.sourceMapOutput = function (options) {
4
+ this._css = [];
5
+ this._rootNode = options.rootNode;
6
+ this._writeSourceMap = options.writeSourceMap;
7
+ this._contentsMap = options.contentsMap;
8
+ this._contentsIgnoredCharsMap = options.contentsIgnoredCharsMap;
9
+ this._sourceMapFilename = options.sourceMapFilename;
10
+ this._outputFilename = options.outputFilename;
11
+ this._sourceMapURL = options.sourceMapURL;
12
+ if (options.sourceMapBasepath) {
13
+ this._sourceMapBasepath = options.sourceMapBasepath.replace(/\\/g, '/');
14
+ }
15
+ this._sourceMapRootpath = options.sourceMapRootpath;
16
+ this._outputSourceFiles = options.outputSourceFiles;
17
+ this._sourceMapGeneratorConstructor = options.sourceMapGenerator || require("source-map").SourceMapGenerator;
18
+
19
+ if (this._sourceMapRootpath && this._sourceMapRootpath.charAt(this._sourceMapRootpath.length-1) !== '/') {
20
+ this._sourceMapRootpath += '/';
21
+ }
22
+
23
+ this._lineNumber = 0;
24
+ this._column = 0;
25
+ };
26
+
27
+ tree.sourceMapOutput.prototype.normalizeFilename = function(filename) {
28
+ filename = filename.replace(/\\/g, '/');
29
+
30
+ if (this._sourceMapBasepath && filename.indexOf(this._sourceMapBasepath) === 0) {
31
+ filename = filename.substring(this._sourceMapBasepath.length);
32
+ if (filename.charAt(0) === '\\' || filename.charAt(0) === '/') {
33
+ filename = filename.substring(1);
34
+ }
35
+ }
36
+ return (this._sourceMapRootpath || "") + filename;
37
+ };
38
+
39
+ tree.sourceMapOutput.prototype.add = function(chunk, fileInfo, index, mapLines) {
40
+
41
+ //ignore adding empty strings
42
+ if (!chunk) {
43
+ return;
44
+ }
45
+
46
+ var lines,
47
+ sourceLines,
48
+ columns,
49
+ sourceColumns,
50
+ i;
51
+
52
+ if (fileInfo) {
53
+ var inputSource = this._contentsMap[fileInfo.filename];
54
+
55
+ // remove vars/banner added to the top of the file
56
+ if (this._contentsIgnoredCharsMap[fileInfo.filename]) {
57
+ // adjust the index
58
+ index -= this._contentsIgnoredCharsMap[fileInfo.filename];
59
+ if (index < 0) { index = 0; }
60
+ // adjust the source
61
+ inputSource = inputSource.slice(this._contentsIgnoredCharsMap[fileInfo.filename]);
62
+ }
63
+ inputSource = inputSource.substring(0, index);
64
+ sourceLines = inputSource.split("\n");
65
+ sourceColumns = sourceLines[sourceLines.length-1];
66
+ }
67
+
68
+ lines = chunk.split("\n");
69
+ columns = lines[lines.length-1];
70
+
71
+ if (fileInfo) {
72
+ if (!mapLines) {
73
+ this._sourceMapGenerator.addMapping({ generated: { line: this._lineNumber + 1, column: this._column},
74
+ original: { line: sourceLines.length, column: sourceColumns.length},
75
+ source: this.normalizeFilename(fileInfo.filename)});
76
+ } else {
77
+ for(i = 0; i < lines.length; i++) {
78
+ this._sourceMapGenerator.addMapping({ generated: { line: this._lineNumber + i + 1, column: i === 0 ? this._column : 0},
79
+ original: { line: sourceLines.length + i, column: i === 0 ? sourceColumns.length : 0},
80
+ source: this.normalizeFilename(fileInfo.filename)});
81
+ }
82
+ }
83
+ }
84
+
85
+ if (lines.length === 1) {
86
+ this._column += columns.length;
87
+ } else {
88
+ this._lineNumber += lines.length - 1;
89
+ this._column = columns.length;
90
+ }
91
+
92
+ this._css.push(chunk);
93
+ };
94
+
95
+ tree.sourceMapOutput.prototype.isEmpty = function() {
96
+ return this._css.length === 0;
97
+ };
98
+
99
+ tree.sourceMapOutput.prototype.toCSS = function(env) {
100
+ this._sourceMapGenerator = new this._sourceMapGeneratorConstructor({ file: this._outputFilename, sourceRoot: null });
101
+
102
+ if (this._outputSourceFiles) {
103
+ for(var filename in this._contentsMap) {
104
+ if (this._contentsMap.hasOwnProperty(filename))
105
+ {
106
+ var source = this._contentsMap[filename];
107
+ if (this._contentsIgnoredCharsMap[filename]) {
108
+ source = source.slice(this._contentsIgnoredCharsMap[filename]);
109
+ }
110
+ this._sourceMapGenerator.setSourceContent(this.normalizeFilename(filename), source);
111
+ }
112
+ }
113
+ }
114
+
115
+ this._rootNode.genCSS(env, this);
116
+
117
+ if (this._css.length > 0) {
118
+ var sourceMapURL,
119
+ sourceMapContent = JSON.stringify(this._sourceMapGenerator.toJSON());
120
+
121
+ if (this._sourceMapURL) {
122
+ sourceMapURL = this._sourceMapURL;
123
+ } else if (this._sourceMapFilename) {
124
+ sourceMapURL = this.normalizeFilename(this._sourceMapFilename);
125
+ }
126
+
127
+ if (this._writeSourceMap) {
128
+ this._writeSourceMap(sourceMapContent);
129
+ } else {
130
+ sourceMapURL = "data:application/json," + encodeURIComponent(sourceMapContent);
131
+ }
132
+
133
+ if (sourceMapURL) {
134
+ this._css.push("/*# sourceMappingURL=" + sourceMapURL + " */");
135
+ }
136
+ }
137
+
138
+ return this._css.join('');
139
+ };
140
+
141
+ })(require('./tree'));
@@ -0,0 +1,215 @@
1
+ (function (tree) {
2
+ tree.toCSSVisitor = function(env) {
3
+ this._visitor = new tree.visitor(this);
4
+ this._env = env;
5
+ };
6
+
7
+ tree.toCSSVisitor.prototype = {
8
+ isReplacing: true,
9
+ run: function (root) {
10
+ return this._visitor.visit(root);
11
+ },
12
+
13
+ visitRule: function (ruleNode, visitArgs) {
14
+ if (ruleNode.variable) {
15
+ return [];
16
+ }
17
+ return ruleNode;
18
+ },
19
+
20
+ visitMixinDefinition: function (mixinNode, visitArgs) {
21
+ return [];
22
+ },
23
+
24
+ visitExtend: function (extendNode, visitArgs) {
25
+ return [];
26
+ },
27
+
28
+ visitComment: function (commentNode, visitArgs) {
29
+ if (commentNode.isSilent(this._env)) {
30
+ return [];
31
+ }
32
+ return commentNode;
33
+ },
34
+
35
+ visitMedia: function(mediaNode, visitArgs) {
36
+ mediaNode.accept(this._visitor);
37
+ visitArgs.visitDeeper = false;
38
+
39
+ if (!mediaNode.rules.length) {
40
+ return [];
41
+ }
42
+ return mediaNode;
43
+ },
44
+
45
+ visitDirective: function(directiveNode, visitArgs) {
46
+ if (directiveNode.currentFileInfo.reference && !directiveNode.isReferenced) {
47
+ return [];
48
+ }
49
+ if (directiveNode.name === "@charset") {
50
+ // Only output the debug info together with subsequent @charset definitions
51
+ // a comment (or @media statement) before the actual @charset directive would
52
+ // be considered illegal css as it has to be on the first line
53
+ if (this.charset) {
54
+ if (directiveNode.debugInfo) {
55
+ var comment = new tree.Comment("/* " + directiveNode.toCSS(this._env).replace(/\n/g, "")+" */\n");
56
+ comment.debugInfo = directiveNode.debugInfo;
57
+ return this._visitor.visit(comment);
58
+ }
59
+ return [];
60
+ }
61
+ this.charset = true;
62
+ }
63
+ return directiveNode;
64
+ },
65
+
66
+ checkPropertiesInRoot: function(rules) {
67
+ var ruleNode;
68
+ for(var i = 0; i < rules.length; i++) {
69
+ ruleNode = rules[i];
70
+ if (ruleNode instanceof tree.Rule && !ruleNode.variable) {
71
+ throw { message: "properties must be inside selector blocks, they cannot be in the root.",
72
+ index: ruleNode.index, filename: ruleNode.currentFileInfo ? ruleNode.currentFileInfo.filename : null};
73
+ }
74
+ }
75
+ },
76
+
77
+ visitRuleset: function (rulesetNode, visitArgs) {
78
+ var rule, rulesets = [];
79
+ if (rulesetNode.firstRoot) {
80
+ this.checkPropertiesInRoot(rulesetNode.rules);
81
+ }
82
+ if (! rulesetNode.root) {
83
+ if (rulesetNode.paths) {
84
+ rulesetNode.paths = rulesetNode.paths
85
+ .filter(function(p) {
86
+ var i;
87
+ if (p[0].elements[0].combinator.value === ' ') {
88
+ p[0].elements[0].combinator = new(tree.Combinator)('');
89
+ }
90
+ for(i = 0; i < p.length; i++) {
91
+ if (p[i].getIsReferenced() && p[i].getIsOutput()) {
92
+ return true;
93
+ }
94
+ }
95
+ return false;
96
+ });
97
+ }
98
+
99
+ // Compile rules and rulesets
100
+ var nodeRules = rulesetNode.rules, nodeRuleCnt = nodeRules ? nodeRules.length : 0;
101
+ for (var i = 0; i < nodeRuleCnt; ) {
102
+ rule = nodeRules[i];
103
+ if (rule && rule.rules) {
104
+ // visit because we are moving them out from being a child
105
+ rulesets.push(this._visitor.visit(rule));
106
+ nodeRules.splice(i, 1);
107
+ nodeRuleCnt--;
108
+ continue;
109
+ }
110
+ i++;
111
+ }
112
+ // accept the visitor to remove rules and refactor itself
113
+ // then we can decide now whether we want it or not
114
+ if (nodeRuleCnt > 0) {
115
+ rulesetNode.accept(this._visitor);
116
+ } else {
117
+ rulesetNode.rules = null;
118
+ }
119
+ visitArgs.visitDeeper = false;
120
+
121
+ nodeRules = rulesetNode.rules;
122
+ if (nodeRules) {
123
+ this._mergeRules(nodeRules);
124
+ nodeRules = rulesetNode.rules;
125
+ }
126
+ if (nodeRules) {
127
+ this._removeDuplicateRules(nodeRules);
128
+ nodeRules = rulesetNode.rules;
129
+ }
130
+
131
+ // now decide whether we keep the ruleset
132
+ if (nodeRules && nodeRules.length > 0 && rulesetNode.paths.length > 0) {
133
+ rulesets.splice(0, 0, rulesetNode);
134
+ }
135
+ } else {
136
+ rulesetNode.accept(this._visitor);
137
+ visitArgs.visitDeeper = false;
138
+ if (rulesetNode.firstRoot || (rulesetNode.rules && rulesetNode.rules.length > 0)) {
139
+ rulesets.splice(0, 0, rulesetNode);
140
+ }
141
+ }
142
+ if (rulesets.length === 1) {
143
+ return rulesets[0];
144
+ }
145
+ return rulesets;
146
+ },
147
+
148
+ _removeDuplicateRules: function(rules) {
149
+ if (!rules) { return; }
150
+
151
+ // remove duplicates
152
+ var ruleCache = {},
153
+ ruleList, rule, i;
154
+
155
+ for(i = rules.length - 1; i >= 0 ; i--) {
156
+ rule = rules[i];
157
+ if (rule instanceof tree.Rule) {
158
+ if (!ruleCache[rule.name]) {
159
+ ruleCache[rule.name] = rule;
160
+ } else {
161
+ ruleList = ruleCache[rule.name];
162
+ if (ruleList instanceof tree.Rule) {
163
+ ruleList = ruleCache[rule.name] = [ruleCache[rule.name].toCSS(this._env)];
164
+ }
165
+ var ruleCSS = rule.toCSS(this._env);
166
+ if (ruleList.indexOf(ruleCSS) !== -1) {
167
+ rules.splice(i, 1);
168
+ } else {
169
+ ruleList.push(ruleCSS);
170
+ }
171
+ }
172
+ }
173
+ }
174
+ },
175
+
176
+ _mergeRules: function (rules) {
177
+ if (!rules) { return; }
178
+
179
+ var groups = {},
180
+ parts,
181
+ rule,
182
+ key;
183
+
184
+ for (var i = 0; i < rules.length; i++) {
185
+ rule = rules[i];
186
+
187
+ if ((rule instanceof tree.Rule) && rule.merge) {
188
+ key = [rule.name,
189
+ rule.important ? "!" : ""].join(",");
190
+
191
+ if (!groups[key]) {
192
+ groups[key] = [];
193
+ } else {
194
+ rules.splice(i--, 1);
195
+ }
196
+
197
+ groups[key].push(rule);
198
+ }
199
+ }
200
+
201
+ Object.keys(groups).map(function (k) {
202
+ parts = groups[k];
203
+
204
+ if (parts.length > 1) {
205
+ rule = parts[0];
206
+
207
+ rule.value = new (tree.Value)(parts.map(function (p) {
208
+ return p.value;
209
+ }));
210
+ }
211
+ });
212
+ }
213
+ };
214
+
215
+ })(require('./tree'));
@@ -1,6 +1,6 @@
1
1
  (function (tree) {
2
2
 
3
- tree.debugInfo = function(env, ctx) {
3
+ tree.debugInfo = function(env, ctx, lineSeperator) {
4
4
  var result="";
5
5
  if (env.dumpLineNumbers && !env.compress) {
6
6
  switch(env.dumpLineNumbers) {
@@ -11,7 +11,7 @@ tree.debugInfo = function(env, ctx) {
11
11
  result = tree.debugInfo.asMediaQuery(ctx);
12
12
  break;
13
13
  case 'all':
14
- result = tree.debugInfo.asComment(ctx)+tree.debugInfo.asMediaQuery(ctx);
14
+ result = tree.debugInfo.asComment(ctx) + (lineSeperator || "") + tree.debugInfo.asMediaQuery(ctx);
15
15
  break;
16
16
  }
17
17
  }
@@ -24,22 +24,74 @@ tree.debugInfo.asComment = function(ctx) {
24
24
 
25
25
  tree.debugInfo.asMediaQuery = function(ctx) {
26
26
  return '@media -sass-debug-info{filename{font-family:' +
27
- ('file://' + ctx.debugInfo.fileName).replace(/([.:/\\])/g, function(a){if(a=='\\') a = '\/'; return '\\' + a}) +
27
+ ('file://' + ctx.debugInfo.fileName).replace(/([.:\/\\])/g, function (a) {
28
+ if (a == '\\') {
29
+ a = '\/';
30
+ }
31
+ return '\\' + a;
32
+ }) +
28
33
  '}line{font-family:\\00003' + ctx.debugInfo.lineNumber + '}}\n';
29
34
  };
30
35
 
31
36
  tree.find = function (obj, fun) {
32
37
  for (var i = 0, r; i < obj.length; i++) {
33
- if (r = fun.call(obj, obj[i])) { return r }
38
+ r = fun.call(obj, obj[i]);
39
+ if (r) { return r; }
34
40
  }
35
41
  return null;
36
42
  };
43
+
37
44
  tree.jsify = function (obj) {
38
45
  if (Array.isArray(obj.value) && (obj.value.length > 1)) {
39
- return '[' + obj.value.map(function (v) { return v.toCSS(false) }).join(', ') + ']';
46
+ return '[' + obj.value.map(function (v) { return v.toCSS(false); }).join(', ') + ']';
40
47
  } else {
41
48
  return obj.toCSS(false);
42
49
  }
43
50
  };
44
51
 
52
+ tree.toCSS = function (env) {
53
+ var strs = [];
54
+ this.genCSS(env, {
55
+ add: function(chunk, fileInfo, index) {
56
+ strs.push(chunk);
57
+ },
58
+ isEmpty: function () {
59
+ return strs.length === 0;
60
+ }
61
+ });
62
+ return strs.join('');
63
+ };
64
+
65
+ tree.outputRuleset = function (env, output, rules) {
66
+ var ruleCnt = rules.length, i;
67
+ env.tabLevel = (env.tabLevel | 0) + 1;
68
+
69
+ // Compressed
70
+ if (env.compress) {
71
+ output.add('{');
72
+ for (i = 0; i < ruleCnt; i++) {
73
+ rules[i].genCSS(env, output);
74
+ }
75
+ output.add('}');
76
+ env.tabLevel--;
77
+ return;
78
+ }
79
+
80
+ // Non-compressed
81
+ var tabSetStr = '\n' + Array(env.tabLevel).join(" "), tabRuleStr = tabSetStr + " ";
82
+ if (!ruleCnt) {
83
+ output.add(" {" + tabSetStr + '}');
84
+ } else {
85
+ output.add(" {" + tabRuleStr);
86
+ rules[0].genCSS(env, output);
87
+ for (i = 1; i < ruleCnt; i++) {
88
+ output.add(tabRuleStr);
89
+ rules[i].genCSS(env, output);
90
+ }
91
+ output.add(tabSetStr + '}');
92
+ }
93
+
94
+ env.tabLevel--;
95
+ };
96
+
45
97
  })(require('./tree'));