fix --pretty output when context is multi-line

Fixes #22097
This commit is contained in:
Alex Eagle 2018-02-21 14:07:58 -08:00
parent 72a7194b6c
commit 2e66e74e14
6 changed files with 74 additions and 1 deletions

View file

@ -289,8 +289,8 @@ namespace ts {
gutterWidth = Math.max(ellipsis.length, gutterWidth);
}
context += host.getNewLine();
for (let i = firstLine; i <= lastLine; i++) {
context += host.getNewLine();
// If the error spans over 5 lines, we'll only show the first 2 and last 2 lines,
// so we'll skip ahead to the second-to-last line.
if (hasMoreThanFiveLines && firstLine + 1 < i && i < lastLine - 1) {

View file

@ -0,0 +1,24 @@
tests/cases/compiler/multiLineContextDiagnosticWithPretty.ts:2:5 - error TS2322: Type '{ a: { b: string; }; }' is not assignable to type '{ c: string; }'.
Object literal may only specify known properties, and 'a' does not exist in type '{ c: string; }'.
2 a: {
   ~~~~
3 b: '',
  ~~~~~~~~~~~~~~
4 }
  ~~~~~
==== tests/cases/compiler/multiLineContextDiagnosticWithPretty.ts (1 errors) ====
const x: {c: string} = {
a: {
~~~~
b: '',
~~~~~~~~~~~~~~
}
~~~~~
!!! error TS2322: Type '{ a: { b: string; }; }' is not assignable to type '{ c: string; }'.
!!! error TS2322: Object literal may only specify known properties, and 'a' does not exist in type '{ c: string; }'.
};

View file

@ -0,0 +1,14 @@
//// [multiLineContextDiagnosticWithPretty.ts]
const x: {c: string} = {
a: {
b: '',
}
};
//// [multiLineContextDiagnosticWithPretty.js]
var x = {
a: {
b: ''
}
};

View file

@ -0,0 +1,13 @@
=== tests/cases/compiler/multiLineContextDiagnosticWithPretty.ts ===
const x: {c: string} = {
>x : Symbol(x, Decl(multiLineContextDiagnosticWithPretty.ts, 0, 5))
>c : Symbol(c, Decl(multiLineContextDiagnosticWithPretty.ts, 0, 10))
a: {
>a : Symbol(a, Decl(multiLineContextDiagnosticWithPretty.ts, 0, 24))
b: '',
>b : Symbol(b, Decl(multiLineContextDiagnosticWithPretty.ts, 1, 8))
}
};

View file

@ -0,0 +1,16 @@
=== tests/cases/compiler/multiLineContextDiagnosticWithPretty.ts ===
const x: {c: string} = {
>x : { c: string; }
>c : string
>{ a: { b: '', }} : { a: { b: string; }; }
a: {
>a : { b: string; }
>{ b: '', } : { b: string; }
b: '',
>b : string
>'' : ""
}
};

View file

@ -0,0 +1,6 @@
// @pretty: true
const x: {c: string} = {
a: {
b: '',
}
};