1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-01-08 16:24:11 +01:00

Replace expression closures (methods).

Expression closures are to be axed. See https://bugzil.la/1083458.
This commit is contained in:
Doug Kearns
2015-07-23 01:55:32 +10:00
parent c035aa936b
commit 77d59cdfd1
45 changed files with 1595 additions and 1045 deletions

View File

@@ -101,7 +101,9 @@ update(CommandOption, {
* E.g. "foo,bar"
* @final
*/
LIST: ArgType("list", function parseListArg(arg, quoted) Option.splitList(quoted))
LIST: ArgType("list", function parseListArg(arg, quoted) {
return Option.splitList(quoted);
})
});
/**
@@ -198,7 +200,9 @@ var Command = Class("Command", {
* @param {string} name The candidate name.
* @returns {boolean}
*/
hasName: function hasName(name) Command.hasName(this.parsedSpecs, name),
hasName: function hasName(name) {
return Command.hasName(this.parsedSpecs, name);
},
/**
* A helper function to parse an argument string.
@@ -212,12 +216,13 @@ var Command = Class("Command", {
* @returns {Args}
* @see Commands#parseArgs
*/
parseArgs: function parseArgs(args, complete, extra)
this.modules.commands.parseArgs(args, {
parseArgs: function parseArgs(args, complete, extra) {
return this.modules.commands.parseArgs(args, {
__proto__: this,
complete: complete,
extra: extra
}),
});
},
complained: Class.Memoize(() => new RealSet),
@@ -300,7 +305,7 @@ var Command = Class("Command", {
* whether to purge the command from history when clearing
* private data.
*/
domains: function (args) [],
domains: function (args) { return []; },
/**
* @property {boolean} At what index this command's literal arguments
@@ -343,8 +348,10 @@ var Command = Class("Command", {
explicitOpts: Class.Memoize(() => ({})),
has: function AP_has(opt) hasOwnProperty(this.explicitOpts, opt)
|| typeof opt === "number" && hasOwnProperty(this, opt),
has: function AP_has(opt) {
return hasOwnProperty(this.explicitOpts, opt) ||
typeof opt === "number" && hasOwnProperty(this, opt);
},
get literalArg() {
let { literal } = this.command;
@@ -369,7 +376,11 @@ var Command = Class("Command", {
this.options.forEach(function (opt) {
if (opt.default !== undefined) {
let prop = Object.getOwnPropertyDescriptor(opt, "default") ||
{ configurable: true, enumerable: true, get: function () opt.default };
{
configurable: true,
enumerable: true,
get: function () { return opt.default; }
};
if (prop.get && !prop.set)
prop.set = function (val) { Class.replaceProperty(this, opt.names[0], val); };
@@ -430,9 +441,10 @@ var Command = Class("Command", {
this.modules.dactyl.warn(loc + message);
}
}, {
hasName: function hasName(specs, name)
specs.some(([long, short]) =>
name.indexOf(short) == 0 && long.indexOf(name) == 0),
hasName: function hasName(specs, name) {
return specs.some(([long, short]) => name.indexOf(short) == 0 &&
long.indexOf(name) == 0);
},
// TODO: do we really need more than longNames as a convenience anyway?
/**
@@ -453,10 +465,12 @@ var Command = Class("Command", {
// Prototype.
var Ex = Module("Ex", {
Local: function Local(dactyl, modules, window) ({
get commands() { return modules.commands; },
get context() { return modules.contexts.context; }
}),
Local: function Local(dactyl, modules, window) {
return {
get commands() { return modules.commands; },
get context() { return modules.contexts.context; }
};
},
_args: function E_args(cmd, args) {
args = Array.slice(args);
@@ -506,7 +520,9 @@ var Ex = Module("Ex", {
});
},
__noSuchMethod__: function __noSuchMethod__(meth, args) this._run(meth).apply(this, args)
__noSuchMethod__: function __noSuchMethod__(meth, args) {
return this._run(meth).apply(this, args);
}
});
var CommandHive = Class("CommandHive", Contexts.Hive, {
@@ -849,10 +865,12 @@ var Commands = Module("commands", {
COUNT_ALL: -2, // :%...
/** @property {Iterator(Command)} @private */
iterator: function iterator() iter.apply(null, this.hives.array)
.sort((a, b) => (a.serialGroup - b.serialGroup ||
a.name > b.name))
.iterValues(),
iterator: function iterator() {
return iter.apply(null, this.hives.array)
.sort((a, b) => (a.serialGroup - b.serialGroup ||
a.name > b.name))
.iterValues();
},
/** @property {string} The last executed Ex command line. */
repeat: null,
@@ -921,8 +939,10 @@ var Commands = Module("commands", {
* any of the command's names.
* @returns {Command}
*/
get: function get(name, full) iter(this.hives).map(([i, hive]) => hive.get(name, full))
.find(identity),
get: function get(name, full) {
return iter(this.hives).map(([i, hive]) => hive.get(name, full))
.find(identity);
},
/**
* Returns true if a command invocation contains a URL referring to the
@@ -1261,7 +1281,14 @@ var Commands = Module("commands", {
complete.advance(args.completeStart);
complete.keys = {
text: "names",
description: function (opt) messages.get(["command", params.name, "options", opt.names[0], "description"].join("."), opt.description)
description: function (opt) {
return messages.get(["command",
params.name,
"options",
opt.names[0],
"description"].join("."),
opt.description);
}
};
complete.title = ["Options"];
if (completeOpts)
@@ -1478,10 +1505,12 @@ var Commands = Module("commands", {
return [len - str.length, arg, quote];
},
quote: function quote(str) Commands.quoteArg[
/[\b\f\n\r\t]/.test(str) ? '"' :
/[\s"'\\]|^$|^-/.test(str) ? "'"
: ""](str)
quote: function quote(str) {
return Commands.quoteArg[
/[\b\f\n\r\t]/.test(str) ? '"' :
/[\s"'\\]|^$|^-/.test(str) ? "'"
: ""](str);
}
}, {
completion: function initCompletion(dactyl, modules, window) {
const { completion, contexts } = modules;
@@ -1557,7 +1586,10 @@ var Commands = Module("commands", {
args[i] = start + i + end;
let params = {
args: { __proto__: args, toString: function () this.join(" ") },
args: {
__proto__: args,
toString: function () { return this.join(" "); }
},
bang: args.bang ? "!" : "",
count: args.count
};
@@ -1611,7 +1643,9 @@ var Commands = Module("commands", {
_("group.cantChangeBuiltin", _("command.commands")));
let completer = args["-complete"];
let completerFunc = function (context, args) modules.completion.exMacro(context, args, this);
let completerFunc = function (context, args) {
return modules.completion.exMacro(context, args, this);
};
if (completer) {
if (/^custom,/.test(completer)) {
@@ -1637,14 +1671,18 @@ var Commands = Module("commands", {
let added = args["-group"].add(cmd.split(","),
args["-description"],
contexts.bindMacro(args, "-ex",
function makeParams(args, modifiers) ({
args: {
__proto__: args,
toString: function () this.string
},
bang: this.bang && args.bang ? "!" : "",
count: this.count && args.count
})),
function makeParams(args, modifiers) {
return {
args: {
__proto__: args,
toString: function () {
return this.string;
}
},
bang: this.bang && args.bang ? "!" : "",
count: this.count && args.count
};
}),
{
argCount: args["-nargs"],
bang: args["-bang"],
@@ -1782,13 +1820,15 @@ var Commands = Module("commands", {
name: ["listc[ommands]", "lc"],
description: "List all Ex commands along with their short descriptions",
index: "ex-cmd",
iterate: function (args) commands.iterator().map(cmd => ({
__proto__: cmd,
columns: [
cmd.hive == commands.builtin ? "" : ["span", { highlight: "Object", style: "padding-right: 1em;" },
cmd.hive.name]
]
})),
iterate: function (args) {
return commands.iterator().map(cmd => ({
__proto__: cmd,
columns: [
cmd.hive == commands.builtin ? "" : ["span", { highlight: "Object", style: "padding-right: 1em;" },
cmd.hive.name]
]
}));
},
iterateIndex: function (args) {
let tags = help.tags;
return this.iterate(args).filter(cmd => (cmd.hive === commands.builtin ||
@@ -1796,8 +1836,10 @@ var Commands = Module("commands", {
},
format: {
headings: ["Command", "Group", "Description"],
description: function (cmd) template.linkifyHelp(cmd.description + (cmd.replacementText ? ": " + cmd.action : "")),
help: function (cmd) ":" + cmd.name
description: function (cmd) {
return template.linkifyHelp(cmd.description + (cmd.replacementText ? ": " + cmd.action : ""));
},
help: function (cmd) { return ":" + cmd.name; }
}
});