Skip to content

Commit

Permalink
fix: Constructors were improperly reported as inherited
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Gerrit0 committed Mar 13, 2021
1 parent 49eb74e commit b908c09
Show file tree
Hide file tree
Showing 28 changed files with 766 additions and 381 deletions.
10 changes: 9 additions & 1 deletion .eslintrc
Expand Up @@ -29,7 +29,15 @@

// Feel free to turn one of these back on and submit a PR!
"@typescript-eslint/no-non-null-assertion": 0,
"@typescript-eslint/explicit-module-boundary-types": 0
"@typescript-eslint/explicit-module-boundary-types": 0,

"no-restricted-syntax": [
"error",
{
"selector": "ImportDeclaration[source.value=/^node:/]",
"message": "This will break on Node 10"
}
]
},
"overrides": [
{
Expand Down
15 changes: 12 additions & 3 deletions src/lib/converter/context.ts
Expand Up @@ -190,6 +190,8 @@ export class Context {
nameOverride ?? exportSymbol?.name ?? symbol?.name ?? "unknown"
);
const reflection = new DeclarationReflection(name, kind, this.scope);
reflection.escapedName = symbol?.escapedName;

this.addChild(reflection);
if (symbol && this.converter.isExternal(symbol)) {
reflection.setFlag(ReflectionFlag.External);
Expand All @@ -199,16 +201,23 @@ export class Context {
}
this.registerReflection(reflection, symbol);

return reflection;
}

finalizeDeclarationReflection(
reflection: DeclarationReflection,
symbol: ts.Symbol | undefined,
exportSymbol?: ts.Symbol
) {
this.exportSymbol = exportSymbol;
this.converter.trigger(
ConverterEvents.CREATE_DECLARATION,
this,
reflection,
symbol && this.converter.getNodesForSymbol(symbol, kind)[0]
symbol &&
this.converter.getNodesForSymbol(symbol, reflection.kind)[0]
);
this.exportSymbol = undefined;

return reflection;
}

addChild(reflection: DeclarationReflection) {
Expand Down
4 changes: 1 addition & 3 deletions src/lib/converter/convert-expression.ts
Expand Up @@ -17,9 +17,7 @@ export function convertDefaultValue(
}
}

export function convertExpression(
expression: ts.Expression
): string | undefined {
export function convertExpression(expression: ts.Expression) {
switch (expression.kind) {
case ts.SyntaxKind.StringLiteral:
case ts.SyntaxKind.TrueKeyword:
Expand Down
1 change: 1 addition & 0 deletions src/lib/converter/converter.ts
Expand Up @@ -323,6 +323,7 @@ export class Converter extends ChildableComponent<
void 0,
entryName
);
context.finalizeDeclarationReflection(reflection, symbol);
moduleContext = context.withScope(reflection);
}

Expand Down
4 changes: 2 additions & 2 deletions src/lib/converter/factories/index-signature.ts
Expand Up @@ -44,12 +44,12 @@ export function convertIndexSignature(context: Context, symbol: ts.Symbol) {
indexDeclaration.type
);
context.registerReflection(index, indexSymbol);
context.scope.indexSignature = index;

context.trigger(
ConverterEvents.CREATE_SIGNATURE,
index,
indexDeclaration
);

context.scope.indexSignature = index;
}
}
20 changes: 18 additions & 2 deletions src/lib/converter/factories/signature.ts
Expand Up @@ -44,7 +44,9 @@ export function createSignature(
commentDeclaration ??= declaration;

const sigRef = new SignatureReflection(
context.scope.name,
kind == ReflectionKind.ConstructorSignature
? `new ${context.scope.parent!.name}`
: context.scope.name,
kind,
context.scope
);
Expand Down Expand Up @@ -75,12 +77,26 @@ export function createSignature(
}

context.registerReflection(sigRef, undefined);

switch (kind) {
case ReflectionKind.GetSignature:
context.scope.getSignature = sigRef;
break;
case ReflectionKind.SetSignature:
context.scope.setSignature = sigRef;
break;
case ReflectionKind.CallSignature:
case ReflectionKind.ConstructorSignature:
context.scope.signatures ??= [];
context.scope.signatures.push(sigRef);
break;
}

context.trigger(
ConverterEvents.CREATE_SIGNATURE,
sigRef,
commentDeclaration
);
return sigRef;
}

function convertParameters(
Expand Down
6 changes: 6 additions & 0 deletions src/lib/converter/jsdoc.ts
Expand Up @@ -48,6 +48,8 @@ export function convertJsDocAlias(
context.withScope(reflection),
declaration.parent
);

context.finalizeDeclarationReflection(reflection, symbol, exportSymbol);
}

export function convertJsDocCallback(
Expand All @@ -61,6 +63,8 @@ export function convertJsDocCallback(
symbol,
exportSymbol
);
context.finalizeDeclarationReflection(alias, symbol, exportSymbol);

const ac = context.withScope(alias);

alias.type = convertJsDocSignature(ac, declaration.typeExpression);
Expand All @@ -78,6 +82,8 @@ function convertJsDocInterface(
symbol,
exportSymbol
);
context.finalizeDeclarationReflection(reflection, symbol, exportSymbol);

const rc = context.withScope(reflection);

const type = context.checker.getDeclaredTypeOfSymbol(symbol);
Expand Down

0 comments on commit b908c09

Please sign in to comment.