Skip to content

Commit

Permalink
fix(doc): error on comment undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
aesteves60 authored and dpellier committed Jul 29, 2024
1 parent 83011d6 commit c9883e5
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 67 deletions.
10 changes: 5 additions & 5 deletions packages/ods/scripts/generate-typedoc-md.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function convertJsonToMarkdown(jsonItems) {
const hasEnums = enums.length;

const tableOfContents = [
'## Table of Contents',
'## Table of Contents',
hasProps ? '[• Properties](#properties)\n' : '',
hasMethods ? '[• Methods](#methods)\n' : '',
hasEvents ? '[• Events](#events)\n' : '',
Expand Down Expand Up @@ -104,7 +104,7 @@ function getClasses(jsonItems) {
.map((prop) => {
return [
`### ${prop.name}`,
`• ${prop.flags.isOptional ? '\`Optional\`': ''} **${prop.name}**: [${printType(prop.type)}] ${prop.defaultValue ? `= \`${prop.defaultValue}\`` : ''}`,
`• ${prop.flags.isOptional ? '\`Optional\`' : ''} **${prop.name}**: [${printType(prop.type)}] ${prop.defaultValue ? `= \`${prop.defaultValue}\`` : ''}`,
`${prop.comment?.summary?.[0].text ? '**Description**: ' + prop.comment?.summary?.[0].text : ''}`,
].join('\n\n');
});
Expand All @@ -123,10 +123,10 @@ function getClasses(jsonItems) {
const methods = children
.filter(({ kind, decorators }) => kind === ReflectionKind.Method && decorators?.[0]?.escapedText === 'Method')
.map((method) => {
const returnType = `\`${method.signatures[0].type.name}\`\<${printType(method.signatures[0].type.typeArguments[0])}\>`
return [
const returnType = `\`${method.signatures[0].type.name}\`\<${printType(method.signatures[0].type.typeArguments[0])}\>`
return [
`### ${method.name}\n\n▸ **${method.name}**(): ${returnType}`,
`${method.signatures?.[0].comment.summary?.[0].text ? '**Description**: ' + method.signatures?.[0].comment.summary?.[0].text : ''}`,
`${method.signatures?.[0].comment?.summary?.[0].text ? '**Description**: ' + method.signatures?.[0].comment?.summary?.[0].text : ''}`,
`#### Returns\n${returnType}`,
].join('\n\n');
});
Expand Down
72 changes: 36 additions & 36 deletions packages/ods/scripts/typedoc-plugin-decorator.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,49 @@
const td = require("typedoc");
const td = require('typedoc');
const ts = td.TypeScript;

/** @param {td.Application} app */
exports.load = function (app) {
// Add decorator info to reflections
// if you need parameters, you need app.converter.on(td.Converter.EVENT_CREATE_PARAMETER)
app.converter.on(td.Converter.EVENT_CREATE_DECLARATION, addDecoratorInfo);
// Add decorator info to reflections
// if you need parameters, you need app.converter.on(td.Converter.EVENT_CREATE_PARAMETER)
app.converter.on(td.Converter.EVENT_CREATE_DECLARATION, addDecoratorInfo);

// Add decorator info to serialized json
app.serializer.addSerializer({
priority: 0,
supports(item) {
return item instanceof td.DeclarationReflection;
},
toObject(item, obj, _ser) {
if (item.decorators) {
obj.decorators = item.decorators;
}
return obj;
},
});
// Add decorator info to serialized json
app.serializer.addSerializer({
priority: 0,
supports(item) {
return item instanceof td.DeclarationReflection;
},
toObject(item, obj, _ser) {
if (item.decorators) {
obj.decorators = item.decorators;
}
return obj;
},
});
};

/**
* @param {td.Context} context
* @param {td.DeclarationReflection} decl
*/
function addDecoratorInfo(context, decl) {
const symbol = context.project.getSymbolFromReflection(decl);
if (!symbol) {
return;
}
const declaration = symbol.valueDeclaration;
if (!declaration) {
return;
}
if (!ts.isPropertyDeclaration(declaration) && !ts.isMethodDeclaration(declaration)) {
return;
}
const symbol = context.project.getSymbolFromReflection(decl);
if (!symbol) {
return;
}
const declaration = symbol.valueDeclaration;
if (!declaration) {
return;
}
if (!ts.isPropertyDeclaration(declaration) && !ts.isMethodDeclaration(declaration)) {
return;
}

const decorators = declaration.modifiers?.filter(ts.isDecorator);
decl.decorators = decorators?.map((d) => {
return {
expression: d.getText(),
escapedText: d.expression.expression.escapedText,
};
});
}
const decorators = declaration.modifiers?.filter(ts.isDecorator);
decl.decorators = decorators?.map((d) => {
return {
expression: d.getText(),
escapedText: d.expression.expression.escapedText,
};
});
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
## Table of Contents
[• Properties](#properties)

[• Methods](#methods)

[• Events](#events)

[• Enums](#enums)

Expand All @@ -12,30 +10,14 @@

**color**: [_primary_] = `ODS_SPINNER_COLOR.primary`

**Description**: test typedoc comment props

### size

**size**: [`sm` | `md` | `lg`] = `ODS_SPINNER_SIZE.md`


## Methods
### someMethodTest

**someMethodTest**(): `Promise`<`string` | `number`>

**Description**: test typedoc comment methods

#### Returns
`Promise`<`string` | `number`>
## Events
### focusEvent

**focusEvent**(): `EventEmitter`<_void_>

**Description**: test typedoc comment event

#### Returns
`EventEmitter`<_void_>
## Enums
## Enumeration: ODS_SPINNER_COLOR

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
# Class: OdsText
## Table of Contents
[• Properties](#properties)

[• Methods](#methods)

[• Events](#events)

[• Enums](#enums)

## Properties
### preset
Expand All @@ -11,22 +18,22 @@

**getFormattedText**(): `Promise`<_string_>

#### Returns
`Promise`<_string_>


#### Returns
`Promise`<_string_>
## Events
### focusEvent

**focusEvent**(): `EventEmitter`<`FocusEventDetail`>

#### Returns
`EventEmitter`<`FocusEventDetail`>


# Enumeration: ODS_TEXT_PRESET
#### Returns
`EventEmitter`<`FocusEventDetail`>
## Enums
## Enumeration: ODS_TEXT_PRESET

## Enumeration Members
### headline

**headline** = `"headline"`
Expand Down

0 comments on commit c9883e5

Please sign in to comment.