Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/lualib/ObjectAssign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
export function __TS__ObjectAssign<T extends object>(this: void, target: T, ...sources: T[]): T {
for (const i of $range(1, sources.length)) {
const source = sources[i - 1];
for (const key in source) {
target[key] = source[key];
if (type(source) === "table") {
for (const key in source) {
target[key] = source[key];
}
}
}

Expand Down
10 changes: 10 additions & 0 deletions test/unit/builtins/object.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ test.each([
util.testExpression`Object.assign(${util.formatCode(initial)}, ${argsString})`.expectToMatchJsResult();
});

test.each([
"Object.assign({}, false)",
"Object.assign({}, null)",
"Object.assign({}, undefined)",
"Object.assign({}, null, undefined)",
"Object.assign({ a: 1 }, false, { b: 2 })",
])("Object.assign skips non-object sources (%p)", expression => {
util.testExpression(expression).expectToMatchJsResult();
});

test.each([{}, { abc: 3 }, { abc: 3, def: "xyz" }])("Object.entries (%p)", obj => {
const testBuilder = util.testExpressionTemplate`Object.entries(${obj})`;
// Need custom matcher because order is not guaranteed in neither JS nor Lua
Expand Down
9 changes: 9 additions & 0 deletions test/unit/spread.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ describe("in object literal", () => {
util.testExpression(expression).expectToMatchJsResult();
});

test.each([
"{ ...((false && { a: 1 }) as any) }",
"{ ...((true && { a: 1 }) as any) }",
"{ a: 1, ...((false && { b: 2 }) as any) }",
"{ ...(null as any), ...(undefined as any) }",
])("of short-circuited operand (%p)", expression => {
util.testExpression(expression).expectToMatchJsResult();
});

test("of object reference", () => {
util.testFunction`
const object = { x: 0, y: 1 };
Expand Down
Loading