Skip to content

Commit

Permalink
fix: Detect references when export * is used
Browse files Browse the repository at this point in the history
Resolves #1551
  • Loading branch information
Gerrit0 committed Mar 25, 2021
1 parent 5071848 commit f0b9192
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 95 deletions.
53 changes: 35 additions & 18 deletions src/lib/converter/symbols.ts
Expand Up @@ -69,6 +69,17 @@ export function convertSymbol(
return;
}

// This check can catch symbols which ought to be documented as references
// but aren't aliased symbols because `export *` was used.
const previous = context.project.getReflectionFromSymbol(symbol);
if (
previous &&
previous.parent?.kindOf(ReflectionKind.Module | ReflectionKind.Project)
) {
createAlias(previous, context, symbol, exportSymbol);
return;
}

let flags = removeFlag(
symbol.flags,
ts.SymbolFlags.Transient |
Expand Down Expand Up @@ -708,27 +719,33 @@ function convertAlias(
exportSymbol ?? symbol
);
} else {
// We already have this. Create a reference.
const ref = new ReferenceReflection(
exportSymbol?.name ?? symbol.name,
reflection,
context.scope
);
context.addChild(ref);
context.registerReflection(ref, symbol);

context.trigger(
ConverterEvents.CREATE_DECLARATION,
ref,
// FIXME this isn't good enough.
context.converter.getNodesForSymbol(
symbol,
ReflectionKind.Reference
)[0]
);
createAlias(reflection, context, symbol, exportSymbol);
}
}

function createAlias(
target: Reflection,
context: Context,
symbol: ts.Symbol,
exportSymbol: ts.Symbol | undefined
) {
// We already have this. Create a reference.
const ref = new ReferenceReflection(
exportSymbol?.name ?? symbol.name,
target,
context.scope
);
context.addChild(ref);
context.registerReflection(ref, symbol);

context.trigger(
ConverterEvents.CREATE_DECLARATION,
ref,
// FIXME this isn't good enough.
context.converter.getNodesForSymbol(symbol, ReflectionKind.Reference)[0]
);
}

function convertVariable(
context: Context,
symbol: ts.Symbol,
Expand Down
64 changes: 20 additions & 44 deletions src/test/converter/exports/specs.json
Expand Up @@ -11,6 +11,14 @@
"kindString": "Module",
"flags": {},
"children": [
{
"id": 50,
"name": "GH1453Helper",
"kind": 16777216,
"kindString": "Reference",
"flags": {},
"target": 41
},
{
"id": 43,
"name": "Mod",
Expand Down Expand Up @@ -44,7 +52,15 @@
"kind": 16777216,
"kindString": "Reference",
"flags": {},
"target": 33
"target": 40
},
{
"id": 46,
"name": "a",
"kind": 16777216,
"kindString": "Reference",
"flags": {},
"target": 36
},
{
"id": 47,
Expand All @@ -55,7 +71,7 @@
"comment": {
"shortText": "An export of a local under a different name."
},
"target": 36
"target": 37
},
{
"id": 42,
Expand Down Expand Up @@ -223,34 +239,6 @@
}
]
},
{
"id": 50,
"name": "GH1453Helper",
"kind": 4194304,
"kindString": "Type alias",
"flags": {},
"type": {
"type": "literal",
"value": "1"
}
},
{
"id": 46,
"name": "a",
"kind": 32,
"kindString": "Variable",
"flags": {
"isConst": true
},
"comment": {
"shortText": "A simple named export that will be exported from export.ts"
},
"type": {
"type": "literal",
"value": 1
},
"defaultValue": "1"
},
{
"id": 18,
"name": "add",
Expand Down Expand Up @@ -334,10 +322,12 @@
"title": "References",
"kind": 16777216,
"children": [
50,
43,
45,
44,
49,
46,
47,
42
]
Expand All @@ -350,20 +340,6 @@
29
]
},
{
"title": "Type aliases",
"kind": 4194304,
"children": [
50
]
},
{
"title": "Variables",
"kind": 32,
"children": [
46
]
},
{
"title": "Functions",
"kind": 64,
Expand Down
45 changes: 12 additions & 33 deletions src/test/renderer/specs/modules/mod2.html
Expand Up @@ -70,10 +70,10 @@ <h2>Index</h2>
<section class="tsd-panel tsd-index-panel">
<div class="tsd-index-content">
<section class="tsd-index-section ">
<h3>Variables</h3>
<h3>References</h3>
<ul class="tsd-index-list">
<li class="tsd-kind-variable tsd-parent-kind-module"><a href="mod2.html#a" class="tsd-kind-icon">a</a></li>
<li class="tsd-kind-variable tsd-parent-kind-module"><a href="mod2.html#gh1475" class="tsd-kind-icon">gh1475</a></li>
<li class="tsd-kind-reference tsd-parent-kind-module"><a href="mod2.html#a" class="tsd-kind-icon">a</a></li>
<li class="tsd-kind-reference tsd-parent-kind-module"><a href="mod2.html#gh1475" class="tsd-kind-icon">gh1475</a></li>
</ul>
</section>
<section class="tsd-index-section ">
Expand All @@ -86,37 +86,16 @@ <h3>Functions</h3>
</section>
</section>
<section class="tsd-panel-group tsd-member-group ">
<h2>Variables</h2>
<section class="tsd-panel tsd-member tsd-kind-variable tsd-parent-kind-module">
<h2>References</h2>
<section class="tsd-panel tsd-member tsd-kind-reference tsd-parent-kind-module">
<a name="a" class="tsd-anchor"></a>
<h3><span class="tsd-flag ts-flagConst">Const</span> a</h3>
<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>
<aside class="tsd-sources">
</aside>
<h3>a</h3>
Re-exports <a href="mod.html#a">a</a>
</section>
<section class="tsd-panel tsd-member tsd-kind-variable tsd-parent-kind-module">
<section class="tsd-panel tsd-member tsd-kind-reference tsd-parent-kind-module">
<a name="gh1475" class="tsd-anchor"></a>
<h3><span class="tsd-flag ts-flagConst">Const</span> gh1475</h3>
<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>
<aside class="tsd-sources">
</aside>
<div class="tsd-type-declaration">
<h4>Type declaration</h4>
<ul class="tsd-parameters">
<li class="tsd-parameter">
<h5><span class="tsd-signature-symbol">get </span>both<span class="tsd-signature-symbol">(): </span><span class="tsd-signature-type">string</span></h5>
</li>
<li class="tsd-parameter">
<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>
</li>
<li class="tsd-parameter">
<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>
</li>
<li class="tsd-parameter">
<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>
</li>
</ul>
</div>
<h3>gh1475</h3>
Re-exports <a href="mod.html#gh1475">gh1475</a>
</section>
</section>
<section class="tsd-panel-group tsd-member-group ">
Expand Down Expand Up @@ -194,10 +173,10 @@ <h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</spa
</nav>
<nav class="tsd-navigation secondary menu-sticky">
<ul class="before-current">
<li class=" tsd-kind-variable tsd-parent-kind-module">
<li class=" tsd-kind-reference tsd-parent-kind-module">
<a href="mod2.html#a" class="tsd-kind-icon">a</a>
</li>
<li class=" tsd-kind-variable tsd-parent-kind-module">
<li class=" tsd-kind-reference tsd-parent-kind-module">
<a href="mod2.html#gh1475" class="tsd-kind-icon">gh1475</a>
</li>
<li class=" tsd-kind-function tsd-parent-kind-module">
Expand Down

0 comments on commit f0b9192

Please sign in to comment.