Files
scriptc/tests/corpus/7750-key-order-javascript-spread-sources/lib.js
T
Malte UblandClaude Opus 5.5 7fb73b7d9d Keep the key order of records spread from values JavaScript built
A literal that starts with `...value` creates value's keys first, in
value's own order. When checked conversions build value's shape (records
JavaScript hands back through replaceable methods, field setters,
generator calls or callbacks), the key-order witness could not order the
literal statically and kept the declared table, so `{ ...draft, id }`
and `{ ...current, ...patch }` enumerated `id` first natively.

Every value of a record shape already enumerates either in its table or
in the order its record source holds: a checked conversion keeps the
source's order there whenever it differs from the table. Such a literal
(an ordered spread) now carries that order over: after it builds the
record, record.sourceSpread gives the record a source listing the keys
it declares in value's order, and the keys value lacks follow in the
table's order, which every literal sequence of the shape agrees with.
The literal then resolves as if value were in its table's order, and its
own shape counts as built at run time, since its values may carry a
source too. It qualifies only when every value of the source has all of
the source's keys, both shapes can keep a source, every later spread of
a shape whose values may carry a source only overwrites the source's
keys, and the source shape resolves (or is the literal's own shape).
Literals of shapes that do not resolve are left as they were.

Programs without such literals compile to identical IR.

Corpus 7750-key-order-javascript-spread-sources.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 10:15:58 -07:00

15 lines
588 B
JavaScript

// Records JavaScript builds in its own key order, handed to TypeScript
// through typed slots: a draft from a "validator", a stored row, and a
// replacement method installed through a computed key.
export function validate(input) {
return { year: input.year, title: input.title, tags: input.tags };
}
export function storeRow(rows, id) {
rows.set(id, { title: "Stored", id, tags: [], year: 1999, createdAt: "t0", version: 1 });
}
export function replace(target, name) {
target[name] = (id) => ({ version: 7, id, year: 2001, title: "Replaced", tags: ["r"], createdAt: "t1" });
}