ts-simple-ast
Version:
TypeScript compiler wrapper for AST navigation and code generation.
28 lines (26 loc) • 1.37 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const formatting_1 = require("./../formatting");
function getNewInsertCode(opts) {
const { structures, newCodes, parent, getSeparator, previousFormattingKind, nextFormattingKind } = opts;
const indentationText = opts.indentationText == null ? parent.getChildIndentationText() : opts.indentationText;
const newLineKind = parent.global.manipulationSettings.getNewLineKind();
return getFormattingKindTextWithIndent(previousFormattingKind) + getChildCode() + getFormattingKindTextWithIndent(nextFormattingKind);
function getChildCode() {
let code = newCodes[0];
for (let i = 1; i < newCodes.length; i++) {
const formattingKind = getSeparator(structures[i - 1], structures[i]);
code += getFormattingKindTextWithIndent(formattingKind);
code += newCodes[i];
}
return code;
}
function getFormattingKindTextWithIndent(formattingKind) {
let code = formatting_1.getFormattingKindText(formattingKind, { newLineKind });
if (formattingKind === formatting_1.FormattingKind.Newline || formattingKind === formatting_1.FormattingKind.Blankline)
code += indentationText;
return code;
}
}
exports.getNewInsertCode = getNewInsertCode;
//# sourceMappingURL=getNewInsertCode.js.map