Handle comments in export declarations between type and type name. (#19565)
This commit is contained in:
1 parent
62ccd0d9bf
commit
a7ce99aa57
4 files changed
+48
-3
No files matched your search
@@ -0,0 +1,15 @@
|
||||
#### Fix comments being dropped on shorthand `type` import/export specifiers (#19565 by @kirkwaiblinger)
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```tsx
|
||||
// Input
|
||||
export { type /* comment */ T } from "foo";
|
||||
import { type /* comment */ T } from "foo";
|
||||
|
||||
// Prettier stable
|
||||
Error: Comment "comment" was not printed. Please report this error!
|
||||
|
||||
// Prettier main
|
||||
export { type /* comment */ T } from "foo";
|
||||
import { type /* comment */ T } from "foo";
|
||||
```
|
||||
@@ -51,11 +51,11 @@ const isChildWontPrint = (node, [parent]) =>
|
||||
parent.value !== parent.key) ||
|
||||
(parent?.type === "ImportSpecifier" &&
|
||||
isShorthandSpecifier(parent) &&
|
||||
parent.imported === node &&
|
||||
parent.imported !== parent.local) ||
|
||||
parent.local === node &&
|
||||
parent.local !== parent.imported) ||
|
||||
(parent?.type === "ExportSpecifier" &&
|
||||
isShorthandSpecifier(parent) &&
|
||||
parent.local === node &&
|
||||
parent.exported === node &&
|
||||
parent.local !== parent.exported);
|
||||
|
||||
/**
|
||||
|
||||
@@ -116,6 +116,16 @@ import type { foo as bar } from 'baz';
|
||||
import type * as foo from './bar';
|
||||
import type foo from 'bar';
|
||||
|
||||
// https://github.com/prettier/prettier/issues/19564
|
||||
export { type /* comment */ T } from 'foo';
|
||||
import { type /* comment */ T } from 'foo';
|
||||
|
||||
export { /* e1 */ type /* e2 */ T /* e3 */ } from 'foo';
|
||||
import { /* i1 */ type /* i2 */ T /* i3 */ } from 'foo';
|
||||
|
||||
export { /* e1 */ type /* e2 */ T /* e3 */ as /* e4 */ U /* e5 */ } from 'foo';
|
||||
import { /* i1 */ type /* i2 */ T /* i3 */ as /* i4 */ U /* i5 */ } from 'foo';
|
||||
|
||||
=====================================output=====================================
|
||||
export type { SomeThing };
|
||||
export type { A as B };
|
||||
@@ -132,5 +142,15 @@ import type { foo as bar } from "baz";
|
||||
import type * as foo from "./bar";
|
||||
import type foo from "bar";
|
||||
|
||||
// https://github.com/prettier/prettier/issues/19564
|
||||
export { type /* comment */ T } from "foo";
|
||||
import { type /* comment */ T } from "foo";
|
||||
|
||||
export { /* e1 */ type /* e2 */ T /* e3 */ } from "foo";
|
||||
import { /* i1 */ type /* i2 */ T /* i3 */ } from "foo";
|
||||
|
||||
export { /* e1 */ type /* e2 */ T /* e3 */ as /* e4 */ U /* e5 */ } from "foo";
|
||||
import { /* i1 */ type /* i2 */ T /* i3 */ as /* i4 */ U /* i5 */ } from "foo";
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
@@ -12,3 +12,13 @@ import type { foo, bar } from 'baz';
|
||||
import type { foo as bar } from 'baz';
|
||||
import type * as foo from './bar';
|
||||
import type foo from 'bar';
|
||||
|
||||
// https://github.com/prettier/prettier/issues/19564
|
||||
export { type /* comment */ T } from 'foo';
|
||||
import { type /* comment */ T } from 'foo';
|
||||
|
||||
export { /* e1 */ type /* e2 */ T /* e3 */ } from 'foo';
|
||||
import { /* i1 */ type /* i2 */ T /* i3 */ } from 'foo';
|
||||
|
||||
export { /* e1 */ type /* e2 */ T /* e3 */ as /* e4 */ U /* e5 */ } from 'foo';
|
||||
import { /* i1 */ type /* i2 */ T /* i3 */ as /* i4 */ U /* i5 */ } from 'foo';
|
||||
Reference in new issue
Block a user