azu / commonjs-to-es-module-codemod

Codemod that convert CommonJS(require/exports) to ES Modules(import/export) for JavaScript/TypeScript
MIT License
80 stars 15 forks source link

Fix crash and preserve comments #11

Closed rtsao closed 1 year ago

rtsao commented 1 year ago

This PR ensures this codemod preserves leading comments (see https://github.com/facebook/jscodeshift/blob/main/recipes/retain-first-comment.md)

Additionally, a workaround is added for a crash resulting from a bug in ast-types (see https://github.com/benjamn/ast-types/issues/425#issuecomment-1007846129)

azu commented 1 year ago

Thanks for PR!

Can you add test for preserving comments?

Probably, you can put some test cases into https://github.com/azu/commonjs-to-es-module-codemod/tree/master/transforms/__testfixtures__ and https://github.com/azu/commonjs-to-es-module-codemod/tree/master/transforms/__tests__

azu commented 1 year ago

Sorry, #13 cause conflict. But makes it easier to add test cases.

azu commented 1 year ago

Preserve comments in https://github.com/azu/commonjs-to-es-module-codemod/releases/tag/v0.5.7 This PR is closed as it is simpler to re-submit the PR.