Skip to content

Commit bee8bf5

Browse files
committed
Fix dotted reserved function lowering
1 parent 7af4945 commit bee8bf5

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

crates/rsscript/src/rust_lower/helpers.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,10 +1537,8 @@ pub(super) fn lower_source_span(span: &Span) -> String {
15371537
}
15381538

15391539
pub(super) fn rust_function_ident(name: &str) -> String {
1540-
name.split('.')
1541-
.map(rust_ident)
1542-
.collect::<Vec<_>>()
1543-
.join("_")
1540+
let joined = name.split('.').collect::<Vec<_>>().join("_");
1541+
rust_ident(&joined)
15441542
}
15451543

15461544
pub(super) fn rust_qualified_function_ident(namespace: &str, name: &str) -> String {
@@ -1735,3 +1733,15 @@ pub(super) fn cargo_crate_name(package_name: &str) -> String {
17351733
pub(super) fn toml_string(value: &str) -> String {
17361734
value.replace('\\', "\\\\").replace('"', "\\\"")
17371735
}
1736+
1737+
#[cfg(test)]
1738+
mod tests {
1739+
use super::{rust_function_ident, rust_ident};
1740+
1741+
#[test]
1742+
fn rust_function_ident_escapes_after_flattening_dotted_names() {
1743+
assert_eq!(rust_function_ident("MultiBuffer.ref"), "MultiBuffer_ref");
1744+
assert_eq!(rust_function_ident("gen"), "r#gen");
1745+
assert_eq!(rust_ident("ref"), "r#ref");
1746+
}
1747+
}

0 commit comments

Comments
 (0)