Files
scriptc/tests/corpus/logical-assignment-dynamic.js
Chris Tate b40a6f6079 feat(compiler): lower frontend collections and string transforms natively
- Keep generic bindings and short-circuit writes scoped to their native execution context.
- Compile Map and Set copies, tuple callbacks and searches, and string-pattern replacement.
- Exercise production frontend registries without Node and preserve mutation, identity, and evaluation order.
2026-09-28 14:38:05 -05:00

31 lines
1.3 KiB
JavaScript

let effects = "";
const object = JSON.parse('{"zero":0,"text":"ok","nothing":null,"flag":false}');
function receiver() { effects += "O"; return object; }
/** @param {string} value */
function key(value) { effects += "K"; return value; }
function value(next) { effects += "V"; return next; }
console.log(receiver()[key("zero")] &&= value(1), effects);
console.log(receiver()[key("zero")] ||= value(2), effects);
console.log(receiver()[key("text")] ||= value("skip"), effects);
console.log(receiver()[key("text")] &&= value("changed"), effects);
console.log(object.nothing &&= value(3), effects);
console.log(object.flag ||= value(true), effects);
console.log(object.missing ||= value("new"), effects);
console.log(JSON.stringify(object));
// Accessor calls cross the checked native object boundary. Reading once
// and preserving the raw RHS result are observable even when setters mutate.
const accessors = JSON.parse("{}");
let stored = 0;
Object.defineProperty(accessors, "item", {
get() { effects += "G"; return stored; },
set(next) { effects += "S"; stored = next + 10; },
enumerable: true,
});
effects = "";
console.log(accessors.item &&= value(4), stored, effects);
effects = "";
console.log(accessors.item ||= value(5), stored, effects);
effects = "";
console.log(accessors.item &&= value(6), stored, effects);