-
• #2
Why do you have a break after default?
-
• #3
Removing it doesn't fix it
Old C++ habits linger.
The left side:Post URL { "method": "GET", "host": "", "path": "/CMD", "pathname": "/CMD", "search": null, "port": null, "query": null } XXX /CMD Length 70 pdata= {"name":"LED1","a":0,"cmd":"pobj.a=!pobj.a;digitalWrite(LED1,pobj.a)"} pdata length= 70 { "name": "LED1", "a": 0, "cmd": "pobj.a=!pobj.a;digitalWrite(LED1,pobj.a)" } Uncaught SyntaxError: BREAK statement outside of SWITCH, FOR or WHILE loop at line 93 col 5 break; ^ Closed >
And the code with the default break commented
function doPost1(req,res){ var length; var a = url.parse(req.url, true); console.log("URL ",a); console.log("XXX ",a.pathname); length=req.headers["Content-Length"]; console.log("Length ",length); console.log("pdata= ",pdata); console.log("pdata length= ",pdata.length); switch (a.pathname){ case "/CMD": if(pdata.length==length){ pobj=JSON.parse(pdata); console.log(pobj); if(pobj.cmd !==null){ eval(pobj.cmd); pdata=JSON.stringify(pobj); res.writeHead(200); res.end(pdata); }else{ res.writeHead(201); res.end(); } //end if pobj.cmd }//endif length else break; case "/LOGdata": console.log("LOGdata= ",pdata); res.writeHead(200); res.end(pdata); break; default: res.writeHead(404); res.end(); // break; }//end switch pdata=""; }//end doPost1
-
• #4
Ok, it looks like this is an Espruino issue caused by
eval
messing up the parse state.It can be caused just by:
function test(){ switch ("a"){ case "a": eval(1); break; } }
To work around this for now, add:
function eval2(x) { return eval(x); }
and then call
eval2
instead ofeval
- hopefully that won't mess you up too much (although the new eval won't have access to the variables in the current scope). -
• #5
Thanks for taking action
Uncaught SyntaxError: BREAK statement outside of SWITCH, FOR or WHILE loop
(But it's not.)
On the left side:
The program continues running.
Part of the code on the right side
Changing the code removes the error.
And on the left side: