less 3.0.0-pre.2 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (205) hide show
  1. package/.eslintrc.json +88 -0
  2. package/.github/stale.yml +17 -0
  3. package/.project +17 -0
  4. package/.settings/org.eclipse.buildship.core.prefs +2 -0
  5. package/.travis.yml +22 -3
  6. package/.vscode/launch.json +14 -0
  7. package/CHANGELOG.md +27 -0
  8. package/Gruntfile.js +191 -86
  9. package/README.md +5 -7
  10. package/appveyor.yml +9 -10
  11. package/bin/lessc +37 -50
  12. package/dist/less.js +1357 -1269
  13. package/dist/less.min.js +7 -7
  14. package/lib/less/contexts.js +20 -16
  15. package/lib/less/default-options.js +65 -0
  16. package/lib/less/environment/abstract-file-manager.js +13 -14
  17. package/lib/less/environment/abstract-plugin-loader.js +45 -36
  18. package/lib/less/environment/environment.js +5 -0
  19. package/lib/less/functions/boolean.js +15 -0
  20. package/lib/less/functions/color.js +54 -24
  21. package/lib/less/functions/data-uri.js +5 -2
  22. package/lib/less/functions/function-registry.js +1 -1
  23. package/lib/less/functions/index.js +2 -1
  24. package/lib/less/functions/number.js +2 -2
  25. package/lib/less/functions/string.js +2 -2
  26. package/lib/less/functions/svg.js +4 -4
  27. package/lib/less/import-manager.js +41 -29
  28. package/lib/less/index.js +28 -3
  29. package/lib/less/less-error.js +112 -13
  30. package/lib/less/parse.js +18 -15
  31. package/lib/less/parser/parser-input.js +4 -4
  32. package/lib/less/parser/parser.js +208 -114
  33. package/lib/less/plugin-manager.js +8 -33
  34. package/lib/less/render.js +6 -2
  35. package/lib/less/source-map-builder.js +3 -0
  36. package/lib/less/source-map-output.js +13 -8
  37. package/lib/less/transform-tree.js +2 -2
  38. package/lib/less/tree/anonymous.js +4 -1
  39. package/lib/less/tree/atrule.js +7 -6
  40. package/lib/less/tree/call.js +25 -3
  41. package/lib/less/tree/color.js +2 -2
  42. package/lib/less/tree/debug-info.js +1 -1
  43. package/lib/less/tree/declaration.js +6 -5
  44. package/lib/less/tree/dimension.js +4 -1
  45. package/lib/less/tree/extend.js +2 -2
  46. package/lib/less/tree/import.js +17 -9
  47. package/lib/less/tree/index.js +3 -7
  48. package/lib/less/tree/js-eval-node.js +1 -1
  49. package/lib/less/tree/media.js +3 -14
  50. package/lib/less/tree/mixin-definition.js +3 -3
  51. package/lib/less/tree/node.js +9 -6
  52. package/lib/less/tree/operation.js +1 -1
  53. package/lib/less/tree/property.js +70 -0
  54. package/lib/less/tree/quoted.js +11 -10
  55. package/lib/less/tree/ruleset.js +115 -71
  56. package/lib/less/tree/selector.js +38 -23
  57. package/lib/less/tree/unit.js +1 -1
  58. package/lib/less/tree/value.js +6 -1
  59. package/lib/less/tree/{ruleset-call.js → variable-call.js} +5 -5
  60. package/lib/less/tree/variable.js +6 -6
  61. package/lib/less/utils.js +40 -0
  62. package/lib/less/visitors/extend-visitor.js +14 -14
  63. package/lib/less/visitors/import-visitor.js +2 -2
  64. package/lib/less/visitors/join-selector-visitor.js +1 -1
  65. package/lib/less/visitors/to-css-visitor.js +51 -84
  66. package/lib/less/visitors/visitor.js +15 -15
  67. package/lib/less-browser/bootstrap.js +21 -5
  68. package/lib/less-browser/cache.js +2 -2
  69. package/lib/less-browser/error-reporting.js +5 -5
  70. package/lib/less-browser/file-manager.js +27 -35
  71. package/lib/less-browser/index.js +12 -17
  72. package/lib/less-browser/plugin-loader.js +8 -45
  73. package/lib/less-browser/utils.js +1 -1
  74. package/lib/less-node/file-manager.js +99 -69
  75. package/lib/less-node/fs.js +1 -1
  76. package/lib/less-node/image-size.js +2 -2
  77. package/lib/less-node/index.js +7 -57
  78. package/lib/less-node/lessc-helper.js +38 -38
  79. package/lib/less-node/plugin-loader.js +18 -79
  80. package/lib/less-node/url-file-manager.js +1 -1
  81. package/lib/less-rhino/index.js +29 -44
  82. package/package.json +16 -9
  83. package/test/browser/common.js +54 -18
  84. package/test/browser/css/plugin/plugin.css +3 -0
  85. package/test/browser/jasmine-jsreporter.js +4 -4
  86. package/test/browser/less/plugin/plugin.js +7 -0
  87. package/test/browser/less/plugin/plugin.less +4 -0
  88. package/test/browser/less.js +11685 -13
  89. package/test/browser/runner-browser-options.js +6 -1
  90. package/test/browser/runner-filemanagerPlugin-options.js +3 -2
  91. package/test/browser/runner-legacy-options.js +2 -1
  92. package/test/browser/runner-main-options.js +0 -1
  93. package/test/browser/runner-modify-vars-spec.js +2 -2
  94. package/test/browser/test-runner-template.tmpl +38 -14
  95. package/test/copy-bom.js +1 -1
  96. package/test/css/calc.css +5 -0
  97. package/test/css/comments2.css +1 -1
  98. package/test/css/compression/compression.css +1 -1
  99. package/test/css/css-grid.css +11 -0
  100. package/test/css/debug/linenumbers-all.css +0 -1
  101. package/test/css/debug/linenumbers-comments.css +0 -1
  102. package/test/css/debug/linenumbers-mediaquery.css +0 -1
  103. package/test/css/functions.css +16 -3
  104. package/test/css/import-module.css +9 -0
  105. package/test/css/import.css +0 -1
  106. package/test/css/legacy/legacy.css +1 -1
  107. package/test/css/merge.css +5 -4
  108. package/test/css/plugin-module.css +1 -0
  109. package/test/css/plugin.css +20 -0
  110. package/test/css/property-accessors.css +49 -0
  111. package/test/css/{css.css → strict-math/css.css} +0 -0
  112. package/test/css/{mixins-args.css → strict-math/mixins-args.css} +0 -0
  113. package/test/css/{parens.css → strict-math/parens.css} +0 -0
  114. package/test/import-module/one/1.less +3 -0
  115. package/test/import-module/one/two/2.less +3 -0
  116. package/test/import-module/one/two/three/3.less +3 -0
  117. package/test/import-module/package.json +11 -0
  118. package/test/index.js +55 -49
  119. package/test/less/calc.less +7 -0
  120. package/test/less/css-grid.less +15 -0
  121. package/test/less/detached-rulesets.less +2 -2
  122. package/test/less/errors/color-invalid-hex-code.less +1 -0
  123. package/test/less/errors/color-invalid-hex-code.txt +1 -1
  124. package/test/less/errors/color-invalid-hex-code2.less +1 -0
  125. package/test/less/errors/color-invalid-hex-code2.txt +1 -1
  126. package/test/less/errors/import-missing.txt +1 -1
  127. package/test/less/errors/plugin/plugin-error-2.js +5 -0
  128. package/test/less/errors/plugin/plugin-error-3.js +5 -0
  129. package/test/less/errors/plugin/plugin-error.js +1 -0
  130. package/test/less/errors/plugin-1.less +1 -0
  131. package/test/less/errors/plugin-1.txt +2 -0
  132. package/test/less/errors/plugin-2.less +1 -0
  133. package/test/less/errors/plugin-2.txt +5 -0
  134. package/test/less/errors/plugin-3.less +1 -0
  135. package/test/less/errors/plugin-3.txt +5 -0
  136. package/test/less/functions.less +18 -0
  137. package/test/less/import-module.less +3 -0
  138. package/test/less/import.less +0 -2
  139. package/test/less/legacy/legacy.less +1 -1
  140. package/test/less/media.less +2 -2
  141. package/test/less/merge.less +6 -3
  142. package/test/less/plugin/plugin-collection.js +9 -0
  143. package/test/less/plugin/plugin-local.js +2 -2
  144. package/test/less/plugin/plugin-scope1.js +3 -0
  145. package/test/less/plugin/plugin-scope2.js +3 -0
  146. package/test/less/plugin/plugin-simple.js +7 -0
  147. package/test/less/plugin/plugin-tree-nodes.js +33 -31
  148. package/test/less/plugin-module.less +7 -0
  149. package/test/less/plugin.less +33 -3
  150. package/test/less/property-accessors.less +67 -0
  151. package/test/less/root-registry/file.less +1 -0
  152. package/test/less/root-registry/root.less +3 -0
  153. package/test/less/{css.less → strict-math/css.less} +0 -0
  154. package/test/less/{mixins-args.less → strict-math/mixins-args.less} +0 -0
  155. package/test/less/{parens.less → strict-math/parens.less} +0 -0
  156. package/test/less-bom/calc.less +7 -0
  157. package/test/less-bom/css-grid.less +15 -0
  158. package/test/less-bom/detached-rulesets.less +2 -2
  159. package/test/less-bom/errors/color-invalid-hex-code.less +1 -0
  160. package/test/less-bom/errors/color-invalid-hex-code.txt +1 -1
  161. package/test/less-bom/errors/color-invalid-hex-code2.less +1 -0
  162. package/test/less-bom/errors/color-invalid-hex-code2.txt +1 -1
  163. package/test/less-bom/errors/import-missing.txt +1 -1
  164. package/test/less-bom/errors/plugin/plugin-error-2.js +5 -0
  165. package/test/less-bom/errors/plugin/plugin-error-3.js +5 -0
  166. package/test/less-bom/errors/plugin/plugin-error.js +1 -0
  167. package/test/less-bom/errors/plugin-1.less +1 -0
  168. package/test/less-bom/errors/plugin-1.txt +2 -0
  169. package/test/less-bom/errors/plugin-2.less +1 -0
  170. package/test/less-bom/errors/plugin-2.txt +5 -0
  171. package/test/less-bom/errors/plugin-3.less +1 -0
  172. package/test/less-bom/errors/plugin-3.txt +5 -0
  173. package/test/less-bom/functions.less +18 -0
  174. package/test/less-bom/import-module.less +3 -0
  175. package/test/less-bom/import.less +0 -2
  176. package/test/less-bom/legacy/legacy.less +1 -1
  177. package/test/less-bom/media.less +2 -2
  178. package/test/less-bom/merge.less +6 -3
  179. package/test/less-bom/plugin/plugin-collection.js +9 -0
  180. package/test/less-bom/plugin/plugin-local.js +2 -2
  181. package/test/less-bom/plugin/plugin-scope1.js +3 -0
  182. package/test/less-bom/plugin/plugin-scope2.js +3 -0
  183. package/test/less-bom/plugin/plugin-simple.js +7 -0
  184. package/test/less-bom/plugin/plugin-tree-nodes.js +33 -31
  185. package/test/less-bom/plugin-module.less +7 -0
  186. package/test/less-bom/plugin.less +33 -3
  187. package/test/less-bom/property-accessors.less +67 -0
  188. package/test/less-bom/root-registry/file.less +1 -0
  189. package/test/less-bom/root-registry/root.less +3 -0
  190. package/test/less-bom/{css.less → strict-math/css.less} +0 -0
  191. package/test/less-bom/{mixins-args.less → strict-math/mixins-args.less} +0 -0
  192. package/test/less-bom/{parens.less → strict-math/parens.less} +0 -0
  193. package/test/less-test.js +75 -17
  194. package/test/modify-vars.js +1 -1
  195. package/test/plugins/visitor/index.js +1 -1
  196. package/.jscsrc +0 -73
  197. package/.jshintrc +0 -11
  198. package/lib/less/tree/alpha.js +0 -28
  199. package/lib/less/tree/directive.js +0 -12
  200. package/lib/less/tree/rule.js +0 -12
  201. package/test/less/errors/functions-2-alpha.less +0 -2
  202. package/test/less/errors/functions-2-alpha.txt +0 -3
  203. package/test/less-bom/errors/functions-2-alpha.less +0 -2
  204. package/test/less-bom/errors/functions-2-alpha.txt +0 -3
  205. package/test/sourcemaps/maps/import-map.map +0 -1
@@ -1,6 +1,8 @@
1
1
  var contexts = require("./contexts"),
2
2
  Parser = require('./parser/parser'),
3
- LessError = require('./less-error');
3
+ LessError = require('./less-error'),
4
+ utils = require('./utils'),
5
+ PromiseConstructor = typeof Promise === 'undefined' ? require('promise') : Promise;
4
6
 
5
7
  module.exports = function(environment) {
6
8
 
@@ -26,6 +28,7 @@ module.exports = function(environment) {
26
28
  this.queue = []; // Files which haven't been imported yet
27
29
  this.files = {}; // Holds the imported parse trees.
28
30
  };
31
+
29
32
  /**
30
33
  * Add an import to be imported
31
34
  * @param path - the raw path
@@ -48,7 +51,9 @@ module.exports = function(environment) {
48
51
  callback(null, {rules:[]}, false, null);
49
52
  }
50
53
  else {
51
- importManager.files[fullPath] = root;
54
+ if (!importManager.files[fullPath]) {
55
+ importManager.files[fullPath] = { root: root, options: importOptions };
56
+ }
52
57
  if (e && !importManager.error) { importManager.error = e; }
53
58
  callback(e, root, importedEqualsRoot, fullPath);
54
59
  }
@@ -68,10 +73,6 @@ module.exports = function(environment) {
68
73
  return;
69
74
  }
70
75
 
71
- if (tryAppendExtension) {
72
- path = importOptions.isPlugin ? path : fileManager.tryAppendExtension(path, ".less");
73
- }
74
-
75
76
  var loadFileCallback = function(loadedFile) {
76
77
  var plugin,
77
78
  resolvedFilename = loadedFile.filename,
@@ -107,7 +108,7 @@ module.exports = function(environment) {
107
108
  }
108
109
 
109
110
  if (importOptions.isPlugin) {
110
- plugin = pluginLoader.evalPlugin(contents, newEnv, importOptions.pluginArgs, newFileInfo);
111
+ plugin = pluginLoader.evalPlugin(contents, newEnv, importManager, importOptions.pluginArgs, newFileInfo);
111
112
  if (plugin instanceof LessError) {
112
113
  fileParsedFunc(plugin, null, resolvedFilename);
113
114
  }
@@ -117,34 +118,45 @@ module.exports = function(environment) {
117
118
  } else if (importOptions.inline) {
118
119
  fileParsedFunc(null, contents, resolvedFilename);
119
120
  } else {
120
- new Parser(newEnv, importManager, newFileInfo).parse(contents, function (e, root) {
121
- fileParsedFunc(e, root, resolvedFilename);
122
- });
123
- }
124
- };
125
- var promise;
126
- var done = function(err, loadedFile) {
127
- if (err) {
128
- fileParsedFunc(err);
129
- } else {
130
- loadFileCallback(loadedFile);
121
+
122
+ // import (multiple) parse trees apparently get altered and can't be cached.
123
+ // TODO: investigate why this is
124
+ if (importManager.files[resolvedFilename]
125
+ && !importManager.files[resolvedFilename].options.multiple
126
+ && !importOptions.multiple) {
127
+
128
+ fileParsedFunc(null, importManager.files[resolvedFilename].root, resolvedFilename);
129
+ }
130
+ else {
131
+ new Parser(newEnv, importManager, newFileInfo).parse(contents, function (e, root) {
132
+ fileParsedFunc(e, root, resolvedFilename);
133
+ });
134
+ }
131
135
  }
132
136
  };
137
+ var promise, context = utils.clone(this.context);
138
+
139
+ if (tryAppendExtension) {
140
+ context.ext = importOptions.isPlugin ? ".js" : ".less";
141
+ }
142
+
133
143
  if (importOptions.isPlugin) {
134
- try {
135
- pluginLoader.tryLoadPlugin(path, currentFileInfo.currentDirectory, done);
136
- }
137
- catch(e) {
138
- callback(e);
139
- }
144
+ promise = pluginLoader.loadPlugin(path, currentFileInfo.currentDirectory, context, environment, fileManager);
140
145
  }
141
146
  else {
142
- promise = fileManager.loadFile(path, currentFileInfo.currentDirectory, this.context, environment, done);
143
- if (promise) {
144
- promise.then(loadFileCallback, fileParsedFunc);
145
- }
147
+ promise = fileManager.loadFile(path, currentFileInfo.currentDirectory, context, environment,
148
+ function(err, loadedFile) {
149
+ if (err) {
150
+ fileParsedFunc(err);
151
+ } else {
152
+ loadFileCallback(loadedFile);
153
+ }
154
+ });
146
155
  }
147
-
156
+ if (promise) {
157
+ promise.then(loadFileCallback, fileParsedFunc);
158
+ }
159
+
148
160
  };
149
161
  return ImportManager;
150
162
  };
package/lib/less/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  module.exports = function(environment, fileManagers) {
2
2
  var SourceMapOutput, SourceMapBuilder, ParseTree, ImportManager, Environment;
3
3
 
4
- var less = {
5
- version: [3, 0, 0],
4
+ var initial = {
5
+ version: [3, 0, 1],
6
6
  data: require('./data'),
7
7
  tree: require('./tree'),
8
8
  Environment: (Environment = require("./environment/environment")),
@@ -26,5 +26,30 @@ module.exports = function(environment, fileManagers) {
26
26
  logger: require('./logger')
27
27
  };
28
28
 
29
- return less;
29
+ // Create a public API
30
+
31
+ var ctor = function(t) {
32
+ return function() {
33
+ var obj = Object.create(t.prototype);
34
+ t.apply(obj, Array.prototype.slice.call(arguments, 0));
35
+ return obj;
36
+ };
37
+ };
38
+ var t, api = Object.create(initial);
39
+ for (var n in initial.tree) {
40
+ /* eslint guard-for-in: 0 */
41
+ t = initial.tree[n];
42
+ if (typeof t === "function") {
43
+ api[n.toLowerCase()] = ctor(t);
44
+ }
45
+ else {
46
+ api[n] = Object.create(null);
47
+ for (var o in t) {
48
+ /* eslint guard-for-in: 0 */
49
+ api[n][o.toLowerCase()] = ctor(t[o]);
50
+ }
51
+ }
52
+ }
53
+
54
+ return api;
30
55
  };
@@ -1,34 +1,72 @@
1
- var utils = require("./utils");
2
-
3
- var LessError = module.exports = function LessError(e, importManager, currentFilename) {
4
-
1
+ var utils = require('./utils');
2
+ /**
3
+ * This is a centralized class of any error that could be thrown internally (mostly by the parser).
4
+ * Besides standard .message it keeps some additional data like a path to the file where the error
5
+ * occurred along with line and column numbers.
6
+ *
7
+ * @class
8
+ * @extends Error
9
+ * @type {module.LessError}
10
+ *
11
+ * @prop {string} type
12
+ * @prop {string} filename
13
+ * @prop {number} index
14
+ * @prop {number} line
15
+ * @prop {number} column
16
+ * @prop {number} callLine
17
+ * @prop {number} callExtract
18
+ * @prop {string[]} extract
19
+ *
20
+ * @param {Object} e - An error object to wrap around or just a descriptive object
21
+ * @param {Object} fileContentMap - An object with file contents in 'contents' property (like importManager) @todo - move to fileManager?
22
+ * @param {string} [currentFilename]
23
+ */
24
+ var LessError = module.exports = function LessError(e, fileContentMap, currentFilename) {
5
25
  Error.call(this);
6
26
 
7
27
  var filename = e.filename || currentFilename;
8
28
 
9
- if (importManager && filename) {
10
- var input = importManager.contents[filename],
29
+ this.message = e.message;
30
+ this.stack = e.stack;
31
+
32
+ if (fileContentMap && filename) {
33
+ var input = fileContentMap.contents[filename],
11
34
  loc = utils.getLocation(e.index, input),
12
35
  line = loc.line,
13
36
  col = loc.column,
14
37
  callLine = e.call && utils.getLocation(e.call, input).line,
15
- lines = input.split('\n');
38
+ lines = input ? input.split('\n') : '';
16
39
 
17
40
  this.type = e.type || 'Syntax';
18
41
  this.filename = filename;
19
42
  this.index = e.index;
20
43
  this.line = typeof line === 'number' ? line + 1 : null;
44
+ this.column = col;
45
+
46
+ if (!this.line && this.stack) {
47
+ var found = this.stack.match(/(<anonymous>|Function):(\d+):(\d+)/);
48
+
49
+ if (found) {
50
+ if (found[2]) {
51
+ this.line = parseInt(found[2]) - 2;
52
+ }
53
+ if (found[3]) {
54
+ this.column = parseInt(found[3]);
55
+ }
56
+ }
57
+ }
58
+
21
59
  this.callLine = callLine + 1;
22
60
  this.callExtract = lines[callLine];
23
- this.column = col;
61
+
24
62
  this.extract = [
25
- lines[line - 1],
26
- lines[line],
27
- lines[line + 1]
63
+ lines[this.line - 2],
64
+ lines[this.line - 1],
65
+ lines[this.line]
28
66
  ];
67
+
29
68
  }
30
- this.message = e.message;
31
- this.stack = e.stack;
69
+
32
70
  };
33
71
 
34
72
  if (typeof Object.create === 'undefined') {
@@ -40,3 +78,64 @@ if (typeof Object.create === 'undefined') {
40
78
  }
41
79
 
42
80
  LessError.prototype.constructor = LessError;
81
+
82
+ /**
83
+ * An overridden version of the default Object.prototype.toString
84
+ * which uses additional information to create a helpful message.
85
+ *
86
+ * @param {Object} options
87
+ * @returns {string}
88
+ */
89
+ LessError.prototype.toString = function(options) {
90
+ options = options || {};
91
+
92
+ var message = '';
93
+ var extract = this.extract || [];
94
+ var error = [];
95
+ var stylize = function (str) { return str; };
96
+ if (options.stylize) {
97
+ var type = typeof options.stylize;
98
+ if (type !== 'function') {
99
+ throw Error('options.stylize should be a function, got a ' + type + '!');
100
+ }
101
+ stylize = options.stylize;
102
+ }
103
+
104
+ if (this.line !== null) {
105
+ if (typeof extract[0] === 'string') {
106
+ error.push(stylize((this.line - 1) + ' ' + extract[0], 'grey'));
107
+ }
108
+
109
+ if (typeof extract[1] === 'string') {
110
+ var errorTxt = this.line + ' ';
111
+ if (extract[1]) {
112
+ errorTxt += extract[1].slice(0, this.column) +
113
+ stylize(stylize(stylize(extract[1].substr(this.column, 1), 'bold') +
114
+ extract[1].slice(this.column + 1), 'red'), 'inverse');
115
+ }
116
+ error.push(errorTxt);
117
+ }
118
+
119
+ if (typeof extract[2] === 'string') {
120
+ error.push(stylize((this.line + 1) + ' ' + extract[2], 'grey'));
121
+ }
122
+ error = error.join('\n') + stylize('', 'reset') + '\n';
123
+ }
124
+
125
+ message += stylize(this.type + 'Error: ' + this.message, 'red');
126
+ if (this.filename) {
127
+ message += stylize(' in ', 'red') + this.filename;
128
+ }
129
+ if (this.line) {
130
+ message += stylize(' on line ' + this.line + ', column ' + (this.column + 1) + ':', 'grey');
131
+ }
132
+
133
+ message += '\n' + error;
134
+
135
+ if (this.callLine) {
136
+ message += stylize('from ', 'red') + (this.filename || '') + '/n';
137
+ message += stylize(this.callLine, 'grey') + ' ' + this.callExtract + '/n';
138
+ }
139
+
140
+ return message;
141
+ };
package/lib/less/parse.js CHANGED
@@ -2,15 +2,18 @@ var PromiseConstructor,
2
2
  contexts = require("./contexts"),
3
3
  Parser = require('./parser/parser'),
4
4
  PluginManager = require('./plugin-manager'),
5
- LessError = require('./less-error');
5
+ LessError = require('./less-error'),
6
+ utils = require('./utils');
6
7
 
7
8
  module.exports = function(environment, ParseTree, ImportManager) {
8
9
  var parse = function (input, options, callback) {
9
- options = options || {};
10
10
 
11
11
  if (typeof options === 'function') {
12
12
  callback = options;
13
- options = {};
13
+ options = utils.defaults(this.options, {});
14
+ }
15
+ else {
16
+ options = utils.defaults(this.options, options || {});
14
17
  }
15
18
 
16
19
  if (!callback) {
@@ -30,7 +33,7 @@ module.exports = function(environment, ParseTree, ImportManager) {
30
33
  } else {
31
34
  var context,
32
35
  rootFileInfo,
33
- pluginManager = new PluginManager(this, true);
36
+ pluginManager = new PluginManager(this, !options.reUsePluginManager);
34
37
 
35
38
  options.pluginManager = pluginManager;
36
39
 
@@ -56,32 +59,32 @@ module.exports = function(environment, ParseTree, ImportManager) {
56
59
  }
57
60
 
58
61
  var imports = new ImportManager(this, context, rootFileInfo);
59
-
62
+ this.importManager = imports;
63
+
64
+ // TODO: allow the plugins to be just a list of paths or names
65
+ // Do an async plugin queue like lessc
66
+
60
67
  if (options.plugins) {
61
68
  options.plugins.forEach(function(plugin) {
62
69
  var evalResult, contents;
63
70
  if (plugin.fileContent) {
64
71
  contents = plugin.fileContent.replace(/^\uFEFF/, '');
65
- evalResult = pluginManager.Loader.evalPlugin(contents, context, plugin.options, plugin.filename);
66
- if (!(evalResult instanceof LessError)) {
67
- pluginManager.addPlugin(plugin);
68
- }
69
- else {
72
+ evalResult = pluginManager.Loader.evalPlugin(contents, context, imports, plugin.options, plugin.filename);
73
+ if (evalResult instanceof LessError) {
70
74
  return callback(evalResult);
71
75
  }
72
-
73
76
  }
74
77
  else {
75
78
  pluginManager.addPlugin(plugin);
76
79
  }
77
80
  });
78
81
  }
79
-
82
+
80
83
  new Parser(context, imports, rootFileInfo)
81
84
  .parse(input, function (e, root) {
82
- if (e) { return callback(e); }
83
- callback(null, root, imports, options);
84
- }, options);
85
+ if (e) { return callback(e); }
86
+ callback(null, root, imports, options);
87
+ }, options);
85
88
  }
86
89
  };
87
90
  return parse;
@@ -1,11 +1,11 @@
1
1
  var chunker = require('./chunker');
2
2
 
3
3
  module.exports = function() {
4
- var input, // LeSS input string
4
+ var input, // Less input string
5
5
  j, // current chunk
6
6
  saveStack = [], // holds state for backtracking
7
7
  furthest, // furthest index the parser has gone to
8
- furthestPossibleErrorMessage,// if this is furthest we got to, this is the probably cause
8
+ furthestPossibleErrorMessage, // if this is furthest we got to, this is the probably cause
9
9
  chunks, // chunkified input
10
10
  current, // current chunk
11
11
  currentPos, // index of current chunk, in `input`
@@ -156,7 +156,7 @@ module.exports = function() {
156
156
 
157
157
  for (var i = 1; i + currentPosition < length; i++) {
158
158
  var nextChar = input.charAt(i + currentPosition);
159
- switch(nextChar) {
159
+ switch (nextChar) {
160
160
  case "\\":
161
161
  i++;
162
162
  continue;
@@ -209,7 +209,7 @@ module.exports = function() {
209
209
 
210
210
  parserInput.peekNotNumeric = function() {
211
211
  var c = input.charCodeAt(parserInput.i);
212
- //Is the first char of the dimension 0-9, '.', '+' or '-'
212
+ // Is the first char of the dimension 0-9, '.', '+' or '-'
213
213
  return (c > CHARCODE_9 || c < CHARCODE_PLUS) || c === CHARCODE_FORWARD_SLASH || c === CHARCODE_COMMA;
214
214
  };
215
215