Removing the last named export creates a star export
Describe the bug
Version: 23.0.0
Calling namedExport.remove() on the last named export in a declaration inserts an export * from 'module'; , instead of removing the declaration.
To Reproduce
import { Project } from "ts-morph";
(async () => {
const project = new Project();
project.addSourceFileAtPath("test.ts");
for (const file of project.getSourceFiles()) {
for (const declaration of file.getExportDeclarations()) {
for (const namedExport of declaration.getNamedExports()) {
namedExport.remove();
}
}
}
await project.save();
})();
Input:
export { a } from "./b";
Output:
export * from "./b";
Expected behavior
An empty file (the export declaration should be simply removed).
I can contribute a bugfix, if someone confirms this really is a bug and not intended
It should go to:
export { } from "./b";
Someone may go to add a named export after removing the last one.
@dsherret I believe there should be 2 methods then, since this behavior is easy to miss
remove and removeAndRemoveDeclarationIfEmpty, or removeWithDeclaration
WDYT?
There's already an exportDeclaration.remove(). I don't think we need so many methods.