Conversation
1b7630c to
4a6fa31
Compare
3e34d92 to
783d928
Compare
813ef3d to
cc76893
Compare
|
pkg.pr.new packages benchmark commit |
9910620 to
d26c8b3
Compare
📊 Bundle Size Comparison
👀 Notable resultsStatic test results:No major changes. Dynamic test results:No major changes. 📋 All resultsClick to reveal the results table (348 entries).
If you wish to run a comparison for other, slower bundlers, run the 'Tree-shake test' from the GitHub Actions menu. |
c321cba to
6a389c9
Compare
There was a problem hiding this comment.
Pull request overview
This PR refactors unplugin-typegpu to Unplugin v3 by consolidating AST traversal into a shared Babel-based core, adding /* #__PURE__ */ hints for improved treeshaking, and making the options parameter optional (typegpu()).
Changes:
- Replaced the previous Rollup/Acorn implementation with a unified Babel-traverse-based core (
src/core/*) used by unplugin and bundler adapters. - Added
/* #__PURE__ */annotations to generated wrappers and autonaming calls to improve treeshaking. - Updated tests/snapshots and documentation/examples to use the now-optional options param.
Reviewed changes
Copilot reviewed 27 out of 29 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| pnpm-workspace.yaml | Updates shared dependency catalog (adds @babel/types, bumps tsdown, adds rollup). |
| packages/unplugin-typegpu/tsdown.config.ts | Updates tsdown dependency/bundling configuration. |
| packages/unplugin-typegpu/test/use-gpu-directive.test.ts | Expands/updates directive transformation tests and snapshots for new wrapper/hoisting behavior and PURE hints. |
| packages/unplugin-typegpu/test/typescript-syntax.test.ts | Adds Babel-only test coverage for TS syntax (as casts). |
| packages/unplugin-typegpu/test/transform.ts | Updates Options import path to new core module. |
| packages/unplugin-typegpu/test/tgsl-transpiling.test.ts | Updates snapshots for PURE hints and formatting changes. |
| packages/unplugin-typegpu/test/regex.test.ts | Updates defaultOptions import path to new core module. |
| packages/unplugin-typegpu/test/parser-options.test.ts | Updates snapshots for PURE hints and formatting changes. |
| packages/unplugin-typegpu/test/auto-naming.test.ts | Updates snapshots for PURE hints and metadata/name formatting changes. |
| packages/unplugin-typegpu/test/aliasing.test.ts | Updates snapshots for PURE hints and metadata/name formatting changes. |
| packages/unplugin-typegpu/src/rollup-impl.ts | Removes old Rollup/Acorn implementation in favor of the new shared core. |
| packages/unplugin-typegpu/src/rolldown-browser.ts | Switches to unpluginFactory and makes options optional for rolldown-browser entry. |
| packages/unplugin-typegpu/src/index.ts | Switches to unpluginFactory, updates exported Options type, adds unloaderPlugin export. |
| packages/unplugin-typegpu/src/core/filter.ts | Adds a local filter helper (copied from unplugin) for Babel-plugin-only filtering. |
| packages/unplugin-typegpu/src/core/factory.ts | Introduces the unified unplugin factory using Babel parser/traverse + MagicStringAST. |
| packages/unplugin-typegpu/src/core/common.ts | Introduces shared traversal logic (naming, directive detection, operator overload rewrites, shell handling). |
| packages/unplugin-typegpu/src/common.ts | Removes old shared helpers in favor of src/core/common.ts. |
| packages/unplugin-typegpu/src/bun.ts | Refactors Bun adapter to call unpluginFactory and makes options optional. |
| packages/unplugin-typegpu/src/babel.ts | Refactors Babel plugin to reuse shared core logic and adds PURE hints. |
| packages/unplugin-typegpu/package.json | Updates dependencies for new architecture (parser/traverse/types, ast-kit, unplugin v3) and repo directory metadata. |
| packages/unplugin-typegpu/README.md | Updates package description and adds Bun usage example. |
| packages/typegpu/tests/unplugin/autoname.test.ts | Updates snapshot expectations around hoisting and PURE hints. |
| packages/tinyest-for-wgsl/tsdown.config.ts | Updates tsdown dependency/bundling configuration. |
| packages/tinyest-for-wgsl/package.json | Moves @babel/types to workspace catalog. |
| package.json | Updates overrides to use catalogs for rollup and @babel/types. |
| apps/typegpu-docs/src/content/docs/tooling/unplugin-typegpu.mdx | Updates docs example to call typegpuPlugin() without {}. |
| apps/treeshake-test/bundleWith.ts | Updates bundler examples to call plugins with no options object. |
| apps/bun-example/preload.ts | Updates Bun example to call typegpu() with no options object. |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| t.returnStatement( | ||
| t.objectExpression( | ||
| ast.externalNames.map((name) => | ||
| t.objectProperty(i(name), i(name), false, /* shorthand */ name !== 'this'), |
There was a problem hiding this comment.
When building the externals object, ast.externalNames may include the string "this" (e.g. class methods). Using t.identifier('this') for the value is not a valid AST node for this and can throw or generate invalid output. Handle this case explicitly (e.g. use t.thisExpression() as the value and a string-literal key like "this").
| t.objectProperty(i(name), i(name), false, /* shorthand */ name !== 'this'), | |
| name === 'this' | |
| ? t.objectProperty(t.stringLiteral('this'), t.thisExpression()) | |
| : t.objectProperty(i(name), i(name), false, /* shorthand */ true), |
1f4003b to
01973ea
Compare
01973ea to
76473dc
Compare
/* #__PURE__ */bundler hint so things can be treeshaken properlytypegpu({})->typegpu())