From 572f290ec09da3f50f5ba6c91f34d5b17f89d7a7 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Tue, 7 May 2019 11:17:34 -0700 Subject: [PATCH] Fix highlighting in the presence of node fields --- cli/src/tests/highlight_test.rs | 1 + lib/binding_rust/lib.rs | 13 +++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/cli/src/tests/highlight_test.rs b/cli/src/tests/highlight_test.rs index c4e86c6f..8cc7f7e6 100644 --- a/cli/src/tests/highlight_test.rs +++ b/cli/src/tests/highlight_test.rs @@ -111,6 +111,7 @@ fn test_highlighting_multiline_scopes_to_html() { " two()", " } three", "`", + "", ] .join("\n"); diff --git a/lib/binding_rust/lib.rs b/lib/binding_rust/lib.rs index 27c62859..b553a28d 100644 --- a/lib/binding_rust/lib.rs +++ b/lib/binding_rust/lib.rs @@ -371,7 +371,10 @@ impl Parser { pub unsafe fn set_cancellation_flag(&self, flag: Option<&AtomicUsize>) { if let Some(flag) = flag { - ffi::ts_parser_set_cancellation_flag(self.0, flag as *const AtomicUsize as *const usize); + ffi::ts_parser_set_cancellation_flag( + self.0, + flag as *const AtomicUsize as *const usize, + ); } else { ffi::ts_parser_set_cancellation_flag(self.0, ptr::null()); } @@ -772,11 +775,9 @@ impl<'a, P> TreePropertyCursor<'a, P> { node_field_id: Option, node_child_index: usize, ) -> usize { - let transitions = if let Some(field_id) = node_field_id { - state.field_transitions.get(&field_id) - } else { - state.kind_transitions.get(&node_kind_id) - }; + let transitions = node_field_id + .and_then(|field_id| state.field_transitions.get(&field_id)) + .or_else(|| state.kind_transitions.get(&node_kind_id)); if let Some(transitions) = transitions { for transition in transitions.iter() {