Skip to content
This repository was archived by the owner on Feb 19, 2018. It is now read-only.

Commit 4ab0913

Browse files
Document that consolidates our consensus on adopting various ES2015+ features into CoffeeScript (#30)
1 parent 7cb3365 commit 4ab0913

File tree

2 files changed

+118
-2
lines changed

2 files changed

+118
-2
lines changed

Features.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# ESNext Features to Support in CoffeeScript
2+
3+
Per the [README](./README.md), we have two main goals for the future of CoffeeScript: adding support for important ES2015+ (ESNext) features that CoffeeScript currently lacks, and changing CoffeeScript’s output to be ESNext code. This document covers the former; see [Compiler.md](./Compiler.md) for the latter.
4+
5+
Features are ordered by priority, which is determined (subjectively) by how important each feature is to the CoffeeScript community. The most important criterion is whether the lack of specific feature affects CoffeeScript’s viability for a potential project: if a developer must choose between CoffeeScript and a particular library or framework, whatever missing feature is causing that choice to need to be made is a top priority for us to fix. This list is based on the [issues](https://github.com/coffeescript6/discuss/issues) for this repo and the discussion in [#8](https://github.com/coffeescript6/discuss/issues/8).
6+
7+
## Top Priority
8+
9+
These features affect interopability and should take priority over all other features. These should be implemented ASAP in the current compiler, in addition to any new compiler that gets created later.
10+
11+
### Modules: `import` and `export` [(#7)](https://github.com/coffeescript6/discuss/issues/7)
12+
13+
This is in progress [here](https://github.com/jashkenas/coffeescript/pull/4300) as a pull request to the original CoffeeScript compiler.
14+
15+
### Classes [(#22)](https://github.com/coffeescript6/discuss/issues/22)
16+
17+
We have consensus that there needs to be some way for CoffeeScript to output ESNext native `class foo extends bar` syntax, in order to interoperate with libraries that use ECMAScript classes. Waiting on a consensus for the approach and syntax in [#22](https://github.com/coffeescript6/discuss/issues/22).
18+
19+
> **This is a breaking change for the current compiler.** Either the `class` keyword gets redefined, or we’re adding a new keyword to implement the new behavior (and old code that might have used that now-reserved keyword could break). We would need to choose whether the breaking change would be opt-in (the current behavior unless a flag was set) or opt-out (the new behavior unless a flag was set). If we go with the “new `esclass` keyword” proposal, the breaking change would likely be opt-*out*.
20+
21+
### Template literals [(#28)](https://github.com/coffeescript6/discuss/issues/28)
22+
23+
Some new libraries require support for ECMAScript template literals, which are incompatible with CoffeeScript’s backticks. Waiting on consensus for the approach and syntax in [#28](https://github.com/coffeescript6/discuss/issues/28).
24+
25+
## Medium Priority
26+
27+
These features aren’t required for CoffeeScript to be used in any project, but there’s great desire in the community for these to be added.
28+
29+
### `const` assignment operator [(#1)](https://github.com/coffeescript6/discuss/issues/1)
30+
31+
For whatever reason, `let` and `const` are among the most popular features introduced by ES2015. Per [#1](https://github.com/coffeescript6/discuss/issues/1), we have consensus that there should be some way to force variable assignment to use `const` instead of `var`. The syntax for such a “`const` assignment” shall be:
32+
33+
```coffee
34+
foo := 42
35+
```
36+
which becomes:
37+
38+
```js
39+
const foo = 42
40+
```
41+
42+
This has the advantage that it’s not a breaking change; currently `:=` fails to compile. Adding support for this new operator includes mimicking with `const` what CoffeeScript currently does with `var`, in that it tracks all assigned variables and initializes them together in one `var` statement at the top of the scope.
43+
44+
There is no need to support `?:=`, since by definition constants can’t be reassigned.
45+
46+
Nothing else would be changed by adding this new operator. Normal assignment is handled as it is today, with `var`. Even though using `:=` would cause `const` to be in the generated output, this feature is “opt in” like modules and the same warning would apply about transpiling CoffeeScript’s output.
47+
48+
### `async`/`await` [(#10)](https://github.com/coffeescript6/discuss/issues/10)
49+
50+
This isn’t even standardized yet; it’s not part of ES2015 or ES2016, though support has started appearing in browsers.
51+
52+
CoffeeScript’s version would add only the `await` keyword, which would automatically cause CoffeeScript to output an `async` keyword where needed. This behavior is similar to how generators are handled, where the presence of a `yield` keyword causes CoffeeScript to declare the function as `function*`: the presence of `await` would cause CoffeeScript to declare its associated function with `async`.
53+
54+
So to take the example from http://stackabuse.com/node-js-async-await-in-es7/, this JavaScript:
55+
56+
```js
57+
var request = require('request-promise');
58+
59+
async function main() {
60+
var body = await request.get('https://api.github.com/repos/scottwrobinson/camo');
61+
console.log('Body:', body);
62+
}
63+
main();
64+
```
65+
66+
could be written in CoffeeScript as:
67+
68+
```coffee
69+
request = require 'request-promise'
70+
71+
main = ->
72+
body = await request.get 'https://api.github.com/repos/scottwrobinson/camo'
73+
console.log 'Body:', body
74+
75+
main()
76+
```
77+
78+
> **This is a breaking change for the current compiler.** The `await` keyword is not currently reserved, so adding it as a reserved word would break any code that currently uses `await` as a variable or function name. We would need to choose whether the breaking change would be opt-in (no `await` unless a flag is set) or opt-out (`await` is a reserved word unless a flag is set). This breaking change would likely be opt-*out*.
79+
80+
## Low Priority
81+
82+
These are nice-to-have features that should be implemented as time permits, probably only in the “new” compiler if one gets created. Any change that causes ES2015 output and isn’t opt-in needs to either be enabled by a flag or only in the new, ESNext-outputting compiler.
83+
84+
### Fat arrows `=>` output as `=>` [(#8)](https://github.com/coffeescript6/discuss/issues/8)
85+
86+
**Only for the new ESNext-outputting compiler, or the original compiler behind a flag.**
87+
88+
Fat arrows should be transpiled into ES2015 `=>`. They took our good idea, let’s celebrate by using it.
89+
90+
### Inferred `let` assignment [(#1)](https://github.com/coffeescript6/discuss/issues/1)
91+
92+
**Only for the new ESNext-outputting compiler, or the original compiler behind a flag.**
93+
94+
When a variable isn’t declared using the new `:=` operator that produces `const` (see above), CoffeeScript should automatically declare it with `let` whenever possible.
95+
96+
### `for … of` [(#11)](https://github.com/coffeescript6/discuss/issues/11)
97+
98+
**Only for the new ESNext-outputting compiler, or the original compiler behind a flag.**
99+
100+
There should be some way to output ESNext `for … of`, perhaps via a new `for` syntax. Awaiting consensus.
101+
102+
## TODO
103+
104+
These are ESNext features where a consensus has yet to be reached on whether CoffeeScript should support them.
105+
106+
### Getters and setters [(#17)](https://github.com/coffeescript6/discuss/issues/17)
107+
108+
## No Action
109+
110+
These are other features that have been discussed, but the consensus at the moment is that no action should be taken to implement them.
111+
112+
### Decorators [(#9)](https://github.com/coffeescript6/discuss/issues/9)
113+
114+
### Type annotations [(#12)](https://github.com/coffeescript6/discuss/issues/12)
115+
116+
### Destructuring assignment [(#18)](https://github.com/coffeescript6/discuss/issues/18)

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ We also should come up with a defined leadership structure and formal process fo
7171

7272
### Framework Incompatibilities: Supporting Essential ES2015 Features
7373

74-
CoffeeScript is hemorrhaging marketshare the longer that incompatibilities with popular frameworks and build tools go unaddressed. We must support modules and classes ASAP, and that means building them in the current compiler. In the case of classes, that probably means a flag to opt-in to new ES2015 class syntax and output. Any other missing ES2015 features that preclude CoffeeScript’s selection for a project must also be addressed immediately, as patches to the current compiler.
74+
CoffeeScript is hemorrhaging marketshare the longer that incompatibilities with popular frameworks and build tools go unaddressed. We must support modules and classes ASAP, and that means building them in the current compiler. In the case of classes, that probably means a flag to opt-in to new ES2015 class syntax and output. Any other missing ES2015 features that preclude CoffeeScript’s selection for a project must also be addressed immediately, as patches to the current compiler. See [proposal for supporting ES2015+ features here](./Features.md).
7575

7676
### Developer Happiness: Supporting Optional ES2015+ Features
7777

78-
Features that developers enjoy in ES2015 that are appropriate to implement in CoffeeScript, like `const`, should be implemented as time permits. These features should be implemented in a new compiler, assuming we build one; and possibly also in the old compiler too if such an implementation is easy and doesn’t break backward compatibility. Any feature implemented in both compilers should have identical syntax. See [technical discussion of how to implement a new compiler here](./COMPILER.md).
78+
Features that developers enjoy in ES2015 that are appropriate to implement in CoffeeScript, like `const`, should be implemented as time permits. These features should be implemented in a new compiler, assuming we build one; and possibly also in the old compiler too if such an implementation is easy and doesn’t break backward compatibility. Any feature implemented in both compilers should have identical syntax. See [technical discussion of how to implement a new compiler here](./Compiler.md).
7979

8080
### Modernizing Output
8181

0 commit comments

Comments
 (0)