Skip to content

Commit 4a3c921

Browse files
committed
Fix pretokenise of negative numbers, and allow untokenising
1 parent 5ab9415 commit 4a3c921

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

plugins/pretokenise.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@
226226
if (val==0) { // it's shorter just to write quotes
227227
resultCode += String.fromCharCode(LEX_RAW_INT0);
228228
} else if (val>=-128 && val<128)
229-
resultCode += String.fromCharCode(LEX_RAW_INT8, val);
229+
resultCode += String.fromCharCode(LEX_RAW_INT8, val&255);
230230
else if (val>=-32768 && val<32768)
231231
resultCode += String.fromCharCode(LEX_RAW_INT16, val&255, (val>>8)&255);
232232
else
@@ -282,6 +282,16 @@
282282
let len = code.charCodeAt(i+1) | (code.charCodeAt(i+2)<<8);
283283
resultCode += Espruino.Core.Utils.toJSONishString(code.substring(i+3, i+3+len));
284284
i+=2+len;
285+
} else if (ch==LEX_RAW_INT0) { // decode raw strings
286+
resultCode += "0";
287+
} else if (ch==LEX_RAW_INT8) { // decode raw strings
288+
let val = code.charCodeAt(i+1);
289+
resultCode += val.toString();
290+
i+=1;
291+
} else if (ch==LEX_RAW_INT16) {
292+
let val = code.charCodeAt(i+1) | (code.charCodeAt(i+2)<<8);
293+
resultCode += val.toString();
294+
i+=2;
285295
} else if (ch<LEX_OPERATOR_START+TOKENS.length) // decoded other tokens
286296
resultCode += TOKENS[ch-LEX_OPERATOR_START];
287297
else {

0 commit comments

Comments
 (0)