Repository navigation
fix: resolve named exports through cyclic barrels - #10
Conversation
Stop revisiting active export states when tracing a barrel cycle, so a later branch can still resolve the named export. Add a regression for two barrels that re-export each other before the leaf export. Validated with 182 tests, build, lint, formatting and installed-check.
webpro
left a comment
There was a problem hiding this comment.
Thanks, Éverton! This fixes a real crash. On main, two barrels that star re-export each other send traceExport into unbounded recursion, and the process dies with a heap out-of-memory error when the cycle is reached before the export is found. With this change every cyclic layout I tried resolves to the leaf file, including a self cycle, a three-file cycle, and aliased and default exports behind a cycle. Projects without cycles come out unchanged. The new test fits in with its neighbors and fails on main.
One optional simplification is noted inline.
| const found = await traceExport(effectiveName, importItem, targetFile.exports, rewrites, ctx, added, visiting); | ||
| visiting.delete(visitKey); |
There was a problem hiding this comment.
Optional: without the delete, the set records every state already tried, which is enough to stop the cycle and visits each file once per name. As written, a state that failed is tried again from every other path, so densely connected cycles get expensive. Eleven barrels that all star re-export each other take about 5 seconds here, against 0.2 seconds without the line and with the same output. canFlattenStarExports and traceStarExports further down keep their visited entries too. The tests pass either way.
| const found = await traceExport(effectiveName, importItem, targetFile.exports, rewrites, ctx, added, visiting); | |
| visiting.delete(visitKey); | |
| const found = await traceExport(effectiveName, importItem, targetFile.exports, rewrites, ctx, added, visiting); |
webpro
left a comment
There was a problem hiding this comment.
Thanks for picking up the suggestion. The set is now a plain visited set, and the dense cycle that took about 5 seconds runs in 0.2. I pushed one commit to your branch that replaces the second test: its fixture did not type-check, and the new one does and covers the alternate route, a barrel reached again under another name. Ready to merge.
|
🚀 This pull request is included in v1.2.0. See Release 1.2.0 for release notes. |
Stop revisiting active export states when tracing a barrel cycle, so a later branch can still resolve the named export. Add a regression for two barrels that re-export each other before the leaf export.
Validated with 182 tests, build, lint, formatting and installed-check.