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
@@ -1,61 +1,128 @@
1
1
  (function (tree) {
2
2
 
3
- tree.Selector = function (elements, extendList) {
3
+ tree.Selector = function (elements, extendList, condition, index, currentFileInfo, isReferenced) {
4
4
  this.elements = elements;
5
- this.extendList = extendList || [];
5
+ this.extendList = extendList;
6
+ this.condition = condition;
7
+ this.currentFileInfo = currentFileInfo || {};
8
+ this.isReferenced = isReferenced;
9
+ if (!condition) {
10
+ this.evaldCondition = true;
11
+ }
6
12
  };
7
13
  tree.Selector.prototype = {
8
14
  type: "Selector",
9
15
  accept: function (visitor) {
10
- this.elements = visitor.visit(this.elements);
11
- this.extendList = visitor.visit(this.extendList)
16
+ if (this.elements) {
17
+ this.elements = visitor.visitArray(this.elements);
18
+ }
19
+ if (this.extendList) {
20
+ this.extendList = visitor.visitArray(this.extendList);
21
+ }
22
+ if (this.condition) {
23
+ this.condition = visitor.visit(this.condition);
24
+ }
25
+ },
26
+ createDerived: function(elements, extendList, evaldCondition) {
27
+ evaldCondition = (evaldCondition != null) ? evaldCondition : this.evaldCondition;
28
+ var newSelector = new(tree.Selector)(elements, extendList || this.extendList, null, this.index, this.currentFileInfo, this.isReferenced);
29
+ newSelector.evaldCondition = evaldCondition;
30
+ newSelector.mediaEmpty = this.mediaEmpty;
31
+ return newSelector;
12
32
  },
13
33
  match: function (other) {
14
34
  var elements = this.elements,
15
35
  len = elements.length,
16
- oelements, olen, max, i;
36
+ olen, i;
17
37
 
18
- oelements = other.elements.slice(
19
- (other.elements.length && other.elements[0].value === "&") ? 1 : 0);
20
- olen = oelements.length;
21
- max = Math.min(len, olen);
38
+ other.CacheElements();
22
39
 
40
+ olen = other._elements.length;
23
41
  if (olen === 0 || len < olen) {
24
- return false;
42
+ return 0;
25
43
  } else {
26
- for (i = 0; i < max; i++) {
27
- if (elements[i].value !== oelements[i].value) {
28
- return false;
44
+ for (i = 0; i < olen; i++) {
45
+ if (elements[i].value !== other._elements[i]) {
46
+ return 0;
29
47
  }
30
48
  }
31
49
  }
32
- return true;
33
- },
34
- eval: function (env) {
35
- return new(tree.Selector)(this.elements.map(function (e) {
36
- return e.eval(env);
37
- }), this.extendList.map(function(extend) {
38
- return extend.eval(env);
39
- }));
50
+
51
+ return olen; // return number of matched elements
40
52
  },
41
- toCSS: function (env) {
42
- if (this._css) { return this._css }
53
+ CacheElements: function(){
54
+ var css = '', len, v, i;
43
55
 
44
- if (this.elements[0].combinator.value === "") {
45
- this._css = ' ';
46
- } else {
47
- this._css = '';
48
- }
56
+ if( !this._elements ){
57
+
58
+ len = this.elements.length;
59
+ for(i = 0; i < len; i++){
60
+
61
+ v = this.elements[i];
62
+ css += v.combinator.value;
63
+
64
+ if( !v.value.value ){
65
+ css += v.value;
66
+ continue;
67
+ }
68
+
69
+ if( typeof v.value.value !== "string" ){
70
+ css = '';
71
+ break;
72
+ }
73
+ css += v.value.value;
74
+ }
75
+
76
+ this._elements = css.match(/[,&#\.\w-]([\w-]|(\\.))*/g);
77
+
78
+ if (this._elements) {
79
+ if (this._elements[0] === "&") {
80
+ this._elements.shift();
81
+ }
49
82
 
50
- this._css += this.elements.map(function (e) {
51
- if (typeof(e) === 'string') {
52
- return ' ' + e.trim();
53
83
  } else {
54
- return e.toCSS(env);
84
+ this._elements = [];
55
85
  }
56
- }).join('');
57
86
 
58
- return this._css;
87
+ }
88
+ },
89
+ isJustParentSelector: function() {
90
+ return !this.mediaEmpty &&
91
+ this.elements.length === 1 &&
92
+ this.elements[0].value === '&' &&
93
+ (this.elements[0].combinator.value === ' ' || this.elements[0].combinator.value === '');
94
+ },
95
+ eval: function (env) {
96
+ var evaldCondition = this.condition && this.condition.eval(env),
97
+ elements = this.elements, extendList = this.extendList;
98
+
99
+ elements = elements && elements.map(function (e) { return e.eval(env); });
100
+ extendList = extendList && extendList.map(function(extend) { return extend.eval(env); });
101
+
102
+ return this.createDerived(elements, extendList, evaldCondition);
103
+ },
104
+ genCSS: function (env, output) {
105
+ var i, element;
106
+ if ((!env || !env.firstSelector) && this.elements[0].combinator.value === "") {
107
+ output.add(' ', this.currentFileInfo, this.index);
108
+ }
109
+ if (!this._css) {
110
+ //TODO caching? speed comparison?
111
+ for(i = 0; i < this.elements.length; i++) {
112
+ element = this.elements[i];
113
+ element.genCSS(env, output);
114
+ }
115
+ }
116
+ },
117
+ toCSS: tree.toCSS,
118
+ markReferenced: function () {
119
+ this.isReferenced = true;
120
+ },
121
+ getIsReferenced: function() {
122
+ return !this.currentFileInfo.reference || this.isReferenced;
123
+ },
124
+ getIsOutput: function() {
125
+ return this.evaldCondition;
59
126
  }
60
127
  };
61
128
 
@@ -5,10 +5,11 @@ tree.UnicodeDescriptor = function (value) {
5
5
  };
6
6
  tree.UnicodeDescriptor.prototype = {
7
7
  type: "UnicodeDescriptor",
8
- toCSS: function (env) {
9
- return this.value;
8
+ genCSS: function (env, output) {
9
+ output.add(this.value);
10
10
  },
11
- eval: function () { return this }
11
+ toCSS: tree.toCSS,
12
+ eval: function () { return this; }
12
13
  };
13
14
 
14
15
  })(require('../tree'));
@@ -1,30 +1,52 @@
1
1
  (function (tree) {
2
2
 
3
- tree.URL = function (val, currentFileInfo) {
3
+ tree.URL = function (val, currentFileInfo, isEvald) {
4
4
  this.value = val;
5
5
  this.currentFileInfo = currentFileInfo;
6
+ this.isEvald = isEvald;
6
7
  };
7
8
  tree.URL.prototype = {
8
9
  type: "Url",
9
10
  accept: function (visitor) {
10
11
  this.value = visitor.visit(this.value);
11
12
  },
12
- toCSS: function () {
13
- return "url(" + this.value.toCSS() + ")";
13
+ genCSS: function (env, output) {
14
+ output.add("url(");
15
+ this.value.genCSS(env, output);
16
+ output.add(")");
14
17
  },
18
+ toCSS: tree.toCSS,
15
19
  eval: function (ctx) {
16
- var val = this.value.eval(ctx), rootpath;
20
+ var val = this.value.eval(ctx),
21
+ rootpath;
17
22
 
18
- // Add the base path if the URL is relative
19
- rootpath = this.currentFileInfo && this.currentFileInfo.rootpath;
20
- if (rootpath && typeof val.value === "string" && ctx.isPathRelative(val.value)) {
21
- if (!val.quote) {
22
- rootpath = rootpath.replace(/[\(\)'"\s]/g, function(match) { return "\\"+match; });
23
+ if (!this.isEvald) {
24
+ // Add the base path if the URL is relative
25
+ rootpath = this.currentFileInfo && this.currentFileInfo.rootpath;
26
+ if (rootpath && typeof val.value === "string" && ctx.isPathRelative(val.value)) {
27
+ if (!val.quote) {
28
+ rootpath = rootpath.replace(/[\(\)'"\s]/g, function(match) { return "\\"+match; });
29
+ }
30
+ val.value = rootpath + val.value;
31
+ }
32
+
33
+ val.value = ctx.normalizePath(val.value);
34
+
35
+ // Add url args if enabled
36
+ if (ctx.urlArgs) {
37
+ if (!val.value.match(/^\s*data:/)) {
38
+ var delimiter = val.value.indexOf('?') === -1 ? '?' : '&';
39
+ var urlArgs = delimiter + ctx.urlArgs;
40
+ if (val.value.indexOf('#') !== -1) {
41
+ val.value = val.value.replace('#', urlArgs + '#');
42
+ } else {
43
+ val.value += urlArgs;
44
+ }
45
+ }
23
46
  }
24
- val.value = rootpath + val.value;
25
47
  }
26
48
 
27
- return new(tree.URL)(val, null);
49
+ return new(tree.URL)(val, this.currentFileInfo, true);
28
50
  }
29
51
  };
30
52
 
@@ -6,7 +6,9 @@ tree.Value = function (value) {
6
6
  tree.Value.prototype = {
7
7
  type: "Value",
8
8
  accept: function (visitor) {
9
- this.value = visitor.visit(this.value);
9
+ if (this.value) {
10
+ this.value = visitor.visitArray(this.value);
11
+ }
10
12
  },
11
13
  eval: function (env) {
12
14
  if (this.value.length === 1) {
@@ -17,11 +19,16 @@ tree.Value.prototype = {
17
19
  }));
18
20
  }
19
21
  },
20
- toCSS: function (env) {
21
- return this.value.map(function (e) {
22
- return e.toCSS(env);
23
- }).join(env.compress ? ',' : ', ');
24
- }
22
+ genCSS: function (env, output) {
23
+ var i;
24
+ for(i = 0; i < this.value.length; i++) {
25
+ this.value[i].genCSS(env, output);
26
+ if (i+1 < this.value.length) {
27
+ output.add((env && env.compress) ? ',' : ', ');
28
+ }
29
+ }
30
+ },
31
+ toCSS: tree.toCSS
25
32
  };
26
33
 
27
34
  })(require('../tree'));
@@ -1,12 +1,16 @@
1
1
  (function (tree) {
2
2
 
3
- tree.Variable = function (name, index, currentFileInfo) { this.name = name, this.index = index, this.currentFileInfo = currentFileInfo };
3
+ tree.Variable = function (name, index, currentFileInfo) {
4
+ this.name = name;
5
+ this.index = index;
6
+ this.currentFileInfo = currentFileInfo || {};
7
+ };
4
8
  tree.Variable.prototype = {
5
9
  type: "Variable",
6
10
  eval: function (env) {
7
- var variable, v, name = this.name;
11
+ var variable, name = this.name;
8
12
 
9
- if (name.indexOf('@@') == 0) {
13
+ if (name.indexOf('@@') === 0) {
10
14
  name = '@' + new(tree.Variable)(name.slice(1)).eval(env).value;
11
15
  }
12
16
 
@@ -19,15 +23,16 @@ tree.Variable.prototype = {
19
23
 
20
24
  this.evaluating = true;
21
25
 
22
- if (variable = tree.find(env.frames, function (frame) {
23
- if (v = frame.variable(name)) {
26
+ variable = tree.find(env.frames, function (frame) {
27
+ var v = frame.variable(name);
28
+ if (v) {
24
29
  return v.value.eval(env);
25
30
  }
26
- })) {
31
+ });
32
+ if (variable) {
27
33
  this.evaluating = false;
28
34
  return variable;
29
- }
30
- else {
35
+ } else {
31
36
  throw { type: 'Name',
32
37
  message: "variable " + name + " is undefined",
33
38
  filename: this.currentFileInfo.filename,
@@ -1,53 +1,145 @@
1
1
  (function (tree) {
2
2
 
3
+ var _visitArgs = { visitDeeper: true },
4
+ _hasIndexed = false;
5
+
6
+ function _noop(node) {
7
+ return node;
8
+ }
9
+
10
+ function indexNodeTypes(parent, ticker) {
11
+ // add .typeIndex to tree node types for lookup table
12
+ var key, child;
13
+ for (key in parent) {
14
+ if (parent.hasOwnProperty(key)) {
15
+ child = parent[key];
16
+ switch (typeof child) {
17
+ case "function":
18
+ // ignore bound functions directly on tree which do not have a prototype
19
+ // or aren't nodes
20
+ if (child.prototype && child.prototype.type) {
21
+ child.prototype.typeIndex = ticker++;
22
+ }
23
+ break;
24
+ case "object":
25
+ ticker = indexNodeTypes(child, ticker);
26
+ break;
27
+ }
28
+ }
29
+ }
30
+ return ticker;
31
+ }
32
+
3
33
  tree.visitor = function(implementation) {
4
34
  this._implementation = implementation;
35
+ this._visitFnCache = [];
36
+
37
+ if (!_hasIndexed) {
38
+ indexNodeTypes(tree, 1);
39
+ _hasIndexed = true;
40
+ }
5
41
  };
6
42
 
7
43
  tree.visitor.prototype = {
8
44
  visit: function(node) {
9
-
10
- if (node instanceof Array) {
11
- return this.visitArray(node);
45
+ if (!node) {
46
+ return node;
12
47
  }
13
48
 
14
- if (!node || !node.type) {
49
+ var nodeTypeIndex = node.typeIndex;
50
+ if (!nodeTypeIndex) {
15
51
  return node;
16
52
  }
17
53
 
18
- var funcName = "visit" + node.type,
19
- func = this._implementation[funcName],
20
- visitArgs, newNode;
21
- if (func) {
22
- visitArgs = {visitDeeper: true};
23
- newNode = func.call(this._implementation, node, visitArgs);
24
- if (this._implementation.isReplacing) {
54
+ var visitFnCache = this._visitFnCache,
55
+ impl = this._implementation,
56
+ aryIndx = nodeTypeIndex << 1,
57
+ outAryIndex = aryIndx | 1,
58
+ func = visitFnCache[aryIndx],
59
+ funcOut = visitFnCache[outAryIndex],
60
+ visitArgs = _visitArgs,
61
+ fnName;
62
+
63
+ visitArgs.visitDeeper = true;
64
+
65
+ if (!func) {
66
+ fnName = "visit" + node.type;
67
+ func = impl[fnName] || _noop;
68
+ funcOut = impl[fnName + "Out"] || _noop;
69
+ visitFnCache[aryIndx] = func;
70
+ visitFnCache[outAryIndex] = funcOut;
71
+ }
72
+
73
+ if (func !== _noop) {
74
+ var newNode = func.call(impl, node, visitArgs);
75
+ if (impl.isReplacing) {
25
76
  node = newNode;
26
77
  }
27
78
  }
28
- if ((!visitArgs || visitArgs.visitDeeper) && node && node.accept) {
79
+
80
+ if (visitArgs.visitDeeper && node && node.accept) {
29
81
  node.accept(this);
30
82
  }
31
- funcName = funcName + "Out";
32
- if (this._implementation[funcName]) {
33
- this._implementation[funcName](node);
83
+
84
+ if (funcOut != _noop) {
85
+ funcOut.call(impl, node);
34
86
  }
87
+
35
88
  return node;
36
89
  },
37
- visitArray: function(nodes) {
38
- var i, newNodes = [];
39
- for(i = 0; i < nodes.length; i++) {
90
+ visitArray: function(nodes, nonReplacing) {
91
+ if (!nodes) {
92
+ return nodes;
93
+ }
94
+
95
+ var cnt = nodes.length, i;
96
+
97
+ // Non-replacing
98
+ if (nonReplacing || !this._implementation.isReplacing) {
99
+ for (i = 0; i < cnt; i++) {
100
+ this.visit(nodes[i]);
101
+ }
102
+ return nodes;
103
+ }
104
+
105
+ // Replacing
106
+ var out = [];
107
+ for (i = 0; i < cnt; i++) {
40
108
  var evald = this.visit(nodes[i]);
41
- if (evald instanceof Array) {
42
- newNodes = newNodes.concat(evald);
43
- } else {
44
- newNodes.push(evald);
109
+ if (!evald.splice) {
110
+ out.push(evald);
111
+ } else if (evald.length) {
112
+ this.flatten(evald, out);
45
113
  }
46
114
  }
47
- if (this._implementation.isReplacing) {
48
- return newNodes;
115
+ return out;
116
+ },
117
+ flatten: function(arr, out) {
118
+ if (!out) {
119
+ out = [];
49
120
  }
50
- return nodes;
121
+
122
+ var cnt, i, item,
123
+ nestedCnt, j, nestedItem;
124
+
125
+ for (i = 0, cnt = arr.length; i < cnt; i++) {
126
+ item = arr[i];
127
+ if (!item.splice) {
128
+ out.push(item);
129
+ continue;
130
+ }
131
+
132
+ for (j = 0, nestedCnt = item.length; j < nestedCnt; j++) {
133
+ nestedItem = item[j];
134
+ if (!nestedItem.splice) {
135
+ out.push(nestedItem);
136
+ } else if (nestedItem.length) {
137
+ this.flatten(nestedItem, out);
138
+ }
139
+ }
140
+ }
141
+
142
+ return out;
51
143
  }
52
144
  };
53
145