Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

🐛 Failed to recognize Instanciation Expression followed by newline #3793

Closed
1 task done
LunaTK opened this issue Nov 19, 2022 · 2 comments
Closed
1 task done

🐛 Failed to recognize Instanciation Expression followed by newline #3793

LunaTK opened this issue Nov 19, 2022 · 2 comments
Labels
S-To triage Status: user report of a possible bug that needs to be triaged

Comments

@LunaTK
Copy link

LunaTK commented Nov 19, 2022

Environment information

CLI:
  Version:              10.0.1
  Color support:        true

Platform:
  CPU Architecture:     aarch64
  OS:                   macos

Environment:
  ROME_LOG_DIR:         unset
  NO_COLOR:             unset
  TERM:                 "xterm-256color"

Rome Configuration:
  Status:               loaded
  Formatter disabled:   false
  Linter disabled:      true

Workspace:
  Open Documents:       0

Discovering running Rome servers...

Running Rome Server: ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

i The client isn't connected to any server but rage discovered this running Rome server.

Server:
  Version:              10.0.1
  Name:                 rome_lsp
  CPU Architecture:     aarch64
  OS:                   macos

Workspace:
  Open Documents:       0

Other Active Server Workspaces:

Workspace:
  Open Documents:       5
  Client Name:          Visual Studio Code
  Client Version:       1.73.1

What happened?

Rome cli fails to format the following code.

// test.ts
class Foo<T> {}

const Bar = Foo<string>
const Baz = 123
❯ yarn rome format test.ts  
yarn run v1.22.11
$ /Users/lunatk/Devsisters/protobuf-auto-form/node_modules/.bin/rome format test.ts
test.ts:4:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  ✖ expected an expression but instead found 'const'
  
    3 │ const Bar = Foo<string>
  > 4 │ const Baz = 123
      │ ^^^^^
    5 │ 
  
  ℹ Expected an expression here
  
    3 │ const Bar = Foo<string>
  > 4 │ const Baz = 123
      │ ^^^^^
    5 │ 
  

Compared 0 files in 1163µs
Skipped 1 files
Error: errors where emitted while running checks
error Command failed with exit code 1.

If there is a trailing semicolon on the instanciation expression, it works.

class Foo<T> {}

const Bar = Foo<string>;    // this works
const Baz = 123                   // rome will append semicolon           

My rome.json.

{
  "linter": {
    "enabled": false
  },
  "formatter": {
    "enabled": true,
    "indentStyle": "space"
  },
  "javascript": {
    "formatter": {
      "quoteStyle": "single"
    }
  }
}

I just noticed that Github markdown has same issue :/, but I guess this is a valid syntax for typescript since it is compiled well by tsc.

https://www.typescriptlang.org/play?#code/MYGwhgzhAEBiD28A8AVAfNA3gXwFC+HgDsIAXaAITACdoBeORJM6gSyIHM0DizKwAXvWgBGAEwBmXEA

Expected result

If there is a newline between them, both of them should be recognized as an Instanciation Expression.

Code of Conduct

  • I agree to follow Rome's Code of Conduct
@LunaTK LunaTK added the S-To triage Status: user report of a possible bug that needs to be triaged label Nov 19, 2022
@LunaTK LunaTK changed the title 🐛 Failed to recognize two consecutive Instanciation Expression without semicolon 🐛 Failed to recognize Instanciation Expression followed by newline Nov 19, 2022
@jeysal
Copy link
Contributor

jeysal commented Nov 20, 2022

Can confirm. Funny that GitHub highlighting also fails on this exact case, but I'm assuming they probably just run some simple rules on the token list and no proper parsing.
And can confirm that TSC and also @babel/parser manage to parse this.

@MichaReiser
Copy link
Contributor

Instantiation expressions aren't fully supported yet #3147

You can follow #3147 to track the status of the implementation.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
S-To triage Status: user report of a possible bug that needs to be triaged
Projects
None yet
Development

No branches or pull requests

3 participants