New 'espruinotools' which fixes pretokenise issue when ID follows ID (fix #416)

pull/422/head
Gordon Williams 2020-05-14 16:24:14 +01:00
parent 7bf0e57882
commit 4f9d3e7794
2 changed files with 37 additions and 39 deletions

View File

@ -17,3 +17,4 @@ Changed for individual apps are listed in `apps/appname/ChangeLog`
* URL fetch is now async * URL fetch is now async
* Adding '#search' after the URL (when not the name of a 'filter' chip) will set up search for that term * Adding '#search' after the URL (when not the name of a 'filter' chip) will set up search for that term
* If `bin/pre-publish.sh` has been run and recent.csv created, add 'Sort By' chip * If `bin/pre-publish.sh` has been run and recent.csv created, add 'Sort By' chip
* New 'espruinotools' which fixes pretokenise issue when ID follows ID (fix #416)

View File

@ -1,6 +1,6 @@
// EspruinoTools bundle (https://github.com/espruino/EspruinoTools) // EspruinoTools bundle (https://github.com/espruino/EspruinoTools)
// Created with https://github.com/espruino/EspruinoWebIDE/blob/gh-pages/extras/create_espruinotools_js.sh // Created with https://github.com/espruino/EspruinoWebIDE/blob/gh-pages/extras/create_espruinotools_js.sh
// Based on EspruinoWebIDE 0.73.4 // Based on EspruinoWebIDE 0.73.7
/** /**
Copyright 2014 Gordon Williams (gw@pur3.co.uk) Copyright 2014 Gordon Williams (gw@pur3.co.uk)
@ -23,6 +23,7 @@ var Espruino;
* *
* Common processors are: * Common processors are:
* *
* jsCodeChanged - called when the code in the editor changes with {code}
* sending - sending code to Espruino (no data) * sending - sending code to Espruino (no data)
* transformForEspruino - transform code ready to be sent to Espruino * transformForEspruino - transform code ready to be sent to Espruino
* transformModuleForEspruino({code,name}) * transformModuleForEspruino({code,name})
@ -4123,7 +4124,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
} else if (isIn(chNum,ch)) { // NUMBER } else if (isIn(chNum,ch)) { // NUMBER
type = "NUMBER"; type = "NUMBER";
var chRange = chNum; var chRange = chNum;
if (ch=="0") { // Handle if (ch=="0") { // Handle
s+=ch; s+=ch;
nextCh(); nextCh();
if ("xXoObB".indexOf(ch)>=0) { if ("xXoObB".indexOf(ch)>=0) {
@ -4132,12 +4133,12 @@ Object.defineProperty(exports, '__esModule', { value: true });
if (ch=="x" || ch=="X") chRange="0123456789ABCDEFabcdef"; if (ch=="x" || ch=="X") chRange="0123456789ABCDEFabcdef";
s+=ch; s+=ch;
nextCh(); nextCh();
} }
} }
while (isIn(chRange,ch) || ch==".") { while (isIn(chRange,ch) || ch==".") {
s+=ch; s+=ch;
nextCh(); nextCh();
} }
} else if (isIn(chQuotes,ch)) { // STRING } else if (isIn(chQuotes,ch)) { // STRING
type = "STRING"; type = "STRING";
var q = ch; var q = ch;
@ -4507,8 +4508,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
fileLoader.click(); fileLoader.click();
} }
/* Save a file with a save file dialog. callback(savedFileName) only called in chrome app case when we knopw the filename*/ // Save a file with a save file dialog
function fileSaveDialog(data, filename, callback) { function fileSaveDialog(data, filename) {
function errorHandler() { function errorHandler() {
Espruino.Core.Notifications.error("Error Saving", true); Espruino.Core.Notifications.error("Error Saving", true);
} }
@ -4524,7 +4525,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
writer.onwriteend = function(e) { writer.onwriteend = function(e) {
writer.onwriteend = function(e) { writer.onwriteend = function(e) {
console.log('FileWriter: complete'); console.log('FileWriter: complete');
if (callback) callback(writableFileEntry.name);
}; };
console.log('FileWriter: writing'); console.log('FileWriter: writing');
writer.write(blob); writer.write(blob);
@ -4535,8 +4535,10 @@ Object.defineProperty(exports, '__esModule', { value: true });
}, errorHandler); }, errorHandler);
}); });
} else { } else {
var rawdata = new Uint8Array(data.length);
for (var i=0;i<data.length;i++) rawdata[i]=data.charCodeAt(i);
var a = document.createElement("a"), var a = document.createElement("a"),
file = new Blob([data], {type: "text/plain"}); file = new Blob([rawdata.buffer], {type: "text/plain"});
var url = URL.createObjectURL(file); var url = URL.createObjectURL(file);
a.href = url; a.href = url;
a.download = filename; a.download = filename;
@ -4765,6 +4767,16 @@ Object.defineProperty(exports, '__esModule', { value: true });
console.log("GET chrome.storage.sync = "+JSON.stringify(value)); console.log("GET chrome.storage.sync = "+JSON.stringify(value));
callback(value); callback(value);
}); });
} else if (typeof window !== 'undefined' && window.localStorage) {
var data = {};
var value = window.localStorage.getItem("CONFIG");
console.log("GET window.localStorage = "+JSON.stringify(value));
try {
data = JSON.parse(value);
} catch (e) {
console.log("Invalid config data");
}
callback(data);
} else if (typeof document != "undefined") { } else if (typeof document != "undefined") {
var data = {}; var data = {};
var cookie = document.cookie; var cookie = document.cookie;
@ -4786,8 +4798,11 @@ Object.defineProperty(exports, '__esModule', { value: true });
function _set(data) { function _set(data) {
if (typeof chrome !== 'undefined' && chrome.storage) { if (typeof chrome !== 'undefined' && chrome.storage) {
console.log("SET chrome.storage.sync = "+JSON.stringify(data)); console.log("SET chrome.storage.sync = "+JSON.stringify(data,null,2));
chrome.storage.sync.set({ CONFIGS : data }); chrome.storage.sync.set({ CONFIGS : data });
} else if (typeof window !== 'undefined' && window.localStorage) {
console.log("SET window.localStorage = "+JSON.stringify(data,null,2));
window.localStorage.setItem("CONFIG",JSON.stringify(data));
} else if (typeof document != "undefined") { } else if (typeof document != "undefined") {
document.cookie = "CONFIG="+btoa(JSON.stringify(data)); document.cookie = "CONFIG="+btoa(JSON.stringify(data));
} }
@ -4811,7 +4826,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
addSection("General", { sortOrder:100, description: "General Web IDE Settings" }); addSection("General", { sortOrder:100, description: "General Web IDE Settings" });
addSection("Communications", { sortOrder:200, description: "Settings for communicating with the Espruino Board" }); addSection("Communications", { sortOrder:200, description: "Settings for communicating with the Espruino Board" });
addSection("Board", { sortOrder:300, description: "Settings for the Espruino Board itself" }); addSection("Board", { sortOrder:300, description: "Settings for the Espruino Board itself" });
} }
function add(name, options) { function add(name, options) {
@ -5076,6 +5090,7 @@ To add a new serial device, you must add an object to
} }
} }
var portInfo = { port:serialPort };
connectionInfo = undefined; connectionInfo = undefined;
flowControlXOFF = false; flowControlXOFF = false;
currentDevice = portToDevice[serialPort]; currentDevice = portToDevice[serialPort];
@ -5088,7 +5103,6 @@ To add a new serial device, you must add an object to
connectionInfo = cInfo; connectionInfo = cInfo;
connectedPort = serialPort; connectedPort = serialPort;
console.log("Connected", cInfo); console.log("Connected", cInfo);
var portInfo = { port:serialPort };
if (connectionInfo.portName) if (connectionInfo.portName)
portInfo.portName = connectionInfo.portName; portInfo.portName = connectionInfo.portName;
Espruino.callProcessor("connected", portInfo, function() { Espruino.callProcessor("connected", portInfo, function() {
@ -5127,8 +5141,8 @@ To add a new serial device, you must add an object to
sendingBinary = false; sendingBinary = false;
flowControlXOFF = false; flowControlXOFF = false;
Espruino.callProcessor("disconnected", undefined, function() { Espruino.callProcessor("disconnected", portInfo, function() {
disconnectCallback(); disconnectCallback(portInfo);
}); });
}); });
}; };
@ -5608,9 +5622,6 @@ To add a new serial device, you must add an object to
// When code is sent to Espruino, search it for modules and add extra code required to load them // When code is sent to Espruino, search it for modules and add extra code required to load them
Espruino.addProcessor("transformForEspruino", function(code, callback) { Espruino.addProcessor("transformForEspruino", function(code, callback) {
if (Espruino.Config.ROLLUP) {
return loadModulesRollup(code, callback);
}
loadModules(code, callback); loadModules(code, callback);
}); });
@ -5787,24 +5798,8 @@ To add a new serial device, you must add an object to
callback(loadedModuleData.join("\n") + "\n" + code); callback(loadedModuleData.join("\n") + "\n" + code);
}); });
} }
} };
function loadModulesRollup(code, callback) {
rollupTools.loadModulesRollup(code)
.then(generated => {
const minified = generated.code;
console.log('rollup: '+minified.length+' bytes');
// FIXME: needs warnings?
Espruino.Core.Notifications.info('Rollup no errors. Bundling ' + code.length + ' bytes to ' + minified.length + ' bytes');
callback(minified);
})
.catch(err => {
console.log('rollup:error', err);
Espruino.Core.Notifications.error("Rollup errors - Bundling failed: " + String(err).trim());
callback(code);
});
}
Espruino.Core.Modules = { Espruino.Core.Modules = {
init : init init : init
@ -6436,18 +6431,18 @@ To add a new serial device, you must add an object to
This Source Code is subject to the terms of the Mozilla Public This Source Code is subject to the terms of the Mozilla Public
License, v2.0. If a copy of the MPL was not distributed with this License, v2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/. file, You can obtain one at http://mozilla.org/MPL/2.0/.
------------------------------------------------------------------ ------------------------------------------------------------------
Try and get any URLS that are from GitHub Try and get any URLS that are from GitHub
------------------------------------------------------------------ ------------------------------------------------------------------
**/ **/
"use strict"; "use strict";
(function(){ (function(){
function init() { function init() {
Espruino.addProcessor("getURL", getGitHub); Espruino.addProcessor("getURL", getGitHub);
} }
function getGitHub(data, callback) { function getGitHub(data, callback) {
var match = data.url.match(/^https?:\/\/github.com\/([^\/]+)\/([^\/]+)\/blob\/([^\/]+)\/(.*)$/); var match = data.url.match(/^https?:\/\/github.com\/([^\/]+)\/([^\/]+)\/blob\/([^\/]+)\/(.*)$/);
if (match) { if (match) {
@ -6457,7 +6452,7 @@ To add a new serial device, you must add an object to
branch : match[3], branch : match[3],
path : match[4] path : match[4]
}; };
var url = "https://raw.githubusercontent.com/"+git.owner+"/"+git.repo+"/"+git.branch+"/"+git.path; var url = "https://raw.githubusercontent.com/"+git.owner+"/"+git.repo+"/"+git.branch+"/"+git.path;
console.log("Found GitHub", JSON.stringify(git)); console.log("Found GitHub", JSON.stringify(git));
callback({url: url}); callback({url: url});
@ -6591,7 +6586,7 @@ To add a new serial device, you must add an object to
return { return {
startIdx : tk.start, startIdx : tk.start,
endIdx : tk.end, endIdx : tk.end,
str : code.substr(tk.start, tk.end), str : code.substring(tk.start, tk.end),
type : tp type : tp
}; };
}}; }};
@ -6802,5 +6797,7 @@ Espruino.transform = function(code, options) {
}); });
}; };
if (!document) Espruino.init();
if ("undefined"!=typeof module) if ("undefined"!=typeof module)
module.exports = Espruino; module.exports = Espruino;