-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Fix Function.prototype.apply.bind #7879
base: main
Are you sure you want to change the base?
Changes from 2 commits
1ec4772
e0a50e9
17225b0
f99e5f5
12429f3
1d65d5c
25594b3
981f523
c56ab68
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -852,9 +852,12 @@ let rec convert cx tparams_map = Ast.Type.(function | |
) | ||
|
||
| "Function$Prototype$Apply" -> | ||
check_type_arg_arity cx loc t_ast targs 0 (fun () -> | ||
let reason = mk_reason RFunctionType loc in | ||
reconstruct_ast (FunProtoApplyT reason) None | ||
let reason = mk_reason RFunctionType loc in | ||
(match convert_type_params () with | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think this is the only place we'd allow a sometimes-parameterized generic. the most similar concept is having a default, but in that case you'd have to use an empty this feels like a new behavior that we should consider carefully. also, we should consider how it interacts with annotating There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like first one because it mirrors TypeScript There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How can I make this support There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mroch you can mimic second one with first one |
||
| [t], targs -> | ||
reconstruct_ast (FunProtoApplyT (reason, Some t)) targs | ||
| _, targs -> | ||
reconstruct_ast (FunProtoApplyT (reason, None)) targs | ||
) | ||
|
||
| "Function$Prototype$Bind" -> | ||
|
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.
This doesn't look right. Look at the
FunT _, BindT _
rule for guidance.call_this_t
field of theBindT
use is the this type corresponding to the call of bind. E.g.,x
inx.bind(...)
. You want the first argument instead.FunT _, BindT _
as a guide, you'll notice some complexity missing from here. Specifically, the constraints involvingResolveSpreadsToMultiflowPartial
. This is needed to figure out the full argument list in the presence of spread arguments.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.
What first argument? This is forwarding From
to
$Function$Prototype$Apply<typeof fn>
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.
If you write a test, I think you will see what I mean. You want the first argument passed to the bind call, which is not
call_this_t
.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.
Ah, sorry, my mistake -- I was confusing BindT with FunProtoBindT. You're right that
call_this_t
is the first parameter.You do still need to do something with
call_args_tlist
, though.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.
You mean something like this?
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.
@samwgoldman I think you were right 😀
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.
@samwgoldman would this mean adding second argument with applied parameters? I think one argument is already too much