@neo-one/smart-contract-compiler
Version:
NEO•ONE TypeScript smart contract compiler.
27 lines (25 loc) • 1.41 kB
JavaScript
import { codeFrameColumns } from '@babel/code-frame';
import * as path from 'path';
import ts from 'typescript';
const MESSAGE_INDENT = ' ';
const getRenderedCallsite = (fileContent, line, column, noHighlight = false) => {
let renderedCallsite = codeFrameColumns(fileContent, { start: { column, line } }, { highlightCode: !noHighlight });
renderedCallsite = renderedCallsite
.split('\n')
.map((renderedLine) => MESSAGE_INDENT + renderedLine)
.join('\n');
renderedCallsite = `\n${renderedCallsite}\n`;
return renderedCallsite;
};
export const getDiagnosticMessage = (diagnostic, { onlyFileName = false, noHighlight = false } = { onlyFileName: false, noHighlight: false }) => {
if (diagnostic.file && diagnostic.start) {
const { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
const fileName = diagnostic.file.fileName;
const filePath = onlyFileName ? path.basename(fileName) : fileName;
const callSite = getRenderedCallsite(diagnostic.file.text, line + 1, character + 1, noHighlight);
return `${filePath} (${line + 1},${character + 1}): ${message}\n${callSite}`;
}
return ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
};
//# sourceMappingURL=getDiagnosticMessage.js.map