react-refresh
Advanced tools
Comparing version 0.0.0-424099da6 to 0.0.0-8d5403877
{ | ||
"branch": "master", | ||
"buildNumber": "28757", | ||
"checksum": "dfcc1ce", | ||
"commit": "424099da6", | ||
"buildNumber": "35115", | ||
"checksum": "1fa61b1", | ||
"commit": "8d5403877", | ||
"environment": "ci", | ||
"reactVersion": "16.8.6-canary-424099da6" | ||
"reactVersion": "16.9.0-canary-8d5403877" | ||
} |
@@ -1,2 +0,2 @@ | ||
/** @license React v0.0.0-424099da6 | ||
/** @license React v0.0.0-8d5403877 | ||
* react-refresh-babel.development.js | ||
@@ -22,2 +22,3 @@ * | ||
var env = babel.getEnv(); | ||
if (env !== 'development') { | ||
@@ -29,10 +30,11 @@ throw new Error('React Refresh Babel transform should only be enabled in development environment. ' + 'Instead, the environment is: "' + env + '".'); | ||
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,6 @@ 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. | ||
@@ -605,6 +665,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 +674,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 +686,5 @@ } | ||
var node = path.node; | ||
var programPath = void 0; | ||
var insertAfterPath = void 0; | ||
var programPath; | ||
var insertAfterPath; | ||
switch (path.parent.type) { | ||
@@ -634,2 +695,3 @@ case 'Program': | ||
break; | ||
case 'ExportNamedDeclaration': | ||
@@ -639,2 +701,3 @@ insertAfterPath = path.parentPath; | ||
break; | ||
case 'ExportDefaultDeclaration': | ||
@@ -644,18 +707,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 +737,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 +747,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 +765,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 +787,2 @@ var declarators = []; | ||
persistentID = _ref.persistentID; | ||
path.pushContainer('body', t.expressionStatement(t.callExpression(t.identifier('$RefreshReg$'), [handle, t.stringLiteral(persistentID)]))); | ||
@@ -738,2 +804,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 +808,0 @@ |
@@ -1,2 +0,2 @@ | ||
/** @license React v0.0.0-424099da6 | ||
/** @license React v0.0.0-8d5403877 | ||
* react-refresh-babel.production.min.js | ||
@@ -10,14 +10,14 @@ * | ||
'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)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$"),[])});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; |
@@ -1,2 +0,2 @@ | ||
/** @license React v0.0.0-424099da6 | ||
/** @license React v0.0.0-8d5403877 | ||
* react-refresh-runtime.development.js | ||
@@ -27,8 +27,7 @@ * | ||
// 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,79 +38,23 @@ | ||
/** | ||
* Similar to invariant but only logs a warning if the condition is not met. | ||
* This can be used to log issues in development environments in critical | ||
* paths. Removing the logging code for production environments will keep the | ||
* same logic and follow the same code paths. | ||
*/ | ||
var PossiblyWeakMap = typeof WeakMap === 'function' ? WeakMap : Map; // We never remove these associations. | ||
// It's OK to reference families, but use WeakMap/Set for types. | ||
var warningWithoutStack = function () {}; | ||
{ | ||
warningWithoutStack = function (condition, format) { | ||
for (var _len = arguments.length, args = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { | ||
args[_key - 2] = arguments[_key]; | ||
} | ||
if (format === undefined) { | ||
throw new Error('`warningWithoutStack(condition, format, ...args)` requires a warning ' + 'message argument'); | ||
} | ||
if (args.length > 8) { | ||
// Check before the condition to catch violations early. | ||
throw new Error('warningWithoutStack() currently supports at most 8 arguments.'); | ||
} | ||
if (condition) { | ||
return; | ||
} | ||
if (typeof console !== 'undefined') { | ||
var argsWithFormat = args.map(function (item) { | ||
return '' + item; | ||
}); | ||
argsWithFormat.unshift('Warning: ' + format); | ||
// We intentionally don't use spread (or .apply) directly because it | ||
// breaks IE9: https://github.com/facebook/react/issues/13610 | ||
Function.prototype.apply.call(console.error, console, argsWithFormat); | ||
} | ||
try { | ||
// --- Welcome to debugging React --- | ||
// This error was thrown as a convenience so that you can use this stack | ||
// to find the callsite that caused this warning to fire. | ||
var argIndex = 0; | ||
var message = 'Warning: ' + format.replace(/%s/g, function () { | ||
return args[argIndex++]; | ||
}); | ||
throw new Error(message); | ||
} catch (x) {} | ||
}; | ||
} | ||
var warningWithoutStack$1 = warningWithoutStack; | ||
// In old environments, we'll leak previous types after every edit. | ||
var PossiblyWeakMap = typeof WeakMap === 'function' ? WeakMap : Map; | ||
// 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 setRefreshHandler = null; | ||
var scheduleRefresh = null; | ||
var scheduleRoot = null; | ||
var findHostInstancesForRefresh = null; | ||
var pendingUpdates = []; // This is injected by the renderer via DevTools global hook. | ||
// 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 helpersByRendererID = new Map(); | ||
var helpersByRoot = new Map(); // 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(); | ||
var didSomeRootFailOnMount = false; | ||
@@ -124,3 +67,4 @@ function computeFullKey(signature) { | ||
var fullKey = signature.ownKey; | ||
var hooks = void 0; | ||
var hooks; | ||
try { | ||
@@ -139,2 +83,3 @@ hooks = signature.getCustomHooks(); | ||
var hook = hooks[i]; | ||
if (typeof hook !== 'function') { | ||
@@ -146,3 +91,5 @@ // Something's wrong. Assume we need to remount. | ||
} | ||
var nestedHookSignature = allSignaturesByType.get(hook); | ||
if (nestedHookSignature === undefined) { | ||
@@ -153,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; | ||
@@ -172,8 +122,11 @@ } | ||
} | ||
if (prevSignature === undefined || nextSignature === undefined) { | ||
return false; | ||
} | ||
if (computeFullKey(prevSignature) !== computeFullKey(nextSignature)) { | ||
return false; | ||
} | ||
if (nextSignature.forceReset) { | ||
@@ -194,5 +147,7 @@ return false; | ||
} | ||
if (haveEqualSignatures(prevType, nextType)) { | ||
return true; | ||
} | ||
return false; | ||
@@ -214,3 +169,2 @@ } | ||
var updatedFamilies = new Set(); | ||
var updates = pendingUpdates; | ||
@@ -221,3 +175,2 @@ pendingUpdates = []; | ||
nextType = _ref[1]; | ||
// Now that we got a real edit, we can create associations | ||
@@ -228,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)) { | ||
@@ -237,35 +189,26 @@ 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 | ||
}; | ||
if (typeof setRefreshHandler !== 'function') { | ||
warningWithoutStack$1(false, 'Could not find the setRefreshHandler() implementation. ' + 'This likely means that injectIntoGlobalHook() was either ' + 'called before the global DevTools hook was set up, or after the ' + 'renderer has already initialized. Please file an issue with a reproducing case.'); | ||
return null; | ||
} | ||
if (typeof scheduleRefresh !== 'function') { | ||
warningWithoutStack$1(false, 'Could not find the scheduleRefresh() implementation. ' + 'This likely means that injectIntoGlobalHook() was either ' + 'called before the global DevTools hook was set up, or after the ' + 'renderer has already initialized. Please file an issue with a reproducing case.'); | ||
return null; | ||
} | ||
if (typeof scheduleRoot !== 'function') { | ||
warningWithoutStack$1(false, 'Could not find the scheduleRoot() implementation. ' + 'This likely means that injectIntoGlobalHook() was either ' + 'called before the global DevTools hook was set up, or after the ' + 'renderer has already initialized. Please file an issue with a reproducing case.'); | ||
return null; | ||
} | ||
var scheduleRefreshForRoot = scheduleRefresh; | ||
var scheduleRenderForRoot = scheduleRoot; | ||
// Even if there are no roots, set the handler on first update. | ||
// This ensures that if *new* roots are mounted, they'll use the resolve handler. | ||
setRefreshHandler(resolveFamily); | ||
helpersByRendererID.forEach(function (helpers) { | ||
// Even if there are no roots, set the handler on first update. | ||
// This ensures that if *new* roots are mounted, they'll use the resolve handler. | ||
helpers.setRefreshHandler(resolveFamily); | ||
}); | ||
var didError = false; | ||
var firstError = null; | ||
failedRoots.forEach(function (element, root) { | ||
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 { | ||
scheduleRenderForRoot(root, element); | ||
helpers.scheduleRoot(root, element); | ||
} catch (err) { | ||
@@ -275,9 +218,15 @@ if (!didError) { | ||
firstError = err; | ||
} | ||
// Keep trying other roots. | ||
} // Keep trying other roots. | ||
} | ||
}); | ||
mountedRoots.forEach(function (root) { | ||
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 { | ||
scheduleRefreshForRoot(root, update); | ||
helpers.scheduleRefresh(root, update); | ||
} catch (err) { | ||
@@ -287,13 +236,14 @@ if (!didError) { | ||
firstError = err; | ||
} | ||
// Keep trying other roots. | ||
} // Keep trying other roots. | ||
} | ||
}); | ||
if (didError) { | ||
throw firstError; | ||
} | ||
return update; | ||
} | ||
} | ||
function register(type, id) { | ||
@@ -304,18 +254,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); | ||
@@ -325,5 +280,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) { | ||
@@ -334,2 +289,3 @@ switch (type.$$typeof) { | ||
break; | ||
case REACT_MEMO_TYPE: | ||
@@ -342,6 +298,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; | ||
@@ -358,9 +313,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) { | ||
@@ -371,3 +326,2 @@ computeFullKey(signature); | ||
} | ||
function getFamilyByID(id) { | ||
@@ -378,3 +332,2 @@ { | ||
} | ||
function getFamilyByType(type) { | ||
@@ -385,13 +338,13 @@ { | ||
} | ||
function findAffectedHostInstances(families) { | ||
{ | ||
if (typeof findHostInstancesForRefresh !== 'function') { | ||
warningWithoutStack$1(false, 'Could not find the findHostInstancesForRefresh() implementation. ' + 'This likely means that injectIntoGlobalHook() was either ' + 'called before the global DevTools hook was set up, or after the ' + 'renderer has already initialized. Please file an issue with a reproducing case.'); | ||
return new Set(); | ||
} | ||
var findInstances = findHostInstancesForRefresh; | ||
var affectedInstances = new Set(); | ||
mountedRoots.forEach(function (root) { | ||
var instancesForRoot = findInstances(root, families); | ||
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); | ||
instancesForRoot.forEach(function (inst) { | ||
@@ -404,3 +357,2 @@ affectedInstances.add(inst); | ||
} | ||
function injectIntoGlobalHook(globalObject) { | ||
@@ -410,6 +362,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) { | ||
@@ -419,27 +371,40 @@ // However, if there is no DevTools extension, we'll need to set up the global hook ourselves. | ||
// Otherwise, the renderer will think that there is no global hook, and won't do the injection. | ||
var nextID = 0; | ||
globalObject.__REACT_DEVTOOLS_GLOBAL_HOOK__ = hook = { | ||
supportsFiber: true, | ||
inject: function () {}, | ||
inject: function (injected) { | ||
return nextID++; | ||
}, | ||
onCommitFiberRoot: function (id, root, maybePriorityLevel, didError) {}, | ||
onCommitFiberUnmount: function () {} | ||
}; | ||
} | ||
} // 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) { | ||
findHostInstancesForRefresh = injected.findHostInstancesForRefresh; | ||
scheduleRefresh = injected.scheduleRefresh; | ||
scheduleRoot = injected.scheduleRoot; | ||
setRefreshHandler = injected.setRefreshHandler; | ||
return oldInject.apply(this, arguments); | ||
}; | ||
var id = oldInject.apply(this, arguments); | ||
// We also want to track currently mounted roots. | ||
if (typeof injected.scheduleRefresh === 'function' && typeof injected.setRefreshHandler === 'function') { | ||
// This version supports React Refresh. | ||
helpersByRendererID.set(id, injected); | ||
} | ||
return id; | ||
}; // 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. | ||
@@ -456,4 +421,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. | ||
@@ -463,2 +427,3 @@ } else if (wasMounted && !isMounted) { | ||
mountedRoots.delete(root); | ||
if (didError) { | ||
@@ -468,3 +433,18 @@ // We'll remount it on future edits. | ||
failedRoots.set(root, alternate.memoizedState.element); | ||
} else { | ||
helpersByRoot.delete(root); | ||
} | ||
} else if (!wasMounted && !isMounted) { | ||
if (didError && !failedRoots.has(root)) { | ||
// The root had an error during the initial mount. | ||
// We can't read its last element from the memoized state | ||
// because there was no previously committed alternate. | ||
// Ideally, it would be nice if we had a way to extract | ||
// the last attempted rendered element, but accessing the update queue | ||
// would tie this package too closely to the reconciler version. | ||
// So instead, we just set a flag. | ||
// TODO: Maybe we could fix this as the same time as when we fix | ||
// DevTools to not depend on `alternate.memoizedState.element`. | ||
didSomeRootFailOnMount = true; | ||
} | ||
} | ||
@@ -480,4 +460,6 @@ } else { | ||
} | ||
function hasUnrecoverableErrors() { | ||
return didSomeRootFailOnMount; | ||
} // Exposed for testing. | ||
// Exposed for testing. | ||
function _getMountedRootCount() { | ||
@@ -487,5 +469,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. | ||
@@ -512,7 +492,8 @@ // | ||
// ); | ||
function createSignatureFunctionForTransform() { | ||
{ | ||
var call = 0; | ||
var savedType = void 0; | ||
var hasCustomHooks = void 0; | ||
var savedType; | ||
var hasCustomHooks; | ||
return function (type, key, forceReset, getCustomHooks) { | ||
@@ -525,2 +506,3 @@ switch (call++) { | ||
break; | ||
case 1: | ||
@@ -530,4 +512,6 @@ if (hasCustomHooks) { | ||
} | ||
break; | ||
} | ||
return type; | ||
@@ -537,3 +521,2 @@ }; | ||
} | ||
function isLikelyComponentType(type) { | ||
@@ -550,19 +533,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': | ||
@@ -576,2 +564,3 @@ { | ||
return true; | ||
default: | ||
@@ -581,4 +570,6 @@ return false; | ||
} | ||
return false; | ||
} | ||
default: | ||
@@ -601,2 +592,3 @@ { | ||
injectIntoGlobalHook: injectIntoGlobalHook, | ||
hasUnrecoverableErrors: hasUnrecoverableErrors, | ||
_getMountedRootCount: _getMountedRootCount, | ||
@@ -608,2 +600,4 @@ createSignatureFunctionForTransform: createSignatureFunctionForTransform, | ||
// This is hacky but makes it work with both Rollup and Jest. | ||
var runtime = ReactFreshRuntime.default || ReactFreshRuntime; | ||
@@ -610,0 +604,0 @@ |
@@ -1,2 +0,2 @@ | ||
/** @license React v0.0.0-424099da6 | ||
/** @license React v0.0.0-8d5403877 | ||
* react-refresh-runtime.production.min.js | ||
@@ -3,0 +3,0 @@ * |
@@ -7,3 +7,3 @@ { | ||
], | ||
"version": "0.0.0-424099da6", | ||
"version": "0.0.0-8d5403877", | ||
"homepage": "https://reactjs.org/", | ||
@@ -10,0 +10,0 @@ "bugs": "https://github.com/facebook/react/issues", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
50487
1129