You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Updating the babel plugin to handle the new syntax was a bit tricky.
invariant was also originally not part of the scope, but because the plugin that validated arguments to warning also expected invariant to have the same interface, I had to choose between forking the plugin or also transforming invariant.
Some of the expressions may look funny; they were generated by this codemod:
'use strict';module.exports=functiontransformer(file,api){constj=api.jscodeshift;returnj(file.source).find(j.CallExpression).filter(path=>{constcallee=path.value.callee;if(callee.type!=='Identifier'){returnfalse;}constname=callee.name;constscope=path.scope.lookup(name);return(// "isGlobal" just means file scope, even in Modules(scope===null||scope.isGlobal)&&(name==='warning'||name==='warningWithoutStack'||name==='lowPriorityWarning'||name==='lowPriorityWarningWithoutStack'||name==='invariant'));}).forEach(path=>{constfirstArgument=path.value.arguments[0];if(firstArgument.type==='StringLiteral'){// already transformed?return;}if(firstArgument.type==='Literal'){if(firstArgument.value){if(path.parentPath.value.type==='ExpressionStatement'){path.prune();}else{path.replace(j.identifier('undefined'));}return;}path.value.arguments.shift();return;}path.value.arguments.shift();if(path.parentPath.value.type==='ExpressionStatement'){returnpath.parentPath.replace(j.ifStatement(j.unaryExpression('!',firstArgument),j.blockStatement([path.parentPath.node])));}else{returnpath.replace(j.sequenceExpression([j.logicalExpression('||',firstArgument,path.node),j.identifier('undefined'),]));}}).toSource();};
invariant was also originally not part of the scope, but because the plugin that validated arguments to warning also expected invariant to have the same interface, I had to choose between forking the plugin or also transforming invariant.
Can you please fork the plugin instead? We have separate plans to replace those with throw Error expressions in the source and I'd rather not update those callsites twice.
I personally hate the wrap-warning-with-env-check transform. Can we make an eslint rule instead of relying on a babel plugin to do it for us? The end game is to get to writing console.error directly.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part 2 of #16753
Updating the babel plugin to handle the new syntax was a bit tricky.
invariant
was also originally not part of the scope, but because the plugin that validated arguments towarning
also expectedinvariant
to have the same interface, I had to choose between forking the plugin or also transforminginvariant
.Some of the expressions may look funny; they were generated by this codemod: