Skip to content

Commit b908c09

Browse files
committed
fix: Constructors were improperly reported as inherited
All of this is horrible. Surely there's a better way, but I've been banging on this for nearly a whole day now. Also makes these properties get set with broken references earlier so that typedoc-plugin-no-inherit works. Closes #1528 Closes #1527
1 parent 49eb74e commit b908c09

28 files changed

+766
-381
lines changed

.eslintrc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,15 @@
2929

3030
// Feel free to turn one of these back on and submit a PR!
3131
"@typescript-eslint/no-non-null-assertion": 0,
32-
"@typescript-eslint/explicit-module-boundary-types": 0
32+
"@typescript-eslint/explicit-module-boundary-types": 0,
33+
34+
"no-restricted-syntax": [
35+
"error",
36+
{
37+
"selector": "ImportDeclaration[source.value=/^node:/]",
38+
"message": "This will break on Node 10"
39+
}
40+
]
3341
},
3442
"overrides": [
3543
{

src/lib/converter/context.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ export class Context {
190190
nameOverride ?? exportSymbol?.name ?? symbol?.name ?? "unknown"
191191
);
192192
const reflection = new DeclarationReflection(name, kind, this.scope);
193+
reflection.escapedName = symbol?.escapedName;
194+
193195
this.addChild(reflection);
194196
if (symbol && this.converter.isExternal(symbol)) {
195197
reflection.setFlag(ReflectionFlag.External);
@@ -199,16 +201,23 @@ export class Context {
199201
}
200202
this.registerReflection(reflection, symbol);
201203

204+
return reflection;
205+
}
206+
207+
finalizeDeclarationReflection(
208+
reflection: DeclarationReflection,
209+
symbol: ts.Symbol | undefined,
210+
exportSymbol?: ts.Symbol
211+
) {
202212
this.exportSymbol = exportSymbol;
203213
this.converter.trigger(
204214
ConverterEvents.CREATE_DECLARATION,
205215
this,
206216
reflection,
207-
symbol && this.converter.getNodesForSymbol(symbol, kind)[0]
217+
symbol &&
218+
this.converter.getNodesForSymbol(symbol, reflection.kind)[0]
208219
);
209220
this.exportSymbol = undefined;
210-
211-
return reflection;
212221
}
213222

214223
addChild(reflection: DeclarationReflection) {

src/lib/converter/convert-expression.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ export function convertDefaultValue(
1717
}
1818
}
1919

20-
export function convertExpression(
21-
expression: ts.Expression
22-
): string | undefined {
20+
export function convertExpression(expression: ts.Expression) {
2321
switch (expression.kind) {
2422
case ts.SyntaxKind.StringLiteral:
2523
case ts.SyntaxKind.TrueKeyword:

src/lib/converter/converter.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ export class Converter extends ChildableComponent<
323323
void 0,
324324
entryName
325325
);
326+
context.finalizeDeclarationReflection(reflection, symbol);
326327
moduleContext = context.withScope(reflection);
327328
}
328329

src/lib/converter/factories/index-signature.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ export function convertIndexSignature(context: Context, symbol: ts.Symbol) {
4444
indexDeclaration.type
4545
);
4646
context.registerReflection(index, indexSymbol);
47+
context.scope.indexSignature = index;
48+
4749
context.trigger(
4850
ConverterEvents.CREATE_SIGNATURE,
4951
index,
5052
indexDeclaration
5153
);
52-
53-
context.scope.indexSignature = index;
5454
}
5555
}

src/lib/converter/factories/signature.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ export function createSignature(
4444
commentDeclaration ??= declaration;
4545

4646
const sigRef = new SignatureReflection(
47-
context.scope.name,
47+
kind == ReflectionKind.ConstructorSignature
48+
? `new ${context.scope.parent!.name}`
49+
: context.scope.name,
4850
kind,
4951
context.scope
5052
);
@@ -75,12 +77,26 @@ export function createSignature(
7577
}
7678

7779
context.registerReflection(sigRef, undefined);
80+
81+
switch (kind) {
82+
case ReflectionKind.GetSignature:
83+
context.scope.getSignature = sigRef;
84+
break;
85+
case ReflectionKind.SetSignature:
86+
context.scope.setSignature = sigRef;
87+
break;
88+
case ReflectionKind.CallSignature:
89+
case ReflectionKind.ConstructorSignature:
90+
context.scope.signatures ??= [];
91+
context.scope.signatures.push(sigRef);
92+
break;
93+
}
94+
7895
context.trigger(
7996
ConverterEvents.CREATE_SIGNATURE,
8097
sigRef,
8198
commentDeclaration
8299
);
83-
return sigRef;
84100
}
85101

86102
function convertParameters(

src/lib/converter/jsdoc.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ export function convertJsDocAlias(
4848
context.withScope(reflection),
4949
declaration.parent
5050
);
51+
52+
context.finalizeDeclarationReflection(reflection, symbol, exportSymbol);
5153
}
5254

5355
export function convertJsDocCallback(
@@ -61,6 +63,8 @@ export function convertJsDocCallback(
6163
symbol,
6264
exportSymbol
6365
);
66+
context.finalizeDeclarationReflection(alias, symbol, exportSymbol);
67+
6468
const ac = context.withScope(alias);
6569

6670
alias.type = convertJsDocSignature(ac, declaration.typeExpression);
@@ -78,6 +82,8 @@ function convertJsDocInterface(
7882
symbol,
7983
exportSymbol
8084
);
85+
context.finalizeDeclarationReflection(reflection, symbol, exportSymbol);
86+
8187
const rc = context.withScope(reflection);
8288

8389
const type = context.checker.getDeclaredTypeOfSymbol(symbol);

0 commit comments

Comments
 (0)