Skip to content

Commit

Permalink
Immediately destructure out propVariables rather than using it as a n…
Browse files Browse the repository at this point in the history
…amespace
  • Loading branch information
golopot committed Jun 12, 2019
1 parent 3a1a0d1 commit 9a63e19
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/util/usedPropTypes.js
Expand Up @@ -39,7 +39,7 @@ function createPropVariables() {
if (!hasBeenWritten) {
// copy on write
propVariables = new Map(propVariables);
Object.assign(stack[stack.length - 1], { propVariables, hasBeenWritten: true });
Object.assign(stack[stack.length - 1], {propVariables, hasBeenWritten: true});
stack[stack.length - 1].hasBeenWritten = true;
}
return propVariables.set(name, allNames);
Expand Down Expand Up @@ -271,6 +271,8 @@ module.exports = function usedPropTypesInstructions(context, components, utils)
const checkAsyncSafeLifeCycles = versionUtil.testReactVersion(context, '16.3.0');

const propVariables = createPropVariables();
const pushScope = propVariables.pushScope;
const popScope = propVariables.popScope;

/**
* Mark a prop type as used
Expand Down Expand Up @@ -422,7 +424,7 @@ module.exports = function usedPropTypesInstructions(context, components, utils)
* FunctionDeclaration, or FunctionExpression
*/
function handleFunctionLikeExpressions(node) {
propVariables.pushScope();
pushScope();
handleSetStateUpdater(node);
markDestructuredFunctionArgumentsAsUsed(node);
}
Expand Down Expand Up @@ -497,11 +499,11 @@ module.exports = function usedPropTypesInstructions(context, components, utils)

FunctionExpression: handleFunctionLikeExpressions,

'FunctionDeclaration:exit': propVariables.popScope,
'FunctionDeclaration:exit': popScope,

'ArrowFunctionExpression:exit': propVariables.popScope,
'ArrowFunctionExpression:exit': popScope,

'FunctionExpression:exit': propVariables.popScope,
'FunctionExpression:exit': popScope,

JSXSpreadAttribute(node) {
const component = components.get(utils.getParentComponent());
Expand Down

0 comments on commit 9a63e19

Please sign in to comment.