Skip to content

Commit

Permalink
🐛 Fixes variable name clash bug (#169)
Browse files Browse the repository at this point in the history
* 🐛 Fixes variable name clash bug

* docs(changeset): Fixes a bug where variable names clash with type properties of the same name, causing a "Missing converter for: [path]" error
  • Loading branch information
danieldelcore authored Mar 4, 2021
1 parent d889453 commit 4589e9f
Showing 4 changed files with 77 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/shiny-dolls-kiss.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'extract-react-types': patch
---

Fixes a bug where variable names clash with type properties of the same name, causing a "Missing converter for: [path]" error
Original file line number Diff line number Diff line change
@@ -233,6 +233,59 @@ Object {
}
`;

exports[`TypeScript: does not conflict with ambiguously named type properties 1`] = `
Object {
"kind": "generic",
"name": Object {
"kind": "id",
"name": "Icon",
"type": null,
},
"value": Object {
"kind": "object",
"members": Array [
Object {
"key": Object {
"kind": "id",
"name": "size",
},
"kind": "property",
"leadingComments": Array [
Object {
"raw": " Icon sizes",
"type": "commentLine",
"value": "Icon sizes",
},
],
"optional": true,
"value": Object {
"kind": "union",
"types": Array [
Object {
"kind": "string",
"value": "small",
},
Object {
"kind": "string",
"value": "medium",
},
Object {
"kind": "string",
"value": "large",
},
Object {
"kind": "string",
"value": "xlarge",
},
],
},
},
],
"referenceIdName": "IconProps",
},
}
`;

exports[`TypeScript: follow export default export 1`] = `
Object {
"kind": "generic",
18 changes: 18 additions & 0 deletions packages/extract-react-types/converters-typescript.test.js
Original file line number Diff line number Diff line change
@@ -618,6 +618,24 @@ const TESTS = [
export default MyComponent;
`
},
{
name: 'does not conflict with ambiguously named type properties ',
typeSystem: 'typescript',
code: `
import React, { FC } from 'react';
const size = 'My var name conflicts with the property name';
export interface IconProps {
// Icon sizes
size?: 'small' | 'medium' | 'large' | 'xlarge';
}
const Icon: FC<IconProps> = ({ size = 'medium' }) => null;
export default Icon;
`
}
];

2 changes: 1 addition & 1 deletion packages/extract-react-types/src/index.js
Original file line number Diff line number Diff line change
@@ -846,7 +846,7 @@ converters.TSTypeLiteral = (path, context): K.Obj => ({
converters.TSPropertySignature = (path, context): K.Property => ({
kind: 'property',
optional: !!path.node.optional,
key: convert(path.get('key'), context),
key: { kind: 'id', name: path.node.key.name },
value: convert(path.get('typeAnnotation'), context)
});

0 comments on commit 4589e9f

Please sign in to comment.