Don't mutate SignatureObject from services

This commit is contained in:
Ron Buckton
2024-04-17 21:30:59 -04:00
parent 74b510aff2
commit 9e56c70e49
3 changed files with 33 additions and 10 deletions

View File

@@ -42,6 +42,7 @@ import {
UnionOrIntersectionType,
UnionType,
} from "./_namespaces/ts";
import { SignatureObjectInternals } from "./signatureObjectInternals";
import { SymbolObjectInternals } from "./symbolObjectInternals";
/** @internal */
@@ -316,11 +317,11 @@ export class SignatureObject implements Signature {
}
getDocumentationComment(): SymbolDisplayPart[] {
throw new TypeError("Not implemented");
return SignatureObjectInternals.internals.getDocumentationComment(this);
}
getJsDocTags(): JSDocTagInfo[] {
throw new TypeError("Not implemented");
return SignatureObjectInternals.internals.getJsDocTags(this);
}
}

View File

@@ -0,0 +1,16 @@
import { JSDocTagInfo, Signature, SymbolDisplayPart } from "./types";
/** @internal */
export class SignatureObjectInternals {
static internals = new SignatureObjectInternals();
getDocumentationComment(signature: Signature): SymbolDisplayPart[];
getDocumentationComment(_signature: Signature): SymbolDisplayPart[] {
throw new TypeError("Not implemented.");
}
getJsDocTags(signature: Signature): JSDocTagInfo[];
getJsDocTags(_signature: Signature): JSDocTagInfo[] {
throw new TypeError("Not implemented.");
}
}

View File

@@ -2,6 +2,7 @@ import {
SignatureObject,
SymbolObject,
} from "../compiler/objectConstructors";
import { SignatureObjectInternals } from "../compiler/signatureObjectInternals";
import { SymbolObjectInternals } from "../compiler/symbolObjectInternals";
import {
__String,
@@ -374,15 +375,20 @@ function ensureSignatureExtraFields(signature: Signature) {
return extra;
}
SignatureObject.prototype.getDocumentationComment = function (this: Signature): SymbolDisplayPart[] {
const extra = ensureSignatureExtraFields(this);
return extra.documentationComment ??= getDocumentationComment(singleElementArray(this.declaration), this.checker);
};
class ServicesSignatureObjectInternals extends SignatureObjectInternals {
override getDocumentationComment(signature: Signature): SymbolDisplayPart[] {
const extra = ensureSignatureExtraFields(signature);
return extra.documentationComment ??= getDocumentationComment(singleElementArray(signature.declaration), signature.checker);
}
SignatureObject.prototype.getJsDocTags = function (this: Signature): JSDocTagInfo[] {
const extra = ensureSignatureExtraFields(this);
return extra.jsDocTags ??= getJsDocTagsOfDeclarations(singleElementArray(this.declaration), this.checker);
};
override getJsDocTags(signature: Signature): JSDocTagInfo[] {
const extra = ensureSignatureExtraFields(signature);
return extra.jsDocTags ??= getJsDocTagsOfDeclarations(singleElementArray(signature.declaration), signature.checker);
}
}
// Override the internals for signatures
SignatureObjectInternals.internals = new ServicesSignatureObjectInternals();
/**
* Returns whether or not the given node has a JSDoc "inheritDoc" tag on it.