Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions crates/perry/src/commands/compile/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -847,10 +847,7 @@ pub(super) fn declaration_sidecar_for_resolved_import(
return canonical_existing_declaration(resolved_path.to_path_buf());
}

if !(import_source.starts_with("./")
|| import_source.starts_with("../")
|| import_source.starts_with('/'))
{
if !(is_relative_specifier(import_source) || import_source.starts_with('/')) {
let (package_name, subpath) = parse_package_specifier(import_source);
if let Some(package_dir) = package_dir_for_resolved_path(resolved_path, &package_name) {
if let Some(sidecar) = resolve_package_declaration_entry(
Expand Down Expand Up @@ -897,7 +894,7 @@ pub(super) fn resolve_relative_import_path(
import_source: &str,
importer_path: &Path,
) -> Option<PathBuf> {
if !import_source.starts_with("./") && !import_source.starts_with("../") {
if !is_relative_specifier(import_source) {
return None;
}
let parent = importer_path.parent()?;
Expand All @@ -906,6 +903,21 @@ pub(super) fn resolve_relative_import_path(
path.canonicalize().ok()
}

/// True for ECMAScript relative-import specifiers. Besides the obvious `./x`
/// and `../x`, the bare `"."` and `".."` are also relative — they resolve to
/// the current / parent **directory**'s `index` file. `@tanstack/table-core`'s
/// source uses `import { _getVisibleLeafColumns } from '..'` (the package
/// barrel); without matching `".."` here it fell through to bare-package
/// resolution, `import.resolved_path` never matched the index module, and every
/// name imported through it lowered to an unresolved raw extern symbol → link
/// failure (`__getVisibleLeafColumns`). Refs #5141.
pub(super) fn is_relative_specifier(import_source: &str) -> bool {
import_source.starts_with("./")
|| import_source.starts_with("../")
|| import_source == "."
|| import_source == ".."
}

/// Resolve an import specifier to a file path
pub(super) fn resolve_import(
import_source: &str,
Expand Down Expand Up @@ -938,11 +950,8 @@ pub(super) fn resolve_import(
None
};

// Handle relative imports (./ or ../)
if import_source.starts_with("./")
|| import_source.starts_with("../")
|| subpath_import_target.is_some()
{
// Handle relative imports (./ or ../, plus bare "." / ".." directory imports)
if is_relative_specifier(import_source) || subpath_import_target.is_some() {
if let Some(canonical) = subpath_import_target
.or_else(|| resolve_relative_import_path(import_source, importer_path))
{
Expand Down