@xtrek/ts-migrate-plugins
Version:
Set of codemods, which are doing transformation of js/jsx to ts/tsx
30 lines (29 loc) • 1.17 kB
TypeScript
import ts from 'typescript';
/**
* Tracks updates to a ts.SourceFile as text changes.
* This is useful to preserve as much of the original whitespace in the source
* file as possible. Re-printing the entire file causes blank lines to be lost.
*
* See: https://github.com/microsoft/TypeScript/issues/843
*/
declare class UpdateTracker {
private sourceFile;
private updates;
private printer;
constructor(sourceFile: ts.SourceFile);
private insert;
/**
* Adds a return type annotation to a function.
* replaceNode would require reprinting the entire function body, losing all whitespace details.
*/
addReturnAnnotation(node: ts.SignatureDeclaration, type: ts.TypeNode): void;
insertNodes<T extends ts.Node>(pos: number, nodes: ts.NodeArray<T>): void;
private replace;
replaceNode(oldNode: ts.Node | undefined, newNode: ts.Node | undefined): void;
replaceNodes<T extends ts.Node>(oldNodes: ts.NodeArray<T>, newNodes: ts.NodeArray<T>, addParens?: boolean): void;
/**
* Returns the result of applying all tracked changes to the source file.
*/
apply(): string;
}
export default UpdateTracker;