Skip to content

Commit faf5fc9

Browse files
committed
Fix issues thrown up by linting in #192
1 parent e270057 commit faf5fc9

File tree

5 files changed

+27
-37
lines changed

5 files changed

+27
-37
lines changed

core/terminal.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -483,10 +483,9 @@
483483
var pos = cursor[0].getBoundingClientRect();
484484
var terminalfocus = document.getElementById("terminalfocus");
485485
var x = Math.min(pos.left, terminal.offsetWidth);
486-
// TODO: 'y' is already defined in outer scope, but this redeclaration doesn't appear to be used in this scope?
487-
var y = Math.min(pos.top-tPos.top, terminal.height-terminalfocus.offsetHeight);
486+
var y = Math.min(pos.top-tPos.top, terminal.height-terminalfocus.offsetHeight);
488487
terminalfocus.style.left=x+"px";
489-
terminalfocus.style.top=(pos.top-tPos.top)+"px";
488+
terminalfocus.style.top=y+"px";
490489
}
491490
};
492491

core/utils.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,6 @@
1919

2020
}
2121

22-
// function decodeBase64(d) {
23-
// return Buffer.from(d,'base64').toString('binary');
24-
// }
25-
26-
// function encodeBase64(d) {
27-
// return Buffer.from(d,'binary').toString('base64');
28-
// }
29-
3022
function isWindows() {
3123
return (typeof navigator!="undefined") && navigator.userAgent.indexOf("Windows")>=0;
3224
}

plugins/compiler.js

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -49,31 +49,33 @@
4949
});
5050
}
5151

52-
/* Replace this node with the given text, and
53-
update node start/end positions of other nodes
54-
we're interested in */
55-
function replaceNode(node, newCode) {
56-
// TODO: Where is 'code' defined? Is this a global?
57-
code = code.substr(0,node.start) + newCode + code.substr(node.end);
58-
var offs = newCode.length - (node.end-node.start); // offset for future code snippets
52+
/** Given a string containing code, this parses it using acorn
53+
* then attempts to find functions with the string "compiled"
54+
* in them and sends them off to the compiler.
55+
*/
56+
function compileCode(code, description, callback) {
57+
var tasks = [];
5958

60-
// TODO: Also unclear where 'tasks' is defined, there's nothing in this scope to declare it
61-
for (var i in tasks)
62-
if (tasks[i].node.start > node.start) {
63-
tasks[i].node.start += offs;
64-
tasks[i].node.end += offs;
65-
}
66-
}
59+
/* Replace this node with the given text, and
60+
update node start/end positions of other nodes
61+
we're interested in */
62+
function replaceNode(node, newCode) {
63+
code = code.substr(0,node.start) + newCode + code.substr(node.end);
64+
var offs = newCode.length - (node.end-node.start); // offset for future code snippets
65+
for (var i in tasks)
66+
if (tasks[i].node.start > node.start) {
67+
tasks[i].node.start += offs;
68+
tasks[i].node.end += offs;
69+
}
70+
}
6771

68-
function compileCode(code, description, callback) {
6972
if (!Espruino.Config.COMPILATION)
7073
return callback(code);
7174

7275
var board = Espruino.Core.Env.getBoardData();
73-
var tasks = 0; // TODO: This is re-declared as an array at #73, but this outer scoped 'tasks' is not modified
7476
try {
75-
var ast = acorn.parse(code);
76-
var tasks = [];
77+
var ast = acorn.parse(code, {ecmaVersion: 2020});
78+
tasks = [];
7779
// function xyz() { "compiled" ... }
7880
ast.body.forEach(function(node) {
7981
if (node.type=="FunctionDeclaration") {

plugins/minify.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,7 @@
194194
_callback(code);
195195
};
196196
})();
197-
198-
// TODO: None of the below block is called
197+
199198
var minifyCode = code;
200199
var minifyCallback = callback;
201200
if (isModule) {
@@ -208,13 +207,12 @@
208207
callback(minified.substr(header.length, minified.length-(header.length+footer.length+1)));
209208
}
210209
}
211-
// End of unused block
212210

213211
switch(level){
214212
case "WHITESPACE_ONLY":
215213
case "SIMPLE_OPTIMIZATIONS":
216-
case "ADVANCED_OPTIMIZATIONS": minifyCodeGoogle(code, callback, level, description); break;
217-
case "ESPRIMA": minifyCodeEsprima(code, callback, description); break;
214+
case "ADVANCED_OPTIMIZATIONS": minifyCodeGoogle(minifyCode, minifyCallback, level, description); break;
215+
case "ESPRIMA": minifyCodeEsprima(minifyCode, minifyCallback, description); break;
218216
default: callback(code); break;
219217
}
220218
}

plugins/pretokenise.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,12 @@
236236
if (needSpaceBetween(lastCh, ch))
237237
resultCode += " ";
238238
if (ch>=LEX_OPERATOR_START) {
239-
var len
240239
if (ch==LEX_RAW_STRING8) { // decode raw strings
241-
len = code.charCodeAt(i+1);
240+
let len = code.charCodeAt(i+1);
242241
resultCode += Espruino.Core.Utils.toJSONishString(code.substring(i+2, i+2+len));
243242
i+=1+len;
244243
} else if (ch==LEX_RAW_STRING16) {
245-
len = code.charCodeAt(i+1) | (code.charCodeAt(i+2)<<8);
244+
let len = code.charCodeAt(i+1) | (code.charCodeAt(i+2)<<8);
246245
resultCode += Espruino.Core.Utils.toJSONishString(code.substring(i+3, i+3+len));
247246
i+=2+len;
248247
} else if (ch<LEX_OPERATOR_START+TOKENS.length) // decoded other tokens

0 commit comments

Comments
 (0)