-
-
Notifications
You must be signed in to change notification settings - Fork 75
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
Named export arrow function name inference #125
Comments
@tomchentw within reason we've been trying to support ES modules and other bleeding edge ES features provided by babel -- I'd definitely accept a pull request, with the caveat that we should be fairly careful, since we've accidentally created invalid syntax in the past trying to address the issue of function name preservation. A good way to interact with me directly is in the slack I've created for the various devtools I help manage: |
I can confirm this is fixed by #126. For |
@tomchentw Upgrading and running jest with I'd like to request the issue be reopened. |
That's because of issues with jest caching; it should be a separate issue. |
Description
When a React component is defined as a named export arrow function, the name of it cannot be inferred correctly in jest coverage mode. (To be precise, it's node that cannot infer it) It generates inconsistent result compared with the stored snapshots.
What's a named export arrow function?
Digging in
It turns out the above
MyFancyComponent
will be transpiled (properbabel-preset-env
) into this:where the instrument code is inserted along with the arrow function, generating a
SequenceExpression
. However,node
(I'm using8.2.1
) cannot infer the name of the arrow function inside a sequence expression.A possible solution
Modify the
insertCounter
function inistanbul-lib-instrument/src/visitor.js
as follows:Thus, the generated code would be something like:
Thus,
node
can infer foo now :)Questions
istanbul
projects?Repos
I put my changes of
istanbul-lib-instrument
into my forked repo:I also published it as a scoped npm module under
@tomchentw/istanbul-lib-instrument
, hence I can forkedbabel-plugin-istanbul
to add a failing case and fix it:Related issues
#63
……and maybe more.
The text was updated successfully, but these errors were encountered: