UNPKG

ts-simple-ast

Version:

TypeScript compiler wrapper for AST navigation and code generation.

15 lines (14 loc) 720 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tree_1 = require("./../tree"); /** * Replaces the text in a source file and assumes only the nodes will shift (no tree structure should change). * * This is very useful when making formatting changes that won't change the AST structure. */ function replaceSourceFileTextForFormatting(opts) { var sourceFile = opts.sourceFile, newText = opts.newText; var tempSourceFile = sourceFile.global.compilerFactory.createTempSourceFileFromText(newText, { filePath: sourceFile.getFilePath() }); tree_1.replaceTreeStraight(sourceFile, tempSourceFile); } exports.replaceSourceFileTextForFormatting = replaceSourceFileTextForFormatting;