Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const importChanges = importSpecifiers.map((specifier, index) => {
const text = importText(specifier);
// import is not the one we're looking for, can be skipped
if (text !== importAsIs) {
return undefined;
}
// identifier has not been imported, simply replace the old text with the new text
if (!isAlreadyImported) {
return change_1.createReplaceChange(sourceFile, specifier, importAsIs, importToBe);
}
const nextIdentifier = importSpecifiers[index + 1];
// identifer is not the last, also clean up the comma
if (nextIdentifier) {
return change_1.createRemoveChange(sourceFile, specifier, specifier.getStart(sourceFile), nextIdentifier.getStart(sourceFile));
}
// there are no imports following, just remove it
return change_1.createRemoveChange(sourceFile, specifier, specifier.getStart(sourceFile), specifier.getEnd());
});
return importChanges.filter(Boolean);
const text = importText(specifier);
// import is not the one we're looking for, can be skipped
if (text !== importAsIs) {
return undefined;
}
// identifier has not been imported, simply replace the old text with the new text
if (!isAlreadyImported) {
return change_1.createReplaceChange(sourceFile, specifier, importAsIs, importToBe);
}
const nextIdentifier = importSpecifiers[index + 1];
// identifer is not the last, also clean up the comma
if (nextIdentifier) {
return change_1.createRemoveChange(sourceFile, specifier, specifier.getStart(sourceFile), nextIdentifier.getStart(sourceFile));
}
// there are no imports following, just remove it
return change_1.createRemoveChange(sourceFile, specifier, specifier.getStart(sourceFile), specifier.getEnd());
});
return importChanges.filter(Boolean);