Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit f5f7337

Browse files
committed
feat: support prop-types repository
Since react move to prop-types it should be supported here as well. Closes #439
1 parent 19181ce commit f5f7337

File tree

6 files changed

+135
-54
lines changed

6 files changed

+135
-54
lines changed

Diff for: package-lock.json

+91-53
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"@types/babel-generator": "^6.25.0",
4242
"@types/diff": "^3.2.2",
4343
"@types/node": "^8.0.50",
44+
"@types/prop-types": "15.5.2",
4445
"@types/react": "^16.0.21",
4546
"ava": "^0.23.0",
4647
"babel-core": "^6.26.0",
@@ -52,6 +53,7 @@
5253
"cz-conventional-changelog": "2.1.0",
5354
"diff": "3.4.0",
5455
"nyc": "11.3.0",
56+
"prop-types": "15.6.0",
5557
"react": "^16.0.0",
5658
"rimraf": "2.6.2",
5759
"source-map-support": "0.5.0",

Diff for: src/typings.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ function getReactComponentName(ast: AstQuery): string|undefined {
204204
}
205205

206206
function getPropTypesName(ast: AstQuery): string|undefined {
207-
const res = ast.query(`
207+
let res = ast.query(`
208208
// ImportDeclaration[
209209
/:source StringLiteral[@value == 'react']
210210
]
@@ -216,6 +216,18 @@ function getPropTypesName(ast: AstQuery): string|undefined {
216216
if (res.length > 0) {
217217
return res[0].name;
218218
}
219+
res = ast.query(`
220+
// ImportDeclaration[
221+
/:source StringLiteral[@value == 'prop-types']
222+
]
223+
/:specifiers *[
224+
/ Identifier[@name == 'PropTypes']
225+
]
226+
/:local Identifier
227+
`);
228+
if (res.length > 0) {
229+
return res[0].name;
230+
}
219231
return undefined;
220232
}
221233

Diff for: tests/parsing-test.ts

+3
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,6 @@ test('Parsing should create definition from file with named export specifiers',
9696
test('Parsing should create preact definition', t => {
9797
compare(t, 'path', 'preact-definition.jsx', 'preact-definition.d.ts', {}, 'preact');
9898
});
99+
test('Parsing should suppport props-types repo', t => {
100+
compare(t, 'path', 'prop-types.jsx', 'prop-types.d.ts', {});
101+
});

Diff for: tests/prop-types.d.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
declare module 'path' {
2+
import {Component} from 'react';
3+
4+
export interface Props {
5+
optionalString?: string;
6+
}
7+
8+
export default class extends Component<Props, any> {
9+
render(): JSX.Element;
10+
}
11+
}

Diff for: tests/prop-types.jsx

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import {Component} from 'react';
2+
import * as PropTypes from 'prop-types';
3+
4+
export default class extends Component {
5+
6+
static propTypes = {
7+
optionalString: PropTypes.string
8+
};
9+
10+
render() {
11+
return (
12+
<div></div>
13+
);
14+
}
15+
}

0 commit comments

Comments
 (0)