NeilFraser / JS-Interpreter

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

Include in REACT typescript ? #248

Closed ignatandrei closed 1 year ago

ignatandrei commented 1 year ago

Hello I want to make a npm package from Blockly + Interpreter + Swagger ( see https://github.com/ignatandrei/blocklyAutomation/ and a demo at https://visualapi.azurewebsites.net/ )

However, because the interpreter is a <script src in a HTML file, I cannot include in the package

I wanted to import to typescript REACT , but it gives me es-lint-errors a lot and ,even I get rid, I cannot access the this.Interpreter variable ( it says that is null)

Do someone has some experience ?

toyknight commented 1 year ago

There's a third party js-interpreter package in the npm repo, maybe you can try your luck there.

Or if you want the latest source code your best bet is probably setting allowJs to true in your tsconfig.json, copying the acorn.js + interpreter.js to your project and write a ts definition for it (or get it from somewhere else). You will likely have to modify the module exporting part in the js source code for it to work in node.js enviroment.

ignatandrei commented 1 year ago

Thanks for the answer . I understand that. The TS definition is what bothers me ( I come from a C# world, and , despite my efforts, it is somehow obscure) Being that one of the uses of JS-Interpreter is Blockly that has achieved the transition to TypeSCript, how difficult is to make an official release with TS?

Thanks again

NeilFraser commented 1 year ago

As someone who has experienced the JS to TS conversion of Blockly firsthand, I can promise you that JS-Interpreter will never make the same mistake. The costs are horrendous, and (despite the hype) the benefits are virtually non-existent. It was a difficult lesson to learn.

ignatandrei commented 1 year ago

I do regret that....