Skip to content

Offline, privacy-first grammar checker. Fast, open-source, Rust-powered

fix(harper-typst): reversed span causing crash (#3366)

Elijah Potterad976fde3042
diff --git a/harper-typst/src/lib.rs b/harper-typst/src/lib.rs
index 71c060fd4..48bf46efb 100644
--- a/harper-typst/src/lib.rs
+++ b/harper-typst/src/lib.rs
@@ -86,4 +86,15 @@ mod tests {
Typst.parse_str("#(.$#$$$. ");
Typst.parse_str("=#{m\"\".'m\"\"#p#");
}
+
+ #[test]
+ fn issue_2126_show_rule_preserves_token_order() {
+ let tokens = Typst.parse_str("#show \"a\": \"a\"");
+ let spans = tokens
+ .iter()
+ .map(|token| (token.span.start, token.span.end))
+ .collect_vec();
+
+ assert_eq!(spans, vec![(7, 8), (12, 13)]);
+ }
}
diff --git a/harper-typst/src/typst_translator.rs b/harper-typst/src/typst_translator.rs
index ee24aad2c..e14fc8a64 100644
--- a/harper-typst/src/typst_translator.rs
+++ b/harper-typst/src/typst_translator.rs
@@ -418,8 +418,8 @@ impl<'a> TypstTranslator<'a> {
parse_args(&mut set_rule.args().items())
],
Expr::ShowRule(show_rule) => merge![
- recurse!(show_rule.transform()),
- show_rule.selector().and_then(|expr| recurse!(expr))
+ show_rule.selector().and_then(|expr| recurse!(expr)),
+ recurse!(show_rule.transform())
],
Expr::Contextual(contextual) => recurse!(contextual.body()),
Expr::Conditional(conditional) => merge![