|
| 1 | +* Start date: 2020-04-05 |
| 2 | +* Scope: Collective |
| 3 | +* RFC PR: <!-- leave this empty --> |
| 4 | +* Implementation issue(s): <!-- leave this empty --> |
| 5 | + |
| 6 | +# Summary |
| 7 | + |
| 8 | +Adopt JavaScript 2015-2019 syntax supported natively by Node.js where appropriate. |
| 9 | + |
| 10 | +## Basic example |
| 11 | + |
| 12 | +An example of a library updated to leverage ES2015-2019 features can be seen here <https://github.com/vfile/vfile-message/pull/8> |
| 13 | + |
| 14 | +## Motivation |
| 15 | + |
| 16 | +There are two goals: |
| 17 | +1. Easing contribution for new members |
| 18 | +2. Allow for additional instrumentation and tooling |
| 19 | + |
| 20 | +### Easing Contributing |
| 21 | + |
| 22 | +The [State of JS survey 2019](https://2019.stateofjs.com/), indicates that 85-90% of JavaScript developers have used ES2015 features [[1]](https://2018.stateofjs.com/javascript-flavors/es6/), which holds consistent with the 2018 results where 86.3% indicated they had used it and would use it again [[2]](https://2018.stateofjs.com/javascript-flavors/es6/). |
| 23 | + |
| 24 | +### Additional Instrumentation and Tooling |
| 25 | + |
| 26 | +Tools like ESLint provide additional analysis for features using ES205-2019 syntax. [[3]](https://eslint.org/docs/rules/#ecmascript-6) [[4]](https://github.com/xjamundx/eslint-plugin-promise) |
| 27 | + |
| 28 | +## Detailed design |
| 29 | + |
| 30 | +Leverage ES2015+ features where applicable with Unified: |
| 31 | +* [`class`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/class) for representing classes |
| 32 | +* [Default parameters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Default_parameters) to represent default values |
| 33 | +* [`let`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let) and [`const`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const) for block scoped variables |
| 34 | +* [Arrow functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions) where `this` cannot/should not be changed with [`.bind`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind) |
| 35 | +* [Rest parameters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters) for representing an arbitrary number of parameters ([arguments](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments)) |
| 36 | +* [Promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) for values that may resolve later (already used in Unified) |
| 37 | +* [Async Await](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function) syntax for Promises |
| 38 | + |
| 39 | +Platform support for these features can be seen at: |
| 40 | +* <https://kangax.github.io/compat-table/es6> |
| 41 | +* <https://kangax.github.io/compat-table/es2016plus> |
| 42 | + |
| 43 | +The features listed above are supported on: |
| 44 | +* Node 8, 10, and 12 LTS |
| 45 | +* Chrome, Edge, Firefox, and Safari |
| 46 | + |
| 47 | +## Drawbacks |
| 48 | + |
| 49 | +There are two main drawbacks: |
| 50 | +1. Changes are primarily internal |
| 51 | +2. Legacy support |
| 52 | + |
| 53 | +### Changes are Primarily Internal |
| 54 | + |
| 55 | +These changes would not change the public API of Unified, VFile, Remark, etc. |
| 56 | +This would be a set of internal changes which could benefit maintainability long-term, but would not have an immediate benefit for downstream adopters. |
| 57 | + |
| 58 | +### Legacy Support |
| 59 | + |
| 60 | +While many browsers and all active release lines of Node support ES2015-ES2019. |
| 61 | +Not all platforms do, Nod.js 4 and earlier, Internet Explorer browser, and [Rhino](https://github.com/mozilla/rhino) do not fully support ES2015. [[5]](https://kangax.github.io/compat-table/es6/) |
| 62 | +To continue use on these platforms code would need to be transpiled to ES5, using [Babel](https://babeljs.io), [TypeScript](https://www.typescriptlang.org/), or a similar tool. |
| 63 | + |
| 64 | +## Alternatives |
| 65 | + |
| 66 | +What other designs have been considered? |
| 67 | +What is the impact of not doing this? |
| 68 | + |
| 69 | +## Adoption strategy |
| 70 | + |
| 71 | +> If we implement this proposal, how will existing unified developers adopt it? |
| 72 | +
|
| 73 | +These changes would mostly be internal, most public APIs would be completely unchanged, APIs that do change, would likely have subtle changes. |
| 74 | + |
| 75 | +Adoption of this would take a bottom up approach, starting at the lowest level dependencies (vfile, vfile-message, etc), working up to the shared libraries (unified, unified-engine, etc), then into the language specific tooling (remark, rehype, retext, redot, etc). |
| 76 | + |
| 77 | +> Is this a breaking change? |
| 78 | +
|
| 79 | +This is open for debate since Unified does not have an explicit browser/Node support matrix. |
| 80 | +These changes would be primarily non-breaking, we could mark them as breaking to communicate the implicit change in support matrix. |
| 81 | + |
| 82 | +> Can we write a codemod? |
| 83 | +
|
| 84 | +There is an existing codemod that can help with this <https://github.com/lebab/lebab> |
| 85 | + |
| 86 | +> Should we coordinate with other projects or libraries? |
| 87 | +
|
| 88 | +This would primarily be internal. |
| 89 | + |
| 90 | +## Unresolved questions |
| 91 | + |
| 92 | +- [ ] Would this be considered a breaking change? |
0 commit comments