Skip to content

Commit 6d78350

Browse files
committed
Fix how namespaces are found
1 parent 9c08961 commit 6d78350

File tree

3 files changed

+26
-13
lines changed

3 files changed

+26
-13
lines changed

src/parsers/typeResolver.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -290,19 +290,24 @@ export function getTypeNamespaces(type: ts.Type): string[] {
290290
return [];
291291
}
292292

293+
if (symbol.name === '__function' || symbol.name === '__type') {
294+
return [];
295+
}
296+
297+
const declaration = symbol.valueDeclaration ?? symbol.declarations?.[0];
298+
if (!declaration) {
299+
return [];
300+
}
301+
293302
const namespaces: string[] = [];
294-
let currentSymbol: ts.Symbol | undefined = symbol.parent;
303+
let currentDeclaration: ts.Node = declaration.parent;
295304

296-
while (currentSymbol) {
297-
if (
298-
currentSymbol &&
299-
currentSymbol.valueDeclaration &&
300-
ts.isModuleDeclaration(currentSymbol.valueDeclaration)
301-
) {
302-
namespaces.unshift(currentSymbol.name);
305+
while (currentDeclaration != null && !ts.isSourceFile(currentDeclaration)) {
306+
if (ts.isModuleDeclaration(currentDeclaration)) {
307+
namespaces.unshift(currentDeclaration.name.getText());
303308
}
304309

305-
currentSymbol = currentSymbol.parent;
310+
currentDeclaration = currentDeclaration.parent;
306311
}
307312

308313
return namespaces;

test/base-ui-component/output.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@
111111
"type": {
112112
"kind": "object",
113113
"name": "State",
114-
"parentNamespaces": [],
114+
"parentNamespaces": [
115+
"BaseUIComponent"
116+
],
115117
"properties": [
116118
{
117119
"name": "state",
@@ -243,7 +245,9 @@
243245
"type": {
244246
"kind": "object",
245247
"name": "State",
246-
"parentNamespaces": [],
248+
"parentNamespaces": [
249+
"BaseUIComponent"
250+
],
247251
"properties": [
248252
{
249253
"name": "state",

test/exports/output.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,9 @@
152152
"type": {
153153
"kind": "object",
154154
"name": "Params",
155-
"parentNamespaces": [],
155+
"parentNamespaces": [
156+
"functionAndNamespaceDeclaration"
157+
],
156158
"properties": [
157159
{
158160
"name": "a",
@@ -183,7 +185,9 @@
183185
"returnValueType": {
184186
"kind": "reference",
185187
"name": "Element",
186-
"parentNamespaces": []
188+
"parentNamespaces": [
189+
"JSX"
190+
]
187191
}
188192
}
189193
]

0 commit comments

Comments
 (0)