Live data from Hacker News

JSIR: A High-Level IR for JavaScript

discourse.llvm.org

31–33 of 33 posts

Re: JSIR: A High-Level IR for JavaScript

#31

Earlier quoted context omitted.

Right on. That makes sense. Thanks for spelling it out! I do think aligning the semantics will be the easier part, honestly, because I'm only trying to transpile the supported source for the game engine. Since that's all written in typescript and I'm not guaranteeing full parity if you are trying to transpile arbitrary ts/js (only the source that can be parsed the same way the game engine is parsed), I'm expecting it…

I don't see anything wrong that would disqualify your plan. But if the alternative is regex, and you're writing already in TypeScript, you may take a look at ts-morph [0]. TS has very good compiler APIs and that gets you something much safer than text-based replacement while still staying relatively small for a constrained subset. ts-morph wraps those APIs cleanly. Btw, JS doesn't even have an official bytecode. The…

oh, hell yeah! I hadn't heard of ts-morph. Seems like it would make transpiling to C# much simpler. I'll definitely give it a try. Thanks!

Re: JSIR: A High-Level IR for JavaScript

#32

They're presenting this under the banner "the need for source to source transformations." That seems a bit disingenuous given this is not a source-preserving IR! All comments and nonstandard spacing would be completely removed from your code if you gave it a round trip through this format. That doesn't sound like 99.9% source recovery to me...

Especially as JSDoc is used for type annotations and even type checking in some projects. It's not in ECMA standard but widely used and well supported. The IR as it is implemented today will run into serious trouble.

Re: JSIR: A High-Level IR for JavaScript

#33

They're presenting this under the banner "the need for source to source transformations." That seems a bit disingenuous given this is not a source-preserving IR! All comments and nonstandard spacing would be completely removed from your code if you gave it a round trip through this format. That doesn't sound like 99.9% source recovery to me...

the comments are preserved afaict from replies in that thread
Post reply on HN