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"
|
// 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user