···
const exportName = isFragment
226
-
const imp = ` as typeof import('./${nameParts
226
+
let imp = ` as typeof import('./${nameParts
.replace('.ts', '')}').${exportName}`;
···
const span = { length: 1, start: node.end };
240
-
// TODO: if we have a typeImport but the name has been updated/is wrong
241
-
// we need to leave the "as x" typecast
243
-
source.text.substring(0, span.start) +
245
-
source.text.substring(
246
-
span.start + span.length,
242
+
// We only want the oldExportName here to be present
243
+
// that way we can diff its length vs the new one
244
+
const oldExportName = typeImport
249
+
// Remove ` as ` from the beginning,
250
+
// this because getText() gives us everything
251
+
// but ` as ` meaning we need to keep that part
253
+
imp = imp.slice(4);
254
+
text = source.text.replace(typeImport.getText(), imp);
255
+
span.length = imp.length + ((oldExportName || '').length - exportName.length);
258
+
source.text.substring(0, span.start) +
260
+
source.text.substring(
261
+
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);
274
+
if (!!typeImport) {
275
+
// To update the types, otherwise data is stale
276
+
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