diff --git a/cli/src/tests/query_test.rs b/cli/src/tests/query_test.rs index 6e722aef..b6b76cd1 100644 --- a/cli/src/tests/query_test.rs +++ b/cli/src/tests/query_test.rs @@ -5520,3 +5520,33 @@ fn f() { ); assert_eq!(matches, flipped_matches); } + +#[test] +fn test_wildcard_parent_allows_fallible_child_patterns() { + let language = get_language("javascript"); + let mut parser = Parser::new(); + parser.set_language(&language).unwrap(); + + let source_code = r#" +function foo() { + "bar" +} + "#; + + let query = Query::new( + &language, + "(function_declaration + (_ + (expression_statement) + ) + ) @part", + ) + .unwrap(); + + assert_query_matches( + &language, + &query, + source_code, + &[(0, vec![("part", "function foo() {\n \"bar\"\n}")])], + ); +} diff --git a/lib/src/query.c b/lib/src/query.c index a594342f..12829a20 100644 --- a/lib/src/query.c +++ b/lib/src/query.c @@ -3004,7 +3004,7 @@ bool ts_query__step_is_fallible( return ( next_step->depth != PATTERN_DONE_MARKER && next_step->depth > step->depth && - !next_step->parent_pattern_guaranteed + (!next_step->parent_pattern_guaranteed || step->symbol == WILDCARD_SYMBOL) ); }