Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert to JS #22

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Convert to JS #22

wants to merge 8 commits into from

Conversation

gitgrimbo
Copy link

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