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

feat: return transformed code as a string, do not wrap in vm.Script #9253

Merged
merged 13 commits into from
Dec 1, 2019

Conversation

SimenB
Copy link
Member

@SimenB SimenB commented Dec 1, 2019

Summary

Extracted from #9252. Since jest-runtime is the one injecting arguments into the module wrapper, it should also say which arguments those are. This makes @jest/transform less coupled to the module wrapper, and thus to Jest's use case. It's marked as a breaking change since it changes @jest/transform's interface, but it's not a breaking change for users of Jest.

Test plan

Added some tests

CHANGELOG.md Outdated Show resolved Hide resolved
@SimenB SimenB force-pushed the pass-in-module-wrapper-arguments branch from ef1a97e to 9289c94 Compare December 1, 2019 16:27
@SimenB
Copy link
Member Author

SimenB commented Dec 1, 2019

We could ditch the wrapping in @jest/transform entirely, and instead do that in jest-runtime directly. It's a weird coupling anyways.

EDIT: Currently doing this, and it's way cleaner. Probably something I should have done when @jest/transform was split out from jest-runtime

@SimenB SimenB force-pushed the pass-in-module-wrapper-arguments branch from 56ebbf7 to 4965e77 Compare December 1, 2019 20:05
@SimenB SimenB changed the title feat: pass in wrapper arguments to transformer feat: return transformed code as a string, do not wrap in vm.Script Dec 1, 2019
@SimenB SimenB requested a review from thymikee December 1, 2019 20:06
@SimenB
Copy link
Member Author

SimenB commented Dec 1, 2019

@thymikee I've moved the entire wrapping into jest-runtime, I think it turned out way cleaner. Now @jest/transform does not have to care about the wrapper at all, neither creating it nor passing the correct arguments to it. I've also made jest-environment not care about the wrapper, since it actually doesn't care. It just invokes the script passed to it and returns the result. I'm quite happy with how this turned out


scriptTransformer.transform('/fruits/banana.js', {
// to make sure jest isn't declared twice
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was broken anyways - if we declared it and then removed it here, we would still inject it from jest-runtime

Copy link
Collaborator

@thymikee thymikee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lovely

@SimenB SimenB merged commit 1d8245d into jestjs:master Dec 1, 2019
@SimenB SimenB deleted the pass-in-module-wrapper-arguments branch December 1, 2019 21:45
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants