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

Add source mappings for serialized properties with available declaration #60005

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

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
Comment on lines 1161 to 1166
const folder = this.getRealFolder(base);
// this line can throw on purpose, don't use Debug.assert to avoid redundant debugger hits
// eslint-disable-next-line no-restricted-syntax
if (folder === null || folder === undefined) {
throw new Error(`Directory not found: ${base}`);
}
Copy link
Member

Choose a reason for hiding this comment

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

Do you mind sending this as a separate change; I've been wanting to do this for a while so would be nice to get in regardless of the status of this PR.

No need to leave the comment, and I suspect that a plain truthiness check is fine too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

openFilesForSession([mainTs], session);
session.executeCommandSeq<ts.server.protocol.DefinitionAndBoundSpanRequest>({
command: ts.server.protocol.CommandTypes.DefinitionAndBoundSpan,
arguments: { file: mainTs.path, line: 3, offset: "caller.foo".length - 2 },
Copy link
Member

Choose a reason for hiding this comment

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

Pls use protocolFileLocationFromSubstring to get line and offset

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

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

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

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
5 participants