Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Emit array spreads using the native es array spread syntax #7034

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

zth
Copy link
Collaborator

@zth zth commented Sep 12, 2024

Builds on @cometkim work in #7030 to also have array spreads be emitted as actual ES array spreads.

Example:

let x = [1, 2, 3]
let y = [...x, 4, 5, 6]

Outputs:

let x = [
  1,
  2,
  3
];

let y = [
  ...x,
  4,
  5,
  6
];

2 issues that needs to be fixed currently:

  • Can't use pipes for some reason when spreading an expression. Probably need to special case the first pipe for it to work. Will add a failing test.
  • Comments seem broken, they get output in the wrong location as it's reformatted. Probably missing something obvious.
  • Something changed in the list concat syntax output. Need to investigate. Actually I just misread this, the change looks fine.

Comment on lines +2 to +3
let x = [1, 2, 3, ...Js.Array2.map(xx, v => v * 2)]
let y = [...x, 4, 5, ...x, 6, ...x->Js.Array2.map(v => v * 2)]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Top Js.Array2.map works (no pipe), but bottom does not (using pipes). @cristianoc got any spontaneous ideas about this?

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.

1 participant