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: babel-plugin-proposal-function-bind: ts-ignore #14707
fix: babel-plugin-proposal-function-bind: ts-ignore #14707
Conversation
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/52429/ |
Could you add a test? |
Test for what exactly? This is more like refactoring to fix TypeScript errors, this cases already tested in |
Ah, I mistakenly thought this was a bug fix. |
return bind.object; | ||
} | ||
|
||
t.assertMemberExpression(bind.callee); |
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.
Q: Does Babel parser ensures that bind.callee
is always a member expression? If so we can remove the runtime assertion and just cast bind.callee
as a member expression. Or we refine the AST types so that bind.callee must be a member expression.
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.
Yes, babel-parser
ensures that, if no bind.object
exists, this is expression like:
::console.log
And it cannot contain any other Expression
or Babel parser throws:
Binding should be performed on object property. (1:2)
This check is needed for TypeScript, since it can infer types without it.
If you just remove the comment line:
// @ts-ignore Fixme: should check bind.callee type first
So the purpose of PR is making TypeScript happy and removing a Fixme
comment :). I agree that everything works good without this check either but, additional check makes code little bit more clear since function bind has two cases of work that supported by Babel (according to current implementation), as I wrote on the beginning.
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.
Looks good, I'm in favor of changing the definition of ast, as long as it doesn't compromise compatibility.
9184945
to
88d11d1
Compare
Fixes #1, Fixes #2
ts-ignore
Get rid of
ts-ignore
inbabel-plugin-proposal-function-bind
. AddedisMemberExpression
check, since when there is noobject
,callee
ofBindExpression
is AlwaysMemberExpression
, otherwise we see:for such code:
So it should always used as
MemberExpression
:And produce:
In cases when we have
object
:console::log
We have such signature:
And both
callee
andobject
can be anyExpression
.