{"record":{"id":"46288d84dc4f6509","repo":"biomejs/biome","slug":"token-kind-kind-cannot-be-transformed-to-text","errorCode":null,"errorMessage":"token kind {kind:?} cannot be transformed to text","messagePattern":"token kind (.+?) cannot be transformed to text","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/biome_html_factory/src/make.rs","lineNumber":34,"sourceCode":"    )\n}\n\n/// Create a new single-quoted string literal token with no attached trivia\npub fn html_string_literal_single_quotes(text: &str) -> HtmlSyntaxToken {\n    HtmlSyntaxToken::new_detached(\n        HtmlSyntaxKind::HTML_STRING_LITERAL,\n        &format!(\"'{text}'\"),\n        [],\n        [],\n    )\n}\n\n/// Create a new token with the specified syntax kind and no attached trivia\npub fn token(kind: HtmlSyntaxKind) -> HtmlSyntaxToken {\n    if let Some(text) = kind.to_string() {\n        HtmlSyntaxToken::new_detached(kind, text, [], [])\n    } else {\n        panic!(\"token kind {kind:?} cannot be transformed to text\")\n    }\n}\n","sourceCodeStart":16,"sourceCodeEnd":37,"githubUrl":"https://github.com/biomejs/biome/blob/405dedb0ff65dd29927faf587f6542e3c29db248/crates/biome_html_factory/src/make.rs#L16-L37","documentation":"biome_html_factory::make::token(kind) builds a detached HTML token using the fixed source text that HtmlSyntaxKind::to_string() maps the kind to (make.rs:30-35). Only kinds with static text - punctuation, keywords, fixed tokens - have such a mapping; kinds whose text depends on the source (IDENT, HTML_STRING_LITERAL, error/bogus kinds) return None and hit this panic. It is a factory misuse guard: the token text must be provided explicitly for dynamic kinds.","triggerScenarios":"Calling make::token(HtmlSyntaxKind::IDENT), make::token(HtmlSyntaxKind::HTML_STRING_LITERAL), or passing any variable-content or error kind. Typically hit when porting code from another language factory (e.g. biome_js_factory::make::token) where the same kind names do carry static text, or when constructing nodes in tests via make:: token.","commonSituations":"Writing or updating HTML parser/formatter code or snapshot tests in crates/biome_html_parser, biome_html_formatter, biome_html_factory after a grammar regeneration added new kinds; copying factory idioms from the JS factory where token(JSX_TEXT-like kinds) worked.","solutions":["Use the dedicated constructors that take the text: make::ident(text) for IDENT, make::html_string_literal(text) / make::html_string_literal_single_quotes(text) for HTML_STRING_LITERAL (make.rs:5-27)","Build the token directly with HtmlSyntaxToken::new_detached(kind, text, [], []) for any other dynamic kind","Check kind.to_string().is_some() before calling make::token when the kind comes from user input or a match over many kinds","If you believe the kind should have static text (keyword/punct), verify it is declared with text in the generated HtmlSyntaxKind list; re-run just gen-grammar html if the grammar was changed"],"exampleFix":"// before\nlet tok = biome_html_factory::make::token(HtmlSyntaxKind::HTML_STRING_LITERAL); // panics\n\n// after\nlet tok = biome_html_factory::make::html_string_literal(\"color: red\");","handlingStrategy":"validation","validationCode":"// Rust - only call make::token for kinds with fixed source text\nif kind.to_string().is_some() {\n    let tok = biome_html_factory::make::token(kind);\n} else {\n    // dynamic kind: supply the text explicitly\n    let tok = HtmlSyntaxToken::new_detached(kind, \"actual text\", [], []);\n}","typeGuard":"fn has_static_text(kind: HtmlSyntaxKind) -> bool {\n    kind.to_string().is_some()\n}","tryCatchPattern":null,"preventionTips":["Prefer the specific constructors (ident, html_string_literal, html_string_literal_single_quotes) over the generic token()","In tests, build tokens from parsed source (parse(text).syntax().first_token()) rather than synthesizing kinds","Treat panic! as a factory contract: dynamic-content kinds never go through make::token"],"tags":["rust","html","ast","token-factory","panic"],"backgroundTag":"ast-token-factory-invalid-kind","analyzedSha":"405dedb0ff65dd29927faf587f6542e3c29db248","analyzedAt":"2026-08-20T00:25:09.682Z","contentChangedAt":"2026-08-20T00:25:09.682Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}