example - rename rename-symbol to .ts

This commit is contained in:
2020-01-29 13:43:51 +05:30
parent f68a4bc7da
commit 0224f9bb3d
@@ -12,7 +12,6 @@ foo = 3;
// Renames all references to the first identifier with the text "foo"
const identifierText = "foo";
const identifierMatchIndex = 1;
const newIdentifierText = "bar";
const transformerProgram = (program: ts.Program) => {
@@ -21,7 +20,6 @@ const transformerProgram = (program: ts.Program) => {
const transformerFactory: ts.TransformerFactory<ts.SourceFile> = context => {
return sourceFile => {
// 1. Find the symbol, if any
let identifierCurrentIndex = -1;
const findSymbolVisitor = (node: ts.Node): ts.Symbol | undefined => {
if (ts.isIdentifier(node)) {
const relatedSymbol = typeChecker.getSymbolAtLocation(node);
@@ -29,15 +27,10 @@ const transformerProgram = (program: ts.Program) => {
if (relatedSymbol === undefined) {
return;
}
console.log(relatedSymbol.escapedName);
if (relatedSymbol.escapedName === identifierText) {
identifierCurrentIndex += 1;
if (identifierCurrentIndex === identifierMatchIndex) {
console.log("found");
return relatedSymbol;
}
}
}
return ts.forEachChild(node, findSymbolVisitor);
};