···
const exportName = isFragment
+
let imp = ` as typeof import('./${nameParts
.replace('.ts', '')}').${exportName}`;
···
const span = { length: 1, start: node.end };
+
// We only want the oldExportName here to be present
+
// that way we can diff its length vs the new one
+
const oldExportName = typeImport
+
// Remove ` as ` from the beginning,
+
// this because getText() gives us everything
+
// but ` as ` meaning we need to keep that part
+
text = source.text.replace(typeImport.getText(), imp);
+
span.length = imp.length + ((oldExportName || '').length - exportName.length);
+
source.text.substring(0, span.start) +
+
span.start + span.length,
info.project.projectService.getScriptInfo(filename);
const snapshot = scriptInfo!.getSnapshot();
···
source.update(text, { span, newLength: imp.length });
scriptInfo!.editContent(0, snapshot.getLength(), text);
info.languageServiceHost.writeFile!(source.fileName, text);
+
// To update the types, otherwise data is stale
+
scriptInfo!.reloadFromFile();
scriptInfo!.registerFileUpdate();
// script info contains a lot of utils that might come in handy here
// to save even if the user has local changes, if we could make that work