-
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 handling of parameters that are function calls #4427
[CS2] Fix handling of parameters that are function calls #4427
Conversation
…the function body
…to follow usual ES idiom
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 have a little question, but I don't think it should hold up a merge.
@@ -1945,7 +1945,7 @@ exports.Code = class Code extends Base | |||
# encountered, add these other parameters to the list to be output in | |||
# the function definition. | |||
else | |||
if param.isComplex() | |||
if param.isComplex() or param.isCall() |
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.
So a call does not count as "complex"? What happens if we change .isComplex()
to also check for calls instead?
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 just couldn’t remember what isComplex
meant 😄 But I did remember that we documented it here, which says:
If
node.isComplex() is false
, it is safe to usenode
more than once. Otherwise you need to store the value ofnode
in a variable and output that variable several times instead. Kind of like this:5
is not complex.returnFive()
is complex. It’s all about “do we need to cache this expression?”
So there it is—returnFive()
is exactly our use case. Thanks for the suggestion!
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.
Nice!
…ed-parameter-evaluation-order
@@ -2110,7 +2112,7 @@ exports.Param = class Param extends Base | |||
@reference = node | |||
|
|||
isComplex: -> | |||
@name.isComplex() | |||
@name.isComplex() or (@value? and @value instanceof Call) |
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.
Bit of a nit-pick but the check for @value?
is redundant (@value instanceof Call
doesn't depend on the existence of @value
).
Neat fix 👍 made one small change request 😄 |
That's a really good idea! However, I'm sure there's one or two places where |
@@ -2110,7 +2112,7 @@ exports.Param = class Param extends Base | |||
@reference = node | |||
|
|||
isComplex: -> | |||
@name.isComplex() | |||
@name.isComplex() or @value instanceof Call |
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.
Ugh, pity I didn't think of this sooner: this should probably just be @name.isComplex() or @value.isComplex()
, the following is still broken:
i = 0
({ a = ++i }, b = ++i) ->
It generates:
// Generated by CoffeeScript 2.0.0-alpha
var i;
i = 0;
(function(arg, b = ++i) { // 'b' will be set first (b === 1)
var a, ref;
a = (ref = arg.a) != null ? ref : ++i; // 'a' will be set second (a === 2)
});
Fixes #4406. Also revises output of generator functions to be
function*
rather thanfunction *
, to follow accepted idiom.@connec, any notes?