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

Commit 8bf9ccb

Browse files
authored
Merge pull request #459 from KnisterPeter/prop-types-namespace-import
feat: support any name for namespace import of `prop-types`
2 parents 01a4784 + fe26b1e commit 8bf9ccb

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

src/typings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ function getPropTypesName(ast: AstQuery): string|undefined {
235235
/:source StringLiteral[@value == 'prop-types']
236236
]
237237
/:specifiers *[
238-
/ Identifier[@name == 'PropTypes']
238+
ImportNamespaceSpecifier || / Identifier[@name == 'PropTypes']
239239
]
240240
/:local Identifier
241241
`);

tests/parsing-test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,6 @@ test('Parsing should create preact definition', t => {
105105
test('Parsing should suppport props-types repo', t => {
106106
compare(t, 'path', 'prop-types.jsx', 'prop-types.d.ts', {});
107107
});
108+
test('Parsing should suppport props-types repo (with a default import)', t => {
109+
compare(t, 'path', 'prop-types-default-import.jsx', 'prop-types.d.ts', {});
110+
});

tests/prop-types-default-import.jsx

Lines changed: 15 additions & 0 deletions
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+
}

tests/prop-types.jsx

Lines changed: 2 additions & 2 deletions
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)