Skip to content

Conversation

@amcasey
Copy link
Member

@amcasey amcasey commented Mar 23, 2018

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

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 amcasey requested review from a user and weswigham March 23, 2018 18:05

// ==ORGANIZED==

/*A*/ import /*B*/ { /*C*/ F1 /*D*/ } /*G*/ from /*H*/ "lib" /*I*/; /*J*/ //K
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure why we lost the space, but it doesn't seem very problematic since this commenting pattern is very unusual.

Copy link

Choose a reason for hiding this comment

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

It looks like the space wasn't present in the input, so this is a good change.

*/
/* @internal */
export function suppressTrailingTrivia(node: Node) {
Debug.assertDefined(node);
Copy link

Choose a reason for hiding this comment

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

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
Copy link

Choose a reason for hiding this comment

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

It looks like the space wasn't present in the input, so this is a good change.

@weswigham
Copy link
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.

@amcasey amcasey closed this Mar 23, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants