question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Handle function name inference

See original GitHub issue

The best way to explain things is via a repo: https://github.com/kentcdodds/issue-babel-plugin-istanbul-fn-name

Here’s a copy/paste of the README:

issue-babel-plugin-istanbul-fn-name

This demonstrates that due to how babel-plugin-istanbul wraps functions, the name of the function is lost

This is a bug and should be fixed.

Why?

This is causing issues with Jest snapshot testing of React components

Reproduce:

See the npm scripts, or just run things manually:

node test.js

Everything passes fine

babel-node --plugins istanbul test.js

You get two failures. One for the Foobar function:

const Foobar = function() {}

And the other for the Bar function:

const Bar = () => {}

The istanbul-transformed (babel --plugins istanbul index.js) version of these functions looks like this:

const Bar = (++cov_1788vtfzzh.s[0], () => {
  ++cov_1788vtfzzh.f[1];
});

const Foobar = (++cov_1788vtfzzh.s[2], function () {
  ++cov_1788vtfzzh.f[3];
});

This makes it so the JS engine can’t do function name inference which causes the issue.

I’m not sure what the babel plugin can do about arrow functions… Can’t really give those a name. Definitely possible, but you’d have to do some fancy work to make things work.

But for the function expression that’s simple enough.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:8
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
kentcdoddscommented, Jan 3, 2017

Poof!

~/Desktop/issue-babel-plugin-istanbul-fn-name (master)
⛄  $ npm run test:babel-node

> issue-babel-plugin-istanbul-fn-name@1.0.0 test:babel-node /Users/kdodds/Desktop/issue-babel-plugin-istanbul-fn-name
> babel-node --plugins istanbul test.js

Passed! 💚
1reaction
bcoecommented, Jan 2, 2017

@kentcdodds could I convince you to try out:

npm cache clear; npm i babel-plugin-istanbul@next? I believe it has some new logic for handling inferred function names which should solve this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does the Airbnb style guide say that relying on function ...
Function name property isn't supposed to be used for anything but debugging in client-side application because function original name is lost ...
Read more >
JavaScript Arrow Functions: How to debug them with name ...
In summary, it is a good practice to use function name inference to name the arrow functions if you want to debug your...
Read more >
Why does the Airbnb style guide say that relying on function ...
Function name property isn't supposed to be used for anything but debugging in client-side application because function original name is lost during ...
Read more >
Function.prototype.name - JavaScript - MDN Web Docs
The name property is typically inferred from how the function is defined. In the following sections, we will describe the various ways in...
Read more >
Adapting Your Own Inference Container - Amazon SageMaker
If none of the Amazon SageMaker prebuilt inference containers suffice for your ... and the handle method is invoked for all incoming inference...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found