@7nohe/openapi-react-query-codegen
Version:
OpenAPI React Query Codegen
17 lines (16 loc) • 754 B
JavaScript
import ts from "typescript";
export function addJSDocToNode(node, jsDoc) {
if (!jsDoc) {
return node;
}
// replace the first /** with *
// we do this because ts.addSyntheticLeadingComment will add /* to the beginning but we want /**
const removedFirstLine = jsDoc.trim().replace(/^\/\*\*/, "*");
// remove the last */ because ts.addSyntheticLeadingComment will add it
const removedSecondLine = removedFirstLine.replace(/\*\/$/, "");
const split = removedSecondLine.split("\n");
const trimmed = split.map((line) => line.trim());
const joined = trimmed.join("\n");
const nodeWithJSDoc = ts.addSyntheticLeadingComment(node, ts.SyntaxKind.MultiLineCommentTrivia, joined, true);
return nodeWithJSDoc;
}