UNPKG

ts-simple-ast

Version:

TypeScript compiler wrapper for AST navigation and code generation.

21 lines (19 loc) 956 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /* istanbul ignore next */ function getInsertErrorMessageText(preText, currentNode, newNode) { let text = `${preText} Perhaps a syntax error was inserted (Current: ${currentNode.getKindName()} -- New: ${newNode.getKindName()}).\n\nCode:\n`; const sourceFileText = newNode.getSourceFile().getFullText(); const startPos = Math.max(0, sourceFileText.lastIndexOf("\n", newNode.getPos()) - 50); let endPos = Math.min(sourceFileText.length, sourceFileText.indexOf("\n", newNode.getEnd()) + 50); if (endPos === -1) endPos = sourceFileText.length; text += sourceFileText.substring(startPos, endPos); if (startPos !== 0) text = "..." + text; if (endPos !== sourceFileText.length) text += "..."; return text; } exports.getInsertErrorMessageText = getInsertErrorMessageText; //# sourceMappingURL=getInsertErrorMessageText.js.map