Socket
Socket
Sign inDemoInstall

react-refresh

Package Overview
Dependencies
0
Maintainers
7
Versions
1645
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.4.0 to 0.4.1

252

cjs/react-refresh-babel.development.js

@@ -22,3 +22,4 @@ /** @license React vundefined

var env = babel.getEnv();
if (env !== 'development') {
if (env !== 'development' && typeof expect !== 'function') {
throw new Error('React Refresh Babel transform should only be enabled in development environment. ' + 'Instead, the environment is: "' + env + '".');

@@ -29,10 +30,11 @@ }

var t = babel.types;
var registrationsByProgramPath = new Map();
var registrationsByProgramPath = new Map();
function createRegistration(programPath, persistentID) {
var handle = programPath.scope.generateUidIdentifier('c');
if (!registrationsByProgramPath.has(programPath)) {
registrationsByProgramPath.set(programPath, []);
}
var registrations = registrationsByProgramPath.get(programPath);

@@ -52,2 +54,3 @@ registrations.push({

var node = path.node;
switch (node.type) {

@@ -58,8 +61,10 @@ case 'Identifier':

return false;
}
// export default hoc(Foo)
} // export default hoc(Foo)
// const X = hoc(Foo)
callback(inferredName, node, null);
return true;
}
case 'FunctionDeclaration':

@@ -73,2 +78,3 @@ {

}
case 'ArrowFunctionExpression':

@@ -78,8 +84,10 @@ {

return false;
}
// let Foo = () => {}
} // let Foo = () => {}
// export default hoc1(hoc2(() => {}))
callback(inferredName, node, path);
return true;
}
case 'FunctionExpression':

@@ -93,9 +101,13 @@ {

}
case 'CallExpression':
{
var argsPath = path.get('arguments');
if (argsPath === undefined || argsPath.length === 0) {
return false;
}
var calleePath = path.get('callee');
switch (calleePath.node.type) {

@@ -109,10 +121,13 @@ case 'MemberExpression':

var foundInside = findInnerComponents(innerName, firstArgPath, callback);
if (!foundInside) {
return false;
}
// const Foo = hoc1(hoc2(() => {}))
} // const Foo = hoc1(hoc2(() => {}))
// export default memo(React.forwardRef(function() {}))
callback(inferredName, node, path);
return true;
}
default:

@@ -124,12 +139,17 @@ {

}
case 'VariableDeclarator':
{
var init = node.init;
if (init === null) {
return false;
}
var name = node.id.name;
if (!isComponentishName(name)) {
return false;
}
switch (init.type) {

@@ -140,2 +160,3 @@ case 'ArrowFunctionExpression':

break;
case 'CallExpression':

@@ -147,2 +168,3 @@ {

var calleeType = callee.type;
if (calleeType === 'Import') {

@@ -155,7 +177,6 @@ return false;

return false;
}
// Neither require nor import. Might be a HOC.
} // Neither require nor import. Might be a HOC.
// Pass through.
} else if (calleeType === 'MemberExpression') {
// Could be something like React.forwardRef(...)
} else if (calleeType === 'MemberExpression') {// Could be something like React.forwardRef(...)
// Pass through.

@@ -166,28 +187,41 @@ } else {

}
break;
}
case 'TaggedTemplateExpression':
// Maybe something like styled.div`...`
break;
default:
return false;
}
var initPath = path.get('init');
var _foundInside = findInnerComponents(inferredName, initPath, callback);
if (_foundInside) {
return true;
}
// See if this identifier is used in JSX. Then it's a component.
} // See if this identifier is used in JSX. Then it's a component.
var binding = path.scope.getBinding(name);
if (binding === undefined) {
return;
}
var isLikelyUsedAsType = false;
var referencePaths = binding.referencePaths;
for (var i = 0; i < referencePaths.length; i++) {
var ref = referencePaths[i];
if (ref.node.type !== 'JSXIdentifier' && ref.node.type !== 'Identifier') {
continue;
}
var refParent = ref.parent;
if (refParent.type === 'JSXOpeningElement') {

@@ -198,2 +232,3 @@ isLikelyUsedAsType = true;

var fnName = void 0;
switch (_callee.type) {

@@ -203,2 +238,3 @@ case 'Identifier':

break;
case 'MemberExpression':

@@ -208,2 +244,3 @@ fnName = _callee.property.name;

}
switch (fnName) {

@@ -218,2 +255,3 @@ case 'createElement':

}
if (isLikelyUsedAsType) {

@@ -227,2 +265,3 @@ // const X = ... + later <X />

}
return false;

@@ -254,2 +293,3 @@ }

return true;
default:

@@ -262,5 +302,7 @@ return false;

var fnHookCalls = hookCalls.get(functionNode);
if (fnHookCalls === undefined) {
return null;
}
return {

@@ -278,8 +320,8 @@ key: fnHookCalls.map(function (call) {

var hasForceResetCommentByFile = new WeakMap();
var hasForceResetCommentByFile = new WeakMap(); // We let user do /* @refresh reset */ to reset state in the whole file.
// We let user do /* @refresh reset */ to reset state in the whole file.
function hasForceResetComment(path) {
var file = path.hub.file;
var hasForceReset = hasForceResetCommentByFile.get(file);
if (hasForceReset !== undefined) {

@@ -291,4 +333,6 @@ return hasForceReset;

var comments = file.ast.comments;
for (var i = 0; i < comments.length; i++) {
var cmt = comments[i];
if (cmt.value.indexOf('@refresh reset') !== -1) {

@@ -307,4 +351,2 @@ hasForceReset = true;

customHooks = signature.customHooks;
var forceReset = hasForceResetComment(scope.path);

@@ -314,3 +356,4 @@ var customHooksInScope = [];

// Check if a corresponding binding exists where we emit the signature.
var bindingName = void 0;
var bindingName;
switch (callee.type) {

@@ -321,3 +364,5 @@ case 'MemberExpression':

}
break;
case 'Identifier':

@@ -327,2 +372,3 @@ bindingName = callee.name;

}
if (scope.hasBinding(bindingName)) {

@@ -336,13 +382,14 @@ customHooksInScope.push(callee);

});
var args = [node, t.stringLiteral(key)];
var args = [node, t.stringLiteral(key)];
if (forceReset || customHooksInScope.length > 0) {
args.push(t.booleanLiteral(forceReset));
}
if (customHooksInScope.length > 0) {
args.push(
// TODO: We could use an arrow here to be more compact.
args.push( // TODO: We could use an arrow here to be more compact.
// However, don't do it until AMA can run them natively.
t.functionExpression(null, [], t.blockStatement([t.returnStatement(t.arrayExpression(customHooksInScope))])));
}
return args;

@@ -354,3 +401,2 @@ }

var seenForOutro = new WeakSet();
var hookCalls = new WeakMap();

@@ -360,8 +406,7 @@ var HookCallsVisitor = {

var node = path.node;
var callee = node.callee;
// Note: this visitor MUST NOT mutate the tree in any way.
var callee = node.callee; // Note: this visitor MUST NOT mutate the tree in any way.
// It runs early in a separate traversal and should be very fast.
var name = null;
switch (callee.type) {

@@ -371,2 +416,3 @@ case 'Identifier':

break;
case 'MemberExpression':

@@ -376,24 +422,31 @@ name = callee.property.name;

}
if (name === null || !/^use[A-Z]/.test(name)) {
return;
}
var fnScope = path.scope.getFunctionParent();
if (fnScope === null) {
return;
}
} // This is a Hook call. Record it.
// This is a Hook call. Record it.
var fnNode = fnScope.block;
if (!hookCalls.has(fnNode)) {
hookCalls.set(fnNode, []);
}
var hookCallsForFn = hookCalls.get(fnNode);
var key = '';
if (path.parent.type === 'VariableDeclarator') {
// TODO: if there is no LHS, consider some other heuristic.
key = path.parentPath.get('id').getSource();
}
} // Some built-in Hooks reset on edits to arguments.
// Some built-in Hooks reset on edits to arguments.
var args = path.get('arguments');
if (name === 'useState' && args.length > 0) {

@@ -414,3 +467,2 @@ // useState second argument is initial state.

};
return {

@@ -422,2 +474,3 @@ visitor: {

var declPath = path.get('declaration');
if (decl.type !== 'CallExpression') {

@@ -429,12 +482,11 @@ // For now, we only support possible HOC calls here.

return;
}
} // Make sure we're not mutating the same tree twice.
// This can happen if another Babel plugin replaces parents.
// Make sure we're not mutating the same tree twice.
// This can happen if another Babel plugin replaces parents.
if (seenForRegistration.has(node)) {
return;
}
seenForRegistration.add(node);
// Don't mutate the tree above this point.
seenForRegistration.add(node); // Don't mutate the tree above this point.
// This code path handles nested cases like:

@@ -446,2 +498,3 @@ // export default memo(() => {})

// export default memo(function Named() {})
var inferredName = '%default%';

@@ -457,2 +510,3 @@ var programPath = path.parentPath;

}
var handle = createRegistration(programPath, persistentID);

@@ -462,8 +516,8 @@ targetPath.replaceWith(t.assignmentExpression('=', handle, targetExpr));

},
FunctionDeclaration: {
enter: function (path) {
var node = path.node;
var programPath = void 0;
var insertAfterPath = void 0;
var programPath;
var insertAfterPath;
switch (path.parent.type) {

@@ -474,2 +528,3 @@ case 'Program':

break;
case 'ExportNamedDeclaration':

@@ -479,2 +534,3 @@ insertAfterPath = path.parentPath;

break;
case 'ExportDefaultDeclaration':

@@ -484,6 +540,9 @@ insertAfterPath = path.parentPath;

break;
default:
return;
}
var id = node.id;
if (id === null) {

@@ -493,17 +552,19 @@ // We don't currently handle anonymous default exports.

}
var inferredName = id.name;
if (!isComponentishName(inferredName)) {
return;
}
} // Make sure we're not mutating the same tree twice.
// This can happen if another Babel plugin replaces parents.
// Make sure we're not mutating the same tree twice.
// This can happen if another Babel plugin replaces parents.
if (seenForRegistration.has(node)) {
return;
}
seenForRegistration.add(node);
// Don't mutate the tree above this point.
seenForRegistration.add(node); // Don't mutate the tree above this point.
// export function Named() {}
// function Named() {}
findInnerComponents(inferredName, path, function (persistentID, targetExpr) {

@@ -517,18 +578,21 @@ var handle = createRegistration(programPath, persistentID);

var id = node.id;
if (id === null) {
return;
}
var signature = getHookCallsSignature(node);
if (signature === null) {
return;
}
} // Make sure we're not mutating the same tree twice.
// This can happen if another Babel plugin replaces parents.
// Make sure we're not mutating the same tree twice.
// This can happen if another Babel plugin replaces parents.
if (seenForSignature.has(node)) {
return;
}
seenForSignature.add(node);
// Don't mutate the tree above this point.
seenForSignature.add(node); // Don't mutate the tree above this point.
var sigCallID = path.scope.generateUidIdentifier('_s');

@@ -538,14 +602,11 @@ path.scope.parent.push({

init: t.callExpression(t.identifier('$RefreshSig$'), [])
});
// The signature call is split in two parts. One part is called inside the function.
}); // The signature call is split in two parts. One part is called inside the function.
// This is used to signal when first render happens.
path.get('body').unshiftContainer('body', t.expressionStatement(t.callExpression(sigCallID, [])));
// The second call is around the function itself.
path.get('body').unshiftContainer('body', t.expressionStatement(t.callExpression(sigCallID, []))); // The second call is around the function itself.
// This is used to associate a type with a signature.
// Unlike with $RefreshReg$, this needs to work for nested
// declarations too. So we need to search for a path where
// we can insert a statement rather than hardcoding it.
var insertAfterPath = null;

@@ -558,2 +619,3 @@ path.find(function (p) {

});
if (insertAfterPath === null) {

@@ -570,14 +632,15 @@ return;

var signature = getHookCallsSignature(node);
if (signature === null) {
return;
}
} // Make sure we're not mutating the same tree twice.
// This can happen if another Babel plugin replaces parents.
// Make sure we're not mutating the same tree twice.
// This can happen if another Babel plugin replaces parents.
if (seenForSignature.has(node)) {
return;
}
seenForSignature.add(node);
// Don't mutate the tree above this point.
seenForSignature.add(node); // Don't mutate the tree above this point.
var sigCallID = path.scope.generateUidIdentifier('_s');

@@ -587,9 +650,10 @@ path.scope.parent.push({

init: t.callExpression(t.identifier('$RefreshSig$'), [])
});
// The signature call is split in two parts. One part is called inside the function.
}); // The signature call is split in two parts. One part is called inside the function.
// This is used to signal when first render happens.
path.get('body').unshiftContainer('body', t.expressionStatement(t.callExpression(sigCallID, [])));
// The second call is around the function itself.
if (path.node.body.type !== 'BlockStatement') {
path.node.body = t.blockStatement([t.returnStatement(path.node.body)]);
}
path.get('body').unshiftContainer('body', t.expressionStatement(t.callExpression(sigCallID, []))); // The second call is around the function itself.
// This is used to associate a type with a signature.

@@ -605,6 +669,6 @@

});
if (insertAfterPath === null) {
return;
}
// Special case when a function would get an inferred name:
} // Special case when a function would get an inferred name:
// let Foo = () => {}

@@ -614,8 +678,8 @@ // let Foo = function() {}

// we don't mess up the inferred 'Foo' function name.
insertAfterPath.insertAfter(t.expressionStatement(t.callExpression(sigCallID, createArgumentsForSignature(path.parent.id, signature, insertAfterPath.scope))));
// Result: let Foo = () => {}; __signature(Foo, ...);
insertAfterPath.insertAfter(t.expressionStatement(t.callExpression(sigCallID, createArgumentsForSignature(path.parent.id, signature, insertAfterPath.scope)))); // Result: let Foo = () => {}; __signature(Foo, ...);
} else {
// let Foo = hoc(() => {})
path.replaceWith(t.callExpression(sigCallID, createArgumentsForSignature(node, signature, path.scope)));
// Result: let Foo = hoc(__signature(() => {}, ...))
path.replaceWith(t.callExpression(sigCallID, createArgumentsForSignature(node, signature, path.scope))); // Result: let Foo = hoc(__signature(() => {}, ...))
}

@@ -626,4 +690,5 @@ }

var node = path.node;
var programPath = void 0;
var insertAfterPath = void 0;
var programPath;
var insertAfterPath;
switch (path.parent.type) {

@@ -634,2 +699,3 @@ case 'Program':

break;
case 'ExportNamedDeclaration':

@@ -639,2 +705,3 @@ insertAfterPath = path.parentPath;

break;
case 'ExportDefaultDeclaration':

@@ -644,18 +711,21 @@ insertAfterPath = path.parentPath;

break;
default:
return;
}
} // Make sure we're not mutating the same tree twice.
// This can happen if another Babel plugin replaces parents.
// Make sure we're not mutating the same tree twice.
// This can happen if another Babel plugin replaces parents.
if (seenForRegistration.has(node)) {
return;
}
seenForRegistration.add(node);
// Don't mutate the tree above this point.
seenForRegistration.add(node); // Don't mutate the tree above this point.
var declPaths = path.get('declarations');
if (declPaths.length !== 1) {
return;
}
var declPath = declPaths[0];

@@ -671,3 +741,5 @@ var inferredName = declPath.node.id.name;

}
var handle = createRegistration(programPath, persistentID);
if ((targetExpr.type === 'ArrowFunctionExpression' || targetExpr.type === 'FunctionExpression') && targetPath.parent.type === 'VariableDeclarator') {

@@ -679,12 +751,9 @@ // Special case when a function would get an inferred name:

// we don't mess up the inferred 'Foo' function name.
insertAfterPath.insertAfter(t.expressionStatement(t.assignmentExpression('=', handle, declPath.node.id)));
// Result: let Foo = () => {}; _c1 = Foo;
insertAfterPath.insertAfter(t.expressionStatement(t.assignmentExpression('=', handle, declPath.node.id))); // Result: let Foo = () => {}; _c1 = Foo;
} else {
// let Foo = hoc(() => {})
targetPath.replaceWith(t.assignmentExpression('=', handle, targetExpr));
// Result: let Foo = _c1 = hoc(() => {})
targetPath.replaceWith(t.assignmentExpression('=', handle, targetExpr)); // Result: let Foo = _c1 = hoc(() => {})
}
});
},
Program: {

@@ -700,15 +769,17 @@ enter: function (path) {

var registrations = registrationsByProgramPath.get(path);
if (registrations === undefined) {
return;
}
} // Make sure we're not mutating the same tree twice.
// This can happen if another Babel plugin replaces parents.
// Make sure we're not mutating the same tree twice.
// This can happen if another Babel plugin replaces parents.
var node = path.node;
if (seenForOutro.has(node)) {
return;
}
seenForOutro.add(node);
// Don't mutate the tree above this point.
seenForOutro.add(node); // Don't mutate the tree above this point.
registrationsByProgramPath.delete(path);

@@ -720,3 +791,2 @@ var declarators = [];

persistentID = _ref.persistentID;
path.pushContainer('body', t.expressionStatement(t.callExpression(t.identifier('$RefreshReg$'), [handle, t.stringLiteral(persistentID)])));

@@ -738,2 +808,4 @@ declarators.push(t.variableDeclarator(handle));

// This is hacky but makes it work with both Rollup and Jest.
var babel = ReactFreshBabelPlugin$2.default || ReactFreshBabelPlugin$2;

@@ -740,0 +812,0 @@

@@ -10,14 +10,14 @@ /** @license React vundefined

'use strict';function v(q){function r(a,b){var d=a.scope.generateUidIdentifier("c");l.has(a)||l.set(a,[]);l.get(a).push({handle:d,persistentID:b});return d}function t(a){return"string"===typeof a&&"A"<=a[0]&&"Z">=a[0]}function m(a,b,d){var c=b.node;switch(c.type){case "Identifier":if(!t(c.name))break;d(a,c,null);return!0;case "FunctionDeclaration":return d(a,c.id,null),!0;case "ArrowFunctionExpression":if("ArrowFunctionExpression"===c.body.type)break;d(a,c,b);return!0;case "FunctionExpression":return d(a,
c,b),!0;case "CallExpression":var f=b.get("arguments");if(void 0===f||0===f.length)break;var g=b.get("callee");switch(g.node.type){case "MemberExpression":case "Identifier":g=g.getSource();if(!m(a+"$"+g,f[0],d))return!1;d(a,c,b);return!0;default:return!1}case "VariableDeclarator":if(f=c.init,null!==f&&(g=c.id.name,t(g))){switch(f.type){case "ArrowFunctionExpression":case "FunctionExpression":break;case "CallExpression":c=f.callee;var e=c.type;if("Import"===e)return!1;if("Identifier"===e){if(0===c.name.indexOf("require")||
0===c.name.indexOf("import"))return!1}else if("MemberExpression"!==e)return!1;break;case "TaggedTemplateExpression":break;default:return!1}c=b.get("init");if(m(a,c,d))return!0;g=b.scope.getBinding(g);if(void 0===g)return;b=!1;g=g.referencePaths;for(e=0;e<g.length;e++){var h=g[e];if("JSXIdentifier"===h.node.type||"Identifier"===h.node.type){h=h.parent;if("JSXOpeningElement"===h.type)b=!0;else if("CallExpression"===h.type){h=h.callee;var k=void 0;switch(h.type){case "Identifier":k=h.name;break;case "MemberExpression":k=
h.property.name}switch(k){case "createElement":case "jsx":case "jsxDEV":case "jsxs":b=!0}}if(b)return d(a,f,c),!0}}}}return!1}function w(a){a=n.get(a);return void 0===a?null:{key:a.map(function(a){return a.name+"{"+a.key+"}"}).join("\n"),customHooks:a.filter(function(a){a:switch(a.name){case "useState":case "React.useState":case "useReducer":case "React.useReducer":case "useEffect":case "React.useEffect":case "useLayoutEffect":case "React.useLayoutEffect":case "useMemo":case "React.useMemo":case "useCallback":case "React.useCallback":case "useRef":case "React.useRef":case "useContext":case "React.useContext":case "useImperativeMethods":case "React.useImperativeMethods":case "useDebugValue":case "React.useDebugValue":a=
!0;break a;default:a=!1}return!a}).map(function(a){return e.cloneDeep(a.callee)})}}function C(a){a=a.hub.file;var b=x.get(a);if(void 0!==b)return b;b=!1;for(var d=a.ast.comments,c=0;c<d.length;c++)if(-1!==d[c].value.indexOf("@refresh reset")){b=!0;break}x.set(a,b);return b}function u(a,b,d){var c=b.key;b=b.customHooks;var f=C(d.path),g=[];b.forEach(function(a){var b=void 0;switch(a.type){case "MemberExpression":"Identifier"===a.object.type&&(b=a.object.name);break;case "Identifier":b=a.name}d.hasBinding(b)?
g.push(a):f=!0});a=[a,e.stringLiteral(c)];(f||0<g.length)&&a.push(e.booleanLiteral(f));0<g.length&&a.push(e.functionExpression(null,[],e.blockStatement([e.returnStatement(e.arrayExpression(g))])));return a}if("function"===typeof q.getEnv){var y=q.getEnv();if("development"!==y)throw Error('React Refresh Babel transform should only be enabled in development environment. Instead, the environment is: "'+y+'".');}var e=q.types,l=new Map,x=new WeakMap,k=new WeakSet,p=new WeakSet,z=new WeakSet,n=new WeakMap,
D={CallExpression:function(a){var b=a.node.callee,d=null;switch(b.type){case "Identifier":d=b.name;break;case "MemberExpression":d=b.property.name}if(null!==d&&/^use[A-Z]/.test(d)&&(b=a.scope.getFunctionParent(),null!==b)){b=b.block;n.has(b)||n.set(b,[]);b=n.get(b);var c="";"VariableDeclarator"===a.parent.type&&(c=a.parentPath.get("id").getSource());var f=a.get("arguments");"useState"===d&&0<f.length?c+="("+f[0].getSource()+")":"useReducer"===d&&1<f.length&&(c+="("+f[1].getSource()+")");b.push({callee:a.node.callee,
name:d,key:c})}}};return{visitor:{ExportDefaultDeclaration:function(a){var b=a.node,d=b.declaration,c=a.get("declaration");if("CallExpression"===d.type&&!k.has(b)){k.add(b);var f=a.parentPath;m("%default%",c,function(a,b,c){null!==c&&(a=r(f,a),c.replaceWith(e.assignmentExpression("=",a,b)))})}},FunctionDeclaration:{enter:function(a){var b=a.node,d=void 0,c=void 0;switch(a.parent.type){case "Program":c=a;d=a.parentPath;break;case "ExportNamedDeclaration":c=a.parentPath;d=c.parentPath;break;case "ExportDefaultDeclaration":c=
a.parentPath;d=c.parentPath;break;default:return}var f=b.id;null!==f&&(f=f.name,t(f)&&!k.has(b)&&(k.add(b),m(f,a,function(a,b){a=r(d,a);c.insertAfter(e.expressionStatement(e.assignmentExpression("=",a,b)))})))},exit:function(a){var b=a.node,d=b.id;if(null!==d){var c=w(b);if(null!==c&&!p.has(b)){p.add(b);b=a.scope.generateUidIdentifier("_s");a.scope.parent.push({id:b,init:e.callExpression(e.identifier("$RefreshSig$"),[])});a.get("body").unshiftContainer("body",e.expressionStatement(e.callExpression(b,
[])));var f=null;a.find(function(a){if(a.parentPath.isBlock())return f=a,!0});null!==f&&f.insertAfter(e.expressionStatement(e.callExpression(b,u(d,c,f.scope))))}}}},"ArrowFunctionExpression|FunctionExpression":{exit:function(a){var b=a.node,d=w(b);if(null!==d&&!p.has(b)){p.add(b);var c=a.scope.generateUidIdentifier("_s");a.scope.parent.push({id:c,init:e.callExpression(e.identifier("$RefreshSig$"),[])});a.get("body").unshiftContainer("body",e.expressionStatement(e.callExpression(c,[])));if("VariableDeclarator"===
a.parent.type){var f=null;a.find(function(a){if(a.parentPath.isBlock())return f=a,!0});null!==f&&f.insertAfter(e.expressionStatement(e.callExpression(c,u(a.parent.id,d,f.scope))))}else a.replaceWith(e.callExpression(c,u(b,d,a.scope)))}}},VariableDeclaration:function(a){var b=a.node,d=void 0,c=void 0;switch(a.parent.type){case "Program":c=a;d=a.parentPath;break;case "ExportNamedDeclaration":c=a.parentPath;d=c.parentPath;break;case "ExportDefaultDeclaration":c=a.parentPath;d=c.parentPath;break;default:return}if(!k.has(b)&&
(k.add(b),a=a.get("declarations"),1===a.length)){var f=a[0];m(f.node.id.name,f,function(a,b,h){null!==h&&(a=r(d,a),"ArrowFunctionExpression"!==b.type&&"FunctionExpression"!==b.type||"VariableDeclarator"!==h.parent.type?h.replaceWith(e.assignmentExpression("=",a,b)):c.insertAfter(e.expressionStatement(e.assignmentExpression("=",a,f.node.id))))})}},Program:{enter:function(a){a.traverse(D)},exit:function(a){var b=l.get(a);if(void 0!==b){var d=a.node;if(!z.has(d)){z.add(d);l.delete(a);var c=[];a.pushContainer("body",
e.variableDeclaration("var",c));b.forEach(function(b){var d=b.handle;b=b.persistentID;a.pushContainer("body",e.expressionStatement(e.callExpression(e.identifier("$RefreshReg$"),[d,e.stringLiteral(b)])));c.push(e.variableDeclarator(d))})}}}}}}}var A={default:v},B=A&&v||A;module.exports=B.default||B;
'use strict';function v(q){function r(a,b){var c=a.scope.generateUidIdentifier("c");l.has(a)||l.set(a,[]);l.get(a).push({handle:c,persistentID:b});return c}function t(a){return"string"===typeof a&&"A"<=a[0]&&"Z">=a[0]}function m(a,b,c){var d=b.node;switch(d.type){case "Identifier":if(!t(d.name))break;c(a,d,null);return!0;case "FunctionDeclaration":return c(a,d.id,null),!0;case "ArrowFunctionExpression":if("ArrowFunctionExpression"===d.body.type)break;c(a,d,b);return!0;case "FunctionExpression":return c(a,
d,b),!0;case "CallExpression":var f=b.get("arguments");if(void 0===f||0===f.length)break;var g=b.get("callee");switch(g.node.type){case "MemberExpression":case "Identifier":g=g.getSource();if(!m(a+"$"+g,f[0],c))return!1;c(a,d,b);return!0;default:return!1}case "VariableDeclarator":if(f=d.init,null!==f&&(g=d.id.name,t(g))){switch(f.type){case "ArrowFunctionExpression":case "FunctionExpression":break;case "CallExpression":d=f.callee;var e=d.type;if("Import"===e)return!1;if("Identifier"===e){if(0===d.name.indexOf("require")||
0===d.name.indexOf("import"))return!1}else if("MemberExpression"!==e)return!1;break;case "TaggedTemplateExpression":break;default:return!1}d=b.get("init");if(m(a,d,c))return!0;g=b.scope.getBinding(g);if(void 0===g)return;b=!1;g=g.referencePaths;for(e=0;e<g.length;e++){var h=g[e];if("JSXIdentifier"===h.node.type||"Identifier"===h.node.type){h=h.parent;if("JSXOpeningElement"===h.type)b=!0;else if("CallExpression"===h.type){h=h.callee;var k=void 0;switch(h.type){case "Identifier":k=h.name;break;case "MemberExpression":k=
h.property.name}switch(k){case "createElement":case "jsx":case "jsxDEV":case "jsxs":b=!0}}if(b)return c(a,f,d),!0}}}}return!1}function w(a){a=n.get(a);return void 0===a?null:{key:a.map(function(a){return a.name+"{"+a.key+"}"}).join("\n"),customHooks:a.filter(function(a){a:switch(a.name){case "useState":case "React.useState":case "useReducer":case "React.useReducer":case "useEffect":case "React.useEffect":case "useLayoutEffect":case "React.useLayoutEffect":case "useMemo":case "React.useMemo":case "useCallback":case "React.useCallback":case "useRef":case "React.useRef":case "useContext":case "React.useContext":case "useImperativeMethods":case "React.useImperativeMethods":case "useDebugValue":case "React.useDebugValue":a=
!0;break a;default:a=!1}return!a}).map(function(a){return e.cloneDeep(a.callee)})}}function C(a){a=a.hub.file;var b=x.get(a);if(void 0!==b)return b;b=!1;for(var c=a.ast.comments,d=0;d<c.length;d++)if(-1!==c[d].value.indexOf("@refresh reset")){b=!0;break}x.set(a,b);return b}function u(a,b,c){var d=b.key;b=b.customHooks;var f=C(c.path),g=[];b.forEach(function(a){switch(a.type){case "MemberExpression":if("Identifier"===a.object.type)var b=a.object.name;break;case "Identifier":b=a.name}c.hasBinding(b)?
g.push(a):f=!0});a=[a,e.stringLiteral(d)];(f||0<g.length)&&a.push(e.booleanLiteral(f));0<g.length&&a.push(e.functionExpression(null,[],e.blockStatement([e.returnStatement(e.arrayExpression(g))])));return a}if("function"===typeof q.getEnv){var y=q.getEnv();if("development"!==y&&"function"!==typeof expect)throw Error('React Refresh Babel transform should only be enabled in development environment. Instead, the environment is: "'+y+'".');}var e=q.types,l=new Map,x=new WeakMap,k=new WeakSet,p=new WeakSet,
z=new WeakSet,n=new WeakMap,D={CallExpression:function(a){var b=a.node.callee,c=null;switch(b.type){case "Identifier":c=b.name;break;case "MemberExpression":c=b.property.name}if(null!==c&&/^use[A-Z]/.test(c)&&(b=a.scope.getFunctionParent(),null!==b)){b=b.block;n.has(b)||n.set(b,[]);b=n.get(b);var d="";"VariableDeclarator"===a.parent.type&&(d=a.parentPath.get("id").getSource());var f=a.get("arguments");"useState"===c&&0<f.length?d+="("+f[0].getSource()+")":"useReducer"===c&&1<f.length&&(d+="("+f[1].getSource()+
")");b.push({callee:a.node.callee,name:c,key:d})}}};return{visitor:{ExportDefaultDeclaration:function(a){var b=a.node,c=b.declaration,d=a.get("declaration");if("CallExpression"===c.type&&!k.has(b)){k.add(b);var f=a.parentPath;m("%default%",d,function(a,b,c){null!==c&&(a=r(f,a),c.replaceWith(e.assignmentExpression("=",a,b)))})}},FunctionDeclaration:{enter:function(a){var b=a.node;switch(a.parent.type){case "Program":var c=a;var d=a.parentPath;break;case "ExportNamedDeclaration":c=a.parentPath;d=c.parentPath;
break;case "ExportDefaultDeclaration":c=a.parentPath;d=c.parentPath;break;default:return}var f=b.id;null!==f&&(f=f.name,t(f)&&!k.has(b)&&(k.add(b),m(f,a,function(a,b){a=r(d,a);c.insertAfter(e.expressionStatement(e.assignmentExpression("=",a,b)))})))},exit:function(a){var b=a.node,c=b.id;if(null!==c){var d=w(b);if(null!==d&&!p.has(b)){p.add(b);b=a.scope.generateUidIdentifier("_s");a.scope.parent.push({id:b,init:e.callExpression(e.identifier("$RefreshSig$"),[])});a.get("body").unshiftContainer("body",
e.expressionStatement(e.callExpression(b,[])));var f=null;a.find(function(a){if(a.parentPath.isBlock())return f=a,!0});null!==f&&f.insertAfter(e.expressionStatement(e.callExpression(b,u(c,d,f.scope))))}}}},"ArrowFunctionExpression|FunctionExpression":{exit:function(a){var b=a.node,c=w(b);if(null!==c&&!p.has(b)){p.add(b);var d=a.scope.generateUidIdentifier("_s");a.scope.parent.push({id:d,init:e.callExpression(e.identifier("$RefreshSig$"),[])});"BlockStatement"!==a.node.body.type&&(a.node.body=e.blockStatement([e.returnStatement(a.node.body)]));
a.get("body").unshiftContainer("body",e.expressionStatement(e.callExpression(d,[])));if("VariableDeclarator"===a.parent.type){var f=null;a.find(function(a){if(a.parentPath.isBlock())return f=a,!0});null!==f&&f.insertAfter(e.expressionStatement(e.callExpression(d,u(a.parent.id,c,f.scope))))}else a.replaceWith(e.callExpression(d,u(b,c,a.scope)))}}},VariableDeclaration:function(a){var b=a.node;switch(a.parent.type){case "Program":var c=a;var d=a.parentPath;break;case "ExportNamedDeclaration":c=a.parentPath;
d=c.parentPath;break;case "ExportDefaultDeclaration":c=a.parentPath;d=c.parentPath;break;default:return}if(!k.has(b)&&(k.add(b),a=a.get("declarations"),1===a.length)){var f=a[0];m(f.node.id.name,f,function(a,b,h){null!==h&&(a=r(d,a),"ArrowFunctionExpression"!==b.type&&"FunctionExpression"!==b.type||"VariableDeclarator"!==h.parent.type?h.replaceWith(e.assignmentExpression("=",a,b)):c.insertAfter(e.expressionStatement(e.assignmentExpression("=",a,f.node.id))))})}},Program:{enter:function(a){a.traverse(D)},
exit:function(a){var b=l.get(a);if(void 0!==b){var c=a.node;if(!z.has(c)){z.add(c);l.delete(a);var d=[];a.pushContainer("body",e.variableDeclaration("var",d));b.forEach(function(b){var c=b.handle;b=b.persistentID;a.pushContainer("body",e.expressionStatement(e.callExpression(e.identifier("$RefreshReg$"),[c,e.stringLiteral(b)])));d.push(e.variableDeclarator(c))})}}}}}}}var A={default:v},B=A&&v||A;module.exports=B.default||B;

@@ -27,8 +27,7 @@ /** @license React vundefined

// TODO: We don't use AsyncMode or ConcurrentMode anymore. They were temporary
// (unstable) APIs that have been removed. Can we remove the symbols?
// TODO: We don't use AsyncMode or ConcurrentMode anymore. They were temporary
// (unstable) APIs that have been removed. Can we remove the symbols?
var REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol.for('react.forward_ref') : 0xead0;

@@ -39,27 +38,21 @@

// In old environments, we'll leak previous types after every edit.
var PossiblyWeakMap = typeof WeakMap === 'function' ? WeakMap : Map;
var PossiblyWeakMap = typeof WeakMap === 'function' ? WeakMap : Map; // We never remove these associations.
// It's OK to reference families, but use WeakMap/Set for types.
// We never remove these associations.
// It's OK to reference families, but use WeakMap/Set for types.
var allFamiliesByID = new Map();
var allFamiliesByType = new PossiblyWeakMap();
var allSignaturesByType = new PossiblyWeakMap();
// This WeakMap is read by React, so we only put families
var allSignaturesByType = new PossiblyWeakMap(); // This WeakMap is read by React, so we only put families
// that have actually been edited here. This keeps checks fast.
// $FlowIssue
var updatedFamiliesByType = new PossiblyWeakMap();
// This is cleared on every performReactRefresh() call.
var updatedFamiliesByType = new PossiblyWeakMap(); // This is cleared on every performReactRefresh() call.
// It is an array of [Family, NextType] tuples.
var pendingUpdates = [];
// This is injected by the renderer via DevTools global hook.
var pendingUpdates = []; // This is injected by the renderer via DevTools global hook.
var helpersByRendererID = new Map();
var helpersByRoot = new Map(); // We keep track of mounted roots so we can schedule updates.
var helpersByRoot = new Map();
var mountedRoots = new Set(); // If a root captures an error, we add its element to this Map so we can retry on edit.
// We keep track of mounted roots so we can schedule updates.
var mountedRoots = new Set();
// If a root captures an error, we add its element to this Map so we can retry on edit.
var failedRoots = new Map();

@@ -74,3 +67,4 @@ var didSomeRootFailOnMount = false;

var fullKey = signature.ownKey;
var hooks = void 0;
var hooks;
try {

@@ -89,2 +83,3 @@ hooks = signature.getCustomHooks();

var hook = hooks[i];
if (typeof hook !== 'function') {

@@ -96,3 +91,5 @@ // Something's wrong. Assume we need to remount.

}
var nestedHookSignature = allSignaturesByType.get(hook);
if (nestedHookSignature === undefined) {

@@ -103,6 +100,9 @@ // No signature means Hook wasn't in the source code, e.g. in a library.

}
var nestedHookKey = computeFullKey(nestedHookSignature);
if (nestedHookSignature.forceReset) {
signature.forceReset = true;
}
fullKey += '\n---\n' + nestedHookKey;

@@ -122,8 +122,11 @@ }

}
if (prevSignature === undefined || nextSignature === undefined) {
return false;
}
if (computeFullKey(prevSignature) !== computeFullKey(nextSignature)) {
return false;
}
if (nextSignature.forceReset) {

@@ -144,5 +147,7 @@ return false;

}
if (haveEqualSignatures(prevType, nextType)) {
return true;
}
return false;

@@ -164,3 +169,2 @@ }

var updatedFamilies = new Set();
var updates = pendingUpdates;

@@ -171,3 +175,2 @@ pendingUpdates = [];

nextType = _ref[1];
// Now that we got a real edit, we can create associations

@@ -178,5 +181,4 @@ // that will be read by the React reconciler.

updatedFamiliesByType.set(nextType, family);
family.current = nextType;
family.current = nextType; // Determine whether this should be a re-render or a re-mount.
// Determine whether this should be a re-render or a re-mount.
if (canPreserveStateBetween(prevType, nextType)) {

@@ -187,10 +189,10 @@ updatedFamilies.add(family);

}
});
}); // TODO: rename these fields to something more meaningful.
// TODO: rename these fields to something more meaningful.
var update = {
updatedFamilies: updatedFamilies, // Families that will re-render preserving state
updatedFamilies: updatedFamilies,
// Families that will re-render preserving state
staleFamilies: staleFamilies // Families that will be remounted
};
helpersByRendererID.forEach(function (helpers) {

@@ -201,3 +203,2 @@ // Even if there are no roots, set the handler on first update.

});
var didError = false;

@@ -207,5 +208,7 @@ var firstError = null;

var helpers = helpersByRoot.get(root);
if (helpers === undefined) {
throw new Error('Could not find helpers for a root. This is a bug in React Refresh.');
}
try {

@@ -217,4 +220,4 @@ helpers.scheduleRoot(root, element);

firstError = err;
}
// Keep trying other roots.
} // Keep trying other roots.
}

@@ -224,5 +227,7 @@ });

var helpers = helpersByRoot.get(root);
if (helpers === undefined) {
throw new Error('Could not find helpers for a root. This is a bug in React Refresh.');
}
try {

@@ -234,13 +239,14 @@ helpers.scheduleRefresh(root, update);

firstError = err;
}
// Keep trying other roots.
} // Keep trying other roots.
}
});
if (didError) {
throw firstError;
}
return update;
}
}
function register(type, id) {

@@ -251,18 +257,23 @@ {

}
if (typeof type !== 'function' && typeof type !== 'object') {
return;
}
// This can happen in an edge case, e.g. if we register
} // This can happen in an edge case, e.g. if we register
// return value of a HOC but it returns a cached component.
// Ignore anything but the first registration for each type.
if (allFamiliesByType.has(type)) {
return;
}
// Create family or remember to update it.
} // Create family or remember to update it.
// None of this bookkeeping affects reconciliation
// until the first performReactRefresh() call above.
var family = allFamiliesByID.get(id);
if (family === undefined) {
family = { current: type };
family = {
current: type
};
allFamiliesByID.set(id, family);

@@ -272,5 +283,5 @@ } else {

}
allFamiliesByType.set(type, family);
// Visit inner types because we might not have registered them.
allFamiliesByType.set(type, family); // Visit inner types because we might not have registered them.
if (typeof type === 'object' && type !== null) {

@@ -281,2 +292,3 @@ switch (type.$$typeof) {

break;
case REACT_MEMO_TYPE:

@@ -289,6 +301,5 @@ register(type.type, id + '$type');

}
function setSignature(type, key) {
var forceReset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
var getCustomHooks = arguments[3];
var getCustomHooks = arguments.length > 3 ? arguments[3] : undefined;

@@ -305,9 +316,9 @@ {

}
}
} // This is lazily called during first render for a type.
// It captures Hook list at that time so inline requires don't break comparisons.
// This is lazily called during first render for a type.
// It captures Hook list at that time so inline requires don't break comparisons.
function collectCustomHooksForSignature(type) {
{
var signature = allSignaturesByType.get(type);
if (signature !== undefined) {

@@ -318,3 +329,2 @@ computeFullKey(signature);

}
function getFamilyByID(id) {

@@ -325,3 +335,2 @@ {

}
function getFamilyByType(type) {

@@ -332,3 +341,2 @@ {

}
function findAffectedHostInstances(families) {

@@ -339,5 +347,7 @@ {

var helpers = helpersByRoot.get(root);
if (helpers === undefined) {
throw new Error('Could not find helpers for a root. This is a bug in React Refresh.');
}
var instancesForRoot = helpers.findHostInstancesForRefresh(root, families);

@@ -351,3 +361,2 @@ instancesForRoot.forEach(function (inst) {

}
function injectIntoGlobalHook(globalObject) {

@@ -357,6 +366,6 @@ {

// That code will run before us. So we need to monkeypatch functions on existing hook.
// For React Web, the global hook will be set up by the extension.
// This will also run before us.
var hook = globalObject.__REACT_DEVTOOLS_GLOBAL_HOOK__;
if (hook === undefined) {

@@ -375,8 +384,10 @@ // However, if there is no DevTools extension, we'll need to set up the global hook ourselves.

};
}
} // Here, we just want to get a reference to scheduleRefresh.
// Here, we just want to get a reference to scheduleRefresh.
var oldInject = hook.inject;
hook.inject = function (injected) {
var id = oldInject.apply(this, arguments);
if (typeof injected.scheduleRefresh === 'function' && typeof injected.setRefreshHandler === 'function') {

@@ -386,18 +397,19 @@ // This version supports React Refresh.

}
return id;
};
}; // We also want to track currently mounted roots.
// We also want to track currently mounted roots.
var oldOnCommitFiberRoot = hook.onCommitFiberRoot;
hook.onCommitFiberRoot = function (id, root, maybePriorityLevel, didError) {
var helpers = helpersByRendererID.get(id);
if (helpers === undefined) {
return;
}
helpersByRoot.set(root, helpers);
var current = root.current;
var alternate = current.alternate;
// We need to determine whether this root has just (un)mounted.
var alternate = current.alternate; // We need to determine whether this root has just (un)mounted.
// This logic is copy-pasted from similar logic in the DevTools backend.

@@ -414,4 +426,3 @@ // If this breaks with some refactoring, you'll want to update DevTools too.

failedRoots.delete(root);
} else if (wasMounted && isMounted) {
// Update an existing root.
} else if (wasMounted && isMounted) {// Update an existing root.
// This doesn't affect our mounted root Set.

@@ -421,2 +432,3 @@ } else if (wasMounted && !isMounted) {

mountedRoots.delete(root);
if (didError) {

@@ -452,8 +464,6 @@ // We'll remount it on future edits.

}
function hasUnrecoverableErrors() {
return didSomeRootFailOnMount;
}
} // Exposed for testing.
// Exposed for testing.
function _getMountedRootCount() {

@@ -463,5 +473,3 @@ {

}
}
// This is a wrapper over more primitive functions for setting signature.
} // This is a wrapper over more primitive functions for setting signature.
// Signatures let us decide whether the Hook order has changed on refresh.

@@ -488,7 +496,8 @@ //

// );
function createSignatureFunctionForTransform() {
{
var call = 0;
var savedType = void 0;
var hasCustomHooks = void 0;
var savedType;
var hasCustomHooks;
return function (type, key, forceReset, getCustomHooks) {

@@ -501,2 +510,3 @@ switch (call++) {

break;
case 1:

@@ -506,4 +516,6 @@ if (hasCustomHooks) {

}
break;
}
return type;

@@ -513,3 +525,2 @@ };

}
function isLikelyComponentType(type) {

@@ -526,19 +537,24 @@ {

}
var ownNames = Object.getOwnPropertyNames(type.prototype);
if (ownNames.length > 1 || ownNames[0] !== 'constructor') {
// This looks like a class.
return false;
}
// eslint-disable-next-line no-proto
} // eslint-disable-next-line no-proto
if (type.prototype.__proto__ !== Object.prototype) {
// It has a superclass.
return false;
}
// Pass through.
} // Pass through.
// This looks like a regular function with empty prototype.
}
// For plain functions and arrows, use name as a heuristic.
} // For plain functions and arrows, use name as a heuristic.
var name = type.name || type.displayName;
return typeof name === 'string' && /^[A-Z]/.test(name);
}
case 'object':

@@ -552,2 +568,3 @@ {

return true;
default:

@@ -557,4 +574,6 @@ return false;

}
return false;
}
default:

@@ -584,2 +603,4 @@ {

// This is hacky but makes it work with both Rollup and Jest.
var runtime = ReactFreshRuntime.default || ReactFreshRuntime;

@@ -586,0 +607,0 @@

@@ -7,3 +7,3 @@ {

],
"version": "0.4.0",
"version": "0.4.1",
"homepage": "https://reactjs.org/",

@@ -10,0 +10,0 @@ "bugs": "https://github.com/facebook/react/issues",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc