Skip to content

Commit 62bc8be

Browse files
authored
Replace _all_ tabs in pretty output, not just the first on each line (#42649)
1 parent be18057 commit 62bc8be

6 files changed

Lines changed: 87 additions & 1 deletion

File tree

src/compiler/program.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ namespace ts {
407407
const lineEnd = i < lastLineInFile ? getPositionOfLineAndCharacter(file, i + 1, 0) : file.text.length;
408408
let lineContent = file.text.slice(lineStart, lineEnd);
409409
lineContent = lineContent.replace(/\s+$/g, ""); // trim from end
410-
lineContent = lineContent.replace("\t", " "); // convert tabs to single spaces
410+
lineContent = lineContent.replace(/\t/g, " "); // convert tabs to single spaces
411411

412412
// Output the gutter and the actual contents of the line.
413413
context += indent + formatColorAndReset(padLeft(i + 1 + "", gutterWidth), gutterStyleSequence) + gutterSeparator;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
tests/cases/compiler/prettyFileWithErrorsAndTabs.ts:3:9 - error TS2322: Type 'number' is not assignable to type 'string'.
2+
3+
3 const x: string = 12;
4+
   ~
5+
tests/cases/compiler/prettyFileWithErrorsAndTabs.ts:4:9 - error TS2322: Type 'number' is not assignable to type 'string'.
6+
7+
4 const y: string = 12;
8+
   ~
9+
tests/cases/compiler/prettyFileWithErrorsAndTabs.ts:5:9 - error TS2322: Type 'number' is not assignable to type 'string'.
10+
11+
5 const z: string = 12;
12+
   ~
13+
14+
15+
==== tests/cases/compiler/prettyFileWithErrorsAndTabs.ts (3 errors) ====
16+
function f() {
17+
{
18+
const x: string = 12;
19+
~
20+
!!! error TS2322: Type 'number' is not assignable to type 'string'.
21+
const y: string = 12;
22+
~
23+
!!! error TS2322: Type 'number' is not assignable to type 'string'.
24+
const z: string = 12;
25+
~
26+
!!! error TS2322: Type 'number' is not assignable to type 'string'.
27+
}
28+
}
29+
Found 3 errors.
30+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//// [prettyFileWithErrorsAndTabs.ts]
2+
function f() {
3+
{
4+
const x: string = 12;
5+
const y: string = 12;
6+
const z: string = 12;
7+
}
8+
}
9+
10+
//// [prettyFileWithErrorsAndTabs.js]
11+
function f() {
12+
{
13+
var x = 12;
14+
var y = 12;
15+
var z = 12;
16+
}
17+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
=== tests/cases/compiler/prettyFileWithErrorsAndTabs.ts ===
2+
function f() {
3+
>f : Symbol(f, Decl(prettyFileWithErrorsAndTabs.ts, 0, 0))
4+
{
5+
const x: string = 12;
6+
>x : Symbol(x, Decl(prettyFileWithErrorsAndTabs.ts, 2, 7))
7+
8+
const y: string = 12;
9+
>y : Symbol(y, Decl(prettyFileWithErrorsAndTabs.ts, 3, 7))
10+
11+
const z: string = 12;
12+
>z : Symbol(z, Decl(prettyFileWithErrorsAndTabs.ts, 4, 7))
13+
}
14+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
=== tests/cases/compiler/prettyFileWithErrorsAndTabs.ts ===
2+
function f() {
3+
>f : () => void
4+
{
5+
const x: string = 12;
6+
>x : string
7+
>12 : 12
8+
9+
const y: string = 12;
10+
>y : string
11+
>12 : 12
12+
13+
const z: string = 12;
14+
>z : string
15+
>12 : 12
16+
}
17+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// @pretty: true
2+
function f() {
3+
{
4+
const x: string = 12;
5+
const y: string = 12;
6+
const z: string = 12;
7+
}
8+
}

0 commit comments

Comments
 (0)