-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Description
Is there a way to use the transformations API to transform a TS file and then emit it, all while preserving existing whitespace/formatting in the file? If I do something like the following, all blank lines get removed (I believe the pretty printer does this?):
const result = ts.transform(file, [transformerFactory]);
const newFile = result.transformed[0];
if (ts.isSourceFile(newFile)) {
const newContent = printer.printFile(newFile);
ts.sys.writeFile(newFile.fileName, newContent);
}
If I do newFile.getText() or newFile.getFullText(), the resulting string does not include any of the changes from my transformation.
My ultimate goal is to rewrite a bunch of imports of the form import { foo } from '../../Enum/foo'; to import { foo } from '../../Enum/enums'. It'd be nice to coalesce all the imports from the same file as well, but first things first :D
P.S. I hope this is an appropriate forum for this question. It looked like questions are disallowed with the exception of questions about the compiler API.
Thanks,
Chris