Tools: 馃悰 formatter should not remove generic trailing comma in tsx

Created on 13 Jan 2021  路  2Comments  路  Source: rome/tools


Environment

$ rome rage --summary
Environment Variables
  Object {
    COLORTERM: "truecolor"
    LANG: "en_US.UTF-8"
    TERM: "xterm-256color"
    TERM_PROGRAM: "vscode"
  }

User Config
  unset

Rome Version
  10.0.4-beta-dev

Node Version
  12.16.3

Platform
  darwin x64 18.7.0

Terminal Features
  Object {
    background: "unknown"
    colorDepth: 24
    columns: 170
    cursor: true
    hyperlinks: true
    isTTY: true
    progress: true
    unicode: true
  }

Client Flags
  Object {
    clientName: "cli"
    silent: false
    cwd: ___R$project$rome$$internal$path$index_ts$AbsoluteFilePath: /Users/yeonjuan/Desktop/open-source/tools
    realCwd: ___R$project$rome$$internal$path$index_ts$AbsoluteFilePath: /Users/yeonjuan/Desktop/open-source/tools
  }

Server Status
  Object {
    projects: Array [
      Object {id: 0}
      Object {id: 1}
    ]
    server: Object {
      heapTotal: 27_672_576
      pid: 84_558
      uptime: 0.781767559
    }
    workers: Array [
      Object {
        astCacheSize: 0
        heapTotal: 27_672_576
        ownedBytes: 0n
        ownedFileCount: 0
        pid: 84_558
        uptime: 0.78147324
      }
    ]
  }

Steps To Reproduce


  1. write below example in a file with .tsx extension
// test.tsx
const func = <T,>() => {
}
  1. run formatter
$ ./rome format test.tsx
  • output
const func = <T>() => {}; // ts error: JSX Element `T` has no corresponding closing tag

Expected Results

The result makes ts parsing error so it should not remove trailing comma.

const func = <T,>() => {}; 

confirmed

Most helpful comment

it's the only way for typescript to differentiate the initial type assertion syntax in tsx file with jsx ie

// *.ts
const a = <string>bar;
const b = bar as string;
// *.tsx

// error
const a = <string>bar;

// fine
const a = <string,>bar;
const b = bar as string;

They've introduced the as syntax in v1.6 to preserve assertions in tsx files, the comma trick was introduced later on as far as I know

All 2 comments

At the beginning I thought it was a typescript bug it's not! Although it seems strange having a trailing comma

it's the only way for typescript to differentiate the initial type assertion syntax in tsx file with jsx ie

// *.ts
const a = <string>bar;
const b = bar as string;
// *.tsx

// error
const a = <string>bar;

// fine
const a = <string,>bar;
const b = bar as string;

They've introduced the as syntax in v1.6 to preserve assertions in tsx files, the comma trick was introduced later on as far as I know

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sebmck picture sebmck  路  5Comments

ChristopherBiscardi picture ChristopherBiscardi  路  5Comments

yamadayuki picture yamadayuki  路  3Comments

shanewilson picture shanewilson  路  4Comments

arslivinski picture arslivinski  路  5Comments