fix(unplugin-typegpu): Transform preserves exports#2606
Conversation
|
pkg.pr.new packages benchmark commit |
📊 Bundle Size Comparison
👀 Notable resultsStatic test results:No major changes. Dynamic test results:No major changes. 📋 All resultsClick to reveal the results table (355 entries).
If you wish to run a comparison for other, slower bundlers, run the 'Tree-shake test' from the GitHub Actions menu. |
Resolution Time Benchmark---
config:
themeVariables:
xyChart:
plotColorPalette: "#E63946, #3B82F6, #059669"
---
xychart
title "Random Branching (🔴 PR | 🔵 main | 🟢 release)"
x-axis "max depth" [1, 2, 3, 4, 5, 6, 7, 8]
y-axis "time (ms)"
line [0.85, 1.74, 3.86, 6.58, 6.84, 10.64, 21.02, 22.48]
line [0.89, 1.90, 3.84, 6.34, 6.98, 10.62, 20.76, 25.33]
line [0.95, 1.96, 3.91, 6.41, 7.50, 9.71, 20.84, 23.30]
---
config:
themeVariables:
xyChart:
plotColorPalette: "#E63946, #3B82F6, #059669"
---
xychart
title "Linear Recursion (🔴 PR | 🔵 main | 🟢 release)"
x-axis "max depth" [1, 2, 3, 4, 5, 6, 7, 8]
y-axis "time (ms)"
line [0.35, 0.53, 0.69, 0.80, 1.04, 1.09, 1.38, 1.44]
line [0.29, 0.50, 0.62, 0.75, 1.02, 1.09, 1.37, 1.55]
line [0.31, 0.54, 0.64, 0.82, 1.11, 1.12, 1.43, 1.65]
---
config:
themeVariables:
xyChart:
plotColorPalette: "#E63946, #3B82F6, #059669"
---
xychart
title "Full Tree (🔴 PR | 🔵 main | 🟢 release)"
x-axis "max depth" [1, 2, 3, 4, 5, 6, 7, 8]
y-axis "time (ms)"
line [0.84, 1.84, 3.85, 6.12, 12.09, 24.59, 53.81, 107.93]
line [0.91, 1.94, 3.59, 6.13, 11.76, 25.54, 55.03, 110.61]
line [0.77, 2.02, 3.90, 6.13, 12.59, 25.33, 53.62, 110.62]
|
There was a problem hiding this comment.
Pull request overview
This PR fixes the Babel-based unplugin-typegpu transform so that when a "use gpu" exported function declaration is hoisted/replaced, the corresponding export is preserved (instead of being accidentally removed). It also updates the test suite to assert the corrected Babel output alongside the Rollup output.
Changes:
- Preserve
exportstatements when hoisting transformedexport function .../export default function ...in the Babel plugin. - Extend the existing “hoists exported…” test to cover both Babel and Rollup transforms with separate snapshots.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/unplugin-typegpu/src/babel.ts | When hoisting a transformed exported function declaration, replaces the enclosing export node with an equivalent export (export { id } / export default id) instead of removing it. |
| packages/unplugin-typegpu/test/use-gpu-directive.test.ts | Splits the exported-hoisting test into babel and rollup assertions and adds an inline snapshot verifying Babel now preserves exports. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — fixes the Babel transform of unplugin-typegpu to preserve export declarations when hoisting "use gpu" function declarations, and mirrors the support in the unplugin/rollup code path. Comprehensive tests added for both babel and rollup across named exports, default exports, arrow functions, and anonymous default exports.
- Preserve named exports in Babel transform —
babel.ts: after hoisting, replacesexport functionwithexport { name }andexport default functionwithexport default nameinstead of.remove(). - Mirror default export in unplugin/rollup transform —
factory.ts: adds theExportDefaultDeclarationbranch, appendingexport default <name>;after the hoistedconstfor named default-exported functions. - Expand test coverage — 5 new
describeblocks in the test file, each with parallel babel and rollup inline snapshots, covering named, default, arrow, anonymous default function, and anonymous default arrow function export patterns.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
iwoplaza
left a comment
There was a problem hiding this comment.
Thanks for the fixes! If there's a way to reassociate the comments with the function definitions, then that would be great
| /** ADD */ | ||
| export { add }; | ||
| /** MUL */ | ||
| export { mul };" |
There was a problem hiding this comment.
The only slight nitpick is that the doc comments are associated with the export statements, instead of the function definitions.
| /** ADD */ | ||
| export default add;" |

Uh oh!
There was an error while loading. Please reload this page.