Repository navigation
fix(core): treat a # in an ES module specifier as a fragment - #859
Merged
Merged
Conversation
oxc_resolver follows enhanced-resolve: for a specifier with a `#` and no `?` it first tries the whole specifier as a path. Since #847 encodes the resolved path, `import './a#b.ts'` therefore loaded a file named `a#b.ts` where Node.js resolves `./a` with the fragment `#b.ts`; a file URL with a fragment had the same problem. Keep a URL reference's `?query` / `#fragment` back from the resolver: resolve its decoded pathname alone and append the suffix to the resolved URL, as Node.js does. A `require()` specifier, recognised by its `require` condition, stays a path with `#`, `?` and `%` as file-name characters, as Node.js' CommonJS resolution reads it. Closes #856 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1266bb90b0
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
`--conditions=require` adds `require` to every request's conditions, so an import under it took the CommonJS branch and loaded `a#b.ts` for `./a#b.ts` again. That branch was never needed: register.mjs hands every require() request, recognised by its missing importAttributes, to Node.js' own CommonJS resolution before createResolve is reached. Drop it. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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.
Closes #856
Problem
In an ES module import,
#starts a URL fragment: Node.js resolvesimport './a#b.ts'as./awith the fragment#b.ts. Since #847, oxc-node loaded a file nameda#b.tsinstead, whenever one existed. oxc_resolver follows enhanced-resolve: for a specifier with a#and no?,load_parsefirst tries the whole specifier as a path. #847 re-attached the raw?query#fragmentto the resolver's specifier, sofile:URLs with a fragment were affected the same way.Fix
A URL reference's query and fragment never reach the resolver now. A URL reference is a
file:URL, or a relative or absolute-path specifier in ESM. Its decoded pathname is resolved on its own, and the raw suffix is appended to the resolved URL, as Node.js does.resolver_requestno longer takes a suffix.require()is unaffected:register.mjshands everyrequire()request (noimportAttributes) to Node.js' own CommonJS resolution beforecreateResolveruns, so#and%stay file-name characters there. The request kind isn't inferred from therequirecondition, which--conditions=requireadds to imports too.Verification
Module URLs match plain Node exactly:
./url.mjs#onegives…/url.mjs#one,./url.mjs?q#twogives…/url.mjs?q#two, and an encoded./a%23b.mjsstill loadsa#b.mjs.Tests
The
resolver_requestunit test is updated for the new signature.percent-encoded-paths.spec.tsgains a block for Since #847, a relative import with#loads the file named with the#instead of treating#…as a fragment #856:file:URL with#skip the decoya#b.ts;%23still names the file;--conditions=requirestill reads#as a fragment;require()keeps#and%as file-name characters.The
#cases fail without the change.🤖 Generated with Claude Code