This is a proposal. I’m looking for comments, and eventually project help. Buried this this proposal is an Atom package that is part of this effort.
ES6 is starting to offer many CS features, like classes and fat arrows, but ES6 is stuck with the awful noisy C syntax. But the differences are getting so small that this ancient syntax is virtually the only difference.
Eventually an Atom package will allow you to open a real JS ES6 file, edit in the Atom editor as JSW, and save back again as the same JS. You usually won’t even need a JSW file format. This solves the problem in contributing to JS projects using coffeescript syntax.
The readme …
The utility in this repository is a bi-directional translator between JS and JSW.
# JSW -> func1 arg1, arg2 var hash1 = key1: val1 key2: val2 key3: block let x = y func2 x if q and z func1 "This is text spread over two lines."
JSW Overall Features
JSW syntax is much less noisy than the JS syntax, just like Coffeescript. No more unnecessary parens and braces. No typing of
Some syntax features, like simple line continuations and blocks, are an improvement over Coffeescript.
The translation of JSW to/from JS is one-to-one and reversible. Changing JS to JSW and back preserves the original text. This means that JS commits to GIT will have minimal lines changed, only where JSW changed.
The JSW utility in this repository includes translation to/from JS and JSW. Both directions are equally supported.
The JS produced by translating JSW is easily predictable. It consists of simple short mappings like
->. Writing JSW and debugging with the translated JS takes no mental effort.
JSW takes advantage of new ES6 features. The syntax
->is a replacement for
functionwhile ES6 provides
=>with no change in JSW. The combination of the two matches coffescript.
Coffeescript highlighting works pretty will with JSW (see sample above)
An Atom editor extension, coffee-js-translator, is planned that allows opening normal JS, editing in JSW, and saving in the original JS. This allows working with others who don’t even know about JSW. One does not even need to have JSW files.
JSW features not in Coffeescript
- Most of ES6
- Simple continuations that can break anywhere, including strings
- No hashes require braces
Coffeescript features not in JSW
- Some ES6 replacements not as complete (e.g. Classes)
- All statements are expressions
thisreference in params and object declrations
- Matching ES6 features often have different syntax (e.g. interpolation)
- Combined comparison (0 < x < 1)
JSW to JS Text Mapping
When JS is converted to JSW, a compact set of metadata is added to the bottom of JSW as a comment. This is very similar to how Coffeescript provides a source map. If support for exact JS text matching is not required this can be disabled. In general it can be ignored and the Atom package JSW will hide that metadata when editing.
You are looking at it. No coding has started. Even this readme is a work-in-progress.
Copyright by Mark Hahn using the MIT license.