Skip to content

Commit f0b9192

Browse files
committed
fix: Detect references when export * is used
Resolves #1551
1 parent 5071848 commit f0b9192

File tree

3 files changed

+67
-95
lines changed

3 files changed

+67
-95
lines changed

src/lib/converter/symbols.ts

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,17 @@ export function convertSymbol(
6969
return;
7070
}
7171

72+
// This check can catch symbols which ought to be documented as references
73+
// but aren't aliased symbols because `export *` was used.
74+
const previous = context.project.getReflectionFromSymbol(symbol);
75+
if (
76+
previous &&
77+
previous.parent?.kindOf(ReflectionKind.Module | ReflectionKind.Project)
78+
) {
79+
createAlias(previous, context, symbol, exportSymbol);
80+
return;
81+
}
82+
7283
let flags = removeFlag(
7384
symbol.flags,
7485
ts.SymbolFlags.Transient |
@@ -708,27 +719,33 @@ function convertAlias(
708719
exportSymbol ?? symbol
709720
);
710721
} else {
711-
// We already have this. Create a reference.
712-
const ref = new ReferenceReflection(
713-
exportSymbol?.name ?? symbol.name,
714-
reflection,
715-
context.scope
716-
);
717-
context.addChild(ref);
718-
context.registerReflection(ref, symbol);
719-
720-
context.trigger(
721-
ConverterEvents.CREATE_DECLARATION,
722-
ref,
723-
// FIXME this isn't good enough.
724-
context.converter.getNodesForSymbol(
725-
symbol,
726-
ReflectionKind.Reference
727-
)[0]
728-
);
722+
createAlias(reflection, context, symbol, exportSymbol);
729723
}
730724
}
731725

726+
function createAlias(
727+
target: Reflection,
728+
context: Context,
729+
symbol: ts.Symbol,
730+
exportSymbol: ts.Symbol | undefined
731+
) {
732+
// We already have this. Create a reference.
733+
const ref = new ReferenceReflection(
734+
exportSymbol?.name ?? symbol.name,
735+
target,
736+
context.scope
737+
);
738+
context.addChild(ref);
739+
context.registerReflection(ref, symbol);
740+
741+
context.trigger(
742+
ConverterEvents.CREATE_DECLARATION,
743+
ref,
744+
// FIXME this isn't good enough.
745+
context.converter.getNodesForSymbol(symbol, ReflectionKind.Reference)[0]
746+
);
747+
}
748+
732749
function convertVariable(
733750
context: Context,
734751
symbol: ts.Symbol,

src/test/converter/exports/specs.json

Lines changed: 20 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@
1111
"kindString": "Module",
1212
"flags": {},
1313
"children": [
14+
{
15+
"id": 50,
16+
"name": "GH1453Helper",
17+
"kind": 16777216,
18+
"kindString": "Reference",
19+
"flags": {},
20+
"target": 41
21+
},
1422
{
1523
"id": 43,
1624
"name": "Mod",
@@ -44,7 +52,15 @@
4452
"kind": 16777216,
4553
"kindString": "Reference",
4654
"flags": {},
47-
"target": 33
55+
"target": 40
56+
},
57+
{
58+
"id": 46,
59+
"name": "a",
60+
"kind": 16777216,
61+
"kindString": "Reference",
62+
"flags": {},
63+
"target": 36
4864
},
4965
{
5066
"id": 47,
@@ -55,7 +71,7 @@
5571
"comment": {
5672
"shortText": "An export of a local under a different name."
5773
},
58-
"target": 36
74+
"target": 37
5975
},
6076
{
6177
"id": 42,
@@ -223,34 +239,6 @@
223239
}
224240
]
225241
},
226-
{
227-
"id": 50,
228-
"name": "GH1453Helper",
229-
"kind": 4194304,
230-
"kindString": "Type alias",
231-
"flags": {},
232-
"type": {
233-
"type": "literal",
234-
"value": "1"
235-
}
236-
},
237-
{
238-
"id": 46,
239-
"name": "a",
240-
"kind": 32,
241-
"kindString": "Variable",
242-
"flags": {
243-
"isConst": true
244-
},
245-
"comment": {
246-
"shortText": "A simple named export that will be exported from export.ts"
247-
},
248-
"type": {
249-
"type": "literal",
250-
"value": 1
251-
},
252-
"defaultValue": "1"
253-
},
254242
{
255243
"id": 18,
256244
"name": "add",
@@ -334,10 +322,12 @@
334322
"title": "References",
335323
"kind": 16777216,
336324
"children": [
325+
50,
337326
43,
338327
45,
339328
44,
340329
49,
330+
46,
341331
47,
342332
42
343333
]
@@ -350,20 +340,6 @@
350340
29
351341
]
352342
},
353-
{
354-
"title": "Type aliases",
355-
"kind": 4194304,
356-
"children": [
357-
50
358-
]
359-
},
360-
{
361-
"title": "Variables",
362-
"kind": 32,
363-
"children": [
364-
46
365-
]
366-
},
367343
{
368344
"title": "Functions",
369345
"kind": 64,

src/test/renderer/specs/modules/mod2.html

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ <h2>Index</h2>
7070
<section class="tsd-panel tsd-index-panel">
7171
<div class="tsd-index-content">
7272
<section class="tsd-index-section ">
73-
<h3>Variables</h3>
73+
<h3>References</h3>
7474
<ul class="tsd-index-list">
75-
<li class="tsd-kind-variable tsd-parent-kind-module"><a href="mod2.html#a" class="tsd-kind-icon">a</a></li>
76-
<li class="tsd-kind-variable tsd-parent-kind-module"><a href="mod2.html#gh1475" class="tsd-kind-icon">gh1475</a></li>
75+
<li class="tsd-kind-reference tsd-parent-kind-module"><a href="mod2.html#a" class="tsd-kind-icon">a</a></li>
76+
<li class="tsd-kind-reference tsd-parent-kind-module"><a href="mod2.html#gh1475" class="tsd-kind-icon">gh1475</a></li>
7777
</ul>
7878
</section>
7979
<section class="tsd-index-section ">
@@ -86,37 +86,16 @@ <h3>Functions</h3>
8686
</section>
8787
</section>
8888
<section class="tsd-panel-group tsd-member-group ">
89-
<h2>Variables</h2>
90-
<section class="tsd-panel tsd-member tsd-kind-variable tsd-parent-kind-module">
89+
<h2>References</h2>
90+
<section class="tsd-panel tsd-member tsd-kind-reference tsd-parent-kind-module">
9191
<a name="a" class="tsd-anchor"></a>
92-
<h3><span class="tsd-flag ts-flagConst">Const</span> a</h3>
93-
<div class="tsd-signature tsd-kind-icon">a<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">1</span><span class="tsd-signature-symbol"> = 1</span></div>
94-
<aside class="tsd-sources">
95-
</aside>
92+
<h3>a</h3>
93+
Re-exports <a href="mod.html#a">a</a>
9694
</section>
97-
<section class="tsd-panel tsd-member tsd-kind-variable tsd-parent-kind-module">
95+
<section class="tsd-panel tsd-member tsd-kind-reference tsd-parent-kind-module">
9896
<a name="gh1475" class="tsd-anchor"></a>
99-
<h3><span class="tsd-flag ts-flagConst">Const</span> gh1475</h3>
100-
<div class="tsd-signature tsd-kind-icon">gh1475<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-symbol">{ </span>both<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">; </span><span class="tsd-signature-symbol">get </span>getIt<span class="tsd-signature-symbol">(): </span><span class="tsd-signature-type">number</span><span class="tsd-signature-symbol">; </span><span class="tsd-signature-symbol">set </span>setIt<span class="tsd-signature-symbol">(</span>n<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">number</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol"> }</span><span class="tsd-signature-symbol"> = ...</span></div>
101-
<aside class="tsd-sources">
102-
</aside>
103-
<div class="tsd-type-declaration">
104-
<h4>Type declaration</h4>
105-
<ul class="tsd-parameters">
106-
<li class="tsd-parameter">
107-
<h5><span class="tsd-signature-symbol">get </span>both<span class="tsd-signature-symbol">(): </span><span class="tsd-signature-type">string</span></h5>
108-
</li>
109-
<li class="tsd-parameter">
110-
<h5><span class="tsd-signature-symbol">set </span>both<span class="tsd-signature-symbol">(</span>x<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">): </span><span class="tsd-signature-type">void</span></h5>
111-
</li>
112-
<li class="tsd-parameter">
113-
<h5><span class="tsd-signature-symbol">get </span>get<wbr>It<span class="tsd-signature-symbol">(): </span><span class="tsd-signature-type">number</span></h5>
114-
</li>
115-
<li class="tsd-parameter">
116-
<h5><span class="tsd-signature-symbol">set </span>set<wbr>It<span class="tsd-signature-symbol">(</span>n<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">number</span><span class="tsd-signature-symbol">): </span><span class="tsd-signature-type">void</span></h5>
117-
</li>
118-
</ul>
119-
</div>
97+
<h3>gh1475</h3>
98+
Re-exports <a href="mod.html#gh1475">gh1475</a>
12099
</section>
121100
</section>
122101
<section class="tsd-panel-group tsd-member-group ">
@@ -194,10 +173,10 @@ <h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</spa
194173
</nav>
195174
<nav class="tsd-navigation secondary menu-sticky">
196175
<ul class="before-current">
197-
<li class=" tsd-kind-variable tsd-parent-kind-module">
176+
<li class=" tsd-kind-reference tsd-parent-kind-module">
198177
<a href="mod2.html#a" class="tsd-kind-icon">a</a>
199178
</li>
200-
<li class=" tsd-kind-variable tsd-parent-kind-module">
179+
<li class=" tsd-kind-reference tsd-parent-kind-module">
201180
<a href="mod2.html#gh1475" class="tsd-kind-icon">gh1475</a>
202181
</li>
203182
<li class=" tsd-kind-function tsd-parent-kind-module">

0 commit comments

Comments
 (0)