Skip to content

Conversation

@ycmjason
Copy link
Owner

@ycmjason ycmjason commented Aug 5, 2025

reworked the algorithm for adding comments.

the main pain point of the original implementation in #4 was that adding comment via AST has its limitations. we cannot for example add comment here (or at least I haven't found a way to do that):

happy
 // here
 .birthday()

this is because there's no node for the . that begins on .birthday(). the first node on that line would be the Identifier node for birthday. so if we used AST to insert comment, we end up with:

happy
 .// here
 birthday()

which is obviously horrible.

so I introduced some naive adding again since it seems to be more reliable. I only use AST for:

  1. Inserting // @ts-migrating in string template
  2. Keeping track of which line is in JSX and which line is vanilla.

There are some edge cases where recast / babel parser would not preserve the original formatting of the code which result in incorrect line ordering, this causes the annotation to fail. I have added an example where this will fail here and I have raised an issue in benjamn/recast#1423.

related #1, #2

@ycmjason ycmjason force-pushed the content-aware-annotate-fix branch from 0a6fe79 to 1a99abf Compare August 5, 2025 13:58
});

// Currently failing due to: https://github.com/benjamn/recast/issues/1423
it.skip('should annotate correctly for weird formatted ternary', () => {
Copy link
Owner Author

Choose a reason for hiding this comment

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

failing test

@ycmjason ycmjason merged commit cd5d90f into main Aug 5, 2025
1 check passed
@ycmjason ycmjason deleted the content-aware-annotate-fix branch August 5, 2025 21:05
@ycmjason ycmjason mentioned this pull request Aug 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant