diff options
| author | Laurenz <laurmaedje@gmail.com> | 2025-02-06 22:10:43 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2025-02-06 22:16:07 +0100 |
| commit | 20dd19c64ef03619c49c1a2dfb011988c82d9e2a (patch) | |
| tree | 8e299db78b046a82173b1106606e9367ebc14eb9 | |
| parent | f64d029fe6ff486f8cb4f3be43f9ce04e43c1386 (diff) | |
Fix unnecessary import rename warning (#5828)
| -rw-r--r-- | crates/typst-eval/src/import.rs | 6 | ||||
| -rw-r--r-- | tests/suite/scripting/import.typ | 8 |
2 files changed, 7 insertions, 7 deletions
diff --git a/crates/typst-eval/src/import.rs b/crates/typst-eval/src/import.rs index 27b06af4..1b164148 100644 --- a/crates/typst-eval/src/import.rs +++ b/crates/typst-eval/src/import.rs @@ -44,11 +44,10 @@ impl Eval for ast::ModuleImport<'_> { } // If there is a rename, import the source itself under that name. - let bare_name = self.bare_name(); let new_name = self.new_name(); if let Some(new_name) = new_name { - if let Ok(source_name) = &bare_name { - if source_name == new_name.as_str() { + if let ast::Expr::Ident(ident) = self.source() { + if ident.as_str() == new_name.as_str() { // Warn on `import x as x` vm.engine.sink.warn(warning!( new_name.span(), @@ -57,6 +56,7 @@ impl Eval for ast::ModuleImport<'_> { } } + // Define renamed module on the scope. vm.define(new_name, source.clone()); } diff --git a/tests/suite/scripting/import.typ b/tests/suite/scripting/import.typ index 03e2efc6..49b66ee5 100644 --- a/tests/suite/scripting/import.typ +++ b/tests/suite/scripting/import.typ @@ -255,6 +255,10 @@ // Warning: 17-21 unnecessary import rename to same name #import enum as enum +--- import-rename-necessary --- +#import "module.typ" as module: a +#test(module.a, a) + --- import-rename-unnecessary-mixed --- // Warning: 17-21 unnecessary import rename to same name #import enum as enum: item @@ -263,10 +267,6 @@ // Warning: 31-35 unnecessary import rename to same name #import enum as enum: item as item ---- import-item-rename-unnecessary-string --- -// Warning: 25-31 unnecessary import rename to same name -#import "module.typ" as module - --- import-item-rename-unnecessary-but-ok --- #import "modul" + "e.typ" as module #test(module.b, 1) |
