Skip to content

Conversation

@Andarist
Copy link
Contributor

fixes #60004

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Sep 19, 2024
@typescript-bot typescript-bot added For Backlog Bug PRs that fix a backlog bug and removed For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Sep 19, 2024
sheetalkamat
sheetalkamat previously approved these changes Sep 20, 2024
context.enclosingDeclaration = propertyDeclaration || saveEnclosingDeclaration;
const propertyName = getPropertyNameNodeForSymbol(propertySymbol, context);
if (propertyDeclaration && (isPropertyAssignment(propertyDeclaration) || isShorthandPropertyAssignment(propertyDeclaration) || isMethodDeclaration(propertyDeclaration) || isMethodSignature(propertyDeclaration) || isPropertySignature(propertyDeclaration) || isPropertyDeclaration(propertyDeclaration) || isGetOrSetAccessorDeclaration(propertyDeclaration))) {
setSourceMapRange(propertyName, propertyDeclaration.name);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still feel at least a little uncomfortable with this; why isn't it declaration emit which can do this? The node builder produces lots of nodes, why doesn't this happen elsewhere?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, can this just be done in getPropertyNameNodeForSymbol?

(In any case, this PR is safe, since getPropertyNameNodeForSymbol is returning a new node.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still feel at least a little uncomfortable with this; why isn't it declaration emit which can do this?

the required information is on the symbol, emit works based on the produced nodes and we need to pass somehow the information that it needs from here as this is the place where this information is being lost. This just leaves a breadcrumb that can be picked up by the emitter

Also, can this just be done in getPropertyNameNodeForSymbol?

maybe, im not sure sure ;p I'll try to analyze this

context.enclosingDeclaration = propertyDeclaration || saveEnclosingDeclaration;
const propertyName = getPropertyNameNodeForSymbol(propertySymbol, context);
if (propertyDeclaration && (isPropertyAssignment(propertyDeclaration) || isShorthandPropertyAssignment(propertyDeclaration) || isMethodDeclaration(propertyDeclaration) || isMethodSignature(propertyDeclaration) || isPropertySignature(propertyDeclaration) || isPropertyDeclaration(propertyDeclaration) || isGetOrSetAccessorDeclaration(propertyDeclaration))) {
setSourceMapRange(propertyName, propertyDeclaration.name);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For declaration emit nodes, just use setTextRange rather than setSourceMapRange - there's a helper in scope that takes care of a bunch of sanity checking for you that's absent here. But yeah, you should also be able to move this into getPropertyNameNodeForSymbol so it happens for all callers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using setTextRange doesn't cut it and the results are as on the main branch. Am I using it wrong or missing something?

I have moved the fix to getPropertyNameNodeForSymbol though

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it doesn't seem to help. I don't understand why this isn't working:

propertyNameNode = setTextRange(context, propertyNameNode, declaration.name);

So I would expect the original node stuff to "just work". setTextRange doesn't call setSourceMapRange at all, though, so...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you stick setSourceMapRange(range, location); into setTextRange after setOriginalNode, that actually also changes a whole bunch of other stuff kinda for the better? But then breaks some other JSDoc related code (which I think was another recent bugfix that may conflict?) Dunno if that's a good idea or not, I don't have a good mental model of this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(maybe #59675?)

Copy link
Contributor Author

@Andarist Andarist Jan 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somewhat offtopic, somewhat not. I've wanted to verify some existing behaviors around this so I put this in the code:

diff --git a/src/compiler/factory/emitNode.ts b/src/compiler/factory/emitNode.ts
index beadc29d4c..b4d1e730eb 100644
--- a/src/compiler/factory/emitNode.ts
+++ b/src/compiler/factory/emitNode.ts
@@ -13,6 +13,7 @@ import {
     ImportSpecifier,
     InternalEmitFlags,
     isParseTreeNode,
+    isTypeNodeKind,
     Node,
     NodeArray,
     orderedRemoveItem,
@@ -137,6 +138,9 @@ export function getSourceMapRange(node: Node): SourceMapRange {
  * Sets a custom text range to use when emitting source maps.
  */
 export function setSourceMapRange<T extends Node>(node: T, range: SourceMapRange | undefined): T {
+    if (range && isTypeNodeKind(node.kind)) {
+        throw new Error("Type nodes cannot have source map ranges.");
+    }
     getOrCreateEmitNode(node).sourceMapRange = range;
     return node;
 }

and no existing test has thrown. So it seems that this has never been used on type nodes until now.

@Eigilak
Copy link

Eigilak commented May 14, 2025

Status?

@Jacse
Copy link

Jacse commented Aug 19, 2025

@Andarist @jakebailey is this progressing?

@mamlzy
Copy link

mamlzy commented Sep 9, 2025

sorry for tagging @Andarist, is this pr going to be merged?

@jakebailey jakebailey requested a review from weswigham September 9, 2025 17:09
@prometx11
Copy link

Is there any chance for this to be merged soon?
This is blocking go-to navigation in monorepos, and degrades DX quite a bit.

@jakebailey
Copy link
Member

This needs main merged into it, for one thing.

The other thing I'm wondering is how trivial this is to port over to the Go codebase, just to make sure that this sticks.

@Andarist Andarist force-pushed the fix/mapped-members-mappings branch from 459d8bf to 01983e0 Compare November 20, 2025 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Backlog Bug PRs that fix a backlog bug

Projects

Status: Waiting on author

Development

Successfully merging this pull request may close these issues.

Source mappings are missing for serialized properties

9 participants