-
Notifications
You must be signed in to change notification settings - Fork 48.6k
[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
base: gh/josephsavona/71/base
Are you sure you want to change the base?
Conversation
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]
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: 8ec8b35 Pull Request resolved: #33051
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]
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: f089cdd Pull Request resolved: #33051
ast['loc'] = { | ||
start: {line: null, column: null, index: null}, | ||
end: {line: null, column: null, index: null}, | ||
filename: null, | ||
identifierName: null, | ||
}; |
There was a problem hiding this comment.
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]
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: 3f2255d 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]
There was a problem hiding this 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]
Inspired by #32950. Specifically from facebook/react#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: 2ed6301 Pull Request resolved: facebook/react#33051
This is blocked on playground being broken. It looks like the changes may be breaking the source maps display, which means that the way i'm nulling out source locations may not be safe. Unfortunately the way Babel treats |
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: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.