abstract syntax tree - Modifying TypeScript symbol using compiler API -


i trying use typescript compiler api (1.4) rename symbols across source files, example renaming global variable , references it. started instructions here, used identifiers

function getnodes(sf: ts.sourcefile): ts.node[] {     var nodes: ts.node[] = [];     function allnodes(n: ts.node)     {         ts.foreachchild(n, n => { if (n.kind == ts.syntaxkind.identifier) nodes.push(n); allnodes(n); return false; })     };     allnodes(sf);     return nodes; } 

once create type checker, can resolve nodes (where every reference identifier has separate instance) symbols (where references same variable have same instance):

var checker = program.gettypechecker(true); var symbols = getnodes(sourcefile).map((n, i, array) => checker.getsymbolatlocation(n)); 

great. stuck, since symbol seems immutable. supposed clone , provide kind of lookup table emitter? or custom symbolwriter, or symboldisplaybuilder? can't see many extension points in classes.

for example renaming global variable , references it.

symbols have declarations stored inside them (some docs http://basarat.gitbooks.io/typescript/content/docs/compiler/binder-declarations.html)

you can access these using let declarations = symbol.getdeclarations(); , in fact getrenameinfo in services.ts (source code).


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -