Transparent, bidirectional Transpiler

67 views
Skip to first unread message

Raine Lourie

unread,
Apr 3, 2014, 6:38:00 PM4/3/14
to js-t...@googlegroups.com
I recently coded a library in CoffeeScript and my friend pointed out that it would never get contributions. It's a valid point. Native JS makes your library much more accessible to contributors. 

This got me thinking, I want to be able to write JS using a cleaner syntax like CoffeeScript, but output JS that is indistinguishable from hand-written code. Furthermore, I'd like to be able to convert Javascript to this more succinct language for editing, then back to Javascript when saved. This would allow seamless use of this tool while not diverging from the vanilla JS community. I envision this integrated into editors like Sublime Text. Alternatively it could be a grunt task.

Some of the features that could be transpiled to/from hand-written code:
  • pythonic whitespace
  • string interpolation
  • function arrow syntax
  • multiline strings
  • bracketless objects
  • @instancevar
  • existential operator
  • for... in over arrays
  • for key, value in obj
  • array slicing
  • chained comparisons
A challenge will be editing a js file while preserving existing coding conventions and unedited portions as-is. I also have no experience with compilers, parsers, etc although I have an interest.

I want to get some initial feedback on the idea from other experienced JS developers.
  1. Has this already been done? (I couldn't find anything bidirectional like this in the List of Languages That Compile to JS).
  2. Is this a good idea?
Your honest feedback is appreciated! I'd have to learn a lot to pull this off and I'd like to see if it's worth pursuing before diving in.

Thank you!
-Raine

John J Barton

unread,
Apr 3, 2014, 6:45:07 PM4/3/14
to js-t...@googlegroups.com
Many of the items on your wish list exist in es6. Take a look at the source for traceur compiler to get a sense of how it might look.

jjb


--
--
http://clausreinke.github.com/js-tools/resources.html - tool information
http://groups.google.com/group/js-tools - mailing list information

---
You received this message because you are subscribed to the Google Groups "js-tools" group.
To unsubscribe from this group and stop receiving emails from it, send an email to js-tools+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Raine Lourie

unread,
Apr 3, 2014, 6:50:13 PM4/3/14
to js-t...@googlegroups.com
Thanks John. That'll be great. Pythonic whitespace is still a big goal of mine with this.

I don't think a typical compiler will work in my situation since the output must match the original file's coding conventions for this to be a seamless tool.

-Raine

Raine Lourie

unread,
Apr 3, 2014, 6:55:27 PM4/3/14
to js-t...@googlegroups.com
That is, the syntax would be used just while existing and can be used on existing js files.

Andrei Neculau

unread,
Apr 19, 2014, 5:26:59 PM4/19/14
to js-t...@googlegroups.com
Raine,

If you worry people cannot contribute in coffeescript (any good developer should be able to contribute on a small scale in any language, especially similar ones), then there's no better solution then just writing javascript.

--
If you want to pursue your idea though, I'll add pressure to your lack of experience :)


tl;dr I think the "problem" lies in defining a core AST. Then your language and JavaScript itself is nothing but a view to that AST.
Alternatively you can take one of the well-known JS ASTs and see if you can create CoffeeScript-like "views" out of it.

PS: if you want to experiment a bit with ASTs, have a look at PEGjs and hyperglot

Zach Kelling

unread,
Apr 19, 2014, 5:32:07 PM4/19/14
to js-t...@googlegroups.com
I think this is a great idea and something I've considered as well...there are quite a few JavaScript developers who will stubbornly refuse to use, let alone contribute to a CoffeeScript project. I would use this myself.

-- 
Zach Kelling

Raine Lourie

unread,
May 10, 2014, 9:30:54 AM5/10/14
to js-t...@googlegroups.com
@Andrei: Thanks for the encouragement! It's not that I think people cannot contribute to CoffeeScript, but people are more familiar with Javascript and not everyone learns everything. Making it as easily as possible to contribute is key to Open Source. And for better or worse, as @Zach said, sometimes developers are just stubborn! With a bidirectional CoffeeScript-like language, I could work in my preferred syntax while participating in the vanilla JS community and keeping barriers of entry low.

The AST won't work because the output must match the formatting of the source file. This is a different design goal than most transpilers. Matching the formatting of the output will be what allows full integration with someone who is editing the same file with vanilla js. Maybe it's possible if the AST contains information about the source file formatting. Again, I'm very new when it comes to language and compiler design.

Thanks! I have limited time for fun coding projects now, but I'm eager to keep this idea alive for when the time is right.

-Raine


You received this message because you are subscribed to a topic in the Google Groups "js-tools" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/js-tools/wvhDPWC34RI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to js-tools+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages