Skip to content

Commit

Permalink
fixup! feat(compiler): copy dock block from component to generated types
Browse files Browse the repository at this point in the history
  • Loading branch information
jgroth committed Nov 17, 2022
1 parent a06c92f commit b4ae7ca
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/utils/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,16 @@ export function addDocBlock(str: string, docs?: d.CompilerJsDoc, indentation: nu
return str;
}

return [getDocBlock(docs, indentation), str].filter(Boolean).join(`\n`);
return [formatDocBlock(docs, indentation), str].filter(Boolean).join(`\n`);
}

function getDocBlock(docs: d.CompilerJsDoc, indentation: number = 0): string {
/**
* Formats the given compiled docs to a JavaScript doc block
* @param docs the compiled JS docs
* @param indentation number of spaces to indent the block with
* @returns the formatted doc block
*/
function formatDocBlock(docs: d.CompilerJsDoc, indentation: number = 0): string {
const textDocs = getDocBlockLines(docs);
if (!textDocs.filter(Boolean).length) {
return '';
Expand All @@ -100,6 +106,11 @@ function getDocBlock(docs: d.CompilerJsDoc, indentation: number = 0): string {
return [spaces + '/**', ...textDocs.map((line) => spaces + ` * ${line}`), spaces + ' */'].join(`\n`);
}

/**
* Get all lines part of the doc block
* @param docs the compiled JS docs
* @returns list of lines part of the doc block
*/
function getDocBlockLines(docs: d.CompilerJsDoc): string[] {
return [
...docs.text.split(lineBreakRegex),
Expand Down

0 comments on commit b4ae7ca

Please sign in to comment.