NeilFraser / JS-Interpreter

A sandboxed JavaScript interpreter in JavaScript.
Apache License 2.0
1.98k stars 353 forks source link

Unexpected token error #213

Closed nitesh-1092 closed 3 years ago

nitesh-1092 commented 3 years ago

When I run interpreter on this code, My react application shows unexpected token error and crashes. Is there any way to stop my app from crashing? Please help me. I know it's a syntax error but I don't want any react app to crash. Is there any way to spot the error first. React doesn't supports try/catch. I am adding Blockly to my react app and to run the JS code I am using js-interpreter.

code = var i; for (i = 1; i <= 10; i++) { } const myInterpreter = new Interpreter(code); myInterpreter.run()

image

NeilFraser commented 3 years ago

React doesn't supports try/catch.

I have no experience with React, so this limitation is news to me. But a short Google search seems to indicate that there's now something called Error Boundaries. Could this work for you?

If not, I suggest discussing the issue with people who know React (maybe Stack Overflow). The JS-Interpreter project doesn't have the required knowledge for your chosen framework.

That said, do update this bug with what you find, so that the next React user can be helped. Thanks!