Skip to content

Commit

Permalink
fix(writer): omit moduleName if value is "default" (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
metonym authored Jul 10, 2021
1 parent 61f827d commit 417de1c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/writer/writer-ts-definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export function writeTsDefinition(component: ComponentDocApi) {
${getTypeDefs({ typedefs })}
${prop_def}
export default class ${moduleName} extends SvelteComponentTyped<
export default class ${moduleName === 'default' ? '' : moduleName} extends SvelteComponentTyped<
${props_name},
{${genEventDef({ events })}},
{${genSlotDef({ slots })}}
Expand Down
18 changes: 18 additions & 0 deletions tests/writer-ts-definitions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,21 @@ test("writeTsDefinition", (t) => {
);
t.end();
});

test('writeTsDefinition – "default" module name', (t) => {
const component_api: ComponentDocApi = {
moduleName: "default",
filePath: "./src/ModuleName.svelte",
props: [],
slots: [],
events: [],
typedefs: [],
rest_props: undefined,
};

t.equal(
writeTsDefinition(component_api),
'\n /// <reference types="svelte" />\n import { SvelteComponentTyped } from "svelte";\n \n \n \n export interface defaultProps {\n \n }\n \n\n export default class extends SvelteComponentTyped<\n defaultProps,\n {},\n {}\n > {\n \n }'
);
t.end();
});

0 comments on commit 417de1c

Please sign in to comment.