Skip to content

Commit 9a63e19

Browse files
committed
Immediately destructure out propVariables rather than using it as a namespace
1 parent 3a1a0d1 commit 9a63e19

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

lib/util/usedPropTypes.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function createPropVariables() {
3939
if (!hasBeenWritten) {
4040
// copy on write
4141
propVariables = new Map(propVariables);
42-
Object.assign(stack[stack.length - 1], { propVariables, hasBeenWritten: true });
42+
Object.assign(stack[stack.length - 1], {propVariables, hasBeenWritten: true});
4343
stack[stack.length - 1].hasBeenWritten = true;
4444
}
4545
return propVariables.set(name, allNames);
@@ -271,6 +271,8 @@ module.exports = function usedPropTypesInstructions(context, components, utils)
271271
const checkAsyncSafeLifeCycles = versionUtil.testReactVersion(context, '16.3.0');
272272

273273
const propVariables = createPropVariables();
274+
const pushScope = propVariables.pushScope;
275+
const popScope = propVariables.popScope;
274276

275277
/**
276278
* Mark a prop type as used
@@ -422,7 +424,7 @@ module.exports = function usedPropTypesInstructions(context, components, utils)
422424
* FunctionDeclaration, or FunctionExpression
423425
*/
424426
function handleFunctionLikeExpressions(node) {
425-
propVariables.pushScope();
427+
pushScope();
426428
handleSetStateUpdater(node);
427429
markDestructuredFunctionArgumentsAsUsed(node);
428430
}
@@ -497,11 +499,11 @@ module.exports = function usedPropTypesInstructions(context, components, utils)
497499

498500
FunctionExpression: handleFunctionLikeExpressions,
499501

500-
'FunctionDeclaration:exit': propVariables.popScope,
502+
'FunctionDeclaration:exit': popScope,
501503

502-
'ArrowFunctionExpression:exit': propVariables.popScope,
504+
'ArrowFunctionExpression:exit': popScope,
503505

504-
'FunctionExpression:exit': propVariables.popScope,
506+
'FunctionExpression:exit': popScope,
505507

506508
JSXSpreadAttribute(node) {
507509
const component = components.get(utils.getParentComponent());

0 commit comments

Comments
 (0)