Skip to content

Convert to JS#22

Open
gitgrimbo wants to merge 8 commits intosgentle:masterfrom
gitgrimbo:convert-to-js
Open

Convert to JS#22
gitgrimbo wants to merge 8 commits intosgentle:masterfrom
gitgrimbo:convert-to-js

Conversation

@gitgrimbo
Copy link
Copy Markdown

References #18.

I would say this PR is indicative at the moment and will require some rework, which I'm happy to do.

E.g. I have included two variations of automatic conversion from coffee-script to JS, using:

I have also left most of the indentation alone in order to simplify diffs. The finished code would require proper formatting.

The PR builds on the decaffeinate conversion as I preferred its output.

This commit contains two variations of conversion. The most appropriate
one should be used in a refactored PR.

decaffeinate:
https://github.com/decaffeinate/decaffeinate

- pros
  - retains comments
  - uses es6
    - let and const
    - template strings
  - lists recommendations for further conversion improvements
  - uses one declaration per line (personal preference)
- cons
  - compact object literals on one line (personal preference)
    - e.g. current = {version, support, usage: 0};
  - ifs on one line (personal preference)
    - e.g. if (nums == null) { nums = {}; }

js2coffee:
https://github.com/js2coffee/js2coffee

- pros
  - TODO
- cons
  - TODO
js-beautify -r --indent-size 2 INPUT-FILE
bin.js now requires caniuse-cli.js, and not the coffee-script files.

The new caniuse-cli.js file is a CLI-only file that requires
caniuser.decaffeinate.js

caniuse.decaffeinate.js now provides two main functions:
- toStreams() which will output to either default stdout and stderr,
  or two streams of your choice.
- asString() which will return the output as a string.

This separation will make it simple for other JS code to use the module
to extract the output and use it in other situations, e.g. converting
to HTML.
So we can use the args parser (and more importantly, the default
argument values it provides) in other code, e.g.:

```js
const caniuse = require("caniuse-cmd");

const args = process.argv.slice(2);

console.log(caniuse.asString(args));
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant