Comments (17)
https://github.com/olov/defs seems like a great suggestion, thanks!
from regenerator.
I can do it. But there is a problem - defs uses non-harmony esprima so it's fails with error on trying to parse code with generator.
from regenerator.
Hi! I'll be happy to help out in making sure that defs can be used in the best way possible together with es6-transpiler. defs is usable both as a command-line tool and as an API - see the README for more info.
How would you like to integrate it with regenerator? One option is just to let regenerator spit out code with const and let intact, and then feed that code directly into defs. If regenerator currently changes const and let to var's (without sufficient analysis and transformation) then that's not kosher es6 and thus leaving const and let intact is the better thing to do, so that end-users at least have the option of running it through defs.
To minimize overhead, it's certainly possible to integrate it deeper with defs in a way where you hand off your transformed AST to defs and it does further transformations, and you can then just decompile the AST with escodegen. Even though defs works hard to do do minimal alterations of the input source code, it simultaneously transforms the AST so everything is already in place to handle this mode of operation, save for a configuration parameter or two (which I'll be happy to add).
In either case, I'd be glad if you'll be able to use defs as a dependency instead of a fork, so that we get maximum benefit upstream.
from regenerator.
Hi @olov! How would you feel about exposing an interface to defs
that takes an AST (rather than a string of source code), transforms it, and returns the transformed AST? That would remove the dependency on specific esprima
versions, I think, and allow regenerator
to use defs
to convert all let
and const
declarations to var
declarations before hoisting declarations (see https://github.com/facebook/regenerator/blob/master/lib/hoist.js). To be clear, since regenerator
relies on hoisting all declarations into the outer function scope (so only assignments remain in the inner function), I think the easiest path is to convert everything to var
s and then let regenerator
pick up after that conversion.
As a side-note, regenerator
currently uses https://github.com/benjamn/recast to reprint ASTs with minimal alterations (that's the whole point of recast
), so escodegen
should not be necessary.
from regenerator.
I think allowing an AST as input to defs is the way to go. AST output support is already there so we're set with that.
As for pipeline order defs -> regenerator vs regenerator -> defs, I guess that boils down to where to add any extra code and if I understand you correctly it would require a substantial code effort from your side to have regenerator run first? If so let's go with defs first. defs currently relies on receiving a pure ES5 + constlet AST, so it could have some issues with receiving an AST with generators although I'm pretty sure that we should be able to resolve any of such issues pretty easily. I'll do the first minimal changes for this in a new branch for you to try out.
from regenerator.
@benjamn There is also need to be an option to not to calling defs. In my case (in es6-transpiler) I already translated let/const by using defs before calling regenerator.
from regenerator.
So with olov/defs@1f0a9e9 defs will accept an AST as input. The only extra analysis added is that it takes yield expressions into account when deciding whether it can transform a loop closure into an IIFE or not. Let me know if there are any issues!
from regenerator.
@termi yeah, that can either be done with an explicit regenerator option or perhaps more easily (and robustly) by having regenerator walk the AST once and detect whether there are any constlets in there. Iff so, defs is called.
from regenerator.
In particular, if regenerator is to support anything else than function* and yield (let me know if it already does), say like for-of, then defs need to do so too (in particular in its analysis phase) or else the constlet transformation will be buggy.
from regenerator.
I see no one's done this yet. I will start doing this right now. Sorry for delay - I am in hospital now and very sick.
from regenerator.
@benjamn There is a problem with recast.parse: neither defs nor ast-types doesn't work with File-node wrapper from recast parser. So I have to do something like this:
var recastAst = recast.parse(source, recastOptions);
var ast = recastAst.program;
ast = defs(ast, { ast: true }).ast;
recastAst.program = transform(ast);
recast.print(recastAst, recastOptions);
from regenerator.
@termi just a minor comment on that example (not answering the problem you're having).
Instead of doing ast = defs(ast, { ast: true }).ast;
you can just do defs(ast, { ast: true });
. defs manipulates the AST it receives without copying it first.
from regenerator.
@olov It's quite logical! Thx. BTW, make sure you have a latest version of defs in npm.
from regenerator.
I've been waiting with releasing defs 0.6.0 to make sure we have everything in place for what's needed for regenerator first (don't want to break API immediately after). Once I hear ACK I'll release!
from regenerator.
@termi that seems like a reasonable way to handle the File
node type. Sorry for the confusion!
from regenerator.
@olov I guess that's all. You may now release defs 0.6.0
from regenerator.
defs 0.6.0 released
from regenerator.
Related Issues (20)
- Runtime - Transformation of async/await try...catch prevents inspecting variable defined in catch statement
- Is the copyright @ 2013 kept knowingly or it should be changed every year like other Open Source projects of Facebook?
- "The Function constructor is eval" warning from Mozilla Addons Linter HOT 2
- regeneratorRuntime is not defined on cli
- Minified Error, do you have minified version of it?
- Problem on both using Babel babel/plugin-transform-classes and regenerator for async class methods
- Question: why isn't the minified version of regenerator runtime published?
- docs: NPM package `regenerator-runtime` registry repository link broken
- runtime.js should read Symbol values dynamically HOT 1
- Not able to update the chrome version to 58.
- Latest version error HOT 5
- Crashes when processing sparse array with `await`
- regenerator-runtime new version 0.13.11 not tagged as latest HOT 1
- I need to delete this issue
- Sandbox bug report
- Sandbox bug report
- Compile to pure function
- What changed in version 0.14.0? HOT 2
- `npm deprecate` regenerator-runtmie@<0.13.8 HOT 2
- Generator spec reference link is outdated in `runtime.js` file
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from regenerator.