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

Commit fe26b1e

Browse files
committed
feat: support any name for namespace import of prop-types
1 parent 8c1f418 commit fe26b1e

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

Diff for: src/typings.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ function getPropTypesName(ast: AstQuery): string|undefined {
221221
/:source StringLiteral[@value == 'prop-types']
222222
]
223223
/:specifiers *[
224-
/ Identifier[@name == 'PropTypes']
224+
ImportNamespaceSpecifier || / Identifier[@name == 'PropTypes']
225225
]
226226
/:local Identifier
227227
`);

Diff for: tests/parsing-test.ts

+3
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,6 @@ test('Parsing should create preact definition', t => {
9999
test('Parsing should suppport props-types repo', t => {
100100
compare(t, 'path', 'prop-types.jsx', 'prop-types.d.ts', {});
101101
});
102+
test('Parsing should suppport props-types repo (with a default import)', t => {
103+
compare(t, 'path', 'prop-types-default-import.jsx', 'prop-types.d.ts', {});
104+
});

Diff for: tests/prop-types-default-import.jsx

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import {Component} from 'react';
2+
import 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+
}

Diff for: tests/prop-types.jsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import {Component} from 'react';
2-
import * as PropTypes from 'prop-types';
2+
import * as P from 'prop-types';
33

44
export default class extends Component {
55

66
static propTypes = {
7-
optionalString: PropTypes.string
7+
optionalString: P.string
88
};
99

1010
render() {

0 commit comments

Comments
 (0)