UNPKG

ts-simple-ast

Version:

TypeScript compiler wrapper for static analysis and code manipulation.

19 lines (18 loc) 941 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var utils_1 = require("../../../../utils"); /** * @internal */ function getBodyTextWithoutLeadingIndentation(body) { var sourceFile = body._sourceFile; var textArea = body.getChildSyntaxList() || body; // arrow functions don't have a syntax list var startPos = textArea.getNonWhitespaceStart(); var endPos = Math.max(startPos, textArea._getTrailingTriviaNonWhitespaceEnd()); var width = endPos - startPos; if (width === 0) return ""; var fullText = sourceFile.getFullText().substring(startPos, endPos); return utils_1.StringUtils.indent(fullText, -1 * textArea.getIndentationLevel(), textArea._context.manipulationSettings.getIndentationText(), function (pos) { return sourceFile.isInStringAtPos(pos + startPos); }); } exports.getBodyTextWithoutLeadingIndentation = getBodyTextWithoutLeadingIndentation;