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.56, 3.57, 5.67, 6.92, 8.63, 20.21, 22.07]
line [0.82, 1.55, 3.51, 5.83, 6.48, 9.89, 18.47, 22.09]
line [0.83, 1.64, 3.36, 5.14, 6.33, 9.47, 18.53, 20.84]
---
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.33, 0.51, 0.65, 0.71, 0.96, 1.03, 1.25, 1.42]
line [0.27, 0.47, 0.67, 0.75, 1.02, 0.98, 1.18, 1.33]
line [0.26, 0.45, 0.59, 0.73, 0.98, 1.02, 1.28, 1.38]
---
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.75, 1.86, 3.37, 5.60, 10.81, 22.50, 48.15, 98.18]
line [0.91, 1.80, 3.54, 5.99, 10.73, 22.60, 46.53, 95.17]
line [0.77, 1.86, 3.37, 5.35, 10.56, 21.63, 47.42, 96.07]
|
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
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — added JSDoc comment inheritance in the Babel transform so that leading comments on export function / export default function declarations are preserved on the hoisted const output, directly addressing the reviewer's request about comment reassociation.
- Inherit export-level comments in Babel transform —
babel.ts: when the parent of a hoisted function declaration is an export,t.inheritLeadingCommentscopies comments from the parent export node onto theconstdeclaration, then clears the export node's comments to prevent duplication. - Update inline snapshots — test file snapshots now include
/** MUL */and/** ADD */comments positioned before their respectiveconstdeclarations in the Babel output.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

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