next.js
003c9717 - next-code-frame: basic Go syntax highlighting (#102859)

Commit
1 day ago
next-code-frame: basic Go syntax highlighting (#102859) Adds basic Go syntax highlighting to `next-code-frame`, so `proxy.go` errors in the dev overlay stop being highlighted as JavaScript. **Why** `next-code-frame` only knows `JavaScript` and `Css`, and Turbopack issue code frames always use the JavaScript default. With Go proxy files now rendering code frames (#102837), Go source gets JS keywords (`function`, `let`, …) highlighted, Go keywords (`func`, `nil`, `chan`, …) missed, backtick raw strings parsed as JS template literals (`${` inside them is treated as interpolation), and `/` after punctuation can be read as a regex literal. **Approach** - New `Language::Go` variant with a `GO_KEYWORDS` phf set: the 25 Go keywords plus the predeclared `true`, `false`, `nil`, `iota`. - For Go, a backtick starts a raw string that runs to the next backtick (no escapes or interpolation), and `/` never starts a regex literal. Everything else (strings, runes, comments, numbers, capitalized identifiers) reuses the existing tokenizer. - `Language::from_path` maps `.go` → Go and `.css`/`.scss`/`.sass`/`.less` → Css, else JavaScript. `render_source_code_frame` in `next-napi-bindings` uses it, so Turbopack issue frames pick the language from the source file. - `codeFrameColumns` accepts `language: "go"`; the WASM binding gets `"go"` through the existing serde `camelCase` rename. **Validation** - `cargo test -p next-code-frame --lib` (run in a standalone copy of the crate): 57 passed, including new tests for Go keywords, JS keywords not matching in Go, raw strings with `${` spanning lines, no regex literals in Go (the same input does produce a regex span in JS), and `from_path`. - `cargo clippy --all-targets -- -D warnings` is clean for the crate, and `rustfmt` uses the repo config. - `next-napi-bindings` was not compiled locally. The change there is a one-line `language:` field plus the `parse_language` arm, so CI should confirm it. **Relevant context** The CSS mapping in `from_path` changes Turbopack issue frames for stylesheets from JS keyword highlighting to no keyword highlighting. That matches what `parseScss.ts` already passes for webpack. Co-authored-by: vercel-v[bot] <353008837+vercel-v[bot]@users.noreply.github.com> Co-authored-by: vercel-v[bot] <353008837+vercel-v[bot]@users.noreply.github.com>
Author
Parents
Loading