JavaScript source code generation library for scala [closed]

I'm looking for a library in scala that generates JavaScript from an abstract syntax tree. I want to use it in an compiler that generates JavaScript at the end and I don't want to implement the pretty printing part myself.

Answers:

Answer

I spent half of yesterday researching this. It seems there is no standard, standalone solution. Every project I looked at rolled their own:

How standalone and reusable might these various classes be? Just giving the code a visual onceover, it appears to me that the AST classes in JScala and s2js are standalone and could easily be borrowed by another project. The Scala-JS AST classes seem somewhat more entangled with their surroundings; Lift, even more so. (I welcome edits that improve on my informal impressions.)

How mature and battle-tested are these various projects? My informal impression is that they rank in descending order as follows: Lift, Scala-JS, JScala, s2js.

For my own project, I think I'm going to copy-and-paste the two source files from JScala and see how it goes.

P.S. I also mention, for completeness' sake:

Answer

The Lift web framework generates JavaScript from an AST. However, I've never looked at the generation end of it. The AST is described loosely here http://exploring.liftweb.net/master/index-10.html

Answer

StringTemplate (from ANTLR) is pretty nice for code generation, I'd say, and it does track indentation and keeps indenting nested statements at the right level. Not really pretty printing, but better than nothing. (At the same time, I wonder why you want pretty printed JavaScript, if in the end it's going to be minified anyway.)

There is a Scala wrapper for StringTemplate (at least one, I seem to recall I saw more): http://software.clapper.org/scalasti/

Virtualized-scala doesn't seem to be what you need, I'd say, since that starts with Scala a Scala AST, and that's not what you seem to have.

However, if you're interested in those sort of things as well, you might want to check http://nescala.org/2013/talks#26 (by Alvaro Carrasco) as well.

Answer

There is the Virtualized-Scala project, one of its instances is generating Javascript from Scala code, js-scala. There you will find links for projects and talks about it.

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.