UNPKG

alm

Version:

The best IDE for TypeScript

42 lines (41 loc) 1.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); function diagnosticToCodeError(diagnostic) { var preview = ''; var filePath = ''; var startPosition = { line: 0, character: 0 }; var endPosition = { line: 0, character: 0 }; if (diagnostic.file) { filePath = diagnostic.file.fileName; startPosition = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start); endPosition = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start + diagnostic.length); preview = diagnostic.file.text.substr(diagnostic.start, diagnostic.length); } return { source: 'projectService', filePath: filePath, from: { line: startPosition.line, ch: startPosition.character }, to: { line: endPosition.line, ch: endPosition.character }, message: ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'), preview: preview, level: 'error' }; } exports.diagnosticToCodeError = diagnosticToCodeError; /** * Raw signifies the fact that the output is not being written anywhere * WARNING: only call if proj contains the filePath */ function getRawJsOutput(proj, filePath) { var services = proj.languageService; var output = services.getEmitOutput(filePath); /** We only care about the js output */ var jsFile = output.outputFiles.filter(function (x) { return x.name.endsWith(".js"); })[0]; if (!jsFile) return; return { filePath: jsFile.name, contents: jsFile.text }; } exports.getRawJsOutput = getRawJsOutput;