Skip to content

Commit

Permalink
Update to latest prettier fork
Browse files Browse the repository at this point in the history
Summary:
Contains the following changes to the prettier fork:
1. Rebased the branch to main.
2. Reconfigured the build to strip some modules which were unneeded and causing problems in node
  - pieterv/prettier@195c4d5
3. Add printing support for TypeOperator and ComponentDeclaration renders
  - pieterv/prettier@6f1ea36

Additionally this does:
- Adds unit tests for features that can now be printed
- Fixed flow translator to correctly print `TSImportType` nodes as the AST format has now changed.

Reviewed By: SamChou19815

Differential Revision: D48703263

fbshipit-source-id: ddb425f4c79b0cc897769f10930dd6ec339165d3
  • Loading branch information
pieterv authored and facebook-github-bot committed Aug 26, 2023
1 parent 7c29d52 commit 1745868
Show file tree
Hide file tree
Showing 13 changed files with 2,416 additions and 4,609 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ exports[`flowDefToTSDef conditional-types/infer 1`] = `

type ExtractValues<
T extends
string | {readonly default: string; readonly [$$Key$$: string]: string},
| string
| {readonly default: string; readonly [$$Key$$: string]: string},
> = T[Key] extends {
readonly default: infer X;
readonly [$$Key$$: string]: infer Y;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ exports[`flowDefToTSDef object/mapped-objects 1`] = `
*/

export type FlattenTokens<
T extends
{
readonly [$$Key$$: string]:
| string
| {readonly default: string; readonly [$$Key$$: string]: string};
},
T extends {
readonly [$$Key$$: string]:
| string
| {readonly default: string; readonly [$$Key$$: string]: string};
},
> = {
readonly [Key in keyof T]: T[Key] extends {
readonly default: infer X;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1663,7 +1663,7 @@ const getTransforms = (
return {
type: 'TSImportType',
isTypeOf: true,
parameter: moduleName,
argument: moduleName,
qualifier: null,
typeParameters: null,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1589,7 +1589,7 @@ export interface TSImportEqualsDeclaration extends BaseNode {
export interface TSImportType extends BaseNode {
+type: 'TSImportType';
+isTypeOf: boolean;
+parameter: TypeNode;
+argument: TypeNode;
+qualifier: EntityName | null;
+typeParameters: TSTypeParameterInstantiation | null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe('ComponentDeclaration', () => {
});
});

describe('return type', () => {
describe('renders type', () => {
const code = `
component Foo() renders SpecialType {}
`;
Expand All @@ -103,6 +103,24 @@ describe('ComponentDeclaration', () => {
});
});

describe('renders type (complex)', () => {
const code = `
component Foo() renders (SpecialType | OtherSpecialType) {}
`;

test('ESTree', async () => {
expect(await printForSnapshotESTree(code)).toBe(code.trim());
expect(await parseForSnapshotESTree(code)).toMatchSnapshot();
});

test('Babel', async () => {
expect(await parseForSnapshotBabel(code)).toMatchSnapshot();
expect(await printForSnapshotBabel(code)).toMatchInlineSnapshot(
`"function Foo(): SpecialType | OtherSpecialType {}"`,
);
});
});

describe('type parameters', () => {
const code = `
component Foo<T1, T2>(bar: T1) renders T2 {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
import {parseForSnapshot, printForSnapshot} from '../__test_utils__/parse';

const parserOpts = {enableExperimentalComponentSyntax: true};
// async function printForSnapshotESTree(code: string) {
// return printForSnapshot(code, parserOpts);
// }
async function printForSnapshotESTree(code: string) {
return printForSnapshot(code, parserOpts);
}
async function parseForSnapshotESTree(code: string) {
return parseForSnapshot(code, parserOpts);
}
Expand All @@ -33,8 +33,7 @@ describe('TypeOperator', () => {

test('ESTree', async () => {
expect(await parseForSnapshotESTree(code)).toMatchSnapshot();
// TODO: Prettier support
// expect(await printForSnapshotESTree(code)).toBe(code.trim());
expect(await printForSnapshotESTree(code)).toBe(code.trim());
});

test('Babel', async () => {
Expand All @@ -51,8 +50,7 @@ describe('TypeOperator', () => {

test('ESTree', async () => {
expect(await parseForSnapshotESTree(code)).toMatchSnapshot();
// TODO: Prettier support
// expect(await printForSnapshotESTree(code)).toBe(code.trim());
expect(await printForSnapshotESTree(code)).toBe(code.trim());
});

test('Babel', async () => {
Expand All @@ -62,5 +60,22 @@ describe('TypeOperator', () => {
);
});
});
describe('Nested Union', () => {
const code = `
type T = renders (Foo | Bar) | null;
`;

test('ESTree', async () => {
expect(await parseForSnapshotESTree(code)).toMatchSnapshot();
expect(await printForSnapshotESTree(code)).toBe(code.trim());
});

test('Babel', async () => {
expect(await parseForSnapshotBabel(code)).toMatchSnapshot();
expect(await printForSnapshotBabel(code)).toMatchInlineSnapshot(
`"type T = any | null;"`,
);
});
});
});
});
Loading

0 comments on commit 1745868

Please sign in to comment.