Skip to content

Commit d739298

Browse files
committed
fix: Functions might not have a parent in global files
Closes #1436
1 parent d4f7838 commit d739298

File tree

3 files changed

+57
-21
lines changed

3 files changed

+57
-21
lines changed

src/lib/converter/symbols.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,14 +243,13 @@ function convertFunctionOrMethod(
243243
}
244244

245245
const parentSymbol = context.project.getSymbolFromReflection(context.scope);
246-
assert(parentSymbol, "Missing parent symbol when converting function");
247246

248247
const locationDeclaration =
249248
parentSymbol
250249
?.getDeclarations()
251250
?.find(
252251
(d) => ts.isClassDeclaration(d) || ts.isInterfaceDeclaration(d)
253-
) ?? parentSymbol.getDeclarations()?.[0]?.getSourceFile();
252+
) ?? symbol.getDeclarations()?.[0]?.getSourceFile();
254253
assert(locationDeclaration, "Missing declaration context");
255254

256255
const type = context.checker.getTypeOfSymbolAtLocation(
@@ -269,9 +268,6 @@ function convertFunctionOrMethod(
269268
// All method signatures must have the same modifier flags.
270269
setModifiers(declarations[0], reflection);
271270

272-
const parentSymbol = context.project.getSymbolFromReflection(
273-
context.scope
274-
);
275271
assert(parentSymbol, "Tried to convert a method without a parent.");
276272
if (
277273
parentSymbol
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
declare function gh1436(): void;

src/test/converter/declaration/specs.json

Lines changed: 55 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -198,20 +198,58 @@
198198
},
199199
{
200200
"id": 14,
201+
"name": "global-fn",
202+
"kind": 1,
203+
"kindString": "Module",
204+
"flags": {},
205+
"children": [
206+
{
207+
"id": 15,
208+
"name": "gh1436",
209+
"kind": 64,
210+
"kindString": "Function",
211+
"flags": {},
212+
"signatures": [
213+
{
214+
"id": 16,
215+
"name": "gh1436",
216+
"kind": 4096,
217+
"kindString": "Call signature",
218+
"flags": {},
219+
"type": {
220+
"type": "intrinsic",
221+
"name": "void"
222+
}
223+
}
224+
]
225+
}
226+
],
227+
"groups": [
228+
{
229+
"title": "Functions",
230+
"kind": 64,
231+
"children": [
232+
15
233+
]
234+
}
235+
]
236+
},
237+
{
238+
"id": 17,
201239
"name": "namespaces",
202240
"kind": 1,
203241
"kindString": "Module",
204242
"flags": {},
205243
"children": [
206244
{
207-
"id": 19,
245+
"id": 22,
208246
"name": "GH1124",
209247
"kind": 2,
210248
"kindString": "Namespace",
211249
"flags": {},
212250
"children": [
213251
{
214-
"id": 20,
252+
"id": 23,
215253
"name": "PrimitiveType",
216254
"kind": 4194304,
217255
"kindString": "Type alias",
@@ -239,7 +277,7 @@
239277
}
240278
},
241279
{
242-
"id": 21,
280+
"id": 24,
243281
"name": "Value",
244282
"kind": 32,
245283
"kindString": "Variable",
@@ -257,53 +295,53 @@
257295
"title": "Type aliases",
258296
"kind": 4194304,
259297
"children": [
260-
20
298+
23
261299
]
262300
},
263301
{
264302
"title": "Variables",
265303
"kind": 32,
266304
"children": [
267-
21
305+
24
268306
]
269307
}
270308
]
271309
},
272310
{
273-
"id": 17,
311+
"id": 20,
274312
"name": "GH1366",
275313
"kind": 2,
276314
"kindString": "Namespace",
277315
"flags": {},
278316
"children": [
279317
{
280-
"id": 18,
318+
"id": 21,
281319
"name": "Foo",
282320
"kind": 16777216,
283321
"kindString": "Reference",
284322
"flags": {},
285-
"target": 15
323+
"target": 18
286324
}
287325
],
288326
"groups": [
289327
{
290328
"title": "References",
291329
"kind": 16777216,
292330
"children": [
293-
18
331+
21
294332
]
295333
}
296334
]
297335
},
298336
{
299-
"id": 15,
337+
"id": 18,
300338
"name": "Foo",
301339
"kind": 256,
302340
"kindString": "Interface",
303341
"flags": {},
304342
"children": [
305343
{
306-
"id": 16,
344+
"id": 19,
307345
"name": "prop",
308346
"kind": 1024,
309347
"kindString": "Property",
@@ -319,7 +357,7 @@
319357
"title": "Properties",
320358
"kind": 1024,
321359
"children": [
322-
16
360+
19
323361
]
324362
}
325363
]
@@ -330,15 +368,15 @@
330368
"title": "Namespaces",
331369
"kind": 2,
332370
"children": [
333-
19,
334-
17
371+
22,
372+
20
335373
]
336374
},
337375
{
338376
"title": "Interfaces",
339377
"kind": 256,
340378
"children": [
341-
15
379+
18
342380
]
343381
}
344382
]
@@ -351,7 +389,8 @@
351389
"children": [
352390
1,
353391
7,
354-
14
392+
14,
393+
17
355394
]
356395
}
357396
]

0 commit comments

Comments
 (0)