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

Upgrade source code and builds scripts to ES6/exnext #914

Closed
josdejong opened this issue Aug 6, 2017 · 13 comments
Closed

Upgrade source code and builds scripts to ES6/exnext #914

josdejong opened this issue Aug 6, 2017 · 13 comments

Comments

@josdejong
Copy link
Owner

math.js still uses ES5 as source code. It would be nice to be able to use ES6, since it has a lot of useful improvements like const/let, arrow functions, etc.

To be able to start using ES6 in the source code, we need to:

  • move the source code from lib to src (need to plan this carefully, no open PR's)
  • create a build script which transpiles ES6 code in src into ES5 code in lib (for node.js)
  • extend the script that bundles the source code into dist such that it transpiles to ES5.
  • do some updates in package.json to point to the esnext and es5 code entry points.

Help would be welcome here.

@harrysarson
Copy link
Collaborator

Something like https://lebab.io/ could help with converting the current code base into es6.

@josdejong
Copy link
Owner Author

I hadn't thought about trying to automatically convert code to es6, that could be interesting too, thanks for the tip Harry.

@yoyo837
Copy link

yoyo837 commented Apr 13, 2018

Thanks @josdejong for creating this great library.
This is a good idea, do you have any plans for this?

@josdejong
Copy link
Owner Author

Plans enough but time is the limiting factor here 😄

@harrysarson
Copy link
Collaborator

If we want to use es6 import/export statements we would need to first move all the require() calls into the top level of the module.

@josdejong
Copy link
Owner Author

Yes indeed, good point. I would also like to get rid of all the semicolons :)

In total, it's quite some work, but I think we can do the migration in small steps, something like:

  1. set up a build-script and move the code (as is) to src, have the transpiled code in lib
  2. refactor require() calls with ES6 modules (import / export)
  3. refactoring removing all semicolons
  4. rewrite the examples and documentation to ES6 (where applicable).
  5. where applicable, we can simplify/improve ES5 code by refactoring to ES6. Can be done piece-by-piece I think. Like rewrite use of prototype with class (something like https://lebab.io/ could come in handy there), start using arrow functions where it helps for better readability, replace {foo: foo} with more concise {foo}, etc...

@josdejong josdejong mentioned this issue Jun 6, 2018
7 tasks
@josdejong
Copy link
Owner Author

josdejong commented Jun 6, 2018

I want to setup an ES6 build script today, at first without any refactoring, basically move the code from lib to src. This means that any open pull requests will get merge conflicts but there is nothing big open at this moment except the v5 branch and browser_testing which I will merge first

@josdejong
Copy link
Owner Author

See #1129

@josdejong
Copy link
Owner Author

Implemented via #1129

@josdejong
Copy link
Owner Author

Something like https://lebab.io/ could help with converting the current code base into es6.

I've played around a bit with lebab, it's impressive. Converting var to const/let works nicely. Converting require to import/export gives issues, we need some refactoring here and there to make this work.

@harrysarson
Copy link
Collaborator

Converting require to import/export gives issues, we need some refactoring here and there to make this work.

Am I correct in saying this is because lebab is expecting require to be at the top level and we call require from functions?

@josdejong
Copy link
Owner Author

josdejong commented Jun 9, 2018

Yes exactly, that is one of the reasons (see related discussion #71). And there are other places where we simply have to refactor stuff like using import * as utils from '../../utils' instead of importing specific functions. And for some reason some stuff breaks like type.Complex is not defined, not yet sure what's going wrong there.

@josdejong
Copy link
Owner Author

lebab was of great help so far! Saved a lot of work refactoring var into let/const

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants