feat: Private property access#2594
Conversation
…access-in-externals
|
pkg.pr.new packages benchmark commit |
Bundle size comparison (
|
| 🟢 Decreased | ➖ Unchanged | 🔴 Increased | ❔ Unknown |
|---|---|---|---|
| 0 | 321 | 0 | 0 |
import { ... } in PR vs import * as ... in PR (is the library tree-Shakeable?):
| Test | tsdown |
|---|---|
| tgpu_init.ts | 255.87 kB ( |
| tgpu_initFromDevice.ts | 255.36 kB ( |
| tgpu_resolve.ts | 161.34 kB ( |
| tgpu_resolveWithContext.ts | 161.28 kB ( |
| tgpu_bindGroupLayout.ts | 68.92 kB ( |
| tgpu_mutableAccessor.ts | 65.91 kB ( |
| tgpu_accessor.ts | 65.90 kB ( |
| tgpu_privateVar.ts | 65.27 kB ( |
| tgpu_workgroupVar.ts | 65.27 kB ( |
| tgpu_const.ts | 64.52 kB ( |
| tgpu_fn.ts | 37.98 kB ( |
| tgpu_fragmentFn.ts | 37.88 kB ( |
| tgpu_vertexFn.ts | 37.70 kB ( |
| tgpu_computeFn.ts | 37.40 kB ( |
| tgpu_vertexLayout.ts | 26.63 kB ( |
| tgpu_comptime.ts | 14.43 kB ( |
| tgpu_unroll.ts | 2.60 kB ( |
| tgpu_slot.ts | 1.54 kB ( |
| tgpu_lazy.ts | 1.19 kB ( |
If you wish to run a comparison for other, slower bundlers, run the 'Tree-shake test' from the GitHub Actions menu.
|
@pullfrog review |
There was a problem hiding this comment.
Important
The Rollup externals test isn't actually testing the Rollup path, and the combined public/private #prop case silently resolves the wrong resource. Both need addressing before merge.
Reviewed changes — this PR enables JavaScript private class properties as TypeGPU externals, adds auto-naming for ClassPrivateProperty, and removes the lint rule that unconditionally banned private identifiers.
- Lift the blanket
PrivateIdentifierlint ban inpackages/eslint-plugin/src/rules/noUnsupportedSyntax.tssothis.#propaccess is allowed. - Track
#propchains inpackages/tinyest-for-wgsl/src/externals.tsby handling both BabelPrivateNameand acornPrivateIdentifier. - Auto-name private class fields in
packages/unplugin-typegpu/src/core/common.tsvia a newClassPrivatePropertyvisitor and matchingextractLabelledExpressionbranch. - Add test coverage for private property access across
tinyest-for-wgsl,typegpu, andunplugin-typegpu.
Collision between private #prop and string-key "#prop"
A class that defines both a public '#prop' and a private #prop currently routes both this['#prop'].$ and this.#prop.$ through the same this.#prop external key. The runtime object-based external replacement then resolves the public property value, so the private field value is silently dropped. This matches the limitation noted in the PR body; please either fix the key encoding or add a tracking issue/TODO so the limitation is visible to users and future maintainers.
Technical details
# Collision between private `#prop` and string-key `"#prop"`
## Affected sites
- packages/tinyest-for-wgsl/src/externals.ts:32-35 — private names are encoded as `this.#prop`, identical to the runtime object-property replacement path used for `this["#prop"]`.
- packages/typegpu/src/core/resolve/externals.ts:104-129 — object external replacement uses `externalName\\.(?<prop>...)` and matches `this.#prop` for `this` externals.
## Required outcome
- `this.#prop` (private field) and `this["#prop"]` (public string key) resolve to distinct resources when both are present.
## Suggested approach
Consider encoding private names with a distinct prefix or namespace (e.g., `this.private.#prop`) and teaching the resolver to map that prefix back to the private-field accessor. Alternatively, document the limitation and add a failing/todo test linking to an issue.
## Open questions for the human
- Is the combined case expected to be fixed in this PR, or is there a follow-up issue already planned? Please link it in a code comment so the next agent doesn't re-discover it.Kimi K2 (free via Pullfrog for OSS) | 𝕏
Co-authored-by: Szymon Szulc <103948576+cieplypolar@users.noreply.github.com>
Co-authored-by: Konrad Reczko <66403540+reczkok@users.noreply.github.com>
…ic.mdx Co-authored-by: Konrad Reczko <66403540+reczkok@users.noreply.github.com>
…access-in-externals
…xternals' into feat/private-property-access
|
@reczkok @iwoplaza @cieplypolar this is reviewable again |
There was a problem hiding this comment.
\u2139\ufe0f No critical issues \u2014 minor suggestions inline.
Reviewed changes \u2014 Adds support for accessing class private properties (this.#prop) from 'use gpu' functions by teaching external-chain extraction and auto-naming to recognize private property AST nodes.
- Removes the
PrivateIdentifierban innoUnsupportedSyntax. - Extends
tryFindExternalChainto build chain strings likethis.#prop. - Extends
unplugin-typegpuauto-naming toClassPrivatePropertynodes and assignments to private properties. - Adds parser, resolution, auto-naming, and nested-externals tests for private property access.
Kimi K2 (free via Pullfrog for OSS) | 𝕏
|
One small test-coverage suggestion: the PR body calls out the case where both a public string property named
|

Blocked by #2425
Only the case with both
"#prop"and#proppresent breaks.