1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var logger_1 = require("./logger");
|
4 | var highlight_1 = require("../highlight/highlight");
|
5 | var helpers_1 = require("../util/helpers");
|
6 | var ts = require("typescript");
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | function runTypeScriptDiagnostics(context, tsDiagnostics) {
|
12 | return tsDiagnostics.map(function (tsDiagnostic) {
|
13 | return loadDiagnostic(context, tsDiagnostic);
|
14 | });
|
15 | }
|
16 | exports.runTypeScriptDiagnostics = runTypeScriptDiagnostics;
|
17 | function loadDiagnostic(context, tsDiagnostic) {
|
18 | var d = {
|
19 | level: 'error',
|
20 | type: 'typescript',
|
21 | language: 'typescript',
|
22 | header: 'typescript error',
|
23 | code: tsDiagnostic.code.toString(),
|
24 | messageText: ts.flattenDiagnosticMessageText(tsDiagnostic.messageText, '\n'),
|
25 | relFileName: null,
|
26 | absFileName: null,
|
27 | lines: []
|
28 | };
|
29 | if (tsDiagnostic.file && tsDiagnostic.file.getText) {
|
30 | d.absFileName = tsDiagnostic.file.fileName;
|
31 | d.relFileName = logger_1.Logger.formatFileName(context.rootDir, d.absFileName);
|
32 | var sourceText = tsDiagnostic.file.getText();
|
33 | var srcLines = helpers_1.splitLineBreaks(sourceText);
|
34 | var htmlLines = srcLines;
|
35 | try {
|
36 | htmlLines = helpers_1.splitLineBreaks(highlight_1.highlight(d.language, sourceText, true).value);
|
37 | }
|
38 | catch (e) { }
|
39 | var posData = tsDiagnostic.file.getLineAndCharacterOfPosition(tsDiagnostic.start);
|
40 | var errorLine = {
|
41 | lineIndex: posData.line,
|
42 | lineNumber: posData.line + 1,
|
43 | text: srcLines[posData.line],
|
44 | html: htmlLines[posData.line],
|
45 | errorCharStart: posData.character,
|
46 | errorLength: Math.max(tsDiagnostic.length, 1)
|
47 | };
|
48 | if (errorLine.html && errorLine.html.indexOf('class="hljs') === -1) {
|
49 | try {
|
50 | errorLine.html = highlight_1.highlight(d.language, errorLine.text, true).value;
|
51 | }
|
52 | catch (e) { }
|
53 | }
|
54 | d.lines.push(errorLine);
|
55 | if (errorLine.errorLength === 0 && errorLine.errorCharStart > 0) {
|
56 | errorLine.errorLength = 1;
|
57 | errorLine.errorCharStart--;
|
58 | }
|
59 | d.header = logger_1.Logger.formatHeader('typescript', tsDiagnostic.file.fileName, context.rootDir, errorLine.lineNumber);
|
60 | if (errorLine.lineIndex > 0) {
|
61 | var previousLine = {
|
62 | lineIndex: errorLine.lineIndex - 1,
|
63 | lineNumber: errorLine.lineNumber - 1,
|
64 | text: srcLines[errorLine.lineIndex - 1],
|
65 | html: htmlLines[errorLine.lineIndex - 1],
|
66 | errorCharStart: -1,
|
67 | errorLength: -1
|
68 | };
|
69 | if (previousLine.html && previousLine.html.indexOf('class="hljs') === -1) {
|
70 | try {
|
71 | previousLine.html = highlight_1.highlight(d.language, previousLine.text, true).value;
|
72 | }
|
73 | catch (e) { }
|
74 | }
|
75 | d.lines.unshift(previousLine);
|
76 | }
|
77 | if (errorLine.lineIndex + 1 < srcLines.length) {
|
78 | var nextLine = {
|
79 | lineIndex: errorLine.lineIndex + 1,
|
80 | lineNumber: errorLine.lineNumber + 1,
|
81 | text: srcLines[errorLine.lineIndex + 1],
|
82 | html: htmlLines[errorLine.lineIndex + 1],
|
83 | errorCharStart: -1,
|
84 | errorLength: -1
|
85 | };
|
86 | if (nextLine.html && nextLine.html.indexOf('class="hljs') === -1) {
|
87 | try {
|
88 | nextLine.html = highlight_1.highlight(d.language, nextLine.text, true).value;
|
89 | }
|
90 | catch (e) { }
|
91 | }
|
92 | d.lines.push(nextLine);
|
93 | }
|
94 | }
|
95 | return d;
|
96 | }
|