Set AST source on compile.

This commit is contained in:
Stephen Chung
2022-08-14 18:22:07 +08:00
parent 5f2262214d
commit b35a9762fb
2 changed files with 6 additions and 1 deletions

View File

@@ -106,7 +106,11 @@ impl Engine {
/// ```
#[inline]
pub fn compile_file_with_scope(&self, scope: &Scope, path: PathBuf) -> RhaiResultOf<AST> {
Self::read_file(path).and_then(|contents| Ok(self.compile_with_scope(scope, &contents)?))
Self::read_file(&path).and_then(|contents| {
let mut ast = self.compile_with_scope(scope, &contents)?;
ast.set_source(path.to_string_lossy());
Ok(ast)
})
}
/// Evaluate a script file, returning the result value or an error.
///