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

Fix inline comments #563

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

Fix inline comments #563

wants to merge 2 commits into from

Conversation

mamaniv
Copy link

@mamaniv mamaniv commented Aug 9, 2021

This commit solves an issue described in #562
It also contains a change in the relevant test.

@davidbonnet
Copy link
Owner

Thanks @mamaniv for suggesting this change. It's going in the right direction, however I'm afraid that the performance impact of filter calls with inline functions will be huge. An alternative that doesn't define inline functions (without going through the entire comments list every time) should be faster.

@@ -253,10 +253,13 @@ export const GENERATOR = {
for (let i = 0; i < length; i++) {
const statement = statements[i]
if (writeComments && statement.comments != null) {
formatComments(state, statement.comments, indent, lineEnd)
formatComments(state, statement.comments.filter(comment => comment.end < statement.start), indent, lineEnd)
Copy link
Owner

Choose a reason for hiding this comment

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

IMHO, instead of filtering comments every time, it'd be more efficient to apply the logic in the filter predicate inside the formatComments function.

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.

None yet

2 participants