From df9e31e26d0f170910cafa17e9fb7ae3e219317a Mon Sep 17 00:00:00 2001 From: Klesti Selimaj Date: Tue, 14 Jul 2026 07:59:36 +0200 Subject: [PATCH] fix Analyzer file path #118 --- crates/analyzer/src/transpiler.rs | 32 ++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/crates/analyzer/src/transpiler.rs b/crates/analyzer/src/transpiler.rs index 1f43af0..d771ccc 100644 --- a/crates/analyzer/src/transpiler.rs +++ b/crates/analyzer/src/transpiler.rs @@ -2,7 +2,7 @@ use std::path::{Path, PathBuf}; use mist_codegen::RustCodegen; use mist_parser::rev_mapper::Mapping; -use mist_parser::{MistFmtConfig, parse}; +use mist_parser::{MistFmtConfig, parse, parse_module}; pub struct TranspiledFile { pub mist_path: PathBuf, @@ -30,6 +30,21 @@ pub fn transpile_mist<'a>( rust_path.set_file_name("mod.rs"); } + // Prioritize the module declaration from the source over the file stem. + // Every transpile re-parses so we always pick up the current declaration. + if let Ok(Some((_, ref name))) = parse_module(source) { + if rust_path.file_name().map(|v| v.to_str()).unwrap_or_default() != Some("mod.rs") { + if let Some(ext) = rust_path.extension().map(|e| e.to_owned()) { + let mut new_name = std::ffi::OsString::from(&name.0); + new_name.push("."); + new_name.push(ext); + rust_path.set_file_name(new_name); + } else { + rust_path.set_file_name(&name.0); + } + } + } + let parsed = parse(source).map_err(TranspileError::Parse)?; for item in &parsed.items { @@ -66,6 +81,21 @@ pub fn transpile_mist_no_sem( rust_path.set_file_name("mod.rs"); } + // Prioritize the module declaration from the source over the file stem. + // Every transpile re-parses so we always pick up the current declaration. + if let Ok(Some((_, ref name))) = parse_module(source) { + if rust_path.file_name().map(|v| v.to_str()).unwrap_or_default() != Some("mod.rs") { + if let Some(ext) = rust_path.extension().map(|e| e.to_owned()) { + let mut new_name = std::ffi::OsString::from(&name.0); + new_name.push("."); + new_name.push(ext); + rust_path.set_file_name(new_name); + } else { + rust_path.set_file_name(&name.0); + } + } + } + let parsed = parse(source).map_err(|e| format!("parse error: {e:?}"))?; let mut codegen = RustCodegen::new(mist_path.to_path_buf());