Swap out DOMParser due to Husky error

This commit is contained in:
Brett Upton 2021-08-19 12:28:44 +02:00
parent f79204247a
commit 2de84d9c03
3 changed files with 36 additions and 1 deletions

View File

@ -13,6 +13,7 @@ import {
Pipe,
Property,
Directive,
JsDocTag,
} from './types';
export const isMethod = (methodOrProp: Method | Property): methodOrProp is Method => {
@ -157,7 +158,17 @@ export const extractType = (property: Property, defaultValue: any) => {
const extractDefaultValue = (property: Property) => {
try {
// eslint-disable-next-line no-eval
const value = eval(property.defaultValue);
let value = eval(property.defaultValue);
if (value == null && property.jsdoctags.length > 0) {
property.jsdoctags.forEach((tag: JsDocTag) => {
if (['default', 'defaultvalue'].includes(tag.tagName.escapedText)) {
const tmp = window.document.createElement('DIV');
tmp.innerHTML = tag.comment;
value = tmp.textContent;
}
});
}
return value;
} catch (err) {
logger.debug(`Error extracting ${property.name}: ${property.defaultValue}`);
@ -189,6 +200,7 @@ export const extractArgTypesFromData = (componentData: Class | Directive | Injec
data.forEach((item: Method | Property) => {
const section = mapItemToSection(key, item);
const defaultValue = isMethod(item) ? undefined : extractDefaultValue(item as Property);
const type =
isMethod(item) || (section !== 'inputs' && section !== 'properties')
? { name: 'void' }

View File

@ -7,6 +7,13 @@ export interface Method {
rawdescription?: string;
}
export interface JsDocTag {
comment?: string;
tagName?: {
escapedText?: string;
};
}
export interface Property {
name: string;
decorators?: Decorator[];
@ -15,6 +22,7 @@ export interface Property {
defaultValue?: string;
description?: string;
rawdescription?: string;
jsdoctags?: JsDocTag[];
}
export interface Class {

View File

@ -51,6 +51,21 @@ export class DocButtonComponent<T> {
@Input()
public theDefaultValue = 'Default value in component';
/**
* Setting default value here because compodoc won't get the default value for accessors
* @default The default value
* */
@Input()
get anotherDefaultValue() {
return this._anotherDefaultValue;
}
set anotherDefaultValue(v: string) {
this._anotherDefaultValue = v;
}
_anotherDefaultValue = 'The default value';
/** Appearance style of the button. */
@Input()
public appearance: 'primary' | 'secondary' = 'secondary';