mirror of
https://github.com/bendtherules/ts-transformer-visualizer.git
synced 2026-08-18 13:51:48 +00:00
example - rename rename-symbol to .ts
This commit is contained in:
@@ -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);
|
||||
};
|
||||
Reference in New Issue
Block a user