-
Notifications
You must be signed in to change notification settings - Fork 2k
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
[CS2] Alternative destructuring #4479
Conversation
This dramatically improves the appearance of destructured imports.
So . . . multiple people working in isolation is frustrating, to say the least. I started my branch over a month ago and I thought I had advertised it widely enough . . . anyway let’s try to avoid duplication of effort going forward? I like your approach. It seems a lot cleaner than trying to rework I think the next step would be to merge my branch into yours, or more precisely to merge into yours what few improvements I’ve made that you haven’t. Have you implemented default values yet? I’ve only implemented for the simplest cases in I’ve also started to update the non-ES-output paths of There’s also GeoffreyBooth#4, which tackles object spreads. So we have some merging to do. Do you mind if we move the work into my repo, since I’ve already given everyone access to it? And we can base it off of your branch if you think that makes more sense than refactoring my branch. |
@GeoffreyBooth sure, if you put the branch where you want it I can pick it up from there. Sorry about the duplicated work. I had the idea for how to handle destructuring ages ago but didn't have time to act on it until recently, and I wasn't too aware of what else was going on. My bad! What I've done doesn't cover defaults values, but I think they should be handle-able in the same way. The other case that would be nice to cover would be destructured parameters - again I think it should be possible to get the existing machinery to do most of the work. There quite a few improvements that could be made to |
I’ll move some branches around tonight when I get home. Do you mind taking a look at what I’ve done for default values? (Search for What are destructured parameters? |
@connec I renamed my branch to Closing this PR since now your branch is the source for #4478. Let’s continue the discussion over there. |
I'll take another look tonight. The main approach I'm going for is to use as much of the existing machinery as possible. If you look at the nodes for destructured expressions they look like they should just about compile verbatim, and it's only guard logic in For compiling default values, I was planning to just leverage the existing node structure, e.g. $ echo '{ a = 1 }' | bin/coffee -bns
Block
Assign
Value
Obj
Assign
Value IdentifierLiteral: a
Value NumberLiteral: 1
Value IdentifierLiteral: b We should be able to tweak By destructured parameters I just mean e.g. (function(arg) {
var a
({a} = arg);
}); ...but could be compiled to (function({a}) {
}); Again, I suspect there's some small logic tweak we could make to the parameter handling to make them compile more things in-line. |
Sorry @GeoffreyBooth, I'd started working on a destructuring branch with a slightly different approach! Maybe there are some things in it that might be useful.
For comparison, my goal was to reuse as much of the compilation of
Arr
andObj
as possible. The main change is making themisAssignable
and adding aneachName
method for extracting variable names.Currently, the whole assignment will bail if any entry is a special CS assignable such as default arguments, non-final splats, or soaked values. If I keep going it would be to refactor
compilePatternMatch
to only deal with these special cases, and otherwise delegate back intoAssign
.