Skip to content

Function names in source maps in async functions broken #34977

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

Closed
mprobst opened this issue Nov 7, 2019 · 2 comments
Closed

Function names in source maps in async functions broken #34977

mprobst opened this issue Nov 7, 2019 · 2 comments
Assignees
Labels
Bug A bug in TypeScript Duplicate An existing issue was already created Rescheduled This issue was previously scheduled to an earlier milestone

Comments

@mprobst
Copy link
Contributor

mprobst commented Nov 7, 2019

TypeScript Version: Version 3.8.0-dev.20191105

Search Terms: source map async function

Code

async function asyncMapped() {
  const trace = {stack: ''};
  (Error as any).captureStackTrace(trace);
  return trace;
}

function plainMapped() {
  const trace = {stack: ''};
  (Error as any).captureStackTrace(trace);
  return trace;
}

console.error(plainMapped().stack);

asyncMapped().then(s => {
  console.error(s.stack);
});

Expected behavior:

test.ts:14 Error
    at plainMapped (test.ts:9)
    at test.ts:14
(anonymous) @ test.ts:14
test.ts:16 Error
    at asyncMapped (test.ts:3)
    at step (test.js:32)
    at Object.next (test.js:13)
    at test.js:7
    at new Promise (<anonymous>)
    at __awaiter (test.js:3)
    at asyncMapped (test.ts:1)
    at test.ts:16

Actual behavior:

test.ts:14 Error
    at plainMapped (test.ts:9)
    at test.ts:14
(anonymous) @ test.ts:14
test.ts:16 Error
    at test.ts:3
    at step (test.js:32)
    at Object.next (test.js:13)
    at test.js:7
    at new Promise (<anonymous>)
    at __awaiter (test.js:3)
    at asyncMapped (test.ts:1)
    at test.ts:16

Note how there is no function name emitted for the asyncMapped version.

Playground Link: n/a

Related Issues:

Possibly #13522 ?

@mprobst
Copy link
Contributor Author

mprobst commented Nov 7, 2019

I believe this is a regression introduced in TypeScript 3.5.

@rbuckton
Copy link
Contributor

This doesn't seem to be a regression, as nothing has really changed in the emit. The reason line 3 isn't source mapped is that the function you are evaluating doesn't have a name:

image

The best we could do is give it a name like asyncMapped_1 so that we don't collide with possibly recursive calls of the function.

That is something we discussed in #13522, but the downside is that it adds additional text to the output for a function name that is never used except when debugging.

I'm going to close this as a duplicate of #13522, and we can continue discussion in the original bug.

@rbuckton rbuckton added the Duplicate An existing issue was already created label Dec 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Duplicate An existing issue was already created Rescheduled This issue was previously scheduled to an earlier milestone
Projects
None yet
Development

No branches or pull requests

3 participants