Closed mrcljx closed 2 years ago
Hey @psaren - thank you for the plugin! This PR is a tiny bit "larger" than it needs to be to address my main issue (which is supporting import Icon from "@ant-design/icons";
), but as I was debugging the issue, I found some opportunities to use type-narrowing that would have caught this bug earlier. Let me know if this is too much and you'd rather prefer a smaller PR. Thanks!
Thank you very much for your PR, this is a graceful solution
parseImportModule
used a fewas
casts which would hide a few bugs that would lead to ugly crashes like #10 when alternative imports are used:After this PR, the plugin will not crash on these but instead emit a warning (for the first three cases).
It will also treat the following two lines as equivalent:
This allows a custom
nameFormatter
to rewrite the import properly (in this cases it needs to be@ant-design/icons/es/components/Icon
).Bonus: This PR also improves performance a bit by moving the
astNode.type
before thelibList.find
check.