Skip to content
This repository has been archived by the owner on Oct 18, 2023. It is now read-only.

Identifier source mapping incorrect #7

Closed
DylanPiercey opened this issue May 21, 2022 · 10 comments · Fixed by esbuild-kit/esm-loader#19 or #10
Closed

Identifier source mapping incorrect #7

DylanPiercey opened this issue May 21, 2022 · 10 comments · Fixed by esbuild-kit/esm-loader#19 or #10

Comments

@DylanPiercey
Copy link
Contributor

When debugging a typescript file the identifiers do not seem to be mapping back correctly.

Disabling esbuilds minification (https://github.com/esbuild-kit/core-utils/blob/develop/src/esbuild/index.ts#L32) resolves the issue for me.

This is possibly an esbuild issue, but I wonder if it makes sense to turn off minification here for now, or maybe just to use the minifyWhitespace: true option instead which also works fine.

@DylanPiercey
Copy link
Contributor Author

FYI @privatenumber it seems this issue is in fact with esbuild evanw/esbuild#1296 (comment). Id say it'd be good for now to turn off identifier minification to allow for proper debugging. Happy to put up a pr if you like.

@privatenumber
Copy link
Member

privatenumber commented May 23, 2022

Thanks for the report!

Do you mind providing a quick reproduction (inline code snippets is fine)? I'd like to investigate the problem.

@DylanPiercey
Copy link
Contributor Author

@privatenumber if you create a file with any identifiers and run it with a debugger it will not let you hover over and inspect those identifiers.

Eg

test.ts

const abc = 1;

debugger;
console.log(abc);

Then running tsx --inspect ./test.ts and using whatever debugger you want you'll see if you hover over abc it will not show it's value. If you disable the minify option passed to esbuild you will be able to see the value.

Here you can see the variable got minified to c for me, but not reflected in the debugger:
image

But if I manually change the minify options in my node_modules for this package, I'll see:
image

@DylanPiercey
Copy link
Contributor Author

Again the issue is technically with esbuild, but w/o the workaround here it makes debugging harder.

@privatenumber
Copy link
Member

I'm OK with swapping minify and keepNames out with minifyWhitespace and minifySyntax.

I'm looking to add a small test to test against this behavior though and I can't think of one. I am using new Error().stack, but I'm not sure if source-map-support uses the names property in the stack.

Do you have any ideas?

@DylanPiercey
Copy link
Contributor Author

@privatenumber the best I can come up with is to test against an error that includes the identifier name in the message, eg assignment before initialization like this:

test.ts

(() => abc = 1)();
let abc;
tsx ./test.ts

Yields

./test.ts:1
(() => abc = 1)();
       ^

ReferenceError: Cannot access 'a' before initialization

Removing the minify: true changes the error message to the actual identifier like this:

./test.ts:1
(() => abc = 1)();
       ^

ReferenceError: Cannot access 'abc' before initialization

@AisonSu

This comment was marked as off-topic.

@privatenumber
Copy link
Member

@DylanPiercey Thanks!

@AisonSu I'll create a contributing guide later to explain how to set these up without a mono repo and why I didn't choose a mono repo.

@privatenumber
Copy link
Member

FYI I'm considering re-enabling this now that esbuild supports names via evanw/esbuild#1296

@DylanPiercey
Copy link
Contributor Author

👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants