JS-Interpreter icon indicating copy to clipboard operation
JS-Interpreter copied to clipboard

Support ES6 and beyond

Open KRISACHAN opened this issue 4 years ago • 16 comments

... I saw the lib, acorn.js's version just 0.4.1 .... If I use the high version ecmascript code , for example :

for (let i of [1, 2, 3]) {
console.log(i)
}

It will throw an error ...

The last version of acorn.js is 7.1.0 ,but Js-Interpreter only 0.x

Too terrible

KRISACHAN avatar Mar 27 '20 11:03 KRISACHAN

The limiting factor is not Acorn (though updating it might not be a bad idea anyway), but that JS Intrpreter itself only understands ES5.1. So being able to parse for ... of loops wouldn't help, because the interpreter still wouldn't know how to execute them.

Nevertheless, since no one seems to have opened a "please support ES6" issue yet, I'll repurpose your report accordingly.

cpcallen avatar Mar 27 '20 11:03 cpcallen

Thank you for your answer I try to repackage with [email protected] just now .

Link here: https://github.com/KRISACHAN/acorn_interpreter.bundle.js

I don't know if it's a good idea . :)

Happy Weekend !

KRISACHAN avatar Mar 27 '20 11:03 KRISACHAN

I try to repackage with [email protected] just now.

Just make sure you specify the appropriate options to Acorn so that it will parse ES5 only.

cpcallen avatar Mar 27 '20 14:03 cpcallen

@cpcallen Supporting ES6+ features would be awesome, this is the only "deal breaker" for me of using the lib. Is it something you are considering doing?

sag1v avatar Mar 28 '20 08:03 sag1v

Is it something you are considering doing?

This is a question for @NeilFraser—but I suspect the answer is no, because this will eventually be part of the roadmap of another project (which is actually funded, unlike this one), so in a few years we will have a much better solution.

In the mean time, I would suggest using an ES6->5 transpiler. I have heard that Babel can do this.

cpcallen avatar Mar 28 '20 16:03 cpcallen

Thanks @cpcallen. Actually my use case for this library is to create a JavaScript "visualiser" (similar to devtools), not sure babel can help with this as it will change that actual code i want to visualise.

sag1v avatar Mar 28 '20 16:03 sag1v

Same here, I have tried using source maps to correct this, but they don't seem to come out correctly.

analog-hors avatar Apr 08 '20 23:04 analog-hors

Just to confirm, I have no interest in developing and maintaining an ES6+ version. It would be a step backwards for my projects in that the download times would increase.

However, I recognize that there is a genuine need for ES6+ support in other projects and I'd fully support anyone who wishes to fork the project accordingly.

Sent (awkwardly) from an Android device.

On Wed, 8 Apr 2020, 19:53 KSean222, [email protected] wrote:

Same here, I have tried using source maps to correct this, but they don't seem to come out correctly.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/NeilFraser/JS-Interpreter/issues/186#issuecomment-611252033, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAB5E4A4JTJ42ZQACWAQUM3RLUE6NANCNFSM4LU5LUOA .

NeilFraser avatar Apr 09 '20 00:04 NeilFraser

@KSean222 What do you mean by

... using source maps to correct this...

sag1v avatar Apr 12 '20 14:04 sag1v

@sag1v https://developer.mozilla.org/en-US/docs/Tools/Debugger/How_to/Use_a_source_map Babel can generate source maps when converting to ES5.

analog-hors avatar Apr 12 '20 23:04 analog-hors

https://developer.mozilla.org/en-US/docs/Tools/Debugger/How_to/Use_a_source_map Babel can generate source maps when converting to ES5.

Yeah i know, but how do you think it to sync them? Sounds interesting

sag1v avatar Apr 13 '20 09:04 sag1v

I tried using https://github.com/mozilla/source-map @sag1v

analog-hors avatar Apr 13 '20 09:04 analog-hors

Is it something you are considering doing?

This is a question for @NeilFraser—but I suspect the answer is no, because this will eventually be part of the roadmap of another project (which is actually funded, unlike this one), so in a few years we will have a much better solution.

In the mean time, I would suggest using an ES6->5 transpiler. I have heard that Babel can do this.

What is the name of the funded project?

cheapsteak avatar Aug 19 '20 21:08 cheapsteak

What is the name of the funded project?

Code City. But do note: "will eventually be part of the roadmap"—in its present form Code City is actually a less-complete JavaScript implementation than JS Interpreter is.

cpcallen avatar Sep 02 '20 09:09 cpcallen

I'm very interested in this, as it would be useful for creating a client-side step debugger for Theia IDE.

In theory, how much work are we talking to make this happen? Would it require a major re-write of the interpreter? Or is it just adding ES-6 specific features?

bendavis78 avatar Nov 15 '20 21:11 bendavis78

@bendavis78: It would be a considerable amount of work. ES6 is quite a bit larger language than ES5.1, and ES2020 is even more so. I don't think it necessarily requires a throw-it-away-and-start-from-scratch rewrite: it could certainly be done incrementally—but by the time it was done very little of the original code base will remain.

cpcallen avatar Nov 16 '20 16:11 cpcallen