airbnb/ts-migrate

add-conversions plugin removes blank lines

gmoothart opened this issue · 3 comments

On a run of ts-migrate against my codebase I noticed that some files were having empty lines removed. This is a deal-breaker as far as usability is concerned. I ran a pass of each plugin on the command-line and discovered that add-conversions is the culprit.

Using ts-migrate 0.1.13 from npm.

This is an issue with all plugins that rely on TypeScript transforms. The underlying cause is microsoft/TypeScript#843.

I agree it's a major usability issue. I've been thinking about whether it might be possible to munge the transform output by comparing to the original text. That's essentially how I've worked around the problem in some projects I've converted, by using patch manipulation tools before committing to git.

I'm also having this same issue for the jsdoc plugin. @edsrzf how did you use "patch manipulation tools" to add line breaks back?

I ended up writing two super simple text plugins that essentially replace \n\n with uniquely identifiable text at the start of the pipeline, & then replace that text with \n\n at the end of the pipeline. Works pretty well! https://github.com/protoEvangelion/ts-migrate/blob/tds/packages/ts-migrate-example/official-plugins/src/index.ts