quantizor / markdown-to-jsx

🏭 The most lightweight, customizable React markdown component.
https://markdown-to-jsx.quantizor.dev/
MIT License
2.04k stars 177 forks source link

refactor: replace RuleType enum with a const (#539) #594

Closed roger-schaer closed 3 months ago

roger-schaer commented 4 months ago

Summary

This PR resolves https://github.com/quantizor/markdown-to-jsx/issues/539 by replacing the RuleType enum with a const object.

Description

As mentioned & discussed in https://github.com/quantizor/markdown-to-jsx/issues/539, the current way of declaring the RuleType as an enum causes problems when using isolatedModules in tsconfig.json.

The solution, as described on the TypeScript website, is to simply replace the enum with a simple object const, and declare a type based on its keys & values. Additional updates were needed to correctly use types (and not values) in the various interfaces defined for node types.

This worked correctly, but there were still issues when running tests using Jest with the modifications made in index.tsx. Therefore, an additional change was made in index.cjs.tsx in order to export the RuleType explicitly (as is done with the compiler function).

Testing

Since the updated code is functionally equivalent to the existing version & all existing unit tests pass correctly, it was not clear what type of test could be added.

changeset-bot[bot] commented 4 months ago

🦋 Changeset detected

Latest commit: ca37142ee0d880b2c9bd34fcbab7a2c7b7b5794f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package | Name | Type | | --------------- | ----- | | markdown-to-jsx | Patch |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

roger-schaer commented 4 months ago

Hi @quantizor, just wanted to check if you would have time in the coming weeks to check out this PR, it would unblock some things on my end if this could be merged. Thanks in advance and have a nice summer!

quantizor commented 4 months ago

Hi @quantizor, just wanted to check if you would have time in the coming weeks to check out this PR, it would unblock some things on my end if this could be merged. Thanks in advance and have a nice summer!

Hey Roger! I will try to make time, thanks for the reminder. Lots going on personally at the moment.

roger-schaer commented 4 months ago

Hi @quantizor, just wanted to check if you would have time in the coming weeks to check out this PR, it would unblock some things on my end if this could be merged. Thanks in advance and have a nice summer!

Hey Roger! I will try to make time, thanks for the reminder. Lots going on personally at the moment.

No worries, thank you for your answer and your help!

zivkovicn commented 3 months ago

@quantizor hello, any plans in merging this? thanks

roger-schaer commented 3 months ago

Thanks a lot @quantizor, I tested it now and it works perfectly with the new version!