Contributions are welcome to the Go compiler!
Go 1.17.x
is needed to work with this repo. On Macs, installing via Homebrew is recommended: brew install go
. For Windows & Linux, you can follow Go’s installation guide if you don’t have your own preferred method of package installation.
If you use VS Code as your primary editor, installing the Go extension is highly recommended.
TinyGo is needed to compile the WASM, and is an improvement over Go’s default WASM compiler. TinyGo has installation guides for every OS.
Sometimes you may have to install an older version of tinygo, either to test or because we aren’t using the latest version. To do this on Homebrew:
- Visit tinygo’s Homebrew script
- Go back through the commit history to find the version you want
- Save this anywhere on disk as
tinygo.rb
(e.g.~/Desktop/tinygo.rb
) - Install this local version using
brew install ~/Desktop/tinygo.rb
You will also need Node.js installed, as well as Yarn 1.x (npm i -g yarn
). More often than not, you won’t need to touch JS in this repo, but in case you do, be sure to run yarn
first.
A simple explanation of the compiler process is:
- Tokenizes (
internal/token.go
) - Scans (
internal/js_scanner.go
) - Prints (
internal/printer/print-to-js.go
)
Tokenizing takes the raw .astro
text and turns it into simple tokens such as FrontmatterStart
, FrontmatterEnd
, TagStart
, TagEnd
, etc.
Scanning does a basic scanning of the JS to pull out imports after the tokenizer has made it clear where JS begins and ends.
Printing takes all the output up till now and generates (prints) valid TypeScript that can be executed within Node.
When adding a new feature or debugging an issue, start at the tokenizer, then move onto the scanner, and finally end at the printer. By starting at the lowest level of complexity (tokenizer), it will be easier to reason about.
- Run all tests:
go test -v ./internal/...
- Run a specific folder of tests:
go test -v ./internal/printer
Adding tests for the tokenizer, scanner, and printer can be found in internal/token_test.go
, internal/js_scanner_test.go
, and internal/printer/printer_test.go
, respectively.