-
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] Fix #4631: Expansion that becomes rest parameter causes runtime error #4634
Conversation
LGTM. @helixbass? @connec? |
My only suggestion is to add a regression test. Also, does |
29e1720
to
3d5f8ec
Compare
@connec Tests are added. Detection of the implicit call with dots on the left is improved as I also found few margin error cases, i.e. |
src/rewriter.coffee
Outdated
@@ -267,7 +267,8 @@ exports.Rewriter = class Rewriter | |||
# Added support for spread dots on the left side: f ...a | |||
if (tag in IMPLICIT_FUNC and token.spaced or | |||
tag is '?' and i > 0 and not tokens[i - 1].spaced) and | |||
(nextTag in IMPLICIT_CALL or nextTag is '...' or | |||
(nextTag in IMPLICIT_CALL or | |||
(nextTag is '...' and @tag(i + 2) in IMPLICIT_CALL and not @findTagsBackwards(i, ['INDEX_START', '['])) or |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zdenko why and @tag(i + 2) in IMPLICIT_CALL
? Seems a little arbitrary and tests don't fail without it
Also there's trailing whitespace in the preceding line. I'd recommend setting up your editor to highlight trailing whitespace so it's obvious
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@helixbass tests don't fail because there are no many tests for spred dots on the left side.
@tag(i +2)
is needed to catch cases like { a:1, b ... }
(note the space after the b
).
In this case tag
(b) is in IMPLICIT_FUNC
and nextTag
is ...
, so I need to check@tag (i + 2)
. Otherwise, the rewriter
will compile this into
[IDENTIFIER b] [CALL_START (] [... ...] [CALL_END )]
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should add a test for it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking the same, but I'm not sure what would be a better option: a) put all tests for spread dots in one file, or b) add test cases in files (e.g. arrays
, assignment
, functions
,...).
Basically, we need to cover all cases with spread dots preceding by space:
{ a: 1, b ... }
{
a:1
b ...
}
f = (a ...) ->
[
a
b ...
]
I would opt for option (a).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess with the current test layout you'd need to put some in:
arrays
(array spreads)assignment
(array/object rest destructuring)functions
(argument rest arguments)function_invocation
(spread arguments)objects
(object spreads) - though there are no object spread tests there currently?ranges
(disambiguating spreads from ranges)slicing_and_splicing
(disambiguating spreads from slices and splices)
That is quite spread out, but probably the easiest thing to do for now. We may want a new rests_and_spreads
test file where we can move all the rest/spread tests so all these cases are in one place.
@helixbass or @connec, any further notes? |
@GeoffreyBooth my comment still stands. No tests fail when removing My comment was largely prompted by it seeming like using |
@GeoffreyBooth, @helixbass I'm preparing tests for these cases. It shouldn't take much longer. |
d6b7695
to
91b2b0d
Compare
91b2b0d
to
a4dde9c
Compare
@zdenko thanks for all the extra tests! What about @helixbass’ comment above, about not needing Also do you mind taking a look at #4260? It seems possibly related to this. |
@GeoffreyBooth new tests are cases for obj = {a:1, p ..., b:2}
({
a: p
b
r ...
}) -> In these cases, You might also try these in the current branch:
Perhaps I didn't explain the need for f ... a # f(...a)
f() ... b # f()(...b)
f? ... c # if (typeof f === "function") { f(...c) }
h[0] ... d # h[0](...d) I don't think there were any test cases before with space before/after the dots, so this is the reason no test failed. |
@helixbass what do you think? This is the last PR holding up 2.0.0. |
@zdenko @GeoffreyBooth ok I see how it's being used. It's really the set of tokens that can start something that comes after a left- Found another object spread destructuring bug and just opened as #4651 so probably want to fix that too before 2.0.0? |
Thanks for that other ticket @helixbass. In the interest of taking one thing at a time, do you think we can merge this PR in? And #4651 can get its own PR. |
@GeoffreyBooth ya I didn't mean to imply that this should wait, they're unrelated |
Closes #4631.
After added support for the spread dots on the left side, dots in array slice, e.g. (
[a...b]
) were misinterpreted and the code was compiled to an implicit call. The error occurred when there was a space around the dots.Example: