Files
Chris Tate 2ff5711a54 Keep record layouts stable for shorthand and literal-argument fields
A shorthand property and an object literal passed as an argument no
longer widen the declared record layout of the binding or parameter
that receives them. A widened layout made every existing record that
flowed into that binding or parameter convert to a copy, so later
writes through the copy were lost. Those literals keep a missing
element in their own fields and convert, with a check, into a declared
record.

The debug-variables fixture iterates an array whose elements may be
undefined, so its loop binding keeps the union layout the debugger
check inspects.
2026-10-10 03:40:36 -05:00

39 lines
1.0 KiB
TypeScript

import { reportOther } from "./other.ts";
const moduleValue = 42;
const moduleText = "module";
function inspect(input: number, enabled: boolean, fallback = 9): void {
let value = input + 1;
const text = "hello é";
const update = (): void => {
value += 2;
console.log("capture", value); // debug: capture
};
console.log("locals", value, enabled, text, fallback); // debug: locals
{
const value = 99;
console.log("inner", value); // debug: shadow
}
update();
console.log("outer", value); // debug: restored
const bytes = new Uint8Array([4, 5]);
for (let i = 0; i < bytes.length; i++) {
console.log("loop", i, bytes[i]); // debug: loop
}
for (const item of [6, 7] as (number | undefined)[]) {
console.log("item"); // debug: item
console.log(item);
}
if (enabled) {
var hoisted = input + 10;
} else {
hoisted = 0;
}
console.log("hoisted", hoisted); // debug: hoisted
}
console.log("globals", moduleValue, moduleText); // debug: globals
inspect(3, true);
reportOther();