Skip to content

Commit bb94047

Browse files
committed
fix(parser): parse Date type
Fixes #30
1 parent 93fb992 commit bb94047

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

src/parser.ts

+1
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ export function parseFromProgram(
444444
case 'React.ReactNode': {
445445
return t.unionNode([t.elementNode('node'), t.undefinedNode()]);
446446
}
447+
case 'Date':
447448
case 'React.Component': {
448449
return t.instanceOfNode(typeName);
449450
}

test/date/input.d.ts

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
type Props = {
2+
createdAt: Date;
3+
removedAt?: Date;
4+
};
5+
6+
export default function Foo(props: Props): JSX.Element;

test/date/output.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Foo.propTypes = {
2+
createdAt: PropTypes.instanceOf(Date).isRequired,
3+
removedAt: PropTypes.instanceOf(Date),
4+
};

test/date/output.json

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"type": "ProgramNode",
3+
"body": [
4+
{
5+
"type": "ComponentNode",
6+
"name": "Foo",
7+
"types": [
8+
{
9+
"type": "PropTypeNode",
10+
"name": "createdAt",
11+
"propType": { "type": "InstanceOfNode", "instance": "Date" },
12+
"filenames": {}
13+
},
14+
{
15+
"type": "PropTypeNode",
16+
"name": "removedAt",
17+
"propType": {
18+
"type": "UnionNode",
19+
"types": [{ "type": "UndefinedNode" }, { "type": "InstanceOfNode", "instance": "Date" }]
20+
},
21+
"filenames": {}
22+
}
23+
]
24+
}
25+
]
26+
}

0 commit comments

Comments
 (0)