Skip to content

fix(module): skip the file lookup for type root names that end with a separator - #1008

Merged
camc314 merged 3 commits into
oxc-project:mainfrom
magurotuna:fix/type-root-trailing-separator-candidate
Nov 19, 2026
Merged

camc314 merged 3 commits into
oxc-project:mainfrom
magurotuna:fix/type-root-trailing-separator-candidate

Conversation

@magurotuna

@magurotuna magurotuna commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

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/" /> with typeRoots: ["./types"] picked pkg/.d.ts instead of pkg/index.d.ts. An import such as "lib/" that falls back to typeRoots had the same bug.

get_candidate_from_type_root returns the port of Go's resolutionCandidate that #1009 added. Its directory_only flag 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 in resolveFromTypeRoot.

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 --traceResolution output had one extra line, and it now matches tsgo.

Tests: the regression cases type-root-trailing-separator-name and type-root-trailing-separator-module, with expected output from tsgo at the pinned commit. Both fail without the fix.

AI assistance: written with Claude Code.

…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.
@codspeed

codspeed Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

1 warning

⚠️ 4 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

âś… 8 untouched benchmarks
⏩ 8 skipped benchmarks1


Comparing magurotuna:fix/type-root-trailing-separator-candidate (ee37c7c) with main (1cf4808)

Open in CodSpeed

Footnotes

  1. 8 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@magurotuna
magurotuna marked this pull request as ready for review November 17, 2026 08:52
@camc314
camc314 added this pull request to the merge queue Nov 18, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Nov 18, 2026
magurotuna and others added 2 commits November 18, 2026 23:24
…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
camc314 enabled auto-merge November 19, 2026 11:50
@camc314
camc314 added this pull request to the merge queue Nov 19, 2026
Merged via the queue into oxc-project:main with commit 2dc8ddb Nov 19, 2026
70 checks passed
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants