UNPKG

ts-simple-ast

Version:

TypeScript compiler wrapper for AST navigation and code generation.

22 lines (21 loc) 962 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tree_1 = require("./../tree"); var text_1 = require("./../text"); /** * Changes the child older of two nodes within a parent. * @param opts - Options. */ function changeChildOrder(opts) { var parent = opts.parent, getSiblingFormatting = opts.getSiblingFormatting, oldIndex = opts.oldIndex, newIndex = opts.newIndex; var newText = text_1.getTextChangingChildOrder({ parent: parent, getSiblingFormatting: getSiblingFormatting, oldIndex: oldIndex, newIndex: newIndex }); var sourceFile = parent.sourceFile; var tempSourceFile = sourceFile.global.compilerFactory.createTempSourceFileFromText(newText, { filePath: sourceFile.getFilePath() }); tree_1.replaceTreeChangingChildOrder({ parent: parent, newIndex: newIndex, oldIndex: oldIndex, replacementSourceFile: tempSourceFile }); } exports.changeChildOrder = changeChildOrder;