Skip to content

Commit 1f8e3d0

Browse files
committed
Removing duplications on type declaration
1 parent f0a5425 commit 1f8e3d0

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "Typescript declaration generator for svelte with typescript",
44
"main": "dist/index.js",
55
"types": "dist/index.ts",
6-
"version": "0.3.3",
6+
"version": "0.3.4",
77
"license": "MIT",
88
"homepage": "https://github.com/andrelmlins/svelte-dts",
99
"repository": "https://github.com/andrelmlins/svelte-dts",

src/transformer/svelte.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ class SvelteTransformer implements ITransformer {
5555
);
5656
}
5757

58+
private addTypeForSearch(newType: ts.TypeReferenceNode): void {
59+
const includeType = this.typesForSearch.map(
60+
(item) => item.getText(this.sourceFile) === newType.getText(this.sourceFile)
61+
);
62+
63+
if (!includeType) {
64+
this.typesForSearch.push(newType);
65+
}
66+
}
67+
5868
private compileProperty(node: ts.VariableStatement): void {
5969
node.declarationList.declarations.forEach((declaration) => {
6070
const name = declaration.name.getText(this.sourceFile);
@@ -66,7 +76,7 @@ class SvelteTransformer implements ITransformer {
6676
type = declaration.type.getText(this.sourceFile);
6777

6878
if (ts.isTypeReferenceNode(declaration.type)) {
69-
this.typesForSearch.push(declaration.type);
79+
this.addTypeForSearch(declaration.type);
7080
}
7181

7282
if (ts.isUnionTypeNode(declaration.type)) {
@@ -102,7 +112,7 @@ class SvelteTransformer implements ITransformer {
102112
const type = member.type?.getText(this.sourceFile) || 'any';
103113

104114
if (member.type && ts.isTypeReferenceNode(member.type)) {
105-
this.typesForSearch.push(member.type);
115+
this.addTypeForSearch(member.type);
106116
}
107117

108118
this.events.push({ name, type });

0 commit comments

Comments
 (0)