Repository navigation
fix(module): skip the file lookup for type root names that end with a separator - #1008
Merged
camc314 merged 3 commits intoNov 19, 2026
Conversation
…iling separator Port the `directoryOnly` part of Go `resolutionCandidate` (`resolver.go:48`) for the type root lookups. `resolutionCandidateFromDirectoryPath` (`resolver.go:77`) marks a name that ends with a directory separator as directory-only, and both type root callers skip `loadModuleFromFile` for it: the primary lookup of a type reference directive (`resolver.go:623`) and `resolveFromTypeRoot` (`resolver.go:691`). tsrs computed the flag but did not check it, so a type reference `../pkg/` resolved to `pkg/.d.ts` where tsgo resolves `pkg/index.d.ts`. The same applied to a module name such as `lib/` that falls back to a type root. The upstream case `typeReferenceDirectiveTrailingSlashName` already passed, because it has no `.d.ts` file in the directory and `tsrs-test` does not compare `.trace.json`. Its resolution trace from `tsrs -p` had an extra `File '.../typings/package/.d.ts' does not exist.` line; it now matches tsgo. Go's `directoryPath` field (the dynamic directory form) is not ported here.
Contributor
Merging this PR will not alter performance1 warning
Comparing Footnotes
|
magurotuna
marked this pull request as ready for review
November 17, 2026 08:52
camc314
approved these changes
Nov 18, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to a conflict with the base branch
Nov 18, 2026
…g-separator-candidate `crates/tsrs_module/src/resolver.rs` conflicted with oxc-project#1009, which added `ResolutionCandidate` (with `path`, `directory_path`, and `directory_only`) and `resolution_candidate_from_directory_path`. Keep the oxc-project#1009 type and constructor, and drop the smaller `ResolutionCandidate` of this branch. Keep this branch's change: both type root callers skip the file lookup for a directory-only candidate (Go `HasTrailingDirectorySeparator`, `resolver.go:623` and `resolver.go:691`). AI assistance: written with Claude Code.
camc314
enabled auto-merge
November 19, 2026 11:50
Naz-Ovh
pushed a commit
to 0x-fork/tsrs-typescript.rs
that referenced
this pull request
Nov 20, 2026
…e roots (oxc-project#1049) Go's `resolutionCandidate` has a `directoryOnly` flag for a candidate that was written with a trailing `/`, and its `path` has no trailing separator. oxc-project#1008 ported the checks at the two type root call sites. Five other functions still worked on the string with the trailing `/`: - `try_load_input_file_for_path` and `load_file_name_from_package_json_field` now return `continue_searching()` for a directory-only candidate, as Go does. Before, an `imports` target `./dist.js/` resolved to `dist.d.js/.ts` (TS6263 instead of TS2307), and `./dist/` reported TS2210 without a config file. - `load_module_from_file` and `load_module_from_file_no_implicit_extensions` add extensions to the path without the trailing `/` (Go's `candidate.path`), and pass the directory of that path to `try_adding_extensions` (Go's `candidate.Directory()`). Before, a `typesVersions` substitution `ts/*/` probed `ts/sub/.d.ts` and missed `ts/sub.d.ts`, so tsrs read `ts/sub/index.d.ts`. - `load_module_from_specific_node_modules_directory` builds its candidate with `resolution_candidate_from_directory_path`, as Go does, instead of removing one trailing separator. So `x//` resolves to `node_modules/x.d.ts`, and the trace prints the candidate with its `/`. The new `resolution_candidate_from_normalized` (Go `resolutionCandidateFromNormalized`) reads the flag and the path back from a candidate string. Tests: the regression cases `types-versions-directory-substitution`, `imports-directory-only-target`, and `node-modules-double-trailing-slash`. Expected output is from tsgo at the pinned commit. All three fail without the fix. Two of them have a `node_modules` directory, which `.gitignore` ignores, so the files are added with `git add -f`. AI assistance: written with Claude Code.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A type reference name that ends with
/means a directory. tsgo then skips the file lookup in the type root and looks only inside the directory (package.json,index.d.ts). tsrs tried the file first, so/// <reference types="../pkg/" />withtypeRoots: ["./types"]pickedpkg/.d.tsinstead ofpkg/index.d.ts. An import such as"lib/"that falls back totypeRootshad the same bug.get_candidate_from_type_rootreturns the port of Go'sresolutionCandidatethat #1009 added. Itsdirectory_onlyflag is set for such a name, but both callers still tried the file lookup first. They now skip the file lookup for a directory-only candidate, as Go does in the primary lookup and inresolveFromTypeRoot.The upstream case
typeReferenceDirectiveTrailingSlashNamealready passed, because it has no.d.tsfile in the directory andtsrs-testdoes not compare.trace.json. Its--traceResolutionoutput had one extra line, and it now matches tsgo.Tests: the regression cases
type-root-trailing-separator-nameandtype-root-trailing-separator-module, with expected output from tsgo at the pinned commit. Both fail without the fix.AI assistance: written with Claude Code.