Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(grit): fix node walking #3988

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}`);