Skip to content

Commit

Permalink
fix: Functions might not have a parent in global files
Browse files Browse the repository at this point in the history
Closes #1436
  • Loading branch information
Gerrit0 committed Dec 30, 2020
1 parent d4f7838 commit d739298
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 21 deletions.
6 changes: 1 addition & 5 deletions src/lib/converter/symbols.ts
Expand Up @@ -243,14 +243,13 @@ function convertFunctionOrMethod(
}

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

const locationDeclaration =
parentSymbol
?.getDeclarations()
?.find(
(d) => ts.isClassDeclaration(d) || ts.isInterfaceDeclaration(d)
) ?? parentSymbol.getDeclarations()?.[0]?.getSourceFile();
) ?? symbol.getDeclarations()?.[0]?.getSourceFile();
assert(locationDeclaration, "Missing declaration context");

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

const parentSymbol = context.project.getSymbolFromReflection(
context.scope
);
assert(parentSymbol, "Tried to convert a method without a parent.");
if (
parentSymbol
Expand Down
1 change: 1 addition & 0 deletions src/test/converter/declaration/global-fn.d.ts
@@ -0,0 +1 @@
declare function gh1436(): void;
71 changes: 55 additions & 16 deletions src/test/converter/declaration/specs.json
Expand Up @@ -198,20 +198,58 @@
},
{
"id": 14,
"name": "global-fn",
"kind": 1,
"kindString": "Module",
"flags": {},
"children": [
{
"id": 15,
"name": "gh1436",
"kind": 64,
"kindString": "Function",
"flags": {},
"signatures": [
{
"id": 16,
"name": "gh1436",
"kind": 4096,
"kindString": "Call signature",
"flags": {},
"type": {
"type": "intrinsic",
"name": "void"
}
}
]
}
],
"groups": [
{
"title": "Functions",
"kind": 64,
"children": [
15
]
}
]
},
{
"id": 17,
"name": "namespaces",
"kind": 1,
"kindString": "Module",
"flags": {},
"children": [
{
"id": 19,
"id": 22,
"name": "GH1124",
"kind": 2,
"kindString": "Namespace",
"flags": {},
"children": [
{
"id": 20,
"id": 23,
"name": "PrimitiveType",
"kind": 4194304,
"kindString": "Type alias",
Expand Down Expand Up @@ -239,7 +277,7 @@
}
},
{
"id": 21,
"id": 24,
"name": "Value",
"kind": 32,
"kindString": "Variable",
Expand All @@ -257,53 +295,53 @@
"title": "Type aliases",
"kind": 4194304,
"children": [
20
23
]
},
{
"title": "Variables",
"kind": 32,
"children": [
21
24
]
}
]
},
{
"id": 17,
"id": 20,
"name": "GH1366",
"kind": 2,
"kindString": "Namespace",
"flags": {},
"children": [
{
"id": 18,
"id": 21,
"name": "Foo",
"kind": 16777216,
"kindString": "Reference",
"flags": {},
"target": 15
"target": 18
}
],
"groups": [
{
"title": "References",
"kind": 16777216,
"children": [
18
21
]
}
]
},
{
"id": 15,
"id": 18,
"name": "Foo",
"kind": 256,
"kindString": "Interface",
"flags": {},
"children": [
{
"id": 16,
"id": 19,
"name": "prop",
"kind": 1024,
"kindString": "Property",
Expand All @@ -319,7 +357,7 @@
"title": "Properties",
"kind": 1024,
"children": [
16
19
]
}
]
Expand All @@ -330,15 +368,15 @@
"title": "Namespaces",
"kind": 2,
"children": [
19,
17
22,
20
]
},
{
"title": "Interfaces",
"kind": 256,
"children": [
15
18
]
}
]
Expand All @@ -351,7 +389,8 @@
"children": [
1,
7,
14
14,
17
]
}
]
Expand Down

0 comments on commit d739298

Please sign in to comment.