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

Prevent comment gap when re-arranging first import #85

Merged
merged 1 commit into from
May 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/utils/get-comment-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ export function attachCommentsToOutputNodes(
* This works since late 2022, Babel uses `loc` (if-present) to hint how to render for some cases.
*/
const patchNewFirstImportLocationOnlyOnce = () => {
if (!hasPatchedNewFirstImportLocation) {
if (hasPatchedNewFirstImportLocation) {
return;
}

Expand Down
15 changes: 15 additions & 0 deletions tests/ImportCommentsPreserved/__snapshots__/ppsi.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,21 @@ import { useState } from "react";

`;

exports[`import-comments-no-top-gap.ts - typescript-verify > import-comments-no-top-gap.ts 1`] = `
/**
* @prettier
*/
import { requireValue } from './utils/require/requireValue';
import { fooValue } from './foo';
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
* @prettier
*/
import { fooValue } from "./foo";
import { requireValue } from "./utils/require/requireValue";

`;

exports[`import-comments-outer-comments-block-comments.ts - typescript-verify > import-comments-outer-comments-block-comments.ts 1`] = `
// Loose leading comment before imports (should not be dragged down with B)

Expand Down
5 changes: 5 additions & 0 deletions tests/ImportCommentsPreserved/import-comments-no-top-gap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/**
* @prettier
*/
import { requireValue } from './utils/require/requireValue';
import { fooValue } from './foo';