Replace _all_ tabs in pretty output, not just the first on each line (#42649)

This commit is contained in:
Wesley Wigham 2021-02-04 13:25:53 -08:00 committed by GitHub
parent be18057792
commit 62bc8bec4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 87 additions and 1 deletions

View File

@ -407,7 +407,7 @@ namespace ts {
const lineEnd = i < lastLineInFile ? getPositionOfLineAndCharacter(file, i + 1, 0) : file.text.length;
let lineContent = file.text.slice(lineStart, lineEnd);
lineContent = lineContent.replace(/\s+$/g, ""); // trim from end
lineContent = lineContent.replace("\t", " "); // convert tabs to single spaces
lineContent = lineContent.replace(/\t/g, " "); // convert tabs to single spaces
// Output the gutter and the actual contents of the line.
context += indent + formatColorAndReset(padLeft(i + 1 + "", gutterWidth), gutterStyleSequence) + gutterSeparator;

View File

@ -0,0 +1,30 @@
tests/cases/compiler/prettyFileWithErrorsAndTabs.ts:3:9 - error TS2322: Type 'number' is not assignable to type 'string'.
3 const x: string = 12;
   ~
tests/cases/compiler/prettyFileWithErrorsAndTabs.ts:4:9 - error TS2322: Type 'number' is not assignable to type 'string'.
4 const y: string = 12;
   ~
tests/cases/compiler/prettyFileWithErrorsAndTabs.ts:5:9 - error TS2322: Type 'number' is not assignable to type 'string'.
5 const z: string = 12;
   ~
==== tests/cases/compiler/prettyFileWithErrorsAndTabs.ts (3 errors) ====
function f() {
{
const x: string = 12;
~
!!! error TS2322: Type 'number' is not assignable to type 'string'.
const y: string = 12;
~
!!! error TS2322: Type 'number' is not assignable to type 'string'.
const z: string = 12;
~
!!! error TS2322: Type 'number' is not assignable to type 'string'.
}
}
Found 3 errors.

View File

@ -0,0 +1,17 @@
//// [prettyFileWithErrorsAndTabs.ts]
function f() {
{
const x: string = 12;
const y: string = 12;
const z: string = 12;
}
}
//// [prettyFileWithErrorsAndTabs.js]
function f() {
{
var x = 12;
var y = 12;
var z = 12;
}
}

View File

@ -0,0 +1,14 @@
=== tests/cases/compiler/prettyFileWithErrorsAndTabs.ts ===
function f() {
>f : Symbol(f, Decl(prettyFileWithErrorsAndTabs.ts, 0, 0))
{
const x: string = 12;
>x : Symbol(x, Decl(prettyFileWithErrorsAndTabs.ts, 2, 7))
const y: string = 12;
>y : Symbol(y, Decl(prettyFileWithErrorsAndTabs.ts, 3, 7))
const z: string = 12;
>z : Symbol(z, Decl(prettyFileWithErrorsAndTabs.ts, 4, 7))
}
}

View File

@ -0,0 +1,17 @@
=== tests/cases/compiler/prettyFileWithErrorsAndTabs.ts ===
function f() {
>f : () => void
{
const x: string = 12;
>x : string
>12 : 12
const y: string = 12;
>y : string
>12 : 12
const z: string = 12;
>z : string
>12 : 12
}
}

View File

@ -0,0 +1,8 @@
// @pretty: true
function f() {
{
const x: string = 12;
const y: string = 12;
const z: string = 12;
}
}