๐ Failed to recognize Instanciation Expression followed by newline
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
- [X] I agree to follow Rome's Code of Conduct
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.
Instantiation expressions aren't fully supported yet #3147
You can follow https://github.com/rome/tools/issues/3147 to track the status of the implementation.