Skip to content

Commit

Permalink
fix(grit): fix node walking (#3988)
Browse files Browse the repository at this point in the history
  • Loading branch information
arendjr authored Sep 19, 2024
1 parent 3815905 commit 41ec03e
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
3 changes: 3 additions & 0 deletions crates/biome_grit_patterns/src/grit_target_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,9 @@ impl<'a> AstCursor for GritTargetNodeCursor<'a> {
}

fn goto_next_sibling(&mut self) -> bool {
if self.node == self.root {
return false;
}
match self.node.next_sibling() {
Some(sibling) => {
self.node = sibling;
Expand Down
13 changes: 10 additions & 3 deletions crates/biome_grit_patterns/tests/quick_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ use biome_js_syntax::JsFileSource;
#[ignore]
#[test]
fn test_query() {
let parse_grit_result = parse_grit("`foo.$x && foo.$x()`");
let parse_grit_result = parse_grit(
"`console.log($args)` where {
$args <: contains `world`
}
",
);
if !parse_grit_result.diagnostics().is_empty() {
panic!("Cannot parse query:\n{:?}", parse_grit_result.diagnostics());
}
Expand All @@ -23,7 +28,9 @@ fn test_query() {
println!("Diagnostics from compiling query:\n{:?}", query.diagnostics);
}

let body = r#"foo.bar && foo.bar();
let body = r#"console.log("hello, world");
console.log("hello", world);
console.log(`hello ${world}`);
"#;

let file = GritTargetFile {
Expand All @@ -32,5 +39,5 @@ fn test_query() {
};
let results = query.execute(file).expect("could not execute query");

println!("Results: {results:?}");
println!("Results: {results:#?}");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
`console.log($args)` where {
$args <: contains `world`
}
13 changes: 13 additions & 0 deletions crates/biome_grit_patterns/tests/specs/ts/containsSnippet.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
source: crates/biome_grit_patterns/tests/spec_tests.rs
expression: containsSnippet
---
SnapshotResult {
messages: [],
matched_ranges: [
"2:1-2:28",
"3:1-3:30",
],
rewritten_files: [],
created_files: [],
}
3 changes: 3 additions & 0 deletions crates/biome_grit_patterns/tests/specs/ts/containsSnippet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
console.log("hello, world");
console.log("hello", world);
console.log(`hello ${world}`);

0 comments on commit 41ec03e

Please sign in to comment.