Skip to content

Commit

Permalink
Addon-docs: Fix "Cannot read property 'props'" (#8731)
Browse files Browse the repository at this point in the history
Addon-docs: Fix "Cannot read property 'props'"
  • Loading branch information
shilman authored Nov 6, 2019
2 parents 4233f3e + 0bd6a48 commit 5770c8e
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions addons/docs/src/lib/docgenUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getTypeSystemHandler, getPropTypeSystem } from './type-system-handlers'

export type PropsExtractor = (component: Component) => PropsTableProps | null;

export type PropDefGetter = (type: Component, section: string) => PropDef[];
export type PropDefGetter = (component: Component, section: string) => PropDef[];

export const str = (o: any) => {
if (!o) {
Expand All @@ -17,27 +17,24 @@ export const str = (o: any) => {
throw new Error(`Description: expected string, got: ${JSON.stringify(o)}`);
};

export const hasDocgen = (obj: any) => !!obj.__docgenInfo;
export const hasDocgen = (component: Component) => !!component.__docgenInfo;

export const hasDocgenSection = (obj: any, section: string) =>
obj.__docgenInfo &&
obj.__docgenInfo[section] &&
Object.keys(obj.__docgenInfo[section]).length > 0;
export const hasDocgenSection = (component: Component, section: string) =>
component &&
component.__docgenInfo &&
component.__docgenInfo[section] &&
Object.keys(component.__docgenInfo[section]).length > 0;

export const extractPropsFromDocgen: PropDefGetter = (type, section) => {
const props: Record<string, PropDef> = {};

const docgenInfoProps = type.__docgenInfo[section];
if (!docgenInfoProps) {
export const extractPropsFromDocgen: PropDefGetter = (component, section) => {
if (!hasDocgenSection(component, section)) {
return [];
}

const props: Record<string, PropDef> = {};
const docgenInfoProps = component.__docgenInfo[section];
const propKeys = Object.keys(docgenInfoProps);
if (propKeys.length === 0) {
return [];
}

// Assuming the props for a given type will all have the same type system.
// Assuming the props for a given component will all have the same type system.
const typeSystem = getPropTypeSystem(docgenInfoProps[propKeys[0]]);
const typeSystemHandler = getTypeSystemHandler(typeSystem);

Expand Down

1 comment on commit 5770c8e

@vercel
Copy link

@vercel vercel bot commented on 5770c8e Nov 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.