Skip to content

[compiler] Null out source locations where not explicitly preserved #33051

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

Open
wants to merge 5 commits into
base: gh/josephsavona/71/base
Choose a base branch
from

Conversation

josephsavona
Copy link
Contributor

@josephsavona josephsavona commented Apr 29, 2025

Stack from ghstack (oldest at bottom):

Inspired by #32950. Specifically from #32950 (comment), it sounds like Babel by default emits source map information for all nodes, even when they don't have a loc property set. Code coverage tools then pick up the synthesized source location information for this, leading to the issue described.

It wasn't super clear how to omit nodes from the source map. A few google searches didn't turn up any documented way to do so: the user can do so via a function supplied to babel, but plugins can't. Entire files can be opted out, but not nodes. I asked an LLM which answered that explicitly setting node.loc = null omits the node from source maps, but that didn't work.

What did work was explicitly setting the loc property to an object that follows the shape of a source location, but with all properties nulled out. With that, we get the desired result:

Screenshot 2025-04-30 at 10 50 30 AM

I'm going to feature-flag this since setting some of these properties in this way might break in other versions of Babel or have other issues.

Inspired by #32950. Specifically from #32950 (comment), it sounds like Babel by default emits source map information for all nodes, even when they don't have a `loc` property set. Code coverage tools then pick up the synthesized source location information for this, leading to the issue described.

A few google searches didn't turn up any documented way to opt-out of generating source span information, but AI tools answer that explicitly setting `node.loc = null` omits the node from source maps. This PR is a quick hack to confirm that.

[ghstack-poisoned]
josephsavona added a commit that referenced this pull request Apr 29, 2025
Inspired by #32950. Specifically from #32950 (comment), it sounds like Babel by default emits source map information for all nodes, even when they don't have a `loc` property set. Code coverage tools then pick up the synthesized source location information for this, leading to the issue described.

A few google searches didn't turn up any documented way to opt-out of generating source span information, but AI tools answer that explicitly setting `node.loc = null` omits the node from source maps. This PR is a quick hack to confirm that.

ghstack-source-id: 8ec8b35815c2c798c6850ffda1661916e3208110
Pull Request resolved: #33051
@josephsavona
Copy link
Contributor Author

josephsavona commented Apr 29, 2025

From the preview deployment this doesn't seem to work, at least in the source map viewer.

edit: addressed, see updated description

…preserved"

Inspired by #32950. Specifically from #32950 (comment), it sounds like Babel by default emits source map information for all nodes, even when they don't have a `loc` property set. Code coverage tools then pick up the synthesized source location information for this, leading to the issue described.

A few google searches didn't turn up any documented way to opt-out of generating source span information, but AI tools answer that explicitly setting `node.loc = null` omits the node from source maps. This PR is a quick hack to confirm that.

[ghstack-poisoned]
josephsavona added a commit that referenced this pull request Apr 30, 2025
Inspired by #32950. Specifically from #32950 (comment), it sounds like Babel by default emits source map information for all nodes, even when they don't have a `loc` property set. Code coverage tools then pick up the synthesized source location information for this, leading to the issue described.

A few google searches didn't turn up any documented way to opt-out of generating source span information, but AI tools answer that explicitly setting `node.loc = null` omits the node from source maps. This PR is a quick hack to confirm that.

ghstack-source-id: f089cddb4b5f35050491fa1c02a4b1484f757797
Pull Request resolved: #33051
Comment on lines +2683 to +2688
ast['loc'] = {
start: {line: null, column: null, index: null},
end: {line: null, column: null, index: null},
filename: null,
identifierName: null,
};
Copy link
Contributor Author

@josephsavona josephsavona Apr 30, 2025

Choose a reason for hiding this comment

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

At least on the version of Babel we're using for tests, just setting loc: null wasn't enough to exclude the node from source maps. But setting all of this was enough to exclude them.

…preserved"

Inspired by #32950. Specifically from #32950 (comment), it sounds like Babel by default emits source map information for all nodes, even when they don't have a `loc` property set. Code coverage tools then pick up the synthesized source location information for this, leading to the issue described.

A few google searches didn't turn up any documented way to opt-out of generating source span information, but AI tools answer that explicitly setting `node.loc = null` omits the node from source maps. This PR is a quick hack to confirm that.

[ghstack-poisoned]
josephsavona added a commit that referenced this pull request Apr 30, 2025
Inspired by #32950. Specifically from #32950 (comment), it sounds like Babel by default emits source map information for all nodes, even when they don't have a `loc` property set. Code coverage tools then pick up the synthesized source location information for this, leading to the issue described.

A few google searches didn't turn up any documented way to opt-out of generating source span information, but AI tools answer that explicitly setting `node.loc = null` omits the node from source maps. This PR is a quick hack to confirm that.

ghstack-source-id: 3f2255dfbec8315994d034c45e16802ad7314a86
Pull Request resolved: #33051
…preserved"


Inspired by #32950. Specifically from #32950 (comment), it sounds like Babel by default emits source map information for all nodes, even when they don't have a `loc` property set. Code coverage tools then pick up the synthesized source location information for this, leading to the issue described.

It wasn't super clear how to omit nodes from the source map. A few google searches didn't turn up any documented way to do so: the user can do so via a function supplied to babel, but plugins can't. Entire files can be opted out, but not nodes. I asked an LLM which answered that explicitly setting `node.loc = null` omits the node from source maps, but that didn't work. 

What did work was explicitly setting the `loc` property to an object that follows the shape of a source location, but with all properties nulled out. With that, we get the desired result:

<img width="553" alt="Screenshot 2025-04-30 at 10 50 30 AM" src="https://github.com/user-attachments/assets/cf55fd32-8375-4cfa-8202-49b45ef02931" />

I'm going to feature-flag this since setting some of these properties in this way might break in other versions of Babel or have other issues.

[ghstack-poisoned]
Copy link
Contributor

@mofeiZ mofeiZ left a comment

Choose a reason for hiding this comment

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

Makes sense, I wonder how this affects setting debugger breakpoints with source maps enabled -- missing / greyed out breakpoints are probably less confusing than misleading ones, so let's try it

On a side note, hopefully this is a no-op for fbt enums which rely on sourcemaps

…preserved"


Inspired by #32950. Specifically from #32950 (comment), it sounds like Babel by default emits source map information for all nodes, even when they don't have a `loc` property set. Code coverage tools then pick up the synthesized source location information for this, leading to the issue described.

It wasn't super clear how to omit nodes from the source map. A few google searches didn't turn up any documented way to do so: the user can do so via a function supplied to babel, but plugins can't. Entire files can be opted out, but not nodes. I asked an LLM which answered that explicitly setting `node.loc = null` omits the node from source maps, but that didn't work. 

What did work was explicitly setting the `loc` property to an object that follows the shape of a source location, but with all properties nulled out. With that, we get the desired result:

<img width="553" alt="Screenshot 2025-04-30 at 10 50 30 AM" src="https://github.com/user-attachments/assets/cf55fd32-8375-4cfa-8202-49b45ef02931" />

I'm going to feature-flag this since setting some of these properties in this way might break in other versions of Babel or have other issues.

[ghstack-poisoned]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants