Skip to content

fix(exports): propagate the last error in array target resolution#1267

Merged
Boshen merged 1 commit into
mainfrom
refactor/exports-array-dead-branch
Jul 2, 2026
Merged

fix(exports): propagate the last error in array target resolution#1267
Boshen merged 1 commit into
mainfrom
refactor/exports-array-dead-branch

Conversation

@Boshen

@Boshen Boshen commented Jul 2, 2026

Copy link
Copy Markdown
Member

The "return the last array entry's error" branch in package_target_resolve was dead code: i comes from enumerate(), so i == targets.len() could never be true. Errors from array entries were always swallowed like undefined, so an invalid target in the last fallback entry surfaced as a generic PackagePathNotExported instead of the specific error — despite the comment right below claiming "Return or throw the last fallback resolution null return or error".

This fixes the off-by-one (i + 1 == targets.len()) so the last entry's error now propagates, matching the documented intent and Node's lastException behavior for arrays.

One deliberate exemption: ResolveError::NotFound still falls through. It only arises from re-resolving a bare imports target (e.g. \"#a\": [{\"import\": [\"#b/import.js\"]}]) through the module system, and enhanced-resolve treats an unresolvable candidate there as a soft failure, not a hard error — the ported "Direct and conditional mapping #4" test pins that behavior. Node would actually throw immediately on any non-ERR_INVALID_PACKAGE_TARGET error inside the array loop, which is stricter than enhanced-resolve; the exemption keeps us compatible with the latter.

Adds two imports-field tests: an invalid target in the last array entry now errors (previously Ok(None)), and an invalid target in a non-last entry still falls through to the next entry.

Split out of #1263.

@codecov

codecov Bot commented Jul 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.88%. Comparing base (4837a2e) to head (a867cbe).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1267      +/-   ##
==========================================
+ Coverage   93.85%   93.88%   +0.02%     
==========================================
  Files          21       21              
  Lines        4313     4315       +2     
==========================================
+ Hits         4048     4051       +3     
+ Misses        265      264       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@codspeed-hq

codspeed-hq Bot commented Jul 2, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

⚡ 1 improved benchmark
❌ 2 regressed benchmarks
✅ 18 untouched benchmarks
⏩ 5 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
pm/bun-flat 902.6 µs 941.8 µs -4.16%
pm/bun-isolated 1 ms 1.1 ms -3.24%
pm/yarn-flat 929.6 µs 893.8 µs +4%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing refactor/exports-array-dead-branch (a867cbe) with main (4837a2e)

Open in CodSpeed

Footnotes

  1. 5 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.

@Boshen
Boshen force-pushed the refactor/exports-array-dead-branch branch from 91c9aa0 to 86dc2f5 Compare July 2, 2026 07:16
The "return the last array entry's error" branch was dead: `i` comes
from `enumerate()`, so `i == targets.len()` could never be true, and
errors from array entries were always swallowed - an invalid target in
the last fallback entry surfaced as a generic PackagePathNotExported
instead of the specific error.

Fix the off-by-one (`i + 1 == targets.len()`) so the last entry's
error propagates, implementing the documented "Return or throw the
last fallback resolution null return or error" step. `NotFound` is
exempt: it comes from re-resolving a bare `imports` target through the
module system, which enhanced-resolve lets fall through to a soft
failure rather than a hard error.
@Boshen
Boshen force-pushed the refactor/exports-array-dead-branch branch from 86dc2f5 to a867cbe Compare July 2, 2026 07:26
@Boshen Boshen changed the title refactor(exports): remove dead error branch in array target resolution fix(exports): propagate the last error in array target resolution Jul 2, 2026
@Boshen
Boshen merged commit 0fbd4a3 into main Jul 2, 2026
17 checks passed
@Boshen
Boshen deleted the refactor/exports-array-dead-branch branch July 2, 2026 07:31
@oxc-guard oxc-guard Bot mentioned this pull request Jul 2, 2026
Boshen pushed a commit that referenced this pull request Jul 2, 2026
## 🤖 New release

* `oxc_resolver`: 11.22.0 -> 11.23.0
* `oxc_resolver_napi`: 11.22.0 -> 11.23.0

<details><summary><i><b>Changelog</b></i></summary><p>

## `oxc_resolver`

<blockquote>

##
[11.23.0](v11.22.0...v11.23.0)
- 2026-07-02

### <!-- 0 -->🚀 Features

- *(tsconfig)* expose outDir, declarationDir, resolveJsonModule, checkJs
([#1257](#1257)) (by
@Boshen)

### <!-- 1 -->🐛 Bug Fixes

- *(exports)* propagate the last error in array target resolution
([#1267](#1267)) (by
@Boshen)

### <!-- 2 -->🚜 Refactor

- deduplicate cross-file helpers, drop stale lint allows
([#1269](#1269)) (by
@Boshen)
- *(dts)* deduplicate package entry selection and remove dead code
([#1266](#1266)) (by
@Boshen)
- *(tsconfig)* skip TsConfig deep clone for non-root configs
([#1265](#1265)) (by
@Boshen)
- *(alias)* compile fallback aliases once at construction
([#1264](#1264)) (by
@Boshen)

### <!-- 4 -->⚡ Performance

- *(alias)* scan a packed first-byte array instead of striding over
alias entries
([#1260](#1260)) (by
@Boshen)

### Contributors

* @Boshen
</blockquote>



</p></details>

---
This PR was generated with
[release-plz](https://github.com/release-plz/release-plz/).

Co-authored-by: oxc-guard[bot] <276638029+oxc-guard[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant