Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
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.
I spent half of yesterday researching this. It seems there is no standard, standalone solution. Every project I looked at rolled their own:
Scala-JS: The JavaScript AST classes in Sébastien Doeraene's Scala-JS project are here: https://github.com/sjrd/scala-js/blob/master/compiler/src/main/scala/scala/tools/nsc/backend/js/JSTrees.scala and the conversion to strings is here: https://github.com/sjrd/scala-js/blob/master/compiler/src/main/scala/scala/tools/nsc/backend/js/JSPrinters.scala
JScala: The JavaScript AST classes in Alexander Nemish's JScala project are here: https://github.com/nau/jscala/blob/master/jscala/src/main/scala/org/jscala/model.scala and the conversion to strings is here: https://github.com/nau/jscala/blob/master/jscala/src/main/scala/org/jscala/JavascriptPrinter.scala
s2js: The JavaScript AST classes in Alvaro Carrasco's s2js project are here: https://github.com/alvaroc1/s2js/blob/master/plugin/src/main/scala/com/gravitydev/s2js/Trees.scala and the conversion to strings is here: https://github.com/alvaroc1/s2js/blob/master/plugin/src/main/scala/com/gravitydev/s2js/JsPrinter.scala
Lift (see #thoredge's answer) combines AST classes with string generation in a single file, here: https://github.com/lift/framework/blob/master/web/webkit/src/main/scala/net/liftweb/http/js/JsCommands.scala
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:
js-scala generates JavaScript strings directly from Scala ASTs, rather than going through intermediate JavaScript ASTs. (See for example https://github.com/js-scala/js-scala/blob/master/core/src/main/scala/scala/js/gen/js/Compile.scala) There is a very good blog post comparing js-scala and scala.js here.
I didn't look at Scala-GWT.
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
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.
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.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 months ago.
Improve this question
I'm loving node JS and, coming from a Java background, am interested in even trying it out for some projects where node may seem a bit of a stretch, such as a search engine project.
One thing I've been a bit confused by is it seems JavaScript is lacking traditional data structures, for example a set, which has a precise definition extending even beyond computer science as it has been used in mathematics before computers existed (basically a list that doesn't allow duplicates). It seems when using node JS there is no library like Java.util that has these basic data types that I have grown accustomed to, I realize I could create them myself but this just adds more overhead to the project.
Are there any libs for node (or JavaScript in general) that address this? I think node has a lot of potential to replace the use of a language like Java for a lot of projects as it has so many advantages in terms of development speed, but having to recreate data structures that are taken for granted in a more mature platform could be too much overhead for a small project.
I apologize if there are other questions like this, however I spent some time searching and didn't come up with much.
es6 has a Set class built in:
new Set([iterable]);
see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
Collections.js has Lists, Maps, Queues, Sets, and Heaps, all with consistent interfaces. Github.
it seems JavaScript is lacking traditional data structures...
Yes, this is javascript, the very concept and implementation of data structure is done quite differently from languages like Java.
I'm not sure that you're really going to find what you're looking for with Javascript. Howver, there are some libraries like underscore that should make it easier to build the type of structures that you want.
Its no longer true that node.js doesn't have Set and Map objects among other things. node.js has had them since at latest v12.
But of course, if you want libraries like java has, check npm or github. You're not limited to what comes standard in node.js.
Have you looked into Underscore.js? http://underscorejs.org/
It's not a one to one with java.util but it provides a bunch of commonly needed utility functions.
As a lighter and faster alternative to Underscore.js, Lo-Dash (http://lodash.com/) is getting traction those days... But this is not Java.util! :-)
Have a look at this one: https://github.com/chenglou/data-structures
I think it fits what you are looking for.
js-sdsl
A javascript standard data structure library which benchmark against C++ STL.
This library has strict time complexity guarantee and can be used with confidence.
The latest beta version includes iterator functions which can be used like iterator in c++.
Included data structures
Vector
Stack
Queue
LinkList
Deque
PriorityQueue
Set (using RBTree)
Map (using RBTree)
HashSet (for reference only)
HashMap (for reference only)
Usage
To help you have a better use, we provide this API document.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
I am making a library to generate some custom content. It is pretty verbose, about 1100 lines of code. Although the code is very readable and follows strict naming conventions, I am unsure where to document the API available when including the script file. When including the script in a page, intellisense does not pick up the "public" methods, nor does it for jQuery. jQuery has an awesome website for their API ( http://api.jquery.com/ ), but I do not feel inclined to make something as awesome as that.
Where should I document this custom API?
If in comments, what structure of comments would you suggest?
Edit
My point for intellisense was that even good naming conventions are going to require documented API. So I am definitely interested in a generic approach.
I think jsdoc is pretty popular.
http://code.google.com/p/jsdoc-toolkit/
You would document inline, following the conventions on the link. You would distribute a minified/obfuscated production build for deployment, and the documented one for development (i.e. you could do that)
Edit, you could also find more options here: http://o2js.com/2011/05/01/how-to-document-a-javascript-framework/
It's not generic, but if you didn't mind maintaining separate versions for different editors, Visual Studio's IntelliSense will load and parse XML comments in your JavaScript code. I would suppose MonoDevelop and SharpDevelop could use the same file as well, but I don't think IDEs like IntelliJ or Eclipse would get any use out of it...
HTH.
it depends how complex your api is, for my own small libraries i just make a big comment at the top of the file that contains
a quick writeup of what this is all about
if the library operates on html markup some example code that can be copy&pasted
a list of the functions with their parameters and one-line documentation for each
examples of how the library is typically used
notes/warnings/limitations. there's always something weird going on people won't expect
basically this is what you'd put in a C header file.
i guess you could do all the things i mentioned above in a separate file and then use markdown syntax (i'm too lazy ... also i prefer having everything in a single file).
p.s. some people mention inline-comments (i.e. directly where the functions are).
this is of course an option too. but to me it seems this is convenient only if have the docs auto-generated, it is a horrible way to quickly study the documentation inside the file because it lacks a big picture view.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I am currently writing a plugin for jQuery.
Now I wonder how I should create the documentation for this plugin as I guess that there are better ways than directly writing HTML.
However, I do not want to put my documentation into the sourcecode and thereby making finding the correct lines while debugging impossible. Thus, I am looking for a way to separate documentation and sourcecode.
How is the jQuery documentation generated? When looking into the jQuery sourcecode, I don't find any documentation annotations which makes me hope that I might be able to use the same system as they do.
Are the tools they use somehow documented?
I found the following XML-file while looking for an answer http://api.jquery.com/api/ which seems to be generated sometime inside the "build"-process of jQuery.
I would be happy to write my documentation into a similar file and run some tools over it to "prettify" it for displaying it to the user.
How do you create your documentation for jQuery libaries (except putting it into the sourcecode)?
Does anyone know the tools the jQuery team uses (or at least in which format the documentation originally is)?
Many thanks in advance!
It looks like NaturalDocs provides for documentation in external files (as well as in the source code).
The tool that the Prototype team use for documenting Prototype, PDoc, works purely from comments. (The link died, so I removed it.) So you could have .js files that were purely the PDoc comments for your plug-in. 2015: As far as I can tell, PDoc is dead.
I'd advocate having the comments in the source code — classic maintenance issue having them separated — but if you're set on not doing that, fair 'nuff, both of those seem to be options for you.
While I do not agree that adding documentation to source code can make it harder to find the correct lines during debug, I appreciate the sentiment that certain styles of documentation can be verbose and a bit of an eye sore while trying to just "get into the code."
I really like the approach taken by the folks behind underscore.js and backbone.js in their 'annotated source' documentation.
For example, check out the underscore annotated source here. This documentation was generated based in-line comments, as seen in their source on GitHub. But notice this is not the heavy, multi-line documentation style favoring verbosity over brevity. I realize you asked for out-of-file documentation, but I submit this to you as a potential solution to your problem.
You can generate this type of documentation with Docco, which also includes links to Ruby, Python, and even shell script implementations.
have you looked into jsdoc?
JsDoc Toolkit is an application,
written in JavaScript, for
automatically generating
template-formatted, multi-page HTML
(or XML, JSON, or any other
text-based) documentation from
commented JavaScript source code.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
If you look at the source of Google pages with JavaScript, you'll find that the JavaScript is clearly not readable -- or maintainable. For example, all variables and functions are one-letter named (at least, the first 26 are...); there are no extraneous white-spaces or linebreaks; there are no comments; and so on.
The benefits of this compiler are clear: pages load faster, JavaScript execution is faster, and as a bonus, competitors will have a hard time understanding your obfuscated code.
Clearly, Google is using some sort of a JavaScript-to-JavaScript compacting compiler. I am wondering if what they're using is an in-house tool? If not, what are they using? Are there any publicly available (ideally, free/open-source) tools of that sort?
YUI Compressor is a Java app that will compact and obfuscate your Javascript code. It is a Java app that you run from the command line (and would probably be part of a build process).
Another one is PHP Minify, which does a similar thing.
Another one is ShrinkSafe that is part of Dojo but may be used stand-alone (either in a build script, command line or at the website):
http://shrinksafe.dojotoolkit.org/
You may be looking for GWT - it's Java-to-JavaScript rather than JavaScript-to-JavaScript, but you may still find it useful.
I can't comment on what internal tool, if any, we use for JavaScript-to-JavaScript. (To be honest, I don't even know offhand... I'd have to look it up before explicitly not telling anyone :)
It's actually pretty unlikely to be JS->JS, much more so to be Java->JS. These days I believe the recommended JS compressor (for this is what they're called) is the YUI compressor, but others like /packer/ exist
Crockford.com's JSMin is one step in that direction, assuming you're only looking for minimization and not obfuscation.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
Many languages have standard repositories where people donate useful libraries that they want others to have access to. For instance Perl has CPAN, PHP has PEAR, Ruby has RubyGems, and so on. What is the best option for JavaScript?
I ask because a few months ago I ported Statistics::Distributions from Perl to JavaScript. (When I say ported I mean, "Ran text substitutions, fixed a few things by hand." I did not rewrite it.) Since I've used this module a number of times in Perl, I figure that statistics-distributions.js is likely to be useful to someone. So I've put it under the same open source license as the original (your choice of the GPL or the Artistic License). But I have no idea where to put it so that people who might want it are likely to find it.
It doesn't fit into any sort of framework. It is just a standalone library that gives you the ability to calculate a number of useful statistics distributions to 5 digits of accuracy. In JavaScript.
JSAN (JavaScript Archive Network) sounds like the kind of thing you're looking for, but I've never personally used anything from it apart from Test.Builder.
As long as your JavaScript can be dropped in to people's projects without polluting the global namespace or doing things which are liable to cause breakage in other people's code (adding to Object.prototype, for example) I would just stick it somewhere like Google Code as already suggested.
There is no centralized repository for JavaScript. JS Libraries usually have their own plugin-repositories, but for stand-alone scripts, The best way to promote it is to send it to famous website such as ajaxian or mashable
AFAIK, there is no central JavaScript repository, but you might have success promoting it on Snipplr or as a project on Google Code.
You could start a project on SourceForge to contain useful snippets of code like this (or google for snippets to find one).
Perl, Ruby, PHP, etc all have distribution mechanisms built into the language to consume such libraries.
There's not such a thing built into JS.
There are tons of script archives out there - but no "central" JS repo.
Consider packaging it up as a plugin for one of the major Javascript libraries such as jQuery - see http://docs.jquery.com/Plugins/Authoring for more details. This way it can be included on their plugin page which will get it good exposure as they have a huge developer base and it'll be one of their first ports of call when a need arises for such functionality.
Whilst jQuery is one of the most popular frameworks (if not the most) out there, there are a host if other libraries you could consider using in addition to/instead of it.