Skip to content

Commit f88c5fb

Browse files
committed
fix(generator): sort interface correctly
1 parent 570d73b commit f88c5fb

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

Diff for: src/generator.ts

+14-5
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,20 @@ export function generate(node: t.Node | t.PropTypeNode[], options: GenerateOptio
152152
rest = _.uniqBy(rest, x => (t.isInstanceOfNode(x) ? `${x.type}.${x.instance}` : x.type));
153153

154154
literals = literals.sort((a, b) => a.value.localeCompare(b.value));
155-
rest = rest.sort((a, b) =>
156-
(t.isInstanceOfNode(a) ? `${a.type}.${a.instance}` : a.type).localeCompare(
157-
t.isInstanceOfNode(b) ? `${b.type}.${b.instance}` : b.type,
158-
),
159-
);
155+
156+
const nodeToStringName = (obj: t.Node): string => {
157+
if (t.isInstanceOfNode(obj)) {
158+
return `${obj.type}.${obj.instance}`;
159+
} else if (t.isInterfaceNode(obj)) {
160+
// An interface is PropTypes.shape
161+
// Use `ShapeNode` to get it sorted in the correct order
162+
return `ShapeNode`;
163+
}
164+
165+
return obj.type;
166+
};
167+
168+
rest = rest.sort((a, b) => nodeToStringName(a).localeCompare(nodeToStringName(b)));
160169

161170
if (literals.find(x => x.value === 'true') && literals.find(x => x.value === 'false')) {
162171
rest.push(t.booleanNode());

0 commit comments

Comments
 (0)