fix: resolve function names from preceding source map token#35
Conversation
TypeScript's source map generator attaches the original function name to the `function` keyword token rather than the identifier that follows. When the token at the identifier position has no name, check the immediately preceding token and use its name if it maps to the same original source position. Co-authored-by: bdingman-daedalus <benjamin.dingman4@gmail.com> Co-authored-by: zobell <zobell@gmail.com>
953dd46 to
0a8c5ae
Compare
loewenheim
left a comment
There was a problem hiding this comment.
Hi, thank you very much for the reproduction and the contribution. Unfortunately this fix is a bit ad-hoc and fragile; as you yourself note, it is currently limited to looking behind one token, and I think lifting that restriction would complicate things quite a bit.
I believe the better way to address the problem is to normalize sourcemaps so that pathological cases like this (multiple mappings to the same original source position, only one of which has a name) are taken care of by construction. We've had an issue open for this in rust-sourcemap for a long time, but saw it more as a nice-to-have; seeing that this causes an actual problem for you, we will re-prioritize it.
|
Also, can you expand on how the |
|
Context on how we identified the issue: Regarding the test fixture: |
|
I owe you an apology. This fix is in fact cleaner than what I had in mind. I'll get it merged and deployed as soon as possible. |
This improves name resolution in `symbolic-sourcemapcache` via getsentry/js-source-scopes#35.
This improves name resolution in `symbolic-sourcemapcache` via getsentry/js-source-scopes#35.
This bumps the `symbolic` dependency to 12.18.2, which improves scope name resolution for sourcemap caches (see getsentry/js-source-scopes#35 and getsentry/symbolic#970). This necessitates a (compatible) sourcemap cache version bump so the caches get recomputed.
This bumps the `symbolic` dependency to 12.18.2, which improves scope name resolution for sourcemap caches (see getsentry/js-source-scopes#35 and getsentry/symbolic#970). This necessitates a (compatible) sourcemap cache version bump so the caches get recomputed. ref: INGEST-862
TypeScript's source map generator attaches the original function name to the
functionkeyword token rather than the identifier that follows. When the token at the identifier position has no name, check the immediately preceding token and use its name if it maps to the same original source position.Detailed Problem Description
Some source map generators (notably Closure Compiler) attach the original
function name to the
functionkeyword token rather than to the identifierthat follows it. When looking up a minified identifier like
Uc1bk, thetoken at that position has no name, causing the resolver to fall back to
the literal minified name.
This fix checks the immediately preceding token when the current token has
no name. If it maps to the same original source position (same source file,
line, and column), we use its name. This is safe because tokens mapping to
the same original position are part of the same logical mapping, just split
across multiple VLQ segments.
The same-source-position guard ensures we don't incorrectly inherit names
from unrelated tokens (e.g.,
FoobeforeprototypeinFoo.prototype.bar).