Remove all defaultValue eval-ing in addon-docs

This commit is contained in:
Tom Coleman 2021-05-12 12:54:11 +10:00
parent 1a2d67752d
commit 25e9208e8a
4 changed files with 11 additions and 35 deletions

View File

@ -7,26 +7,18 @@ export const extractArgTypes: ArgTypesExtractor = (component) => {
const { rows } = extractProps(component);
if (rows) {
return rows.reduce((acc: ArgTypes, row: PropDef) => {
const { name, type, sbType, defaultValue: defaultSummary, jsDocTags, required } = row;
const {
name,
type,
sbType,
defaultValue: defaultSummary,
jsDocTags,
required,
...rest
} = row;
let defaultValue;
if (component.defaultProps) {
defaultValue = component.defaultProps[name];
} else {
const defaultValueString =
defaultSummary && (defaultSummary.detail || defaultSummary.summary);
try {
if (defaultValueString) {
// eslint-disable-next-line no-new-func
defaultValue = Function(`"use strict";return (${defaultValueString})`)();
}
// eslint-disable-next-line no-empty
} catch {}
}
acc[row.name] = {
...row,
defaultValue,
acc[name] = {
...rest,
type: { required, ...sbType },
table: {
type,

View File

@ -41,7 +41,6 @@ export const createArgTypes = (docgen: SvelteComponentDoc) => {
required: hasKeyword('required', item.keywords),
summary: item.type?.text,
},
defaultValue: item.defaultValue,
table: {
type: {
summary: item.type?.text,

View File

@ -17,18 +17,10 @@ export const extractArgTypes: ArgTypesExtractor = (component) => {
props.forEach(({ propDef, docgenInfo, jsDocTags }) => {
const { name, type, description, defaultValue: defaultSummary, required } = propDef;
const sbType = section === 'props' ? convert(docgenInfo) : { name: 'void' };
let defaultValue = defaultSummary && (defaultSummary.detail || defaultSummary.summary);
try {
// eslint-disable-next-line no-eval
defaultValue = eval(defaultValue);
// eslint-disable-next-line no-empty
} catch {}
results[name] = {
name,
description,
type: { required, ...sbType },
defaultValue,
table: {
type,
jsDocTags,

View File

@ -14,18 +14,11 @@ export const extractArgTypes: ArgTypesExtractor = (component) => {
props.forEach(({ propDef, docgenInfo, jsDocTags }) => {
const { name, type, description, defaultValue: defaultSummary, required } = propDef;
const sbType = section === 'props' ? convert(docgenInfo) : { name: 'void' };
let defaultValue = defaultSummary && (defaultSummary.detail || defaultSummary.summary);
try {
// eslint-disable-next-line no-eval
defaultValue = eval(defaultValue);
// eslint-disable-next-line no-empty
} catch {}
results[name] = {
name,
description,
type: { required, ...sbType },
defaultValue,
table: {
type,
jsDocTags,