Replace "return {}" statement in plugins with explicit registerPlugin() function (more logical)

This commit is contained in:
Matthew Dean
2016-12-31 11:53:53 -08:00
parent 96c2ffbc0d
commit fda4565e8d
6 changed files with 18 additions and 17 deletions

View File

@@ -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;
}

View File

@@ -1,7 +1,7 @@
return {
registerPlugin({
install: function(less, pluginManager, functions) {
functions.add('func', function() {
return less.Anonymous(location.href);
});
}
}
});

View File

@@ -0,0 +1 @@
@plugin "plugin/plugin-error";

View File

@@ -0,0 +1 @@
SyntaxError: Unexpected token ) in {path}plugin/plugin-error.js

View File

@@ -0,0 +1,3 @@
// jscs:disable
functions.addMultiple({
"test-parse-error" : function() {

View File

@@ -7,8 +7,8 @@ functions.addMultiple({
}
});
return {
registerPlugin({
setOptions: function(raw) {
// do nothing
}
}
});