-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Fix preserveNewlines printer option when a list child has the same start or end as its parent #37846
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
Conversation
@@ -4397,6 +4396,21 @@ namespace ts { | |||
return lines; | |||
} | |||
|
|||
function writeLineSeparatorsAndIndentBefore(node: Node, parent: Node): boolean { |
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.
These functions are extracted from emitParenthesizedExpression
because fixing the actual bug revealed that a JSX example was only working by accident because of the bug, and needed to borrow this code from emitParenthesizedExpression
.
const prevPos = getPreviousNonWhitespacePosition(startPos, sourceFile); | ||
return getLinesBetweenPositions(sourceFile, prevPos || 0, startPos); | ||
const prevPos = getPreviousNonWhitespacePosition(startPos, stopPos, sourceFile); | ||
return getLinesBetweenPositions(sourceFile, prevPos ?? stopPos, startPos); |
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.
Instead of doing this, I could imagine getPreviousNonWhitespacePosition
just returns the stopPos
instead of undefined
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.
I thought about that, but if someone wanted to use this elsewhere without looking at the implementation, I think returning a position that's not actually non-whitespace would be really surprising.
@typescript-bot perf test this |
Heya @DanielRosenwasser, I've started to run the perf test suite on this PR at 6b90e6e. You can monitor the build here. Update: The results are in! |
🔔 other reviewers, my familiarity with the emitter is rusty |
@DanielRosenwasser Here they are:Comparison Report - master..37846
System
Hosts
Scenarios
|
Fixes #37813