|
| 1 | +--- |
| 2 | +author: |
| 3 | + - name: Herrington Darkholme |
| 4 | +search: false |
| 5 | +date: 2025-08-03 |
| 6 | +head: |
| 7 | + - - meta |
| 8 | + - property: og:type |
| 9 | + content: website |
| 10 | + - - meta |
| 11 | + - property: og:title |
| 12 | + content: ast-grep new release 0.39 |
| 13 | + - - meta |
| 14 | + - property: og:url |
| 15 | + content: https://ast-grep.github.io/blog/new-ver-39.html |
| 16 | + - - meta |
| 17 | + - property: og:description |
| 18 | + content: 'ast-grep 0.39 includes new languages support, better file config and Esquery style kind.' |
| 19 | +--- |
| 20 | + |
| 21 | +# ast-grep 0.39 is Here |
| 22 | + |
| 23 | +ast-grep 0.39 is out! This release includes new languages support, better file config and esquery style. |
| 24 | + |
| 25 | +## Esquery Style Kind |
| 26 | + |
| 27 | +ast-grep now supports [ESQuery style](https://github.com/estools/esquery) kind in the `kind` field of the rule configuration. This allows you to write more concise rule in ast-grep. Under the hood, it is equivalent to [relational rules](/guide/rule-config/relational-rule.html) like `has`. |
| 28 | + |
| 29 | +ESQuery is a library for querying the AST using a [CSS style selector](https://developer.mozilla.org/en-US/docs/Learn_web_development/Core/Styling_basics/Basic_selectors) system. |
| 30 | + |
| 31 | +For example, you can write a rule to match all `identifier` nodes that are direct children of `call_expression` nodes like this: |
| 32 | + |
| 33 | +```yaml |
| 34 | +kind: call_expression > identifier |
| 35 | +``` |
| 36 | +
|
| 37 | +This is equivalent to the following relational rule: |
| 38 | +
|
| 39 | +```yaml |
| 40 | +kind: identifier |
| 41 | +inside: |
| 42 | + kind: call_expression |
| 43 | +``` |
| 44 | +
|
| 45 | +Currently, ast-grep's ESQuery style `kind` only supports the following selectors: |
| 46 | + |
| 47 | +* node kind: `identifier` |
| 48 | +* `>`: direct child selectors |
| 49 | +* ` `: descendant selector |
| 50 | +* `+`: next sibling selector |
| 51 | +* `~`: following sibling selector |
| 52 | + |
| 53 | +The corresponding relational rules are: |
| 54 | + |
| 55 | +:::code-group |
| 56 | + |
| 57 | +```yaml [direct child] |
| 58 | +kind: call_expression > identifier |
| 59 | +# is equivalent to |
| 60 | +kind: identifier |
| 61 | +inside: |
| 62 | + kind: call_expression |
| 63 | +``` |
| 64 | + |
| 65 | +```yaml [direct child] |
| 66 | +kind: call_expression identifier |
| 67 | +# is equivalent to |
| 68 | +kind: identifier |
| 69 | +inside: |
| 70 | + kind: call_expression |
| 71 | + stopBy: end # note the stopBy |
| 72 | +``` |
| 73 | + |
| 74 | +```yaml [next sibling] |
| 75 | +kind: decorator + method_definition |
| 76 | +# is equivalent to |
| 77 | +kind: method_definition |
| 78 | +follows: |
| 79 | + kind: decorator |
| 80 | +``` |
| 81 | + |
| 82 | +```yaml [next sibling] |
| 83 | +kind: decorator ~ method_definition |
| 84 | +# is equivalent to |
| 85 | +kind: method_definition |
| 86 | +follows: |
| 87 | + kind: decorator |
| 88 | + stopBy: end # note the stopBy |
| 89 | +``` |
| 90 | + |
| 91 | +::: |
| 92 | + |
| 93 | +If you want to use more ESQuery selectors, please file your use cases in [this ast-grep issue](https://github.com/ast-grep/ast-grep/issues/2127). |
| 94 | + |
| 95 | + |
| 96 | + |
| 97 | +## New Languages Support |
| 98 | + |
| 99 | +ast-grep 0.39 adds support for the following languages: |
| 100 | + |
| 101 | +* [Nix](https://nix.dev/tutorials/nix-language.html) a domain-specific, purely functional, lazily evaluated, dynamically typed programming languages for Nixpkgs and NixOS. |
| 102 | +* [Solidity](https://soliditylang.org/) A statically-typed curly-braces programming language designed for developing smart contracts that run on Ethereum. ($ETH bull run incoming? 🐂) |
| 103 | + |
| 104 | +## `file` in rule config is relative to the project config file |
| 105 | + |
| 106 | +Previously, the files section appears to be treated as relative to the current working directory from which ast-grep was invoked rather than the dir containing the [sgconfig.yml](/reference/sgconfig.html) file. |
| 107 | + |
| 108 | +This has been changed in 0.39, so now the `files` section is relative to the project config file. |
| 109 | + |
| 110 | + |
| 111 | +## Next Steps |
| 112 | + |
| 113 | +Thanks for reading! If you are interested in the new features, please try them out and let us know your feedback. |
0 commit comments