X Tutup
Skip to content

Intermediate SpreadElements fix#832

Merged
Perryvw merged 23 commits intoTypeScriptToLua:masterfrom
hazzard993:smarter-spreading
Mar 15, 2020
Merged

Intermediate SpreadElements fix#832
Perryvw merged 23 commits intoTypeScriptToLua:masterfrom
hazzard993:smarter-spreading

Conversation

@hazzard993
Copy link
Contributor

@hazzard993 hazzard993 commented Feb 27, 2020

Fixes #696

- before
+ after

- [1, ...[2, 3], 4] // --> { 1, 2, 4 }
+ [1, ...[2, 3], 4] // --> { 1, 2, 3, 4 }

- ((...values) => values)(1, ...[2, 3], 4) // --> { 1, 2, 4 }
+ ((...values) => values)(1, ...[2, 3], 4) // --> { 1, 2, 3, 4 }

Uses ArrayConcat only when necessary to replicate TS behavior

[1, ...[2, 3], 4, ...[5, 6]]
    ~~~~~~~~~~~~~~~~~~~~~~~
Using Array.concat here

[1, [2, 3], 4]

Array.concat not needed

[1, ...[2, 3]]

Array.concat not needed


// Only one spread element at the end? Will work as expected
const [firstExpression] = postSpreadExpressions;
if (postSpreadExpressions.length === 1 && ts.isSpreadElement(firstExpression)) {
Copy link
Member

Choose a reason for hiding this comment

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

isn't ts.isSpreadElement(firstExpression) always true by definition of getExpressionsBeforeAndAfterFirstSpread?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

true, that can be refactored

`.expectToMatchJsResult();
});

test("of string literal mixed", () => {
Copy link
Member

Choose a reason for hiding this comment

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

What's mixed about this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to just of string literal

@Perryvw Perryvw requested a review from ark120202 March 8, 2020 11:04
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.

Array spread shouldn't use unpack

3 participants

X Tutup