Open patgrasso opened 7 years ago
@patgrasso -- I don't see an escodegen branch in that repo. Did you ever this working? What did you learn from your experimentation?
One consideration: ndarray is 6.4kb minified whereas escodegen is 97kb minified.
Unfortunately I foolishly did not push any of my experimental changes and had a disk error. To reduce the build size, astring can be used instead of escodegen, which is ~16kb minified and supposedly much faster. Runtime performance should be unaffected barring constructor compilation. Additionally, it might be possible to move most of the code generation into the build process rather than occurring at runtime. I'll do some investigation to that end if the additional 16kb would still be too costly.
Some solutions have been proposed to reduce the string concatenation (#11, #12). I'd like to pitch another alternative: code generation from a dynamically generated AST using escodegen.
You could have something like this:
esprima or acorn can also be used to generate the AST for the static portions of the code:
This would allow for runtime generation of the classes and retention of efficiency, but in a more controlled and maintainable way. It also reads somewhat intuitively (I've been playing around with escodegen, the above are working examples).
Let me know what you think. You can see updates in my fork patgrasso/ndarray (check out the escodegen branch).