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

fix: function name should be obtained from next frame’s position #253

Merged
merged 1 commit into from
Oct 27, 2019

Conversation

JLHwung
Copy link
Contributor

@JLHwung JLHwung commented Oct 1, 2019

This is a follow-up to #220.

In #220 we provided position.name before stack.getFunctionName to support mangled function calls. However, stack.getFunctionName is supposed to return the name of the current function, that is, which function does this frame live in. Regards to the source map, it is the name of the position in next frame instead of in this frame.

To illustrate this issue, here is a reproducible repository I revised from babel/babel#9883:

function foo() {
  console.log(new Error().stack);
}

function bar() {
  foo();    // <-- Here we are supposed to get `bar` as function name but instead get `foo`.
}

bar();

The expected output should be

    at foo (/Users/jh/code/babel-sourcemap-bug/src/index.js:2:15)
    at bar (/Users/jh/code/babel-sourcemap-bug/src/index.js:6:3)
    at Object.<anonymous> (/Users/jh/code/babel-sourcemap-bug/src/index.js:9:1)
   // <--- frames below are omitted --->

The current output after requiring source-map-support/register is

    at foo (/Users/jh/code/babel-sourcemap-bug/dist/src/index.js:2:15)
    at foo (/Users/jh/code/babel-sourcemap-bug/dist/src/index.js:6:3)
    at Object.<anonymous> (/Users/jh/code/babel-sourcemap-bug/dist/src/index.js:1:1)
    // <--- frames below are omitted --->

Apparently foo is incorrectly repeated.

To fix this issue, we reverse the stack processing order and introduce internal state to track next frame position. As wrapCallSite is exported as a public API, I would consider this change as a breaking change.

@JLHwung JLHwung changed the title fix: function name should be obtained from next frams’s position fix: function name should be obtained from next frames’s position Oct 7, 2019
@JLHwung JLHwung changed the title fix: function name should be obtained from next frames’s position fix: function name should be obtained from next frame’s position Oct 7, 2019
@JLHwung
Copy link
Contributor Author

JLHwung commented Oct 22, 2019

@LinusU ping :) This is an upstream issue of babel. Are there anything I can help?

@LinusU
Copy link
Collaborator

LinusU commented Oct 27, 2019

Sorry for the delay, I've been out traveling and my inbox is a mess right now 😅

@LinusU LinusU merged commit 8a92ccf into evanw:master Oct 27, 2019
@LinusU
Copy link
Collaborator

LinusU commented Oct 27, 2019

Released as 0.5.14 :shipit:

@JLHwung
Copy link
Contributor Author

JLHwung commented Oct 28, 2019

@LinusU Cool. Was it also published to npm?

@JLHwung JLHwung deleted the fix-function-name-logic branch October 28, 2019 18:27
@LinusU
Copy link
Collaborator

LinusU commented Oct 28, 2019

Was it also published to npm?

🤦‍♂

It is now! ☺️

@SimenB
Copy link
Contributor

SimenB commented Nov 7, 2019

This broke function names in Jest's stack traces. Using 0.5.13 we get e.g. at Object.toThrowCustomAsyncMatcherError (__tests__/asynchronous.test.js:11:16), and with 0.5.14 we get at Object.<anonymous>.test (__tests__/asynchronous.test.js:11:16). A bunch more examples in https://circleci.com/gh/facebook/jest/73294.

Any idea if we can change anything in Jest to fix it, or was this an honest regression?

(0.5.16 makes no difference, fwiw)

EDIT: I've opened a separate PR just for source-map-support showing it's the only change and tests fail. Master is green. jestjs/jest#9147

@LinusU
Copy link
Collaborator

LinusU commented Nov 8, 2019

@SimenB I think that @JLHwung answered this in jestjs/jest#9147, please let me know if there is anything more that should be done from our side though, I'll try and stay up to date in that thread as well

gzm0 added a commit to gzm0/scala-js that referenced this pull request Jan 19, 2021
The issue with original names was likely due to
evanw/node-source-map-support#253 and not Scala.js related.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants