react-refresh
Advanced tools
Comparing version 0.0.0-experimental-94c0244ba to 0.0.0-experimental-94eed63c49-20240425
'use strict'; | ||
if (process.env.NODE_ENV === 'production') { | ||
module.exports = require('./cjs/react-refresh-babel.production.min.js'); | ||
module.exports = require('./cjs/react-refresh-babel.production.js'); | ||
} else { | ||
module.exports = require('./cjs/react-refresh-babel.development.js'); | ||
} |
@@ -1,5 +0,6 @@ | ||
/** @license React v0.0.0-experimental-94c0244ba | ||
/** | ||
* @license React | ||
* react-refresh-babel.development.js | ||
* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
@@ -19,5 +20,5 @@ * This source code is licensed under the MIT license found in the | ||
if (typeof babel.getEnv === 'function') { | ||
if (typeof babel.env === 'function') { | ||
// Only available in Babel 7. | ||
var env = babel.getEnv(); | ||
var env = babel.env(); | ||
@@ -172,3 +173,3 @@ if (env !== 'development' && !opts.skipEnvCheck) { | ||
} | ||
} else ; | ||
@@ -269,6 +270,24 @@ break; | ||
case 'React.useContext': | ||
case 'useImperativeMethods': | ||
case 'React.useImperativeMethods': | ||
case 'useImperativeHandle': | ||
case 'React.useImperativeHandle': | ||
case 'useDebugValue': | ||
case 'React.useDebugValue': | ||
case 'useId': | ||
case 'React.useId': | ||
case 'useDeferredValue': | ||
case 'React.useDeferredValue': | ||
case 'useTransition': | ||
case 'React.useTransition': | ||
case 'useInsertionEffect': | ||
case 'React.useInsertionEffect': | ||
case 'useSyncExternalStore': | ||
case 'React.useSyncExternalStore': | ||
case 'useFormStatus': | ||
case 'React.useFormStatus': | ||
case 'useFormState': | ||
case 'React.useFormState': | ||
case 'useActionState': | ||
case 'React.useActionState': | ||
case 'useOptimistic': | ||
case 'React.useOptimistic': | ||
return true; | ||
@@ -382,2 +401,34 @@ | ||
function findHOCCallPathsAbove(path) { | ||
var calls = []; | ||
while (true) { | ||
if (!path) { | ||
return calls; | ||
} | ||
var parentPath = path.parentPath; | ||
if (!parentPath) { | ||
return calls; | ||
} | ||
if ( // hoc(_c = function() { }) | ||
parentPath.node.type === 'AssignmentExpression' && path.node === parentPath.node.right) { | ||
// Ignore registrations. | ||
path = parentPath; | ||
continue; | ||
} | ||
if ( // hoc1(hoc2(...)) | ||
parentPath.node.type === 'CallExpression' && path.node !== parentPath.node.callee) { | ||
calls.push(parentPath); | ||
path = parentPath; | ||
continue; | ||
} | ||
return calls; // Stop at other types. | ||
} | ||
} | ||
var seenForRegistration = new WeakSet(); | ||
@@ -497,2 +548,3 @@ var seenForSignature = new WeakSet(); | ||
var insertAfterPath; | ||
var modulePrefix = ''; | ||
@@ -505,2 +557,7 @@ switch (path.parent.type) { | ||
case 'TSModuleBlock': | ||
insertAfterPath = path; | ||
programPath = insertAfterPath.parentPath.parentPath; | ||
break; | ||
case 'ExportNamedDeclaration': | ||
@@ -518,2 +575,19 @@ insertAfterPath = path.parentPath; | ||
return; | ||
} // These types can be nested in typescript namespace | ||
// We need to find the export chain | ||
// Or return if it stays local | ||
if (path.parent.type === 'TSModuleBlock' || path.parent.type === 'ExportNamedDeclaration') { | ||
while (programPath.type !== 'Program') { | ||
if (programPath.type === 'TSModuleDeclaration') { | ||
if (programPath.parentPath.type !== 'Program' && programPath.parentPath.type !== 'ExportNamedDeclaration') { | ||
return; | ||
} | ||
modulePrefix = programPath.node.id.name + '$' + modulePrefix; | ||
} | ||
programPath = programPath.parentPath; | ||
} | ||
} | ||
@@ -541,6 +615,7 @@ | ||
seenForRegistration.add(node); // Don't mutate the tree above this point. | ||
// export function Named() {} | ||
var innerName = modulePrefix + inferredName; // export function Named() {} | ||
// function Named() {} | ||
findInnerComponents(inferredName, path, function (persistentID, targetExpr) { | ||
findInnerComponents(innerName, path, function (persistentID, targetExpr) { | ||
var handle = createRegistration(programPath, persistentID); | ||
@@ -652,3 +727,6 @@ insertAfterPath.insertAfter(t.expressionStatement(t.assignmentExpression('=', handle, targetExpr))); | ||
// let Foo = hoc(() => {}) | ||
path.replaceWith(t.callExpression(sigCallID, createArgumentsForSignature(node, signature, path.scope))); // Result: let Foo = hoc(__signature(() => {}, ...)) | ||
var paths = [path].concat(findHOCCallPathsAbove(path)); | ||
paths.forEach(function (p) { | ||
p.replaceWith(t.callExpression(sigCallID, createArgumentsForSignature(p.node, signature, p.scope))); | ||
}); // Result: let Foo = __signature(hoc(__signature(() => {}, ...)), ...) | ||
} | ||
@@ -661,2 +739,3 @@ } | ||
var insertAfterPath; | ||
var modulePrefix = ''; | ||
@@ -669,2 +748,7 @@ switch (path.parent.type) { | ||
case 'TSModuleBlock': | ||
insertAfterPath = path; | ||
programPath = insertAfterPath.parentPath.parentPath; | ||
break; | ||
case 'ExportNamedDeclaration': | ||
@@ -682,2 +766,19 @@ insertAfterPath = path.parentPath; | ||
return; | ||
} // These types can be nested in typescript namespace | ||
// We need to find the export chain | ||
// Or return if it stays local | ||
if (path.parent.type === 'TSModuleBlock' || path.parent.type === 'ExportNamedDeclaration') { | ||
while (programPath.type !== 'Program') { | ||
if (programPath.type === 'TSModuleDeclaration') { | ||
if (programPath.parentPath.type !== 'Program' && programPath.parentPath.type !== 'ExportNamedDeclaration') { | ||
return; | ||
} | ||
modulePrefix = programPath.node.id.name + '$' + modulePrefix; | ||
} | ||
programPath = programPath.parentPath; | ||
} | ||
} // Make sure we're not mutating the same tree twice. | ||
@@ -701,3 +802,4 @@ // This can happen if another Babel plugin replaces parents. | ||
var inferredName = declPath.node.id.name; | ||
findInnerComponents(inferredName, declPath, function (persistentID, targetExpr, targetPath) { | ||
var innerName = modulePrefix + inferredName; | ||
findInnerComponents(innerName, declPath, function (persistentID, targetExpr, targetPath) { | ||
if (targetPath === null) { | ||
@@ -704,0 +806,0 @@ // For case like: |
@@ -1,5 +0,6 @@ | ||
/** @license React v0.0.0-experimental-94c0244ba | ||
/** | ||
* @license React | ||
* react-refresh-runtime.development.js | ||
* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
@@ -16,52 +17,5 @@ * This source code is licensed under the MIT license found in the | ||
// ATTENTION | ||
// When adding new symbols to this file, | ||
// Please consider also adding to 'react-devtools-shared/src/backend/ReactSymbols' | ||
// The Symbol used to tag the ReactElement-like types. If there is no native Symbol | ||
// nor polyfill, then a plain number is used for performance. | ||
var REACT_ELEMENT_TYPE = 0xeac7; | ||
var REACT_PORTAL_TYPE = 0xeaca; | ||
var REACT_FRAGMENT_TYPE = 0xeacb; | ||
var REACT_STRICT_MODE_TYPE = 0xeacc; | ||
var REACT_PROFILER_TYPE = 0xead2; | ||
var REACT_PROVIDER_TYPE = 0xeacd; | ||
var REACT_CONTEXT_TYPE = 0xeace; | ||
var REACT_FORWARD_REF_TYPE = 0xead0; | ||
var REACT_SUSPENSE_TYPE = 0xead1; | ||
var REACT_SUSPENSE_LIST_TYPE = 0xead8; | ||
var REACT_MEMO_TYPE = 0xead3; | ||
var REACT_LAZY_TYPE = 0xead4; | ||
var REACT_BLOCK_TYPE = 0xead9; | ||
var REACT_SERVER_BLOCK_TYPE = 0xeada; | ||
var REACT_FUNDAMENTAL_TYPE = 0xead5; | ||
var REACT_SCOPE_TYPE = 0xead7; | ||
var REACT_OPAQUE_ID_TYPE = 0xeae0; | ||
var REACT_DEBUG_TRACING_MODE_TYPE = 0xeae1; | ||
var REACT_OFFSCREEN_TYPE = 0xeae2; | ||
var REACT_LEGACY_HIDDEN_TYPE = 0xeae3; | ||
var REACT_FORWARD_REF_TYPE = Symbol.for('react.forward_ref'); | ||
var REACT_MEMO_TYPE = Symbol.for('react.memo'); | ||
if (typeof Symbol === 'function' && Symbol.for) { | ||
var symbolFor = Symbol.for; | ||
REACT_ELEMENT_TYPE = symbolFor('react.element'); | ||
REACT_PORTAL_TYPE = symbolFor('react.portal'); | ||
REACT_FRAGMENT_TYPE = symbolFor('react.fragment'); | ||
REACT_STRICT_MODE_TYPE = symbolFor('react.strict_mode'); | ||
REACT_PROFILER_TYPE = symbolFor('react.profiler'); | ||
REACT_PROVIDER_TYPE = symbolFor('react.provider'); | ||
REACT_CONTEXT_TYPE = symbolFor('react.context'); | ||
REACT_FORWARD_REF_TYPE = symbolFor('react.forward_ref'); | ||
REACT_SUSPENSE_TYPE = symbolFor('react.suspense'); | ||
REACT_SUSPENSE_LIST_TYPE = symbolFor('react.suspense_list'); | ||
REACT_MEMO_TYPE = symbolFor('react.memo'); | ||
REACT_LAZY_TYPE = symbolFor('react.lazy'); | ||
REACT_BLOCK_TYPE = symbolFor('react.block'); | ||
REACT_SERVER_BLOCK_TYPE = symbolFor('react.server.block'); | ||
REACT_FUNDAMENTAL_TYPE = symbolFor('react.fundamental'); | ||
REACT_SCOPE_TYPE = symbolFor('react.scope'); | ||
REACT_OPAQUE_ID_TYPE = symbolFor('react.opaque.id'); | ||
REACT_DEBUG_TRACING_MODE_TYPE = symbolFor('react.debug_trace_mode'); | ||
REACT_OFFSCREEN_TYPE = symbolFor('react.offscreen'); | ||
REACT_LEGACY_HIDDEN_TYPE = symbolFor('react.legacy_hidden'); | ||
} | ||
var PossiblyWeakMap = typeof WeakMap === 'function' ? WeakMap : Map; // We never remove these associations. | ||
@@ -74,3 +28,2 @@ // It's OK to reference families, but use WeakMap/Set for types. | ||
// that have actually been edited here. This keeps checks fast. | ||
// $FlowIssue | ||
@@ -90,6 +43,4 @@ var updatedFamiliesByType = new PossiblyWeakMap(); // This is cleared on every performReactRefresh() call. | ||
// If there is no WeakMap, we won't attempt to do retrying. | ||
// $FlowIssue | ||
var rootElements = // $FlowIssue | ||
typeof WeakMap === 'function' ? new WeakMap() : null; | ||
var rootElements = typeof WeakMap === 'function' ? new WeakMap() : null; | ||
var isPerformingRefresh = false; | ||
@@ -206,2 +157,12 @@ | ||
return clone; | ||
} // This is a safety mechanism to protect against rogue getters and Proxies. | ||
function getProperty(object, property) { | ||
try { | ||
return object[property]; | ||
} catch (err) { | ||
// Intentionally ignore. | ||
return undefined; | ||
} | ||
} | ||
@@ -357,3 +318,3 @@ | ||
if (typeof type === 'object' && type !== null) { | ||
switch (type.$$typeof) { | ||
switch (getProperty(type, '$$typeof')) { | ||
case REACT_FORWARD_REF_TYPE: | ||
@@ -375,10 +336,25 @@ register(type.render, id + '$render'); | ||
{ | ||
allSignaturesByType.set(type, { | ||
forceReset: forceReset, | ||
ownKey: key, | ||
fullKey: null, | ||
getCustomHooks: getCustomHooks || function () { | ||
return []; | ||
if (!allSignaturesByType.has(type)) { | ||
allSignaturesByType.set(type, { | ||
forceReset: forceReset, | ||
ownKey: key, | ||
fullKey: null, | ||
getCustomHooks: getCustomHooks || function () { | ||
return []; | ||
} | ||
}); | ||
} // Visit inner types because we might not have signed them. | ||
if (typeof type === 'object' && type !== null) { | ||
switch (getProperty(type, '$$typeof')) { | ||
case REACT_FORWARD_REF_TYPE: | ||
setSignature(type.render, key, forceReset, getCustomHooks); | ||
break; | ||
case REACT_MEMO_TYPE: | ||
setSignature(type.type, key, forceReset, getCustomHooks); | ||
break; | ||
} | ||
}); | ||
} | ||
} | ||
@@ -448,2 +424,10 @@ } // This is lazily called during first render for a type. | ||
}; | ||
} | ||
if (hook.isDisabled) { | ||
// This isn't a real property on the hook, but it can be set to opt out | ||
// of DevTools integration and associated warnings and logs. | ||
// Using console['warn'] to evade Babel and ESLint | ||
console['warn']('Something has shimmed the React DevTools global hook (__REACT_DEVTOOLS_GLOBAL_HOOK__). ' + 'Fast Refresh is not compatible with this shim and will be disabled.'); | ||
return; | ||
} // Here, we just want to get a reference to scheduleRefresh. | ||
@@ -496,41 +480,40 @@ | ||
if (helpers === undefined) { | ||
return; | ||
} | ||
if (helpers !== undefined) { | ||
helpersByRoot.set(root, helpers); | ||
var current = root.current; | ||
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. | ||
// If this breaks with some refactoring, you'll want to update DevTools too. | ||
helpersByRoot.set(root, helpers); | ||
var current = root.current; | ||
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. | ||
// If this breaks with some refactoring, you'll want to update DevTools too. | ||
if (alternate !== null) { | ||
var wasMounted = alternate.memoizedState != null && alternate.memoizedState.element != null && mountedRoots.has(root); | ||
var isMounted = current.memoizedState != null && current.memoizedState.element != null; | ||
if (alternate !== null) { | ||
var wasMounted = alternate.memoizedState != null && alternate.memoizedState.element != null; | ||
var isMounted = current.memoizedState != null && current.memoizedState.element != null; | ||
if (!wasMounted && isMounted) { | ||
// Mount a new root. | ||
mountedRoots.add(root); | ||
failedRoots.delete(root); | ||
} else if (wasMounted && isMounted) ; else if (wasMounted && !isMounted) { | ||
// Unmount an existing root. | ||
mountedRoots.delete(root); | ||
if (!wasMounted && isMounted) { | ||
if (didError) { | ||
// We'll remount it on future edits. | ||
failedRoots.add(root); | ||
} else { | ||
helpersByRoot.delete(root); | ||
} | ||
} else if (!wasMounted && !isMounted) { | ||
if (didError) { | ||
// We'll remount it on future edits. | ||
failedRoots.add(root); | ||
} | ||
} | ||
} else { | ||
// Mount a new root. | ||
mountedRoots.add(root); | ||
failedRoots.delete(root); | ||
} else if (wasMounted && isMounted) ; else if (wasMounted && !isMounted) { | ||
// Unmount an existing root. | ||
mountedRoots.delete(root); | ||
if (didError) { | ||
// We'll remount it on future edits. | ||
failedRoots.add(root); | ||
} else { | ||
helpersByRoot.delete(root); | ||
} | ||
} else if (!wasMounted && !isMounted) { | ||
if (didError) { | ||
// We'll remount it on future edits. | ||
failedRoots.add(root); | ||
} | ||
} | ||
} else { | ||
// Mount a new root. | ||
mountedRoots.add(root); | ||
} | ||
} // Always call the decorated DevTools hook. | ||
return oldOnCommitFiberRoot.apply(this, arguments); | ||
@@ -558,3 +541,3 @@ }; | ||
// const value = useCustomHook(); | ||
// _s(); /* Second call triggers collecting the custom Hook list. | ||
// _s(); /* Call without arguments triggers collecting the custom Hook list. | ||
// * This doesn't happen during the module evaluation because we | ||
@@ -566,3 +549,3 @@ // * don't want to change the module order with inline requires. | ||
// | ||
// /* First call specifies the signature: */ | ||
// /* Call with arguments attaches the signature to the type: */ | ||
// _s( | ||
@@ -576,33 +559,33 @@ // Hello, | ||
{ | ||
// We'll fill in the signature in two steps. | ||
// First, we'll know the signature itself. This happens outside the component. | ||
// Then, we'll know the references to custom Hooks. This happens inside the component. | ||
// After that, the returned function will be a fast path no-op. | ||
var status = 'needsSignature'; | ||
var savedType; | ||
var hasCustomHooks; | ||
var didCollectHooks = false; | ||
return function (type, key, forceReset, getCustomHooks) { | ||
switch (status) { | ||
case 'needsSignature': | ||
if (type !== undefined) { | ||
// If we received an argument, this is the initial registration call. | ||
savedType = type; | ||
hasCustomHooks = typeof getCustomHooks === 'function'; | ||
setSignature(type, key, forceReset, getCustomHooks); // The next call we expect is from inside a function, to fill in the custom Hooks. | ||
if (typeof key === 'string') { | ||
// We're in the initial phase that associates signatures | ||
// with the functions. Note this may be called multiple times | ||
// in HOC chains like _s(hoc1(_s(hoc2(_s(actualFunction))))). | ||
if (!savedType) { | ||
// We're in the innermost call, so this is the actual type. | ||
savedType = type; | ||
hasCustomHooks = typeof getCustomHooks === 'function'; | ||
} // Set the signature for all types (even wrappers!) in case | ||
// they have no signatures of their own. This is to prevent | ||
// problems like https://github.com/facebook/react/issues/20417. | ||
status = 'needsCustomHooks'; | ||
} | ||
break; | ||
if (type != null && (typeof type === 'function' || typeof type === 'object')) { | ||
setSignature(type, key, forceReset, getCustomHooks); | ||
} | ||
case 'needsCustomHooks': | ||
if (hasCustomHooks) { | ||
collectCustomHooksForSignature(savedType); | ||
} | ||
status = 'resolved'; | ||
break; | ||
return type; | ||
} else { | ||
// We're in the _s() call without arguments, which means | ||
// this is the time to collect custom Hook signatures. | ||
// Only do this once. This path is hot and runs *inside* every render! | ||
if (!didCollectHooks && hasCustomHooks) { | ||
didCollectHooks = true; | ||
collectCustomHooksForSignature(savedType); | ||
} | ||
} | ||
return type; | ||
}; | ||
@@ -647,3 +630,3 @@ } | ||
if (type != null) { | ||
switch (type.$$typeof) { | ||
switch (getProperty(type, '$$typeof')) { | ||
case REACT_FORWARD_REF_TYPE: | ||
@@ -650,0 +633,0 @@ case REACT_MEMO_TYPE: |
@@ -7,4 +7,4 @@ { | ||
], | ||
"version": "0.0.0-experimental-94c0244ba", | ||
"homepage": "https://reactjs.org/", | ||
"version": "0.0.0-experimental-94eed63c49-20240425", | ||
"homepage": "https://react.dev/", | ||
"bugs": "https://github.com/facebook/react/issues", | ||
@@ -17,7 +17,11 @@ "license": "MIT", | ||
"runtime.js", | ||
"build-info.json", | ||
"cjs/", | ||
"umd/" | ||
"cjs/" | ||
], | ||
"main": "runtime.js", | ||
"exports": { | ||
".": "./runtime.js", | ||
"./runtime": "./runtime.js", | ||
"./babel": "./babel.js", | ||
"./package.json": "./package.json" | ||
}, | ||
"repository": { | ||
@@ -30,3 +34,8 @@ "type": "git", | ||
"node": ">=0.10.0" | ||
}, | ||
"devDependencies": { | ||
"react-16-8": "npm:react@16.8.0", | ||
"react-dom-16-8": "npm:react-dom@16.8.0", | ||
"scheduler-0-13": "npm:scheduler@0.13.0" | ||
} | ||
} | ||
} |
'use strict'; | ||
if (process.env.NODE_ENV === 'production') { | ||
module.exports = require('./cjs/react-refresh-runtime.production.min.js'); | ||
module.exports = require('./cjs/react-refresh-runtime.production.js'); | ||
} else { | ||
module.exports = require('./cjs/react-refresh-runtime.development.js'); | ||
} |
Sorry, the diff of this file is not supported yet
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
71756
1840
2
3
9