mirror of
https://github.com/less/less.js.git
synced 2026-05-01 03:00:22 -04:00
Replace "return {}" statement in plugins with explicit registerPlugin() function (more logical)
This commit is contained in:
@@ -12,7 +12,7 @@ function error(msg, type) {
|
||||
}
|
||||
);
|
||||
}
|
||||
AbstractPluginLoader.prototype.evalPlugin = function(contents, context, pluginOptions, fileInfo) {
|
||||
AbstractPluginLoader.prototype.evalPlugin = function(contents, context, imports, pluginOptions, fileInfo) {
|
||||
|
||||
var loader,
|
||||
registry,
|
||||
@@ -54,8 +54,11 @@ AbstractPluginLoader.prototype.evalPlugin = function(contents, context, pluginOp
|
||||
registry = functionRegistry.create();
|
||||
|
||||
try {
|
||||
loader = new Function("module", "require", "functions", "tree", "less", "fileInfo", contents);
|
||||
pluginObj = loader(localModule, this.require, registry, this.less.tree, this.less, fileInfo);
|
||||
var registerPlugin = function(obj) {
|
||||
pluginObj = obj;
|
||||
};
|
||||
loader = new Function("module", "require", "registerPlugin", "functions", "tree", "less", "fileInfo", contents);
|
||||
loader(localModule, this.require, registerPlugin, registry, this.less.tree, this.less, fileInfo);
|
||||
|
||||
if (!pluginObj) {
|
||||
pluginObj = localModule.exports;
|
||||
@@ -78,15 +81,8 @@ AbstractPluginLoader.prototype.evalPlugin = function(contents, context, pluginOp
|
||||
return new this.less.LessError({ message: "Not a valid plugin" });
|
||||
}
|
||||
|
||||
} catch(e) {
|
||||
// TODO pass the error
|
||||
console.log(e.stack);
|
||||
return new this.less.LessError({
|
||||
message: "Plugin evaluation error: '" + e.name + ': ' + e.message.replace(/["]/g, "'") + "'" ,
|
||||
filename: filename,
|
||||
line: this.line,
|
||||
col: this.column
|
||||
});
|
||||
} catch (e) {
|
||||
return new this.less.LessError(e, imports, filename);
|
||||
}
|
||||
|
||||
return pluginObj;
|
||||
@@ -102,7 +98,7 @@ AbstractPluginLoader.prototype.trySetOptions = function(plugin, filename, name,
|
||||
try {
|
||||
plugin.setOptions(options);
|
||||
}
|
||||
catch(e) {
|
||||
catch (e) {
|
||||
error("Error setting options on plugin " + name + '\n' + e.message);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
return {
|
||||
registerPlugin({
|
||||
install: function(less, pluginManager, functions) {
|
||||
functions.add('func', function() {
|
||||
return less.Anonymous(location.href);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
1
test/less/errors/plugin-1.less
Normal file
1
test/less/errors/plugin-1.less
Normal file
@@ -0,0 +1 @@
|
||||
@plugin "plugin/plugin-error";
|
||||
1
test/less/errors/plugin-1.txt
Normal file
1
test/less/errors/plugin-1.txt
Normal file
@@ -0,0 +1 @@
|
||||
SyntaxError: Unexpected token ) in {path}plugin/plugin-error.js
|
||||
3
test/less/errors/plugin/plugin-error.js
Normal file
3
test/less/errors/plugin/plugin-error.js
Normal file
@@ -0,0 +1,3 @@
|
||||
// jscs:disable
|
||||
functions.addMultiple({
|
||||
"test-parse-error" : function() {
|
||||
@@ -7,8 +7,8 @@ functions.addMultiple({
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
registerPlugin({
|
||||
setOptions: function(raw) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user