@jsdocs-io/extractor
Version:
The API extractor for npm packages powering jsdocs.io
28 lines (27 loc) • 1.29 kB
JavaScript
import { apparentType } from "./apparent-type.js";
import { docs } from "./docs.js";
import { formatSignature } from "./format-signature.js";
import { id } from "./id.js";
import { sourceFilePath } from "./source-file-path.js";
export async function extractVariableAssignmentExpression(containerName, exportName, declaration) {
const variableDeclaration = declaration
.getLeft()
.getSymbol()
.getDeclarations()[0];
return {
kind: "variable",
id: id(containerName, "+variable", exportName),
name: exportName,
docs: docs(variableDeclaration),
file: sourceFilePath(variableDeclaration),
line: variableDeclaration.getStartLineNumber(),
signature: await variableAssignmentExpressionSignature(exportName, declaration, variableDeclaration),
};
}
async function variableAssignmentExpressionSignature(name, declaration, variableDeclaration) {
const kind = variableDeclaration.getVariableStatementOrThrow().getDeclarationKind().toString();
const variableType = apparentType(variableDeclaration);
const expressionType = apparentType(declaration);
const type = variableType !== "any" ? variableType : expressionType;
return await formatSignature("variable", `${kind} ${name}: ${type}`);
}