Skip to content
Open
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
47 changes: 47 additions & 0 deletions src/__tests__/__snapshots__/asModule.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`should wrap in module 1`] = `
"declare module \\"myModule\\" {
declare type Test = \\"ok\\" | \\"error\\";
declare type Test2 = \\"ok\\" | \\"error\\";
declare type Maybe<T> =
| {
type: \\"just\\",
value: T,
...
}
| {
type: \\"nothing\\",
...
};
declare type Ref<T> = {
current: T,
...
};
declare var ok: number;
}
"
`;

exports[`should wrap in module with scoped name 1`] = `
"declare module \\"@company/project\\" {
declare type Test = \\"ok\\" | \\"error\\";
declare type Test2 = \\"ok\\" | \\"error\\";
declare type Maybe<T> =
| {
type: \\"just\\",
value: T,
...
}
| {
type: \\"nothing\\",
...
};
declare type Ref<T> = {
current: T,
...
};
declare var ok: number;
}
"
`;
30 changes: 30 additions & 0 deletions src/__tests__/asModule.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { compiler, beautify } from "..";
import "../test-matchers";

it("should wrap in module", () => {
const ts = `
declare export type Test = 'ok' | 'error'
declare type Test2 = 'ok' | 'error'
type Maybe<T> = {type: 'just', value: T} | {type: 'nothing'}
export type Ref<T> = { current: T }

export const ok: number
`;
const result = compiler.compileDefinitionString(ts, { quiet: true, asModule: "myModule" });
expect(beautify(result)).toMatchSnapshot();
expect(result).toBeValidFlowTypeDeclarations();
});

it("should wrap in module with scoped name", () => {
const ts = `
declare export type Test = 'ok' | 'error'
declare type Test2 = 'ok' | 'error'
type Maybe<T> = {type: 'just', value: T} | {type: 'nothing'}
export type Ref<T> = { current: T }

export const ok: number
`;
const result = compiler.compileDefinitionString(ts, { quiet: true, asModule: "@company/project" });
expect(beautify(result)).toMatchSnapshot();
expect(result).toBeValidFlowTypeDeclarations();
});
2 changes: 1 addition & 1 deletion src/parse/transformers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export function declarationFileTransform(options?: Options) {
ctx.factory.createModuleDeclaration(
undefined,
undefined,
ctx.factory.createIdentifier(options.asModule),
ctx.factory.createStringLiteral(options.asModule),
ctx.factory.createModuleBlock(
node.statements.map(statement => {
if (statement.modifiers) {
Expand Down