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
Expose .index
on Position to internally track nodes location
#14174
Expose .index
on Position to internally track nodes location
#14174
Conversation
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.
Yeah, let's expose .index
. It significantly simplifies our internal implementation since we don't need to interact with the WeakMap
anymore.
Also, I like that it consolidates all the location-related nodes data in .loc
, rather than being scattered across three properties (well, we still have .start
and .end
, but @babel/parser
consumers can now use just .loc
).
@@ -17,8 +17,7 @@ export class Position { | |||
this.column = col; | |||
|
|||
// this.index = index; | |||
// Object.defineProperty(this, "index", { enumerable: false, value: index }); | |||
indexes.set(this, index); | |||
Object.defineProperty(this, "index", { enumerable: false, value: index }); |
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.
In this current PR, I've kept it as an
enumerable: false
property, mainly to avoid having to generate all new fixtures, but I'd be happy to make it a normal property and do that too.
Let's make it enumerable
, even if it is a (one-time) annoying change that affects all our fixtures.
ad339d4
to
88cb9a3
Compare
Cool, I just changed it to a normal property. This will make a bunch of tests fail of course, but I'll regenerate them and push that. |
You might have to regenerate them twice, the second time specifying the |
Sounds good, it might end up touching every fixture because of that newline change from the last PR too. |
4b6d25e
to
259a9c2
Compare
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.
💯
Just a small FYI: I wondered why prettier performance on their latest development branch had taken a hit. JS profiler showed the culprit to be the With indexes WeakMap
With index as a property on Position
|
bb26a68
to
c7133ff
Compare
Just a heads up so that it doesn't slip in with all the test changes, in order to get estree tests passing, I made it so that the estree plugin takes |
Hit comment a bit too soon, wanted to end the above thought by saying that I'm happy to change the strategy with estree if someone proposes something else, and wanted to also explain that this issue didn't come up until I made |
Yeah I noticed that you made it non-enumerable in ESTree; I don't particularly care about what it is since technically we shouldn't have a property (because ESTree doesn't have it), but removing it from the AST would require a full traversal. I'm fine with just "partially hiding" it as you did. |
c7133ff
to
d193a18
Compare
.index
on Position to internally track nodes locations
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/51042/ |
d193a18
to
d776456
Compare
.index
on Position to internally track nodes locations.index
on Position to internally track nodes location
Per the discussion in #14130, I am opening this PR to discuss the addition of an
index
property to thePosition
class. For context, we decided to use anindexes
WeakMap in the above PR to avoid adding new members in a patch release, and figured we'd discuss whether to add this property for a minor release. In this current PR, I've kept it as anenumerable: false
property, mainly to avoid having to generate all new fixtures, but I'd be happy to make it a normal property and do that too.Also potentially relevant bug: #14173 - Although this bug can be done with either approach, it would certainly be more elegant to add more instances of
loc.index
thanindexes.get(loc)
.There may exist some performance argument for switching over to
.index
as well, but from what I've seen so far it doesn't seem to be too substantial.