Skip to content

impr(unplugin-typegpu): Support parsing all metadata fields - #3020

Open
cieplypolar wants to merge 50 commits into
mainfrom
impr/unplugin-ast-ext-parser
Open

cieplypolar wants to merge 50 commits into
mainfrom
impr/unplugin-ast-ext-parser

Conversation

@cieplypolar

@cieplypolar cieplypolar commented Sep 14, 2026 •

Copy link
Copy Markdown
Collaborator

Parse ast and externals out of embedded metadata.

@github-actions

github-actions Bot commented Sep 14, 2026 •

Copy link
Copy Markdown

pkg.pr.new

packages
Ready to be installed by your favorite package manager ⬇️

https://pkg.pr.new/software-mansion/TypeGPU/tgpu-gen@2c724e5a7a37e797101346a43bd15bd6f39875f7
https://pkg.pr.new/software-mansion/TypeGPU/typegpu@2c724e5a7a37e797101346a43bd15bd6f39875f7
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/cli@2c724e5a7a37e797101346a43bd15bd6f39875f7
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/color@2c724e5a7a37e797101346a43bd15bd6f39875f7
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/gl@2c724e5a7a37e797101346a43bd15bd6f39875f7
https://pkg.pr.new/software-mansion/TypeGPU/unplugin-typegpu@2c724e5a7a37e797101346a43bd15bd6f39875f7

benchmark
view benchmark

commit
view commit

@github-actions

github-actions Bot commented Sep 14, 2026 •

Copy link
Copy Markdown

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.56, 1.15, 2.38, 3.74, 4.00, 7.38, 14.22, 12.73]
  line [0.54, 1.02, 2.06, 3.69, 4.23, 6.92, 14.26, 14.61]
  line [0.53, 1.07, 2.21, 3.80, 4.11, 6.74, 13.73, 13.22]
Loading
---
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.16, 0.27, 0.41, 0.47, 0.63, 0.70, 0.81, 0.89]
  line [0.19, 0.32, 0.43, 0.47, 0.63, 0.68, 0.77, 0.91]
  line [0.14, 0.31, 0.39, 0.40, 0.60, 0.60, 0.76, 0.78]
Loading
---
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.62, 1.33, 2.57, 3.89, 7.40, 15.30, 31.88, 65.15]
  line [0.58, 1.43, 2.54, 4.19, 7.47, 15.39, 32.91, 66.00]
  line [0.57, 1.23, 2.14, 3.78, 7.71, 14.77, 30.80, 64.24]
Loading

@github-actions

github-actions Bot commented Sep 14, 2026 •

Copy link
Copy Markdown

Bundle size comparison (import * as ... in PR vs import * as ... in target):

🟢 Decreased ➖ Unchanged 🔴 Increased ❔ Unknown
0 355 0 0

No notable changes.

If you wish to run a comparison for other, slower bundlers, run the 'Tree-shake test' from the GitHub Actions menu.

@cieplypolar
cieplypolar added this pull request to stack #2951 September 17, 2026 15:41
@cieplypolar
cieplypolar force-pushed the impr/unplugin-ast-ext-parser branch from c6ccc73 to 0e1183c Compare September 17, 2026 15:46
@cieplypolar
cieplypolar removed this pull request from stack #2951 September 17, 2026 15:46
@cieplypolar
cieplypolar changed the base branch from impr/warn-schema-order to main September 17, 2026 15:47
@cieplypolar
cieplypolar force-pushed the impr/unplugin-ast-ext-parser branch from c8b1cdc to 4fcb009 Compare September 22, 2026 13:48
@cieplypolar
cieplypolar marked this pull request as ready for review September 22, 2026 14:56
@cieplypolar
cieplypolar requested review from aleksanderkatan, iwoplaza, reczkok and vende11s and a lite review from Copilot September 22, 2026 14:57

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

  • Restructured the bundler-rewrite tests (packages/unplugin-typegpu/test/embedded-metadata.test.ts): the shared dualTest block was replaced by explicit [BABEL] / [ROLLUP] tests, and the embedded fn body switched to let a=1,b=2 — a multi-declaration statement tinyest-for-wgsl rejects — so a recognition regression now re-transforms and throws rather than passing on the low occurrence-count assertion alone.
  • Added parses switch statements: asserts the parsed function.ast.body matches transpileBabelFn-derived output for a switch containing fallthrough, default, and an external case ext.
  • Added points astPath to the ast object of the metadata: pins that astPath is the ast property's ObjectExpression (asserting its parentPath is the ast ObjectProperty and that evaluate() yields the expected { params, body }).
  • Dropped the unused output parameter from dualTest, simplifying both collector paths.

The only production source files in this PR are unchanged since the prior review; this delta is test-only. Verified at head: 79/79 tests in embedded-metadata.test.ts pass and pnpm --filter unplugin-typegpu test:types is clean.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

getEmbeddedTypegpuMetadata now throws an unhandled TypeError when a .set(...) call referencing __TYPEGPU_META__ has a single argument — the removed metadataPath === undefined guard was load-bearing. Details inline.

Reviewed changes

  • Descend through metadata wrappers (packages/unplugin-typegpu/src/core/embeddedMetadata.ts): added skipTransparentWrappersDown and switched the metadata argument from skipTransparentWrappersUp(metadataPath) to skipTransparentWrappersDown(callPath.get('arguments.1')), so metadata written as (meta) or (meta as any)! is now unwrapped and recognized.
  • Tests (test/embedded-metadata.test.ts): added a parenthesized metadata variant to the bundler-rewrite matrix and a type-wrapped metadata case asserting the AST parses and the function is not re-transformed. 82 tests pass at head; tsc --noEmit clean.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@cieplypolar
cieplypolar force-pushed the impr/unplugin-ast-ext-parser branch from 30c30cd to 5208e45 Compare October 29, 2026 13:28
@cieplypolar
cieplypolar added this pull request to stack #3292 October 29, 2026 13:30
@cieplypolar cieplypolar changed the title impr(unplugin-typegpu): support parsing all metadata fields impr(unplugin-typegpu): Support parsing all metadata fields Oct 29, 2026

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ No critical issues — the prior crash is fixed; one small test gap inline.

Reviewed changes

  • Restored the metadataPath === undefined guard (packages/unplugin-typegpu/src/core/embeddedMetadata.ts): a .set(...) call referencing __TYPEGPU_META__ with a single argument now returns undefined again instead of throwing TypeError: Cannot read properties of undefined (reading 'node').
  • Kept unwrapping the metadata argument with skipTransparentWrappersDown, so (meta) and (meta as any)! remain recognized; dropped the redundant as NodePath on the callPath.get('arguments.1') call.
  • Tests (test/embedded-metadata.test.ts): added the parenthesized metadata bundler-rewrite variant and a type-wrapped metadata case.

Verified at head 5208e45: 82/82 embedded-metadata.test.ts tests pass, test:types is clean, and a scratch probe confirms the one-argument .set(...) case no longer throws.

Pullfrog  | Fix it ➔ | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

  • Recognize downleveled external getters (packages/unplugin-typegpu/src/core/embeddedMetadata.ts): parseExternalsPath no longer requires an externals property's value to be an ArrowFunctionExpression, so getters that tools such as Babel's transform-arrow-functions lower to function expressions are accepted instead of making parseExternalsPath return undefined and abort the whole transform.
  • Added a regression test (packages/unplugin-typegpu/test/embedded-metadata.test.ts): recognizes external getters downleveled by transform-arrow-functions plugin lowers an arrow getter with transform-arrow-functions, runs the output through dualTest, and asserts the parsed getter bodies.

Verified at head 99777d94: the new test's [BABEL] and [ROLLUP] variants both fail against the pre-change (c17c69a8) parseExternalsPath, confirming the test pins the fix; 275/275 non-Deno unplugin-typegpu tests pass (84 in embedded-metadata.test.ts) and test:types is clean. The sole prior Pullfrog thread (embeddedMetadata.ts:259-261) remains resolved.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

This branch has not been deployed

No deployments
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.

3 participants