Comparing version 0.24.0-beta.6 to 0.24.0-beta.7
@@ -252,3 +252,4 @@ "use strict"; | ||
if (tsTarget) { | ||
token.linkTarget = new ReflectionSymbolId_1.ReflectionSymbolId((0, symbols_1.resolveAliasedSymbol)(tsTarget, checker)); | ||
token.tsLinkTarget = new ReflectionSymbolId_1.ReflectionSymbolId((0, symbols_1.resolveAliasedSymbol)(tsTarget, checker)); | ||
token.tsLinkText = link.text.replace(/^\s*\|\s*/, ""); | ||
} | ||
@@ -255,0 +256,0 @@ } |
@@ -10,4 +10,5 @@ import ts from "typescript"; | ||
} | ||
export declare function getComment(symbol: ts.Symbol, kind: ReflectionKind, config: CommentParserConfig, logger: Logger, commentStyle: CommentStyle, checker: ts.TypeChecker): Comment | undefined; | ||
export declare function getSignatureComment(declaration: ts.SignatureDeclaration | ts.JSDocSignature, config: CommentParserConfig, logger: Logger, commentStyle: CommentStyle, checker: ts.TypeChecker): Comment | undefined; | ||
export declare function getJsDocComment(declaration: ts.JSDocPropertyLikeTag | ts.JSDocCallbackTag | ts.JSDocTypedefTag | ts.JSDocTemplateTag | ts.JSDocEnumTag, config: CommentParserConfig, logger: Logger, checker: ts.TypeChecker): Comment | undefined; | ||
export declare function clearCommentCache(): void; | ||
export declare function getComment(symbol: ts.Symbol, kind: ReflectionKind, config: CommentParserConfig, logger: Logger, commentStyle: CommentStyle, checker: ts.TypeChecker | undefined): Comment | undefined; | ||
export declare function getSignatureComment(declaration: ts.SignatureDeclaration | ts.JSDocSignature, config: CommentParserConfig, logger: Logger, commentStyle: CommentStyle, checker: ts.TypeChecker | undefined): Comment | undefined; | ||
export declare function getJsDocComment(declaration: ts.JSDocPropertyLikeTag | ts.JSDocCallbackTag | ts.JSDocTypedefTag | ts.JSDocTemplateTag | ts.JSDocEnumTag, config: CommentParserConfig, logger: Logger, checker: ts.TypeChecker | undefined): Comment | undefined; |
@@ -6,3 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getJsDocComment = exports.getSignatureComment = exports.getComment = void 0; | ||
exports.getJsDocComment = exports.getSignatureComment = exports.getComment = exports.clearCommentCache = void 0; | ||
const typescript_1 = __importDefault(require("typescript")); | ||
@@ -22,3 +22,10 @@ const models_1 = require("../../models"); | ||
]; | ||
const commentCache = new WeakMap(); | ||
let commentCache = new WeakMap(); | ||
// We need to do this for tests so that changing the tsLinkResolution option | ||
// actually works. Without it, we'd get the old parsed comment which doesn't | ||
// have the TS symbols attached. | ||
function clearCommentCache() { | ||
commentCache = new WeakMap(); | ||
} | ||
exports.clearCommentCache = clearCommentCache; | ||
function getCommentWithCache(discovered, config, logger, checker) { | ||
@@ -25,0 +32,0 @@ if (!discovered) |
@@ -15,3 +15,4 @@ import type { ReflectionSymbolId } from "../../models"; | ||
pos: number; | ||
linkTarget?: ReflectionSymbolId; | ||
tsLinkTarget?: ReflectionSymbolId; | ||
tsLinkText?: string; | ||
} |
@@ -1,2 +0,2 @@ | ||
import { Comment, CommentDisplayPart, Reflection } from "../../models"; | ||
import { Comment, CommentDisplayPart, Reflection, ReflectionSymbolId } from "../../models"; | ||
import { DeclarationReference } from "./declarationReference"; | ||
@@ -7,4 +7,12 @@ export type ExternalResolveResult = { | ||
}; | ||
export type ExternalSymbolResolver = (ref: DeclarationReference, refl: Reflection, part: Readonly<CommentDisplayPart> | undefined) => ExternalResolveResult | string | undefined; | ||
export declare function resolveLinks(comment: Comment, reflection: Reflection, externalResolver: ExternalSymbolResolver, useTsResolution: boolean): void; | ||
export declare function resolvePartLinks(reflection: Reflection, parts: readonly CommentDisplayPart[], externalResolver: ExternalSymbolResolver, useTsResolution: boolean): CommentDisplayPart[]; | ||
/** | ||
* @param ref - Parsed declaration reference to resolve. This may be created automatically for some symbol, or | ||
* parsed from user input. | ||
* @param refl - Reflection that contains the resolved link | ||
* @param part - If the declaration reference was created from a comment, the originating part. | ||
* @param symbolId - If the declaration reference was created from a symbol, or `useTsLinkResolution` is turned | ||
* on and TypeScript resolved the link to some symbol, the ID of that symbol. | ||
*/ | ||
export type ExternalSymbolResolver = (ref: DeclarationReference, refl: Reflection, part: Readonly<CommentDisplayPart> | undefined, symbolId: ReflectionSymbolId | undefined) => ExternalResolveResult | string | undefined; | ||
export declare function resolveLinks(comment: Comment, reflection: Reflection, externalResolver: ExternalSymbolResolver): void; | ||
export declare function resolvePartLinks(reflection: Reflection, parts: readonly CommentDisplayPart[], externalResolver: ExternalSymbolResolver): CommentDisplayPart[]; |
@@ -12,17 +12,17 @@ "use strict"; | ||
const urlPrefix = /^(http|ftp)s?:\/\//; | ||
function resolveLinks(comment, reflection, externalResolver, useTsResolution) { | ||
comment.summary = resolvePartLinks(reflection, comment.summary, externalResolver, useTsResolution); | ||
function resolveLinks(comment, reflection, externalResolver) { | ||
comment.summary = resolvePartLinks(reflection, comment.summary, externalResolver); | ||
for (const tag of comment.blockTags) { | ||
tag.content = resolvePartLinks(reflection, tag.content, externalResolver, useTsResolution); | ||
tag.content = resolvePartLinks(reflection, tag.content, externalResolver); | ||
} | ||
if (reflection instanceof models_1.DeclarationReflection && reflection.readme) { | ||
reflection.readme = resolvePartLinks(reflection, reflection.readme, externalResolver, useTsResolution); | ||
reflection.readme = resolvePartLinks(reflection, reflection.readme, externalResolver); | ||
} | ||
} | ||
exports.resolveLinks = resolveLinks; | ||
function resolvePartLinks(reflection, parts, externalResolver, useTsResolution) { | ||
return parts.flatMap((part) => processPart(reflection, part, externalResolver, useTsResolution)); | ||
function resolvePartLinks(reflection, parts, externalResolver) { | ||
return parts.flatMap((part) => processPart(reflection, part, externalResolver)); | ||
} | ||
exports.resolvePartLinks = resolvePartLinks; | ||
function processPart(reflection, part, externalResolver, useTsResolution) { | ||
function processPart(reflection, part, externalResolver) { | ||
if (part.kind === "inline-tag") { | ||
@@ -32,3 +32,3 @@ if (part.tag === "@link" || | ||
part.tag === "@linkplain") { | ||
return resolveLinkTag(reflection, part, externalResolver, useTsResolution); | ||
return resolveLinkTag(reflection, part, externalResolver); | ||
} | ||
@@ -38,3 +38,3 @@ } | ||
} | ||
function resolveLinkTag(reflection, part, externalResolver, useTsResolution) { | ||
function resolveLinkTag(reflection, part, externalResolver) { | ||
let defaultDisplayText = ""; | ||
@@ -47,13 +47,32 @@ let pos = 0; | ||
let target; | ||
if (useTsResolution && part.target instanceof models_1.ReflectionSymbolId) { | ||
target = reflection.project.getReflectionFromSymbolId(part.target); | ||
if (target) { | ||
// Try to parse a declaration reference if we didn't use the TS symbol for resolution | ||
const declRef = (0, declarationReference_1.parseDeclarationReference)(part.text, pos, end); | ||
// Might already know where it should go if useTsLinkResolution is turned on | ||
if (part.target instanceof models_1.ReflectionSymbolId) { | ||
const tsTarget = reflection.project.getReflectionFromSymbolId(part.target); | ||
if (tsTarget) { | ||
target = tsTarget; | ||
pos = end; | ||
defaultDisplayText = | ||
part.text.replace(/^\s*[A-Z_$][\w$]*[ |]*/i, "") || target.name; | ||
defaultDisplayText = part.tsLinkText || target.name; | ||
} | ||
else if (declRef) { | ||
// If we didn't find a target, we might be pointing to a symbol in another project that will be merged in | ||
// or some external symbol, so ask external resolvers to try resolution. Don't use regular declaration ref | ||
// resolution in case it matches something that would have been merged in later. | ||
const externalResolveResult = externalResolver(declRef[0], reflection, part, part.target instanceof models_1.ReflectionSymbolId | ||
? part.target | ||
: undefined); | ||
defaultDisplayText = part.text.substring(0, pos); | ||
switch (typeof externalResolveResult) { | ||
case "string": | ||
target = externalResolveResult; | ||
break; | ||
case "object": | ||
target = externalResolveResult.target; | ||
defaultDisplayText = | ||
externalResolveResult.caption || defaultDisplayText; | ||
} | ||
} | ||
} | ||
// Try to parse a declaration reference if we didn't use the TS symbol for resolution | ||
const declRef = !target && (0, declarationReference_1.parseDeclarationReference)(part.text, pos, end); | ||
if (declRef) { | ||
if (!target && declRef) { | ||
// Got one, great! Try to resolve the link | ||
@@ -67,3 +86,5 @@ target = (0, declarationReferenceResolver_1.resolveDeclarationReference)(reflection, declRef[0]); | ||
// If we didn't find a link, it might be a @link tag to an external symbol, check that next. | ||
const externalResolveResult = externalResolver(declRef[0], reflection, part); | ||
const externalResolveResult = externalResolver(declRef[0], reflection, part, part.target instanceof models_1.ReflectionSymbolId | ||
? part.target | ||
: undefined); | ||
defaultDisplayText = part.text.substring(0, pos); | ||
@@ -70,0 +91,0 @@ switch (typeof externalResolveResult) { |
@@ -307,6 +307,7 @@ "use strict"; | ||
}; | ||
if (tagName.linkTarget) { | ||
inlineTag.target = tagName.linkTarget; | ||
if (tagName.tsLinkTarget) { | ||
inlineTag.target = tagName.tsLinkTarget; | ||
inlineTag.tsLinkText = tagName.tsLinkText; | ||
} | ||
block.push(inlineTag); | ||
} |
@@ -81,2 +81,5 @@ import ts from "typescript"; | ||
setActiveProgram(program: ts.Program | undefined): void; | ||
getComment(symbol: ts.Symbol, kind: ReflectionKind): import("../models/index").Comment | undefined; | ||
getJsDocComment(declaration: ts.JSDocPropertyLikeTag | ts.JSDocCallbackTag | ts.JSDocTypedefTag | ts.JSDocTemplateTag | ts.JSDocEnumTag): import("../models/index").Comment | undefined; | ||
getSignatureComment(declaration: ts.SignatureDeclaration | ts.JSDocSignature): import("../models/index").Comment | undefined; | ||
/** | ||
@@ -83,0 +86,0 @@ * @param callback The callback function that should be executed with the changed context. |
@@ -117,6 +117,6 @@ "use strict"; | ||
(index_1.ReflectionKind.SomeModule | index_1.ReflectionKind.Reference)) { | ||
reflection.comment = (0, comments_1.getComment)(exportSymbol, reflection.kind, this.converter.config, this.logger, this.converter.commentStyle, this.checker); | ||
reflection.comment = (0, comments_1.getComment)(exportSymbol, reflection.kind, this.converter.config, this.logger, this.converter.commentStyle, this.converter.useTsLinkResolution ? this.checker : undefined); | ||
} | ||
if (symbol && !reflection.comment) { | ||
reflection.comment = (0, comments_1.getComment)(symbol, reflection.kind, this.converter.config, this.logger, this.converter.commentStyle, this.checker); | ||
reflection.comment = (0, comments_1.getComment)(symbol, reflection.kind, this.converter.config, this.logger, this.converter.commentStyle, this.converter.useTsLinkResolution ? this.checker : undefined); | ||
} | ||
@@ -177,2 +177,11 @@ if (this.shouldBeStatic) { | ||
} | ||
getComment(symbol, kind) { | ||
return (0, comments_1.getComment)(symbol, kind, this.converter.config, this.logger, this.converter.commentStyle, this.converter.useTsLinkResolution ? this.checker : undefined); | ||
} | ||
getJsDocComment(declaration) { | ||
return (0, comments_1.getJsDocComment)(declaration, this.converter.config, this.logger, this.converter.useTsLinkResolution ? this.checker : undefined); | ||
} | ||
getSignatureComment(declaration) { | ||
return (0, comments_1.getSignatureComment)(declaration, this.converter.config, this.logger, this.converter.commentStyle, this.converter.useTsLinkResolution ? this.checker : undefined); | ||
} | ||
/** | ||
@@ -179,0 +188,0 @@ * @param callback The callback function that should be executed with the changed context. |
import ts from "typescript"; | ||
import type { Application } from "../application"; | ||
import { Comment, CommentDisplayPart, ProjectReflection, Reflection, SomeType } from "../models/index"; | ||
import { Comment, CommentDisplayPart, ProjectReflection, Reflection, ReflectionSymbolId, SomeType } from "../models/index"; | ||
import { Context } from "./context"; | ||
@@ -9,3 +9,3 @@ import { ConverterComponent } from "./components"; | ||
import type { DocumentationEntryPoint } from "../utils/entry-point"; | ||
import { CommentParserConfig } from "./comments"; | ||
import type { CommentParserConfig } from "./comments"; | ||
import type { CommentStyle, ValidationOptions } from "../utils/options/declaration"; | ||
@@ -141,3 +141,3 @@ import { ExternalSymbolResolver, ExternalResolveResult } from "./comments/linkResolver"; | ||
/** @internal */ | ||
resolveExternalLink(ref: DeclarationReference, refl: Reflection, part?: CommentDisplayPart): ExternalResolveResult | string | undefined; | ||
resolveExternalLink(ref: DeclarationReference, refl: Reflection, part: CommentDisplayPart | undefined, symbolId: ReflectionSymbolId | undefined): ExternalResolveResult | string | undefined; | ||
resolveLinks(comment: Comment, owner: Reflection): void; | ||
@@ -144,0 +144,0 @@ resolveLinks(parts: readonly CommentDisplayPart[], owner: Reflection): CommentDisplayPart[]; |
@@ -25,3 +25,2 @@ "use strict"; | ||
const enum_1 = require("../utils/enum"); | ||
const comments_1 = require("./comments"); | ||
const parser_1 = require("./comments/parser"); | ||
@@ -118,5 +117,5 @@ const rawLexer_1 = require("./comments/rawLexer"); | ||
/** @internal */ | ||
resolveExternalLink(ref, refl, part) { | ||
resolveExternalLink(ref, refl, part, symbolId) { | ||
for (const resolver of this._externalSymbolResolvers) { | ||
const resolved = resolver(ref, refl, part); | ||
const resolved = resolver(ref, refl, part, symbolId); | ||
if (resolved) | ||
@@ -128,6 +127,6 @@ return resolved; | ||
if (comment instanceof index_1.Comment) { | ||
(0, linkResolver_1.resolveLinks)(comment, owner, (ref, part, refl) => this.resolveExternalLink(ref, part, refl), this.useTsLinkResolution); | ||
(0, linkResolver_1.resolveLinks)(comment, owner, (ref, part, refl, id) => this.resolveExternalLink(ref, part, refl, id)); | ||
} | ||
else { | ||
return (0, linkResolver_1.resolvePartLinks)(owner, comment, (ref, part, refl) => this.resolveExternalLink(ref, part, refl), this.useTsLinkResolution); | ||
return (0, linkResolver_1.resolvePartLinks)(owner, comment, (ref, part, refl, id) => this.resolveExternalLink(ref, part, refl, id)); | ||
} | ||
@@ -171,4 +170,3 @@ } | ||
context.project.comment = | ||
symbol && | ||
(0, comments_1.getComment)(symbol, context.project.kind, this.config, this.application.logger, this.commentStyle, context.checker); | ||
symbol && context.getComment(symbol, context.project.kind); | ||
context.trigger(Converter_1.EVENT_CREATE_DECLARATION, context.project); | ||
@@ -175,0 +173,0 @@ moduleContext = context; |
@@ -13,3 +13,2 @@ "use strict"; | ||
const reflections_1 = require("../utils/reflections"); | ||
const comments_1 = require("../comments"); | ||
const ReflectionSymbolId_1 = require("../../models/reflections/ReflectionSymbolId"); | ||
@@ -39,3 +38,3 @@ function createSignature(context, kind, signature, symbol, declaration) { | ||
models_1.ConversionFlags.VariableOrPropertySource))) { | ||
sigRef.comment = (0, comments_1.getSignatureComment)(declaration, context.converter.config, context.logger, context.converter.commentStyle, context.checker); | ||
sigRef.comment = context.getSignatureComment(declaration); | ||
} | ||
@@ -84,5 +83,5 @@ sigRef.typeParameters = convertTypeParameters(sigRefCtx, sigRef, signature.typeParameters); | ||
if (declaration && typescript_1.default.isJSDocParameterTag(declaration)) { | ||
paramRefl.comment = (0, comments_1.getJsDocComment)(declaration, context.converter.config, context.logger, context.checker); | ||
paramRefl.comment = context.getJsDocComment(declaration); | ||
} | ||
paramRefl.comment || (paramRefl.comment = (0, comments_1.getComment)(param, paramRefl.kind, context.converter.config, context.logger, context.converter.commentStyle, context.checker)); | ||
paramRefl.comment || (paramRefl.comment = context.getComment(param, paramRefl.kind)); | ||
context.registerReflection(paramRefl, param); | ||
@@ -131,3 +130,3 @@ context.trigger(converter_events_1.ConverterEvents.CREATE_PARAMETER, paramRefl); | ||
if (typescript_1.default.isJSDocParameterTag(param)) { | ||
paramRefl.comment = (0, comments_1.getJsDocComment)(param, context.converter.config, context.logger, context.checker); | ||
paramRefl.comment = context.getJsDocComment(param); | ||
} | ||
@@ -198,3 +197,3 @@ context.registerReflection(paramRefl, context.getSymbolAtLocation(param)); | ||
if (typescript_1.default.isJSDocTemplateTag(param.parent)) { | ||
paramRefl.comment = (0, comments_1.getJsDocComment)(param.parent, context.converter.config, context.logger, context.checker); | ||
paramRefl.comment = context.getJsDocComment(param.parent); | ||
} | ||
@@ -201,0 +200,0 @@ context.trigger(converter_events_1.ConverterEvents.CREATE_TYPE_PARAMETER, paramRefl, param); |
@@ -14,3 +14,2 @@ "use strict"; | ||
const ReflectionSymbolId_1 = require("../models/reflections/ReflectionSymbolId"); | ||
const comments_1 = require("./comments"); | ||
const converter_events_1 = require("./converter-events"); | ||
@@ -33,3 +32,3 @@ const signature_1 = require("./factories/signature"); | ||
const reflection = context.createDeclarationReflection(models_1.ReflectionKind.TypeAlias, symbol, exportSymbol); | ||
reflection.comment = (0, comments_1.getJsDocComment)(declaration, context.converter.config, context.logger, context.checker); | ||
reflection.comment = context.getJsDocComment(declaration); | ||
reflection.type = context.converter.convertType(context.withScope(reflection), declaration.typeExpression?.type); | ||
@@ -42,3 +41,3 @@ convertTemplateParameters(context.withScope(reflection), declaration.parent); | ||
const alias = context.createDeclarationReflection(models_1.ReflectionKind.TypeAlias, symbol, exportSymbol); | ||
alias.comment = (0, comments_1.getJsDocComment)(declaration, context.converter.config, context.logger, context.checker); | ||
alias.comment = context.getJsDocComment(declaration); | ||
context.finalizeDeclarationReflection(alias); | ||
@@ -52,3 +51,3 @@ const ac = context.withScope(alias); | ||
const reflection = context.createDeclarationReflection(models_1.ReflectionKind.Interface, symbol, exportSymbol); | ||
reflection.comment = (0, comments_1.getJsDocComment)(declaration, context.converter.config, context.logger, context.checker); | ||
reflection.comment = context.getJsDocComment(declaration); | ||
context.finalizeDeclarationReflection(reflection); | ||
@@ -55,0 +54,0 @@ const rc = context.withScope(reflection); |
@@ -43,3 +43,3 @@ "use strict"; | ||
if (!type.reflection) { | ||
const resolveResult = this.owner.resolveExternalLink(type.toDeclarationReference(), owner); | ||
const resolveResult = this.owner.resolveExternalLink(type.toDeclarationReference(), owner, undefined, type.symbolId); | ||
switch (typeof resolveResult) { | ||
@@ -46,0 +46,0 @@ case "string": |
@@ -12,3 +12,5 @@ import type { Reflection, ReflectionSymbolId } from "../reflections"; | ||
* The `@link`, `@linkcode`, and `@linkplain` tags may have a `target` | ||
* property set indicating which reflection/url they link to. | ||
* property set indicating which reflection/url they link to. They may also | ||
* have a `tsLinkText` property which includes the part of the `text` which | ||
* TypeScript thinks should be displayed as the link text. | ||
*/ | ||
@@ -20,2 +22,3 @@ export interface InlineTagDisplayPart { | ||
target?: Reflection | string | ReflectionSymbolId; | ||
tsLinkText?: string; | ||
} | ||
@@ -81,2 +84,3 @@ /** | ||
target?: string | Reflection | ReflectionSymbolId | undefined; | ||
tsLinkText?: string | undefined; | ||
})[]; | ||
@@ -83,0 +87,0 @@ static serializeDisplayParts(serializer: Serializer, parts: CommentDisplayPart[]): JSONOutput.CommentDisplayPart[]; |
@@ -167,2 +167,3 @@ "use strict"; | ||
// TS isn't quite smart enough here... | ||
// GERRIT this is wrong | ||
return { ...part }; | ||
@@ -169,0 +170,0 @@ } |
@@ -185,2 +185,3 @@ /** | ||
target?: string | number | ReflectionSymbolId; | ||
tsLinkText?: string; | ||
} | ||
@@ -187,0 +188,0 @@ export interface SourceReference extends S<M.SourceReference, "fileName" | "line" | "character" | "url"> { |
{ | ||
"name": "typedoc", | ||
"description": "Create api documentation for TypeScript projects.", | ||
"version": "0.24.0-beta.6", | ||
"version": "0.24.0-beta.7", | ||
"homepage": "https://typedoc.org", | ||
@@ -6,0 +6,0 @@ "exports": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1128441
26378