withastro / language-tools

Language tools for Astro
MIT License
240 stars 45 forks source link

πŸ› BUG: astro check cannot parse file #870

Open reisi007 opened 1 month ago

reisi007 commented 1 month ago

Describe the Bug

error astro(1000): The Astro compiler encountered an unknown error while transform this file to TSX. Please create an issue with your code and the error shown in the server's logs: https://github.com/withastro/language-tools/issues

WORKING Pagination.astro

Steps to Reproduce

The Astro JSX compiler has a problem parsing this file.

Only effects Astro check, astro build is fine and the generated files seem to be working just fine....

FAILING Pagination.astro

`panic: runtime error: index out of range [0] with length 0

goroutine 6 [running]: github.com/withastro/compiler/internal/printer.renderTsx(0x1413950, 0x15623c0) github.com/withastro/compiler/internal/printer/print-to-tsx.go:248 +0x1b6 github.com/withastro/compiler/internal/printer.renderTsx(0x1413950, 0x1562140) github.com/withastro/compiler/internal/printer/print-to-tsx.go:523 +0x52f github.com/withastro/compiler/internal/printer.renderTsx(0x1413950, 0x14c9e00) github.com/withastro/compiler/internal/printer/print-to-tsx.go:523 +0x52f github.com/withastro/compiler/internal/printer.renderTsx(0x1413950, 0x14c9b80) github.com/withastro/compiler/internal/printer/print-to-tsx.go:523 +0x52f github.com/withastro/compiler/internal/printer.renderTsx(0x1413950, 0x14c9900) github.com/withastro/compiler/internal/printer/print-to-tsx.go:523 +0x52f github.com/withastro/compiler/internal/printer.renderTsx(0x1413950, 0x14c9540) github.com/withastro/compiler/internal/printer/print-to-tsx.go:147 +0xba github.com/withastro/compiler/internal/printer.PrintToTSX({0x152b200, 0x409}, 0x14c9540, {{0x3c3c4, 0x6}, {0x145c6e0, 0x42}, {0x145c6e0, 0x42}, {0x46f38, ...}, ...}, ...) github.com/withastro/compiler/internal/printer/print-to-tsx.go:30 +0x12 main.main.ConvertToTSX.func3({{}, 0x7ff800010000004b, 0x140c500}, {0x1434200, 0x2, 0x2}) ./astro-wasm.go:263 +0xe syscall/js.handleEvent() syscall/js/func.go:100 +0x23 exit code: 2 There was an error transforming d:/Github/astro-reisinger.pictures/src/components/Pagination.astro to TSX. An empty file will be returned instead. Please create an issue: https://github.com/withastro/language-tools/issues Error: TypeError: Cannot read properties of undefined (reading 'map'). D:\Github\astro-reisinger.pictures\node_modules\@astrojs\compiler\dist\node\sync.cjs:1 `

"astro": "^4.8.3"

wolf-yuan-6115 commented 1 month ago

I'm having the same issue, but not when running astro check, it happens when editing files on Neovim.

A video is attached.

https://github.com/withastro/language-tools/assets/58245644/7f3d30da-b886-40ad-a602-77586e6de8ea

Princesseuh commented 1 month ago

In the file in the OP, the issue is that the closing tag on line 16 has an extra space:

<a class:list={
  ['col-start-1 border-2 hover:border-primary-accent border-primary-alternative flex items-center',
   ' justify-center size-8 rounded-full', {'hidden': !prev}]
- } href={prev}> <span class="i-mdi-arrow-left"> </ span>
+ } href={prev}> <span class="i-mdi-arrow-left"> </span>
</a>

Upstream issue: https://github.com/withastro/compiler/issues/1007

wolf-yuan-6115 commented 1 month ago

In the file in the OP, the issue is that the closing tag on line 16 has an extra space:

<a class:list={
  ['col-start-1 border-2 hover:border-primary-accent border-primary-alternative flex items-center',
   ' justify-center size-8 rounded-full', {'hidden': !prev}]
- } href={prev}> <span class="i-mdi-arrow-left"> </ span>
+ } href={prev}> <span class="i-mdi-arrow-left"> </span>
</a>

Upstream issue: https://github.com/withastro/compiler/issues/1007

My code doesn't contain any whitespace in closing tags, so I'll investigate further.