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:
lib to src (need to plan this carefully, no open PR's)src into ES5 code in lib (for node.js)dist such that it transpiles to ES5.Help would be welcome here.
Something like https://lebab.io/ could help with converting the current code base into es6.
I hadn't thought about trying to automatically convert code to es6, that could be interesting too, thanks for the tip Harry.
Thanks @josdejong for creating this great library.
This is a good idea, do you have any plans for this?
Plans enough but time is the limiting factor here :smile:
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.
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:
src, have the transpiled code in librequire() calls with ES6 modules (import / export)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...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
See #1129
Implemented via #1129
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.
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?
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.
lebab was of great help so far! Saved a lot of work refactoring var into let/const
Most helpful comment
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
v5branch andbrowser_testingwhich I will merge first