diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 2cba011131e..1ce672a6a75 100755 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -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) { diff --git a/tests/baselines/reference/multiLineContextDiagnosticWithPretty.errors.txt b/tests/baselines/reference/multiLineContextDiagnosticWithPretty.errors.txt new file mode 100644 index 00000000000..b0cea3122be --- /dev/null +++ b/tests/baselines/reference/multiLineContextDiagnosticWithPretty.errors.txt @@ -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; }'. + }; + \ No newline at end of file diff --git a/tests/baselines/reference/multiLineContextDiagnosticWithPretty.js b/tests/baselines/reference/multiLineContextDiagnosticWithPretty.js new file mode 100644 index 00000000000..e1097709e04 --- /dev/null +++ b/tests/baselines/reference/multiLineContextDiagnosticWithPretty.js @@ -0,0 +1,14 @@ +//// [multiLineContextDiagnosticWithPretty.ts] +const x: {c: string} = { + a: { + b: '', + } +}; + + +//// [multiLineContextDiagnosticWithPretty.js] +var x = { + a: { + b: '' + } +}; diff --git a/tests/baselines/reference/multiLineContextDiagnosticWithPretty.symbols b/tests/baselines/reference/multiLineContextDiagnosticWithPretty.symbols new file mode 100644 index 00000000000..a3460a8e82b --- /dev/null +++ b/tests/baselines/reference/multiLineContextDiagnosticWithPretty.symbols @@ -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)) + } +}; + diff --git a/tests/baselines/reference/multiLineContextDiagnosticWithPretty.types b/tests/baselines/reference/multiLineContextDiagnosticWithPretty.types new file mode 100644 index 00000000000..1d8875bfb9e --- /dev/null +++ b/tests/baselines/reference/multiLineContextDiagnosticWithPretty.types @@ -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 +>'' : "" + } +}; + diff --git a/tests/cases/compiler/multiLineContextDiagnosticWithPretty.ts b/tests/cases/compiler/multiLineContextDiagnosticWithPretty.ts new file mode 100644 index 00000000000..7f6dea430e7 --- /dev/null +++ b/tests/cases/compiler/multiLineContextDiagnosticWithPretty.ts @@ -0,0 +1,6 @@ +// @pretty: true +const x: {c: string} = { + a: { + b: '', + } +};