Skip to content

Commit 4d284d6

Browse files
Merge pull request #22098 from alexeagle/pretty
fix --pretty output when context is multi-line
2 parents 8e8efaf + 2e66e74 commit 4d284d6

6 files changed

+74
-1
lines changed

src/compiler/program.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,8 @@ namespace ts {
289289
gutterWidth = Math.max(ellipsis.length, gutterWidth);
290290
}
291291

292-
context += host.getNewLine();
293292
for (let i = firstLine; i <= lastLine; i++) {
293+
context += host.getNewLine();
294294
// If the error spans over 5 lines, we'll only show the first 2 and last 2 lines,
295295
// so we'll skip ahead to the second-to-last line.
296296
if (hasMoreThanFiveLines && firstLine + 1 < i && i < lastLine - 1) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
tests/cases/compiler/multiLineContextDiagnosticWithPretty.ts:2:5 - error TS2322: Type '{ a: { b: string; }; }' is not assignable to type '{ c: string; }'.
2+
Object literal may only specify known properties, and 'a' does not exist in type '{ c: string; }'.
3+
4+
2 a: {
5+
   ~~~~
6+
3 b: '',
7+
  ~~~~~~~~~~~~~~
8+
4 }
9+
  ~~~~~
10+
11+
12+
13+
==== tests/cases/compiler/multiLineContextDiagnosticWithPretty.ts (1 errors) ====
14+
const x: {c: string} = {
15+
a: {
16+
~~~~
17+
b: '',
18+
~~~~~~~~~~~~~~
19+
}
20+
~~~~~
21+
!!! error TS2322: Type '{ a: { b: string; }; }' is not assignable to type '{ c: string; }'.
22+
!!! error TS2322: Object literal may only specify known properties, and 'a' does not exist in type '{ c: string; }'.
23+
};
24+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//// [multiLineContextDiagnosticWithPretty.ts]
2+
const x: {c: string} = {
3+
a: {
4+
b: '',
5+
}
6+
};
7+
8+
9+
//// [multiLineContextDiagnosticWithPretty.js]
10+
var x = {
11+
a: {
12+
b: ''
13+
}
14+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
=== tests/cases/compiler/multiLineContextDiagnosticWithPretty.ts ===
2+
const x: {c: string} = {
3+
>x : Symbol(x, Decl(multiLineContextDiagnosticWithPretty.ts, 0, 5))
4+
>c : Symbol(c, Decl(multiLineContextDiagnosticWithPretty.ts, 0, 10))
5+
6+
a: {
7+
>a : Symbol(a, Decl(multiLineContextDiagnosticWithPretty.ts, 0, 24))
8+
9+
b: '',
10+
>b : Symbol(b, Decl(multiLineContextDiagnosticWithPretty.ts, 1, 8))
11+
}
12+
};
13+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
=== tests/cases/compiler/multiLineContextDiagnosticWithPretty.ts ===
2+
const x: {c: string} = {
3+
>x : { c: string; }
4+
>c : string
5+
>{ a: { b: '', }} : { a: { b: string; }; }
6+
7+
a: {
8+
>a : { b: string; }
9+
>{ b: '', } : { b: string; }
10+
11+
b: '',
12+
>b : string
13+
>'' : ""
14+
}
15+
};
16+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// @pretty: true
2+
const x: {c: string} = {
3+
a: {
4+
b: '',
5+
}
6+
};

0 commit comments

Comments
 (0)