diff --git a/src/content/docs/reference/gritql.mdx b/src/content/docs/reference/gritql.mdx index 151a2f043..d641623fd 100644 --- a/src/content/docs/reference/gritql.mdx +++ b/src/content/docs/reference/gritql.mdx @@ -122,10 +122,21 @@ JsIfStatement() as $stmt where { } ``` -You can discover node names for your code by exploring the syntax tree in the [Biome Playground](https://biomejs.dev/playground/). A complete list of all available nodes is also available in the `.ungram` files in the [`xtask/codegen`](https://github.com/biomejs/biome/tree/main/xtask/codegen) directory of the Biome repository. +You can also match specific parts of a node by name. For example, this pattern captures the first branch of a ternary expression using Biome's node field names: + +```grit +JsConditionalExpression(consequent = $cons) where { + register_diagnostic( + span=$cons, + message="Found the consequent branch of a conditional expression" + ) +} +``` + +You can discover node names and field names for your code by exploring the syntax tree in the [Biome Playground](https://biomejs.dev/playground/). A complete list of all available nodes and their fields is also available in the `.ungram` files in the [`xtask/codegen`](https://github.com/biomejs/biome/tree/main/xtask/codegen) directory of the Biome repository. :::caution -Biome's grammar can change between versions, especially for new languages. This may cause node names to change, which could break your patterns. Be prepared to update your queries when upgrading Biome. +Biome's grammar can change between versions, especially for new languages. This may cause node names to change, which could break your patterns. Be prepared to update your queries when upgrading Biome when using node/field names in your patterns. ::: ## JSON Patterns