Skip to content

How to fix errors in your .keysnail.js

Masafumi Oyamada edited this page Sep 24, 2015 · 3 revisions

How to fix errors in your .keysnail.js

This is a simple guide to help you fix errors in your .keysnail.js.

An error occurred in .keysnail.js line XXX: missing { before let block

Most users will meet this "missing { before let block" error. Once syntax called let expression/statement like let (x = foo()) x * x was valid in Firefox, but the syntax was dropped in Firefox 41, and now is causing the errors.

What you have to do is replace let expression/statement in your .keysnail.js with standard JavaScript syntax.

See https://github.com/mooz/keysnail/pull/176 for details.

Here are several examples.

Example 1

Fix

// Original (invalid)
function (ev, arg) {
    let (elem = document.commandDispatcher.focusedElement) elem && elem.blur();
    gBrowser.focus();
    content.focus();
}

to

// Corrected (valid)
function (ev, arg) {
    let elem = document.commandDispatcher.focusedElement;
    if (elem) { elem.blur(); }
    gBrowser.focus();
    content.focus();
}

Example 2

Fix

// Original (invalid)
function (ev, arg) {
    gBrowser.loadOneTab(
        let (url = command.getClipboardText())
            url.indexOf("://") === -1 ?
            util.format("http://www.google.com/search?q=%s&ie=utf-8&oe=utf-8", encodeURIComponent(url)) :
            url,
        null, null, null, false
    );
}, false

to

// Corrected version (valid)
function (ev, arg) {
    let url = command.getClipboardText();
    if (url.indexOf("://") === -1) {
        url = util.format("http://www.google.com/search?q=%s&ie=utf-8&oe=utf-8", encodeURIComponent(url));
    }
    gBrowser.loadOneTab(url, null, null, null, false);
}, false

Example 3

Fix

// Original (invalid)
function (ev) {
    if (!command.kill.ring.length)
        return;

    let (ct = command.getClipboardText())
        (!command.kill.ring.length || ct != command.kill.ring[0]) && command.pushKillRing(ct);

    prompt.selector(
        {
            message: "Paste:",
            collection: command.kill.ring,
            callback: function (i) { if (i >= 0) key.insertText(command.kill.ring[i]); }
        }
    );
}

to

// Corrected (valid)
function (ev) {
    if (!command.kill.ring.length)
        return;

    let ct = command.getClipboardText();
    if (!command.kill.ring.length || ct != command.kill.ring[0]) {
        command.pushKillRing(ct);
    }

    prompt.selector(
        {
            message: "Paste:",
            collection: command.kill.ring,
            callback: function (i) { if (i >= 0) key.insertText(command.kill.ring[i]); }
        }
    );
}