Skip to content

Commit b4a403f

Browse files
authored
Merge pull request #32 from pvasek/fix/regression_v0.0.12
Fixing #31 regression issues for verison v0.0.12
2 parents 934e544 + 7a6ae29 commit b4a403f

File tree

4 files changed

+97
-12
lines changed

4 files changed

+97
-12
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-docgen-typescript",
3-
"version": "0.0.12",
3+
"version": "0.0.13",
44
"description": "",
55
"main": "lib/index.js",
66
"scripts": {
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import * as React from 'react';
2+
3+
type Coords = { x: number; y: number };
4+
5+
export interface Props extends React.HTMLAttributes<Element> {
6+
/**
7+
* The x-axis value of the zoom origin, which corresponds to the mouse pointer
8+
* location relative to the wrapped element without the zoom applied
9+
*/
10+
originX: number;
11+
/** The y-axis value of the zoom origin, which corresponds to the mouse pointer
12+
* location relative to the wrapped element without the zoom applied
13+
*/
14+
originY: number;
15+
/** The zoom level */
16+
scaleFactor: number;
17+
/** Maximum zoom level */
18+
maxScale?: number;
19+
/** Minimum zoom level */
20+
minScale?: number;
21+
/**
22+
* The zoom change handler for controlled components.
23+
* It should update the other props in order to reflect the zoom change.
24+
*/
25+
onZoom(
26+
scale: number,
27+
translateX: number,
28+
translateY: number,
29+
): void;
30+
}
31+
32+
type Matrix = string;
33+
34+
interface State {
35+
matrix: Matrix;
36+
canZoomIn: boolean;
37+
canZoomOut: boolean;
38+
}
39+
40+
function getCanZoomIn({ maxScale = Infinity, scaleFactor }: Props): boolean {
41+
return scaleFactor < maxScale;
42+
}
43+
44+
function getCanZoomOut({ minScale = Infinity, scaleFactor }: Props): boolean {
45+
return scaleFactor > minScale;
46+
}
47+
48+
/** A Zoomable component wraps any DOM element and provides mouse-based
49+
* zooming capabilities. Support for touch gestures is planned soon.
50+
*/
51+
export class Zoomable extends React.PureComponent<Props, State> {
52+
53+
render() {
54+
const {
55+
style,
56+
className,
57+
children,
58+
scaleFactor,
59+
onZoom,
60+
minScale,
61+
maxScale,
62+
originX,
63+
originY,
64+
...rest,
65+
} = this.props;
66+
const { canZoomIn, canZoomOut } = this.state;
67+
68+
return (
69+
<div />
70+
);
71+
}
72+
}
73+
74+
export default Zoomable;

src/__tests__/getFileDocumentation.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,4 +292,11 @@ describe('getFileDocumentation', () => {
292292
assert.equal(p1.name, 'ExternalPropsComponentProps');
293293
// assert.equal(p1.comment, 'ExternalPropsComponentProps props');
294294
});
295+
296+
it('Should parse file that worked in v0.0.11', function() {
297+
const fileName = path.join(__dirname, '../../src/__tests__/data/Regression_v0_0_12.tsx'); // it's running in ./temp
298+
const result = getFileDocumentation(fileName);
299+
assert.ok(result.components);
300+
})
301+
295302
});

src/transformAST.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -172,18 +172,22 @@ export function transformAST(sourceFile: ts.SourceFile, checker: ts.TypeChecker)
172172
.map(i => {
173173
const type = checker.getTypeAtLocation(i.name) as ts.IntersectionType;
174174
const properties: PropertyEntry[] = [];
175-
type.types.forEach(t => {
176-
const props = (t as any).properties;
177-
let ownProperties: string[] = [];
178-
if (props) {
179-
ownProperties = props
180-
.map((p: ts.Symbol) => p.getName());
181-
}
182-
properties.push(...getProperties(checker, t, i));
183175

184-
properties
185-
.forEach(p => p.isOwn = ownProperties.indexOf(p.name) > -1);
186-
});
176+
if (type.types) {
177+
type.types.forEach(t => {
178+
const props = (t as any).properties;
179+
let ownProperties: string[] = [];
180+
if (props) {
181+
ownProperties = props
182+
.map((p: ts.Symbol) => p.getName());
183+
}
184+
properties.push(...getProperties(checker, t, i));
185+
186+
properties
187+
.forEach(p => p.isOwn = ownProperties.indexOf(p.name) > -1);
188+
});
189+
}
190+
187191
const symbol = checker.getSymbolAtLocation(i.name);
188192
return {
189193
name: i.name.getText(),

0 commit comments

Comments
 (0)