Skip to content

Commit 0011384

Browse files
committed
Safe mode: fix panic when annotation doesn't have a name
1 parent 303c075 commit 0011384

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

src/formatter.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ impl Formatter {
5353
.unwrap();
5454
let tree = parser.parse(&content, None).unwrap();
5555
let mut input_tree = GdTree::from_ts_tree(&tree, content.as_bytes());
56-
input_tree.postprocess();
5756

5857
Self {
5958
content,
@@ -145,6 +144,7 @@ impl Formatter {
145144
#[inline(always)]
146145
fn finish(mut self) -> Result<String, Box<dyn std::error::Error>> {
147146
if self.config.safe {
147+
self.input_tree.postprocess();
148148
self.tree = self.parser.parse(&self.content, None).unwrap();
149149

150150
let output_tree = GdTree::from_ts_tree(&self.tree, self.content.as_bytes());
@@ -587,8 +587,9 @@ impl GdTree {
587587
if child.grammar_name != "annotation" {
588588
return None;
589589
}
590-
let annotation_name =
591-
self.nodes[child.children[0]].text.as_deref().unwrap();
590+
let Some(annotation_name) = &self.nodes[child.children[0]].text else {
591+
return None;
592+
};
592593
if annotation_name != "onready" && annotation_name != "export" {
593594
return None;
594595
}

0 commit comments

Comments
 (0)