Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function renameNode(node: Node) {
errors.throwIfWhitespaceOrNotString(newName, nameof(newName));
if (node.getText() === newName)
return;
const renameLocations = languageService.findRenameLocations(node, options);
const renameLocationsBySourceFile = new KeyValueCache();
for (const renameLocation of renameLocations) {
const locations = renameLocationsBySourceFile.getOrCreate(renameLocation.getSourceFile(), () => []);
locations.push(renameLocation);
}
for (const [sourceFile, locations] of renameLocationsBySourceFile.getEntries()) {
replaceSourceFileTextForRename({
sourceFile,
renameLocations: locations,
setInitializer(textOrWriterFunction: string | WriterFunction) {
const text = getTextFromStringOrWriter(this._getWriterWithQueuedChildIndentation(), textOrWriterFunction);
errors.throwIfWhitespaceOrNotString(text, nameof(textOrWriterFunction));
if (this.hasInitializer())
this.removeInitializer();
const semiColonToken = this.getLastChildIfKind(SyntaxKind.SemicolonToken);
insertIntoParentTextRange({
insertPos: semiColonToken != null ? semiColonToken.getPos() : this.getEnd(),
parent: this,
newText: ` = ${text}`
});
return this;
}
set(structure: Partial) {
callBaseSet(Base.prototype, this, structure);
if (structure.name != null) {
errors.throwIfWhitespaceOrNotString(structure.name, nameof.full(structure.name));
const nameNode = this.getNameNode();
if (nameNode == null)
addNameNode(this, structure.name);
else
nameNode.replaceWithText(structure.name);
}
else if (structure.hasOwnProperty(nameof(structure.name))) {
this.removeName();
}
return this;
}
setKeyType(type: string) {
errors.throwIfWhitespaceOrNotString(type, nameof(type));
const keyTypeNode = this.getKeyTypeNode();
if (keyTypeNode.getText() === type)
return this;
keyTypeNode.replaceWithText(type, this._getWriterWithQueuedChildIndentation());
return this;
}
setKeyName(name: string) {
errors.throwIfWhitespaceOrNotString(name, nameof(name));
if (this.getKeyName() === name)
return;
this.getKeyNameNode().replaceWithText(name, this._getWriterWithQueuedChildIndentation());
}