Skip to content

records: keep {{ }} fields in the order written - #261

Merged
vito merged 1 commit into
mainfrom
record-literal-order
Nov 8, 2026
Merged

vito merged 1 commit into
mainfrom
record-literal-order

Conversation

@vito

@vito vito commented Nov 8, 2026

Copy link
Copy Markdown
Owner

Record literals used to store their fields in dependency order: inference visits fields so that each one comes after the siblings it references, and the record type's fields kept that order. {{b: a + 1, a: 1}} had fields a, b. With this change the type keeps the order the fields are written in (b, a). Inference order is unchanged.

Two open PRs depend on this:

Release notes: this is a behavior change, but you can only see it through key order: iterating a record's fields, and the encoders once #255 lands. Equality, field access and type display are unaffected.

Test: TestRecordLiteralKeepsWrittenFieldOrder (pkg/dang/record_order_test.go).

An object literal's fields are inferred in dependency order, and its record
type listed them in that order: {{b: a + 1, a: 1}} had fields a, b. Order
the type's fields as written instead, so whatever iterates them (sortBy's
record keys, JSON.encode's declaration order) sees the fields as the reader
does.

Signed-off-by: Alex Suraci <[email protected]>
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying dang with  Cloudflare Pages  Cloudflare Pages

Latest commit: d9159da
Status: ✅  Deploy successful!
Preview URL: https://59875962.dang-3kk.pages.dev
Branch Preview URL: https://record-literal-order.dang-3kk.pages.dev

View logs

@vito
vito merged commit 1344efb into main Nov 8, 2026
9 checks passed
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.

1 participant