nau / jscala

Scala macro that produces JavaScript from Scala code.
MIT License
205 stars 25 forks source link

Macro annotation could generate singletons, object literals, functions, too #18

Open nafg opened 10 years ago

nafg commented 10 years ago

...so that they can be used in scala, and rendered to javascript.

This would require a different approach than adding a method to the companion object, like the one I described here: https://groups.google.com/d/msg/jscala-user/b8QV0oofg3c/w_95Bjx7GQ0J

nafg commented 10 years ago

Alternatively, jscala might push all annotated definitions to a queue, and then the application could just output all the definitions in bulk, without having to request them by name. Another approach would be, a(n alternative) javascript { } block would return not only the AST, but also a list of dependencies invoked inside it. Dependencies would have some unique id so that you could output them only once per scope. The downside of this is you aren't informed of the dependencies until you invoke them, so if you use it in an ajax response you'd have to add the dep to the page then, rather than the page referring to the dep to begin with.

In either case tracking definition usages needs to be scoped, preferably statically via an implicit Scope instance. (There could be a global default for simple applications.)