withastro / compiler

The Astro compiler. Written in Go. Distributed as WASM.
Other
482 stars 59 forks source link

Expected ";" but found "const" - typescript transformer #997

Open bartlomiejzuber opened 5 months ago

bartlomiejzuber commented 5 months ago

What version of @astrojs/compiler are you using?

2.8.1

What package manager are you using?

npm

What operating system are you using?

Linux

Describe the Bug

In this code sample, the export statement is hoisted, but as const is not.

---
export const allAboutUsPreviewCards = [
] as const;
---

as const is correctly hoisted if the const declaration is only takes up one line.

Link to Minimal Reproducible Example

Live Astro Compiler

ematipico commented 5 months ago

This is an issue with esbuild. I suggest filing an issue there: link to their playground

lilnasy commented 5 months ago

After looking at the response in the esbuild issue, it's clear this is an issue with the compiler.

Export statements are hoisted, which is a term we use for moving code such that it runs at the top-level instead of component-level. It seems like the the variable declaration itself is hoisted, but as const is not, creating invalid typescript code.

lilnasy commented 5 months ago

Updated the issue description to focus on incorrect compilation.