Skip to content

Commit

Permalink
Allow scoped module names
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuanapoli committed Nov 6, 2023
1 parent 61b5de8 commit 74141e6
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 1 deletion.
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

0 comments on commit 74141e6

Please sign in to comment.