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" // Renames all references to the first identifier with the text "foo"
const identifierText = "foo"; const identifierText = "foo";
const identifierMatchIndex = 1;
const newIdentifierText = "bar"; const newIdentifierText = "bar";
const transformerProgram = (program: ts.Program) => { const transformerProgram = (program: ts.Program) => {
@@ -21,7 +20,6 @@ const transformerProgram = (program: ts.Program) => {
const transformerFactory: ts.TransformerFactory<ts.SourceFile> = context => { const transformerFactory: ts.TransformerFactory<ts.SourceFile> = context => {
return sourceFile => { return sourceFile => {
// 1. Find the symbol, if any // 1. Find the symbol, if any
let identifierCurrentIndex = -1;
const findSymbolVisitor = (node: ts.Node): ts.Symbol | undefined => { const findSymbolVisitor = (node: ts.Node): ts.Symbol | undefined => {
if (ts.isIdentifier(node)) { if (ts.isIdentifier(node)) {
const relatedSymbol = typeChecker.getSymbolAtLocation(node); const relatedSymbol = typeChecker.getSymbolAtLocation(node);
@@ -29,13 +27,8 @@ const transformerProgram = (program: ts.Program) => {
if (relatedSymbol === undefined) { if (relatedSymbol === undefined) {
return; return;
} }
console.log(relatedSymbol.escapedName);
if (relatedSymbol.escapedName === identifierText) { if (relatedSymbol.escapedName === identifierText) {
identifierCurrentIndex += 1; return relatedSymbol;
if (identifierCurrentIndex === identifierMatchIndex) {
console.log("found");
return relatedSymbol;
}
} }
} }