less 1.2.2 → 1.3.3

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 (197) hide show
  1. package/.npmignore +1 -0
  2. package/CHANGELOG.md +118 -0
  3. package/CONTRIBUTING.md +50 -0
  4. package/Makefile +14 -2
  5. package/benchmark/benchmark.less +11 -11
  6. package/benchmark/less-benchmark.js +1 -1
  7. package/bin/lessc +77 -21
  8. package/build/amd.js +6 -0
  9. package/build/ecma-5.js +120 -0
  10. package/build/header.js +7 -0
  11. package/build/require-rhino.js +7 -0
  12. package/build/require.js +7 -0
  13. package/lib/less/browser.js +192 -53
  14. package/lib/less/colors.js +1 -0
  15. package/lib/less/functions.js +159 -10
  16. package/lib/less/index.js +125 -56
  17. package/lib/less/lessc_helper.js +62 -0
  18. package/lib/less/parser.js +391 -154
  19. package/lib/less/rhino.js +84 -23
  20. package/lib/less/tree/anonymous.js +15 -1
  21. package/lib/less/tree/assignment.js +3 -1
  22. package/lib/less/tree/call.js +12 -6
  23. package/lib/less/tree/color.js +10 -0
  24. package/lib/less/tree/dimension.js +3 -1
  25. package/lib/less/tree/directive.js +10 -10
  26. package/lib/less/tree/element.js +8 -7
  27. package/lib/less/tree/import.js +17 -14
  28. package/lib/less/tree/media.js +121 -0
  29. package/lib/less/tree/mixin.js +133 -45
  30. package/lib/less/tree/operation.js +5 -0
  31. package/lib/less/tree/quoted.js +15 -1
  32. package/lib/less/tree/ratio.js +13 -0
  33. package/lib/less/tree/rule.js +7 -0
  34. package/lib/less/tree/ruleset.js +236 -37
  35. package/lib/less/tree/selector.js +21 -11
  36. package/lib/less/tree/unicode-descriptor.js +13 -0
  37. package/lib/less/tree/url.js +16 -14
  38. package/lib/less/tree/variable.js +13 -1
  39. package/lib/less/tree.js +28 -0
  40. package/package.json +13 -3
  41. package/test/browser/common.js +74 -0
  42. package/test/browser/css/relative-urls/urls.css +36 -0
  43. package/test/browser/css/rootpath/urls.css +36 -0
  44. package/test/browser/css/rootpath-relative/urls.css +36 -0
  45. package/test/browser/css/urls.css +36 -0
  46. package/test/browser/jasmine-html.js +681 -0
  47. package/test/browser/jasmine.css +82 -0
  48. package/test/browser/jasmine.js +2600 -0
  49. package/test/browser/less/imports/urls.less +4 -0
  50. package/test/browser/less/imports/urls2.less +4 -0
  51. package/test/browser/less/relative-urls/urls.less +33 -0
  52. package/test/browser/less/rootpath/urls.less +33 -0
  53. package/test/browser/less/rootpath-relative/urls.less +33 -0
  54. package/test/browser/less/urls.less +33 -0
  55. package/test/browser/phantom-runner.js +139 -0
  56. package/test/browser/runner-browser.js +3 -0
  57. package/test/browser/runner-main.js +15 -0
  58. package/test/browser/runner-relative-urls.js +4 -0
  59. package/test/browser/runner-rootpath-relative.js +5 -0
  60. package/test/browser/runner-rootpath.js +4 -0
  61. package/test/browser/template.htm +10 -0
  62. package/test/browser-test-prepare.js +29 -0
  63. package/test/css/charsets.css +1 -0
  64. package/test/css/colors.css +22 -0
  65. package/test/css/comments.css +7 -0
  66. package/test/css/css-3.css +57 -2
  67. package/test/css/css-escapes.css +4 -0
  68. package/test/css/css.css +11 -11
  69. package/test/css/debug/linenumbers-all.css +43 -0
  70. package/test/css/debug/linenumbers-comments.css +35 -0
  71. package/test/css/debug/linenumbers-mediaquery.css +35 -0
  72. package/test/css/functions.css +59 -2
  73. package/test/css/ie-filters.css +7 -3
  74. package/test/css/import-once.css +3 -0
  75. package/test/css/import.css +7 -9
  76. package/test/css/javascript.css +3 -2
  77. package/test/css/media.css +168 -0
  78. package/test/css/mixins-args.css +35 -4
  79. package/test/css/mixins-guards.css +13 -0
  80. package/test/css/mixins-important.css +21 -0
  81. package/test/css/mixins-named-args.css +27 -0
  82. package/test/css/mixins-pattern.css +4 -6
  83. package/test/css/mixins.css +50 -0
  84. package/test/css/scope.css +20 -0
  85. package/test/css/selectors.css +76 -0
  86. package/test/css/static-urls/urls.css +42 -0
  87. package/test/css/strings.css +2 -2
  88. package/test/css/urls.css +42 -0
  89. package/test/css/variables.css +0 -1
  90. package/test/css/whitespace.css +4 -0
  91. package/test/less/charsets.less +3 -0
  92. package/test/less/colors.less +27 -0
  93. package/test/less/comments.less +12 -0
  94. package/test/less/css-3.less +54 -6
  95. package/test/less/css-escapes.less +6 -1
  96. package/test/less/css.less +14 -12
  97. package/test/less/debug/import/test.less +25 -0
  98. package/test/less/debug/linenumbers.less +23 -0
  99. package/test/less/errors/bad-variable-declaration1.less +1 -0
  100. package/test/less/errors/bad-variable-declaration1.txt +2 -0
  101. package/test/less/errors/comment-in-selector.less +1 -0
  102. package/test/less/errors/comment-in-selector.txt +2 -0
  103. package/test/less/errors/import-missing.less +1 -0
  104. package/test/less/errors/import-missing.txt +3 -0
  105. package/test/less/errors/import-no-semi.less +1 -0
  106. package/test/less/errors/import-no-semi.txt +2 -0
  107. package/test/less/errors/import-subfolder1.less +1 -0
  108. package/test/less/errors/import-subfolder1.txt +3 -0
  109. package/test/less/errors/import-subfolder2.less +1 -0
  110. package/test/less/errors/import-subfolder2.txt +2 -0
  111. package/test/less/errors/imports/import-subfolder1.less +1 -0
  112. package/test/less/errors/imports/import-subfolder2.less +1 -0
  113. package/test/less/errors/imports/import-test.less +4 -0
  114. package/test/less/errors/imports/subfolder/mixin-not-defined.less +1 -0
  115. package/test/less/errors/imports/subfolder/parse-error-curly-bracket.less +1 -0
  116. package/test/less/errors/javascript-error.less +3 -0
  117. package/test/less/errors/javascript-error.txt +4 -0
  118. package/test/less/errors/mixed-mixin-definition-args-1.less +6 -0
  119. package/test/less/errors/mixed-mixin-definition-args-1.txt +4 -0
  120. package/test/less/errors/mixed-mixin-definition-args-2.less +6 -0
  121. package/test/less/errors/mixed-mixin-definition-args-2.txt +4 -0
  122. package/test/less/errors/mixin-not-defined.less +11 -0
  123. package/test/less/errors/mixin-not-defined.txt +3 -0
  124. package/test/less/errors/mixin-not-matched.less +6 -0
  125. package/test/less/errors/mixin-not-matched.txt +3 -0
  126. package/test/less/errors/mixin-not-matched2.less +6 -0
  127. package/test/less/errors/mixin-not-matched2.txt +3 -0
  128. package/test/less/errors/parse-error-curly-bracket.less +1 -0
  129. package/test/less/errors/parse-error-curly-bracket.txt +2 -0
  130. package/test/less/errors/parse-error-missing-bracket.less +2 -0
  131. package/test/less/errors/parse-error-missing-bracket.txt +2 -0
  132. package/test/less/errors/parse-error-with-import.less +13 -0
  133. package/test/less/errors/parse-error-with-import.txt +4 -0
  134. package/test/less/errors/property-ie5-hack.less +3 -0
  135. package/test/less/errors/property-ie5-hack.txt +4 -0
  136. package/test/less/errors/recursive-variable.less +1 -0
  137. package/test/less/errors/recursive-variable.txt +2 -0
  138. package/test/less/functions.less +64 -2
  139. package/test/less/ie-filters.less +7 -0
  140. package/test/less/import/deeper/import-once-test-a.less +1 -0
  141. package/test/less/import/import-and-relative-paths-test.less +6 -0
  142. package/test/less/import/import-charset-test.less +1 -0
  143. package/test/less/import/import-once-test-c.less +6 -0
  144. package/test/less/import/import-test-a.less +1 -0
  145. package/test/less/import/import-test-c.less +0 -1
  146. package/test/less/import/imports/font.less +8 -0
  147. package/test/less/import/imports/logo.less +5 -0
  148. package/test/less/import/urls.less +1 -0
  149. package/test/less/import-once.less +4 -0
  150. package/test/less/import.less +2 -1
  151. package/test/less/javascript.less +4 -2
  152. package/test/less/media.less +169 -1
  153. package/test/less/mixins-args.less +54 -11
  154. package/test/less/mixins-guards.less +30 -0
  155. package/test/less/mixins-important.less +4 -0
  156. package/test/less/mixins-named-args.less +36 -0
  157. package/test/less/mixins-pattern.less +3 -0
  158. package/test/less/mixins.less +47 -0
  159. package/test/less/scope.less +48 -1
  160. package/test/less/selectors.less +88 -0
  161. package/test/less/static-urls/urls.less +33 -0
  162. package/test/less/strings.less +1 -1
  163. package/test/less/urls.less +33 -0
  164. package/test/less/variables.less +0 -1
  165. package/test/less/whitespace.less +7 -0
  166. package/test/less-test.js +145 -36
  167. package/bench.css +0 -5943
  168. package/benchmark/b1.less +0 -3980
  169. package/dist/less-1.1.0.js +0 -2695
  170. package/dist/less-1.1.0.min.js +0 -16
  171. package/dist/less-1.1.1.js +0 -2710
  172. package/dist/less-1.1.1.min.js +0 -16
  173. package/dist/less-1.1.2.js +0 -2712
  174. package/dist/less-1.1.2.min.js +0 -16
  175. package/dist/less-1.1.3.js +0 -2721
  176. package/dist/less-1.1.3.min.js +0 -16
  177. package/dist/less-1.1.4.js +0 -2769
  178. package/dist/less-1.1.4.min.js +0 -16
  179. package/dist/less-1.1.5.js +0 -2805
  180. package/dist/less-1.1.5.min.js +0 -9
  181. package/dist/less-1.1.6.js +0 -3004
  182. package/dist/less-1.1.6.min.js +0 -9
  183. package/dist/less-1.2.0.js +0 -3293
  184. package/dist/less-1.2.0.min.js +0 -9
  185. package/dist/less-1.2.1.js +0 -3318
  186. package/dist/less-1.2.1.min.js +0 -9
  187. package/dist/less-1.2.2.js +0 -3337
  188. package/dist/less-1.2.2.min.js +0 -9
  189. package/dist/less-rhino-1.1.3.js +0 -2460
  190. package/dist/less-rhino-1.1.5.js +0 -2481
  191. package/foo.less +0 -2
  192. package/lib/less/cssmin.js +0 -355
  193. package/test/html/index.html +0 -10
  194. package/test/html/less.js +0 -3333
  195. package/test/html/lib.less +0 -2
  196. package/test/html/styles.less +0 -8
  197. package/x.less +0 -4
package/lib/less/index.js CHANGED
@@ -1,9 +1,11 @@
1
1
  var path = require('path'),
2
2
  sys = require('util'),
3
+ url = require('url'),
4
+ http = require('http'),
3
5
  fs = require('fs');
4
6
 
5
7
  var less = {
6
- version: [1, 2, 2],
8
+ version: [1, 3, 3],
7
9
  Parser: require('./parser').Parser,
8
10
  importer: require('./parser').importer,
9
11
  tree: require('./tree'),
@@ -33,20 +35,19 @@ var less = {
33
35
  return ee;
34
36
  }
35
37
  },
36
- writeError: function (ctx, options) {
38
+ formatError: function(ctx, options) {
37
39
  options = options || {};
38
40
 
39
41
  var message = "";
40
42
  var extract = ctx.extract;
41
43
  var error = [];
42
- var stylize = options.color ? less.stylize : function (str) { return str };
43
-
44
- if (options.silent) { return }
44
+ var stylize = options.color ? require('./lessc_helper').stylize : function (str) { return str };
45
45
 
46
- if (ctx.stack) { return sys.error(stylize(ctx.stack, 'red')) }
46
+ // only output a stack if it isn't a less error
47
+ if (ctx.stack && !ctx.type) { return stylize(ctx.stack, 'red') }
47
48
 
48
- if (!ctx.hasOwnProperty('index')) {
49
- return sys.error(ctx.stack || ctx.message);
49
+ if (!ctx.hasOwnProperty('index') || !extract) {
50
+ return ctx.stack || ctx.message;
50
51
  }
51
52
 
52
53
  if (typeof(extract[0]) === 'string') {
@@ -62,18 +63,25 @@ var less = {
62
63
  if (typeof(extract[2]) === 'string') {
63
64
  error.push(stylize((ctx.line + 1) + ' ' + extract[2], 'grey'));
64
65
  }
65
- error = error.join('\n') + '\033[0m\n';
66
+ error = error.join('\n') + stylize('', 'reset') + '\n';
66
67
 
67
68
  message += stylize(ctx.type + 'Error: ' + ctx.message, 'red');
68
69
  ctx.filename && (message += stylize(' in ', 'red') + ctx.filename +
69
70
  stylize(':' + ctx.line + ':' + ctx.column, 'grey'));
70
71
 
71
- sys.error(message, error);
72
+ message += '\n' + error;
72
73
 
73
74
  if (ctx.callLine) {
74
- sys.error(stylize('from ', 'red') + (ctx.filename || ''));
75
- sys.error(stylize(ctx.callLine, 'grey') + ' ' + ctx.callExtract);
75
+ message += stylize('from ', 'red') + (ctx.filename || '') + '/n';
76
+ message += stylize(ctx.callLine, 'grey') + ' ' + ctx.callExtract + '/n';
76
77
  }
78
+
79
+ return message;
80
+ },
81
+ writeError: function (ctx, options) {
82
+ options = options || {};
83
+ if (options.silent) { return }
84
+ sys.error(less.formatError(ctx, options));
77
85
  }
78
86
  };
79
87
 
@@ -82,44 +90,122 @@ var less = {
82
90
  'selector', 'quoted', 'expression', 'rule',
83
91
  'call', 'url', 'alpha', 'import',
84
92
  'mixin', 'comment', 'anonymous', 'value',
85
- 'javascript', 'assignment', 'condition', 'paren'
93
+ 'javascript', 'assignment', 'condition', 'paren',
94
+ 'media', 'ratio', 'unicode-descriptor'
86
95
  ].forEach(function (n) {
87
96
  require('./tree/' + n);
88
97
  });
89
98
 
99
+
100
+ var isUrlRe = /^(?:https?:)?\/\//i;
101
+
90
102
  less.Parser.importer = function (file, paths, callback, env) {
91
- var pathname;
92
-
93
- // TODO: Undo this at some point,
94
- // or use different approach.
95
- paths.unshift('.');
96
-
97
- for (var i = 0; i < paths.length; i++) {
98
- try {
99
- pathname = path.join(paths[i], file);
100
- fs.statSync(pathname);
101
- break;
102
- } catch (e) {
103
- pathname = null;
103
+ var pathname, dirname, data;
104
+
105
+ function parseFile(e, data) {
106
+ if (e) return callback(e);
107
+
108
+ var rootpath = env.rootpath,
109
+ j = file.lastIndexOf('/');
110
+
111
+ // Pass on an updated rootpath if path of imported file is relative and file
112
+ // is in a (sub|sup) directory
113
+ //
114
+ // Examples:
115
+ // - If path of imported file is 'module/nav/nav.less' and rootpath is 'less/',
116
+ // then rootpath should become 'less/module/nav/'
117
+ // - If path of imported file is '../mixins.less' and rootpath is 'less/',
118
+ // then rootpath should become 'less/../'
119
+ if(env.relativeUrls && !/^(?:[a-z-]+:|\/)/.test(file) && j != -1) {
120
+ rootpath = rootpath + file.slice(0, j+1); // append (sub|sup) directory path of imported file
104
121
  }
105
- }
106
-
107
- if (pathname) {
108
- fs.readFile(pathname, 'utf-8', function(e, data) {
109
- if (e) return callback(e);
110
122
 
111
- new(less.Parser)({
112
- paths: [path.dirname(pathname)].concat(paths),
113
- filename: pathname
114
- }).parse(data, function (e, root) {
115
- callback(e, root, data);
123
+ env.contents[pathname] = data; // Updating top importing parser content cache.
124
+ new(less.Parser)({
125
+ paths: [dirname].concat(paths),
126
+ filename: pathname,
127
+ contents: env.contents,
128
+ files: env.files,
129
+ syncImport: env.syncImport,
130
+ relativeUrls: env.relativeUrls,
131
+ rootpath: rootpath,
132
+ dumpLineNumbers: env.dumpLineNumbers
133
+ }).parse(data, function (e, root) {
134
+ callback(e, root, pathname);
135
+ });
136
+ };
137
+
138
+ var isUrl = isUrlRe.test( file );
139
+ if (isUrl || isUrlRe.test(paths[0])) {
140
+
141
+ var urlStr = isUrl ? file : url.resolve(paths[0], file),
142
+ urlObj = url.parse(urlStr),
143
+ req = {
144
+ host: urlObj.hostname,
145
+ port: urlObj.port || 80,
146
+ path: urlObj.pathname + (urlObj.search||'')
147
+ };
148
+
149
+ http.get(req, function (res) {
150
+ var body = '';
151
+ res.on('data', function (chunk) {
152
+ body += chunk.toString();
153
+ });
154
+ res.on('end', function () {
155
+ if (res.statusCode === 404) {
156
+ callback({ type: 'File', message: "resource '" + urlStr + "' was not found\n" });
157
+ }
158
+ if (!body) {
159
+ sys.error( 'Warning: Empty body (HTTP '+ res.statusCode + ') returned by "' + urlStr +'"' );
160
+ }
161
+ pathname = urlStr;
162
+ dirname = urlObj.protocol +'//'+ urlObj.host + urlObj.pathname.replace(/[^\/]*$/, '');
163
+ parseFile(null, body);
116
164
  });
165
+ }).on('error', function (err) {
166
+ callback({ type: 'File', message: "resource '" + urlStr + "' gave this Error:\n "+ err +"\n" });
117
167
  });
168
+
118
169
  } else {
119
- if (typeof(env.errback) === "function") {
120
- env.errback(file, paths, callback);
170
+
171
+ // TODO: Undo this at some point,
172
+ // or use different approach.
173
+ var paths = [].concat(paths);
174
+ paths.push('.');
175
+
176
+ for (var i = 0; i < paths.length; i++) {
177
+ try {
178
+ pathname = path.join(paths[i], file);
179
+ fs.statSync(pathname);
180
+ break;
181
+ } catch (e) {
182
+ pathname = null;
183
+ }
184
+ }
185
+
186
+ paths = paths.slice(0, paths.length - 1);
187
+
188
+ if (!pathname) {
189
+
190
+ if (typeof(env.errback) === "function") {
191
+ env.errback(file, paths, callback);
192
+ } else {
193
+ callback({ type: 'File', message: "'" + file + "' wasn't found.\n" });
194
+ }
195
+ return;
196
+ }
197
+
198
+ dirname = path.dirname(pathname);
199
+
200
+ if (env.syncImport) {
201
+ try {
202
+ data = fs.readFileSync(pathname, 'utf-8');
203
+ parseFile(null, data);
204
+ } catch (e) {
205
+ parseFile(e);
206
+ }
121
207
  } else {
122
- callback({ type: 'File', message: "'" + file + "' wasn't found.\n" });
208
+ fs.readFile(pathname, 'utf-8', parseFile);
123
209
  }
124
210
  }
125
211
  }
@@ -128,20 +214,3 @@ require('./functions');
128
214
  require('./colors');
129
215
 
130
216
  for (var k in less) { exports[k] = less[k] }
131
-
132
- // Stylize a string
133
- function stylize(str, style) {
134
- var styles = {
135
- 'bold' : [1, 22],
136
- 'inverse' : [7, 27],
137
- 'underline' : [4, 24],
138
- 'yellow' : [33, 39],
139
- 'green' : [32, 39],
140
- 'red' : [31, 39],
141
- 'grey' : [90, 39]
142
- };
143
- return '\033[' + styles[style][0] + 'm' + str +
144
- '\033[' + styles[style][1] + 'm';
145
- }
146
- less.stylize = stylize;
147
-
@@ -0,0 +1,62 @@
1
+ // lessc_helper.js
2
+ //
3
+ // helper functions for lessc
4
+ sys = require('util');
5
+
6
+ var lessc_helper = {
7
+
8
+ //Stylize a string
9
+ stylize : function(str, style) {
10
+ var styles = {
11
+ 'reset' : [0, 0],
12
+ 'bold' : [1, 22],
13
+ 'inverse' : [7, 27],
14
+ 'underline' : [4, 24],
15
+ 'yellow' : [33, 39],
16
+ 'green' : [32, 39],
17
+ 'red' : [31, 39],
18
+ 'grey' : [90, 39]
19
+ };
20
+ return '\033[' + styles[style][0] + 'm' + str +
21
+ '\033[' + styles[style][1] + 'm';
22
+ },
23
+
24
+ //Print command line options
25
+ printUsage: function() {
26
+ sys.puts("usage: lessc [option option=parameter ...] <source> [destination]");
27
+ sys.puts("");
28
+ sys.puts("If source is set to `-' (dash or hyphen-minus), input is read from stdin.");
29
+ sys.puts("");
30
+ sys.puts("options:");
31
+ sys.puts(" -h, --help Print help (this message) and exit.");
32
+ sys.puts(" --include-path Set include paths. Separated by `:'. Use `;' on Windows.");
33
+ sys.puts(" --no-color Disable colorized output.");
34
+ sys.puts(" -s, --silent Suppress output of error messages.");
35
+ sys.puts(" --strict-imports Force evaluation of imports.");
36
+ sys.puts(" --verbose Be verbose.");
37
+ sys.puts(" -v, --version Print version number and exit.");
38
+ sys.puts(" -x, --compress Compress output by removing some whitespaces.");
39
+ sys.puts(" --yui-compress Compress output using ycssmin");
40
+ sys.puts(" -O0, -O1, -O2 Set the parser's optimization level. The lower");
41
+ sys.puts(" the number, the less nodes it will create in the");
42
+ sys.puts(" tree. This could matter for debugging, or if you");
43
+ sys.puts(" want to access the individual nodes in the tree.");
44
+ sys.puts(" --line-numbers=TYPE Outputs filename and line numbers.");
45
+ sys.puts(" TYPE can be either 'comments', which will output");
46
+ sys.puts(" the debug info within comments, 'mediaquery'");
47
+ sys.puts(" that will output the information within a fake");
48
+ sys.puts(" media query which is compatible with the SASS");
49
+ sys.puts(" format, and 'all' which will do both.");
50
+ sys.puts(" -rp, --rootpath Set rootpath for url rewriting in relative imports and urls.");
51
+ sys.puts(" Works with or withour the relative-urls option.");
52
+ sys.puts(" -ru, --relative-urls re-write relative urls to the base less file.");
53
+ sys.puts("");
54
+ sys.puts("Report bugs to: http://github.com/cloudhead/less.js/issues");
55
+ sys.puts("Home page: <http://lesscss.org/>");
56
+ }
57
+
58
+
59
+ }
60
+
61
+ // Exports helper functions
62
+ for (var h in lessc_helper) { exports[h] = lessc_helper[h] }