Skip to content

feat: Support computed object properties - #2950

Open
cieplypolar wants to merge 8 commits into
impr/separate-acorn-babel-parsersfrom
feat/computed-properties
Open

feat: Support computed object properties#2950
cieplypolar wants to merge 8 commits into
impr/separate-acorn-babel-parsersfrom
feat/computed-properties

Conversation

@cieplypolar

@cieplypolar cieplypolar commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator

In addition to supporting computed object properties, this preserves evaluation order of comptime-known keys and values mentioned in #2944.

Copilot AI lite review requested due to automatic review settings August 31, 2026 14:36

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@cieplypolar cieplypolar changed the title feat: Computed properties support feat: Support computed object properties Aug 31, 2026
@github-actions

github-actions Bot commented Aug 31, 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/eslint-plugin-typegpu@5384ac1572b22b3c89d168d2e1cb600314aa58b3
https://pkg.pr.new/software-mansion/TypeGPU/tinyest@5384ac1572b22b3c89d168d2e1cb600314aa58b3
https://pkg.pr.new/software-mansion/TypeGPU/tinyest-for-wgsl@5384ac1572b22b3c89d168d2e1cb600314aa58b3
https://pkg.pr.new/software-mansion/TypeGPU/typegpu@5384ac1572b22b3c89d168d2e1cb600314aa58b3
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/gl@5384ac1572b22b3c89d168d2e1cb600314aa58b3
https://pkg.pr.new/software-mansion/TypeGPU/unplugin-typegpu@5384ac1572b22b3c89d168d2e1cb600314aa58b3

benchmark
view benchmark

commit
view commit

@cieplypolar
cieplypolar changed the base branch from main to impr/separate-acorn-babel-parsers August 31, 2026 14:39
@github-actions

Copy link
Copy Markdown

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

🟢 Decreased ➖ Unchanged 🔴 Increased (max 0.60%) ❔ Unknown
0 319 6 0

import * as ... in PR vs import * as ... in target (did bundle size increase?):

Test tsdown
tgpu_resolveWithContext.ts 162.87 kB ($${\color{red}+0.6\%}$$)
tgpu_resolve.ts 162.94 kB ($${\color{red}+0.6\%}$$)

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

@github-actions

github-actions Bot commented Aug 31, 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.75, 1.47, 3.34, 5.01, 5.45, 9.57, 18.10, 19.59]
  line [0.68, 1.44, 3.02, 5.02, 5.19, 8.57, 18.00, 19.20]
  line [0.72, 1.44, 3.10, 4.70, 5.34, 9.22, 16.16, 20.34]
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.23, 0.50, 0.61, 0.75, 0.93, 0.91, 1.16, 1.28]
  line [0.20, 0.37, 0.54, 0.61, 0.85, 0.89, 1.08, 1.16]
  line [0.23, 0.38, 0.57, 0.68, 0.89, 0.95, 1.16, 1.22]
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.75, 1.91, 2.77, 5.33, 9.35, 20.09, 42.60, 84.39]
  line [0.72, 1.86, 2.74, 5.45, 9.60, 22.24, 40.10, 85.41]
  line [0.91, 1.95, 4.11, 6.40, 10.18, 20.20, 42.13, 83.98]
Loading

@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.

ℹ️ Minor suggestions only — no blocking issues found. The feature is well-tested and the evaluation-order fix for #2944 is correctly verified.

Reviewed changes — the PR adds computed-property ([key]: value) support to TGSL object literals and fixes #2944 (struct field values are now evaluated in JS source order, key before value). Reviewed against the branch base impr/separate-acorn-babel-parsers (the acorn/babel parser split itself lives in that base and is not in this diff):

  • tinyest AST (nodes.ts): new objectProperty (107) and objectExprWithComputedProps (108) node types, threaded through every consumer — wgslGenerator._expression, glslGenerator.#handleStructReturn, tseynit stringify, and the obfuscator.
  • transpilers.ts: Property/ObjectProperty handlers emit the new node shape; an object literal with any computed key becomes objectExprWithComputedProps, otherwise keys are still collapsed into a plain record (now with duplicate-key detection).
  • codegen: struct/AutoStruct literals resolve in source order (key before value), extra (non-struct-member) fields are still evaluated so side effects run in JS order, and duplicate or runtime-known keys are rejected with clear errors via the new _resolveObjectPropertyKey.
  • eslint/docs/tests: noUnsupportedSyntax drops the computed-key ban; two example shaders reordered to match struct field order; broad new coverage in wgslGenerator.test.ts, glslGenerator.test.ts, parsers.test.ts, tseynit.test.ts and obfuscation.test.ts.

Verification this run: all six affected test files pass (252 tests), test:types passes for typegpu, tinyest-for-wgsl, unplugin-typegpu and @typegpu/gl, and a scratch probe confirmed the acorn and babel key handlers accept the same key shapes for the common cases.

Pullfrog  | Fix all ➔Fix 👍s ➔View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Comment thread packages/tinyest-for-wgsl/src/transpilers.ts Outdated
Comment thread packages/tinyest-for-wgsl/src/transpilers.ts
@cieplypolar
cieplypolar force-pushed the feat/computed-properties branch from fcebfb2 to 8ae3c36 Compare August 31, 2026 16:16

@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

The re-based commits standardized the duplicate-key error wording to Duplicate object property key: 'X'. in the transpilers and the GLSL generator, but the two inline snapshots that pin those messages were not updated. Both tests fail on the head commit and build-and-test (Test unit) is red — please update the snapshots before merging.

Reviewed changes — incremental re-review of commit range fcebfb2..8ae3c369. The branch was force-pushed: the six feature commits were rewritten onto the unchanged base tip 53f47c73 (same subjects, new SHAs). The delta is small and behavior-neutral apart from the message change below:

  • Standardized the duplicate-key error text to Duplicate object property key: 'X'. across both transpiler handlers and the GLSL #handleStructReturn, and added the // Normalize to objectProperty[] / _resolveObjectPropertyKey plumbing comments.
  • Renamed propertiesobj locals in the transpilers and retitled / reworded several object-order tests (e.g. a redundant struct-constructor snapshot replaced with void tgpu.resolve([f]); not.toContain('vary_extra') widened to not.toContain('extra')).
  • Left the WGSL generator's richer two-key message (... found: 'X' and 'Y'.) and its snapshot untouched.

Verification this run: reproduced both failures locally with vitest (tinyest-for-wgsl parsers → 1 failed, @typegpu/gl glslGenerator → 1 failed); all other affected suites pass (wgslGenerator 100, tseynit 30, obfuscation 26, eslint-plugin 38), and the two reordered doc examples (ray-marching, vaporrave) still match their snapshots.

Pullfrog  | Fix all ➔Fix 👍s ➔View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Comment thread packages/tinyest-for-wgsl/tests/parsers.test.ts Outdated
Comment thread packages/typegpu-gl/tests/glslGenerator.test.ts Outdated
@cieplypolar
cieplypolar force-pushed the feat/computed-properties branch 2 times, most recently from 8ae3c36 to 1850ed8 Compare August 31, 2026 16:44

@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 — incremental re-review of commit range 8ae3c369..1850ed89. The delta is exactly the two inline snapshots the last review flagged as CI-breaking: both were updated to the standardized Duplicate object property key: 'X'. wording.

  • Updated the rejects duplicate non-computed object keys snapshot in tinyest-for-wgsl/tests/parsers.test.ts to Duplicate object property key: 'field'., matching both transpiler handlers.
  • Updated the rejects duplicate keys in entry point return snapshot in @typegpu/gl's glslGenerator.test.ts to Duplicate object property key: 'uv'., matching #handleStructReturn's throw.

Verified this run: both previously-failing suites now pass (tinyest-for-wgsl parsers 22/22, @typegpu/gl glslGenerator 36/36), so build-and-test (Test unit) should be green again. The WGSL generator's richer two-key message and the docs example snapshots were left untouched, consistent with the last review.

Pullfrog  | View workflow run | Using DeepSeek 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 — incremental re-review of commit range 1850ed89..ec5ca2a7 (single commit ec5ca2a7c "better error in glsl"). The new commit aligns the GLSL duplicate-key error with the WGSL generator's format:

  • GLSL generator: #handleStructReturn's resolveUniqueKey now throws Duplicate object property key found: 'X' and 'Y'. using stringifyNode (glslGenerator.ts:1030), matching wgslGenerator.ts:906 exactly, instead of the previous single-key Duplicate object property key: 'X'..
  • Test snapshot: the rejects duplicate keys in entry point return snapshot in glslGenerator.test.ts:745 updated to the two-key message ('uv: d.vec2f(1, 2)' and '[getKey()]: d.vec2f(3, 4)'), consistent with the WGSL snapshot at wgslGenerator.test.ts:2243.

Verified this run: @typegpu/gl glslGenerator 36/36 tests pass and @typegpu/gl test:types is green. stringifyNode is already exported through typegpu/~internal (internal.ts:10), so the new import resolves cleanly. The change is error-message text only — codegen is unaffected.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@cieplypolar
cieplypolar force-pushed the feat/computed-properties branch from ec5ca2a to 0c24d42 Compare September 1, 2026 11:18
@cieplypolar
cieplypolar force-pushed the feat/computed-properties branch from 0c24d42 to adadba2 Compare September 4, 2026 15:35

@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

The new obfuscates computed struct keys test fails on the head commit — it calls transpileFn, which is no longer imported into obfuscation.test.ts (the import was switched to transpileFnBabel alone). This breaks the unplugin test suite and the build-and-test gate, so it needs a one-line fix before merging.

Reviewed changes — incremental re-review since the prior pullfrog review (head 0c24d42, force-pushed to adadba218; net delta is the legacy-transpiler computed-property support):

  • Extended the deprecated legacy transpileFn in parsers.ts (createLegacyTraspilers) to support computed object properties, reusing the shared Property/ObjectProperty transpilers and emitting the objectProperty/objectExprWithComputedProps nodes instead of throwing.
  • Updated parsers.test.ts so the legacy path asserts computed keys transpile (snapshot includes [108,[[107,"id",[5,"1"],true],...]]) plus existing spread/method/dup-key rejection tests.
  • Reworked obfuscation.test.ts: converted existing usages to transpileFnBabel and added the new obfuscates computed struct keys case (which is the one that fails).

Verified this run: tinyest-for-wgsl parsers suite passes with the legacy change; the failing obfuscation test reproduces locally and passes immediately once line 429 uses transpileFnBabel (snapshot unchanged).

Pullfrog  | Fix all ➔Fix 👍s ➔View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Comment thread packages/unplugin-typegpu/test/obfuscation.test.ts Outdated
@cieplypolar
cieplypolar force-pushed the feat/computed-properties branch from adadba2 to 5384ac1 Compare September 4, 2026 15:40
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.

2 participants