Skip to content

Commit e1ab18a

Browse files
feat: better metavar detection
BREAKING CHANGE: metavar in pattern is more intuitive now. Previously we only treat leaf node and error node as metavar. This commit will detect metavar as long as the text in the node matches metavar regex pattern. This results in a more intuitive pattern syntax. However, this introduces 5% perf overhead and is a breaking change. Breaking change is ok since the matching is better now.
1 parent 489aff3 commit e1ab18a

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

crates/core/src/match_tree.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ fn match_leaf_meta_var<'tree, D: Doc>(
4242
fn is_node_eligible_for_meta_var(goal: &Node<impl Doc>, is_leaf: bool) -> bool {
4343
// allow Error as meta_var
4444
// see https://github.com/ast-grep/ast-grep/issues/526
45-
is_leaf || goal.is_error()
45+
extract_var_from_node(goal).is_some()
46+
// is_leaf || goal.is_error()
4647
}
4748

4849
fn try_get_ellipsis_mode(node: &Node<impl Doc>) -> Result<Option<String>, ()> {

0 commit comments

Comments
 (0)