$ open source · GPL-3.0 — need a commercial license? imqueue.com →

Home > @imqueue/rpc > parseSourceComments

parseSourceComments() function

Extracts method JSDoc blocks from original source text of a given class.

The text may be TypeScript (type annotations, generics, modifiers, decorators), which acorn cannot parse — so extraction is textual: the search is narrowed to the class region (from the class declaration to the next class declaration or EOF), and each doc block is attributed to the method whose declaration head immediately follows it. When several blocks precede a method, the closest one wins, matching the runtime parser.

Signature:

export declare function parseSourceComments(src: string, className: string): {
    [method: string]: string;
};

Parameters

Parameter

Type

Description

src

string

source file text (TypeScript or JavaScript)

className

string

class to extract method docs for {{ [method: string]: string }} - map of method name to raw JSDoc block body (delimiters excluded, as acorn reports comment values)

Returns:

{ [method: string]: string; }