Skip to content

Fix destructuring assignment of multiReturn (closes #995) - #997

Merged
Perryvw merged 3 commits into
TypeScriptToLua:masterfrom
yancouto:multi-return-995
Mar 6, 2021
Merged

Fix destructuring assignment of multiReturn (closes #995)#997
Perryvw merged 3 commits into
TypeScriptToLua:masterfrom
yancouto:multi-return-995

Conversation

@yancouto

@yancouto yancouto commented Mar 4, 2021

Copy link
Copy Markdown
Contributor

Fixed the issue. Turns out we were dealing with this problem on normal assignments, so something like this works:

let a, b;
[a, ...b] = string.find("a", "b");

This is handled here: https://github.com/TypeScriptToLua/TypeScriptToLua/blob/master/src/transformation/visitors/binary-expression/assignments.ts#L94-L97

Maybe this is an indicative that this needs some refactoring, as that code should be common. However, I just fixed the issue locally, and added a test showing it is now working.

The only other change is a snapshot of a test that's supposed to fail, so that shouldn't be a problem I believe.

npm test works.

@Perryvw Perryvw linked an issue Mar 5, 2021 that may be closed by this pull request

@Perryvw Perryvw left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, looks good! I only have some minor comments.

Comment thread test/unit/language-extensions/multi.spec.ts
Comment thread test/unit/language-extensions/multi.spec.ts Outdated
export {a, b};
`
.setOptions(multiProjectOptions)
.expectToEqual({ b: [] });

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also check the value of a here? (should be undefined)

`
.setOptions(multiProjectOptions)
.expectToEqual({ a: 1, b: [2, 3] });
util.testModule`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests should only test one thing, could you split this second testModule into a second test("Destructuring assignment of LuaMultiReturn returning nil", () => {

@Perryvw
Perryvw merged commit b84686f into TypeScriptToLua:master Mar 6, 2021
@yancouto
yancouto deleted the multi-return-995 branch March 7, 2021 00:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug when destructuring a result directly.

2 participants