-
-
Notifications
You must be signed in to change notification settings - Fork 1
Conversation
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.
Oh interesting - It's been a while! 😅
Good call with still wrapping the statements in a block to avoid variable colissions! Not sure but didn't we add some way for transformers to write something to the CLI if they actually changed stuff? Maybe we should add a message that folks should clean this up?
So I looked some more into this, and added a special handling for when there is only a single statement - in this case, we can rewrite it nicer: configureScope((scope) => {
scope.setTag('xx', 'yy');
}); becomes getCurrentScope().setTag('xx', 'yy'); Which is much nicer! I found another edge case though I also need to handle, which is |
|
||
// Very hacky, but we check if the callee (e.g. hub.configureScope() or getCurrentHub().configureScope()) | ||
// contains "hub", and if so, we use `getScope()` instead of `getCurrentScope()` | ||
let getScopeMethodName = /hub/i.test(j(calleeObj).toSource()) ? 'getScope' : 'getCurrentScope'; |
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.
@Lms24 I added this somewhat hacky check, but I think it should work well enough...
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, it has to be
getScope()
instead ofgetCurrentScope()
😬
Are we adding another transformer to replace getCurrentHub().getScope()
with getCurrentScope()
?
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.
Yeah, figured that too - we should also do that then! But I guess that will be a general getCurrentHub()
transformer that rewrites that to all the new/global APIs instead!
if (callbackBody.type !== 'BlockStatement') { | ||
return; | ||
} |
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 about configureScope(scope => scope.setTag(...))
?
|
||
// Very hacky, but we check if the callee (e.g. hub.configureScope() or getCurrentHub().configureScope()) | ||
// contains "hub", and if so, we use `getScope()` instead of `getCurrentScope()` | ||
let getScopeMethodName = /hub/i.test(j(calleeObj).toSource()) ? 'getScope' : 'getCurrentScope'; |
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, it has to be
getScope()
instead ofgetCurrentScope()
😬
Are we adding another transformer to replace getCurrentHub().getScope()
with getCurrentScope()
?
OK, I think I fix all/most edge cases - ran it on the monorepo, and it seemed good to me - no false positives anymore, at least! |
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! 🚀
Rewrites usages of
configureScope()
to usegetCurrentScope()
instead. Note that this will rewrite this to codeblocks, which may not be the preferred syntax in all cases, but it's the only way to make this work somewhat reliably
with avoiding variable clashes etc.
This will rewrite:
to