Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions examples/react-styleguidist-example/components/HocComponent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import * as React from 'react';

/**
* Row properties.
*/
export interface IRowProps {
/** prop1 description */
prop1?: string;
/** prop2 description */
prop2: number;
/**
* prop3 description
*/
prop3: () => void;
/** prop4 description */
prop4: 'option1' | 'option2' | "option3";
}

/**
* Form row.
*/
class Component extends React.Component<IRowProps, {}> {

render() {
return <div>Test</div>;
}
};

export function hoc<T>(Component: T): T {
// do whatever you need but return the same type T
return Component as T;
}

/** This example shows HocComponent */
export const HocComponent = hoc(Component);
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
{
"name": "react-docgen-typescript",
"version": "0.0.8",
"version": "0.0.9",
"description": "",
"main": "lib/index.js",
"scripts": {
"tsc": "tsc",
"prepublish": "tsc -d",
"test": "tsc && mocha ./lib/**/__tests__/**.js",
"test:debug": "tsc && mocha --debug ./lib/**/__tests__/**.js",
"example": "tsc && node ./node_modules/react-styleguidist/bin/styleguidist server --config ./examples/react-styleguidist-example/styleguide.config.js"
"example": "tsc && node ./node_modules/react-styleguidist/bin/styleguidist server --config ./examples/react-styleguidist-example/styleguide.config.js",
"print": "npm run tsc && node ./lib/print.js",
"print:sample1": "npm run tsc && node ./lib/print.js ./src/__tests__/data/ColumnHigherOrderComponent.tsx simple"
},
"author": "pvasek",
"license": "MIT",
Expand All @@ -21,17 +24,14 @@
"@types/node": "^7.0.5",
"@types/react": "^15.0.14",
"@types/react-dom": "^0.14.23",
"@types/react-redux": "^4.4.36",
"babel-core": "^6.8.0",
"babel-loader": "^6.2.4",
"chai": "^3.5.0",
"file-loader": "^0.8.5",
"mocha": "^2.5.3",
"react": "^15.4.2",
"react-bluekit": "^0.4.1",
"react-dom": "^15.4.2",
"react-styleguidist": "^2.2.1",
"ts-node": "^2.1.0",
"typescript": "^2.2.1"
},
"files": [
Expand Down
2 changes: 2 additions & 0 deletions src/__tests__/__sourceMapInit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import * as sourceMapSupport from "source-map-support";
sourceMapSupport.install();
74 changes: 74 additions & 0 deletions src/__tests__/data/ColumnHigherOrderComponent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import * as React from 'react';
/**
* Column properties.
*/
export interface IColumnProps extends React.HTMLAttributes<any> {
/** prop1 description */
prop1?: string;
/** prop2 description */
prop2: number;
/**
* prop3 description
*/
prop3: () => void;
/** prop4 description */
prop4: 'option1' | 'option2' | "option3";
}

/**
* Form column.
*/
class Column extends React.Component<IColumnProps, {}> {
public static defaultProps: Partial<IColumnProps> = {
prop1: 'prop1'
};

render() {
const {prop1} = this.props;
return <div>{prop1}</div>;
}
}

/**
* Row properties.
*/
export interface IRowProps {
/** prop1 description */
prop1?: string;
/** prop2 description */
prop2: number;
/**
* prop3 description
*/
prop3: () => void;
/** prop4 description */
prop4: 'option1' | 'option2' | "option3";
}

/**
* Form row.
*/
const Row = (props: IRowProps) => {
const innerFunc = (props: IRowProps) => {
return <span>Inner Func</span>
};
const innerNonExportedFunc = (props: IRowProps) => {
return <span>Inner Func</span>
};
return <div>Test</div>;
};

function hoc<T>(C: T): T {
return ((props) => <div>{C}</div>) as any as T;
}

/** ColumnHighOrderComponent1 specific comment */
export const ColumnHighOrderComponent1 = hoc(Column);

export const ColumnHighOrderComponent2 = hoc(Column);

/** RowHighOrderComponent1 specific comment */
export const RowHighOrderComponent1 = hoc(Row);

export const RowHighOrderComponent2 = hoc(Row);

55 changes: 55 additions & 0 deletions src/__tests__/data/transformAST.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const unexportedVar = 10;
export const exportedVar = 10;

/** unexportedVarFunction comment */
const unexportedVarFunction = (param1: string): number => 0
;
/** exportedVarFunction comment */
export const exportedVarFunction = (param1: number, param2: string): string => "";

function unexportedFunction(param1: number): string {
return "";
}

function exportedFunction(param1: string, param2: number): number {
return 0;
}

interface UnexportedInterface {
/** prop1 comment */
prop1: string;
}

export interface ExportedInterface {
/** prop1 comment */
prop1: string;
/** prop2 comment */
prop2: string;
}

export class OurBaseClass<T1, T2> {
}

/** UnexportedClass comment */
class UnexportedClass extends OurBaseClass<ExportedInterface, {}> {
method1(): string {
return "";
}
}

/** ExportedClass comment */
export class ExportedClass {
method1(): string {
return "";
}
method2(): number {
return 0;
}
}

export function hoc<T>(component: T): T {
return component;
}

/** exportedHoc comment */
export const exportedHoc = hoc(ExportedClass);
75 changes: 29 additions & 46 deletions src/__tests__/docgenConverter.spec.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,27 @@
import { assert } from 'chai';
import * as path from 'path';
import { getDocumentation } from '../parser';
import { convertToDocgen, StyleguidistComponent } from "../docgenConverter";
import { getFileDocumentation } from '../getFileDocumentation';
import { convertToDocgen } from '../docgenConverter';
import { StyleguidistComponent } from '../propTypesParser';

describe('docgenConverter', () => {
it('Should work with class Component', () => {
const result = convertToDocgen({
classes: [
components: [
{
name: 'name1',
comment: 'comment1',
extends: 'Component',
propInterface: 'PropsInterface',
}
],
interfaces: [
{
name: 'PropsInterface',
comment: 'props comment',
members: [
{
name: 'prop1',
comment: 'prop1 comment',
isRequired: true,
text: 'prop1 text',
type: 'prop1 type'
}
]
}
]
propInterface: {
name: 'PropsInterface',
comment: 'props comment',
members: [{
name: 'prop1',
comment: 'prop1 comment',
isRequired: true,
type: 'prop1 type'
}]},
}]
});

assert.equal('name1', result.displayName);
Expand All @@ -41,29 +34,21 @@ describe('docgenConverter', () => {

it('Should work with functional StatelessComponent', () => {
const result = convertToDocgen({
classes: [
components: [
{
name: 'name1',
comment: 'comment1',
extends: 'StatelessComponent',
propInterface: 'PropsInterface',
}
],
interfaces: [
{
name: 'PropsInterface',
comment: 'props comment',
members: [
{
name: 'prop1',
comment: 'prop1 comment',
isRequired: true,
text: 'prop1 text',
type: 'prop1 type'
}
]
}
]
propInterface: {
name: 'PropsInterface',
comment: 'props comment',
members: [{
name: 'prop1',
comment: 'prop1 comment',
isRequired: true,
type: 'prop1 type'
}]}
}]
});

assert.equal('name1', result.displayName);
Expand All @@ -81,15 +66,14 @@ describe('docgenConverter', () => {
console.warn = () => warnCallCount++;
try {
result = convertToDocgen({
classes: [
components: [
{
name: 'name1',
comment: 'comment1',
extends: 'Component',
propInterface: null,
}
],
interfaces: []
]
});
} finally {
console.warn = originalWarn;
Expand All @@ -107,15 +91,14 @@ describe('docgenConverter', () => {
console.warn = () => warnCallCount++;
try {
result = convertToDocgen({
classes: [
components: [
{
name: 'name1',
comment: 'comment1',
extends: 'PureComponent',
propInterface: null,
}
],
interfaces: []
]
});
} finally {
console.warn = originalWarn;
Expand Down
Loading