-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Keep original function name when renaming scoped functions #5537
Conversation
@aaronang, thanks for your PR! By analyzing the history of the files in this pull request, we identified @hzoo, @existentialism and @loganfsmyth to be potential reviewers. |
Codecov Report
@@ Coverage Diff @@
## 7.0 #5537 +/- ##
==========================================
- Coverage 85.49% 85.47% -0.02%
==========================================
Files 200 200
Lines 9506 9507 +1
Branches 2701 2701
==========================================
- Hits 8127 8126 -1
- Misses 883 885 +2
Partials 496 496
Continue to review full report at Codecov.
|
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.
It might be better to patch the Renamer
class to preserve the name instead.
But regardless of how it is done, there is a problem with assigning the function to a var -- it's no longer hoisted 😕
_blockHoist
hacks may be needed 😢
@@ -140,8 +140,7 @@ export default function ({ node, parent, scope, id }) { | |||
if (t.isIdentifier(id)) { | |||
const binding = scope.parent.getBinding(id.name); | |||
if (binding && binding.constant && scope.getBinding(id.name) === binding) { | |||
// always going to reference this method | |||
node.id = id; | |||
node.id = Object.assign({}, id, { name: id.loc.identifierName }); |
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 think you can use object spread here ({ ...id, name: id.loc.identifierName }
)
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.
there is t.clone(id)
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/4777/ |
1 similar comment
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/4777/ |
I'm triaging old PR on Babel. Since this has been inactive for ages, I'm going to close it. Feel free to re-open if you think it is worth pursuing still, but I'm assuming at this point feedback won't be that useful, and it'll still be here as a reference for the issue you're trying to fix. |
I don't really know what the consequences are of this change. So, I am looking forward to receiving feedback.