mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-24 06:14:01 +08:00
- Preserve async factory results and mixed table layouts through inference and destructuring. - Support checked Map and Object.fromEntries construction with native weak collections. - Keep native weak-key lifetimes and engine-backed collection identities intact.
11 lines
419 B
JavaScript
11 lines
419 B
JavaScript
function defineStruct(fields, options) {
|
|
const layout = [];
|
|
for (const [name, type, settings = {}] of fields) {
|
|
layout.push({ name, type, default: settings.default });
|
|
}
|
|
return layout;
|
|
}
|
|
const a = defineStruct([["first", "number", { default: 7 }], ["second", "number"]]);
|
|
const b = defineStruct([["name", "string", { default: "yes" }]], {});
|
|
console.log(a.length, a[0].default, a[1].default, b[0].default);
|