Preserve leading trivia when organizing imports#22832
Closed
amcasey wants to merge 1 commit intomicrosoft:masterfrom
Closed
Preserve leading trivia when organizing imports#22832amcasey wants to merge 1 commit intomicrosoft:masterfrom
amcasey wants to merge 1 commit intomicrosoft:masterfrom
Conversation
When organizing imports, we used to move the leading and trailing trivia of each individual import with that import as it was repositioned or deleted. This had the unfortunate effect of repositioning or deleting the header comment of the file. Our new approach is to leave the leading trivia of the first import ahead of the resulting block of imports (i.e. it no longer follows the first import as it is repositioned or deleted). Trailing trivia on the first import and trivia on subsequent imports are treated as before. Caveat: We had to hack around emitter limitation microsoft#22831. Fixes microsoft#22723 Fixes microsoft#22724 Fixes microsoft#22731
amcasey
commented
Mar 23, 2018
|
|
||
| // ==ORGANIZED== | ||
|
|
||
| /*A*/ import /*B*/ { /*C*/ F1 /*D*/ } /*G*/ from /*H*/ "lib" /*I*/; /*J*/ //K |
Member
Author
There was a problem hiding this comment.
I'm not sure why we lost the space, but it doesn't seem very problematic since this commenting pattern is very unusual.
There was a problem hiding this comment.
It looks like the space wasn't present in the input, so this is a good change.
ghost
approved these changes
Mar 23, 2018
| */ | ||
| /* @internal */ | ||
| export function suppressTrailingTrivia(node: Node) { | ||
| Debug.assertDefined(node); |
There was a problem hiding this comment.
Seems unnecessary as getOrCreateEmitNode will crash on undefined input anyway, and as of #22088 the type system should help with this.
|
|
||
| // ==ORGANIZED== | ||
|
|
||
| /*A*/ import /*B*/ { /*C*/ F1 /*D*/ } /*G*/ from /*H*/ "lib" /*I*/; /*J*/ //K |
There was a problem hiding this comment.
It looks like the space wasn't present in the input, so this is a good change.
Member
|
I pulled this in and proposed a different fix in #22836 which I think is more appropriate (and less hacky) until we make our token comment emit more robust. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When organizing imports, we used to move the leading and trailing trivia
of each individual import with that import as it was repositioned or
deleted. This had the unfortunate effect of repositioning or deleting
the header comment of the file.
Our new approach is to leave the leading trivia of the first import
ahead of the resulting block of imports (i.e. it no longer follows the
first import as it is repositioned or deleted). Trailing trivia on the
first import and trivia on subsequent imports are treated as before.
Caveat: We had to hack around emitter limitation #22831.
Fixes #22723
Fixes #22724
Fixes #22731