Skip to content

Commit 60b3ff7

Browse files
authored
Merge pull request #146 from fstxz/annotation-name
Safe mode: fix panic when annotation doesn't have a name
2 parents 52fca19 + 0011384 commit 60b3ff7

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,
@@ -146,6 +145,7 @@ impl Formatter {
146145
#[inline(always)]
147146
fn finish(mut self) -> Result<String, Box<dyn std::error::Error>> {
148147
if self.config.safe {
148+
self.input_tree.postprocess();
149149
self.tree = self.parser.parse(&self.content, None).unwrap();
150150

151151
let output_tree = GdTree::from_ts_tree(&self.tree, self.content.as_bytes());
@@ -599,8 +599,9 @@ impl GdTree {
599599
if child.grammar_name != "annotation" {
600600
return None;
601601
}
602-
let annotation_name =
603-
self.nodes[child.children[0]].text.as_deref().unwrap();
602+
let Some(annotation_name) = &self.nodes[child.children[0]].text else {
603+
return None;
604+
};
604605
if annotation_name != "onready" && annotation_name != "export" {
605606
return None;
606607
}

0 commit comments

Comments
 (0)