-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Support yield statements #19
Conversation
954f91a
to
d14e0a8
Compare
@twada Also, just FYI - I don't know if you are an Intellij user, but if so, I hope you find this useful: https://github.com/jamestalmage/intellij-code-to-string-js |
61e204a
to
08955f8
Compare
'}', | ||
'', | ||
'var gen = myGenerator(3);', | ||
'gen.next().value.then((val) => gen.next(val)).catch(done);' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This exhausts the generator similar to how co
would.
We could also just pull in co
as a dev dependency if you want, but I opted to avoid adding another one for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but I opted to avoid adding another one for now.
Agreed. Thanks.
@jamestalmage I've released espower 1.1.0 and restarted Travis build.
Wow this is so useful for creating our tests! |
woot! Green! |
08955f8
to
5fb7050
Compare
try { | ||
top = ast = esprima.parse(jsCode, parserOptions()); | ||
} catch (e) { | ||
ast = esprima.parse(wrappedInGenerator(jsCode), parserOptions()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you add inline comments explaining why this catch clause is needed and how it work? (just like a description of this pull-req)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!!
From what I can tell, there is no way to get esprima to parse a yield statement that is not wrapped in a generator function. To work around this: try to parse normally first, then try parsing by wrapping with a generator statement. If it works the second time, then we assume it is due to a yield statement.
5fb7050
to
7f9ac14
Compare
@jamestalmage Thank you for your great contribution! |
awesome! Thanks! |
Just released power-assert-formatter 1.2.0. Thank you for your great contribution! |
From what I can tell, there is no way to get esprima to parse a yield statement that is not wrapped in a generator function.
To work around this, I do the following:
This will require additional modifications on the instrumentation side of things before the output looks correct (my test will need to be modified at that point). The result of the yield is not captured.