Skip to content

Commit

Permalink
[compiler] Always emit variable decl in gating mode
Browse files Browse the repository at this point in the history
This PR makes it so we always emit a const VariableDeclaration for
compiled functions in gating mode. If the original declaration's parent
was an ExportDefaultDeclaration we'll also append a new
ExportDefaultDeclaration pointing to the new identifier. This allows
code that adds optional properties to the function declaration to still
work in gating mode

ghstack-source-id: 5705479135baa268eeb3c85bfbf1883964e84916
Pull Request resolved: #29806

DiffTrain build for [20841f9](20841f9)
  • Loading branch information
poteto committed Jun 7, 2024
1 parent 39e6b27 commit cdfa569
Show file tree
Hide file tree
Showing 34 changed files with 470 additions and 410 deletions.
2 changes: 1 addition & 1 deletion compiled/facebook-www/REVISION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
142b2a8230130ddf3de8a9c8e7799a291f4d1a97
20841f9a6205a633e6d08a274db974481daaca23
2 changes: 1 addition & 1 deletion compiled/facebook-www/REVISION_TRANSFORMS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
142b2a8230130ddf3de8a9c8e7799a291f4d1a97
20841f9a6205a633e6d08a274db974481daaca23
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ if (
) {
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
}
var ReactVersion = '19.0.0-www-classic-142b2a8230-20240607';
var ReactVersion = '19.0.0-www-classic-20841f9a62-20240607';

// Re-export dynamic flags from the www version.
var dynamicFeatureFlags = require('ReactFeatureFlags');
Expand Down
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ if (
) {
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
}
var ReactVersion = '19.0.0-www-modern-142b2a8230-20240607';
var ReactVersion = '19.0.0-www-modern-20841f9a62-20240607';

// Re-export dynamic flags from the www version.
var dynamicFeatureFlags = require('ReactFeatureFlags');
Expand Down
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-prod.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -665,4 +665,4 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.0.0-www-classic-142b2a8230-20240607";
exports.version = "19.0.0-www-classic-20841f9a62-20240607";
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-prod.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -665,4 +665,4 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.0.0-www-modern-142b2a8230-20240607";
exports.version = "19.0.0-www-modern-20841f9a62-20240607";
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-profiling.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.0.0-www-classic-142b2a8230-20240607";
exports.version = "19.0.0-www-classic-20841f9a62-20240607";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-profiling.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.0.0-www-modern-142b2a8230-20240607";
exports.version = "19.0.0-www-modern-20841f9a62-20240607";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
72 changes: 39 additions & 33 deletions compiled/facebook-www/ReactART-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function _assertThisInitialized(self) {
return self;
}

var ReactVersion = '19.0.0-www-classic-142b2a8230-20240607';
var ReactVersion = '19.0.0-www-classic-20841f9a62-20240607';

var LegacyRoot = 0;
var ConcurrentRoot = 1;
Expand Down Expand Up @@ -6228,7 +6228,7 @@ var ownerHasKeyUseWarning;
var ownerHasFunctionTypeWarning;
var ownerHasSymbolTypeWarning;

var warnForMissingKey = function (child, returnFiber) {};
var warnForMissingKey = function (returnFiber, workInProgress, child) {};

{
didWarnAboutMaps = false;
Expand All @@ -6243,7 +6243,7 @@ var warnForMissingKey = function (child, returnFiber) {};
ownerHasFunctionTypeWarning = {};
ownerHasSymbolTypeWarning = {};

warnForMissingKey = function (child, returnFiber) {
warnForMissingKey = function (returnFiber, workInProgress, child) {
if (child === null || typeof child !== 'object') {
return;
}
Expand Down Expand Up @@ -6302,15 +6302,9 @@ var warnForMissingKey = function (child, returnFiber) {};
// Give the component that originally created this child.
childOwnerAppendix = " It was passed a child from " + ownerName + ".";
}
} // We create a fake Fiber for the child to log the stack trace from.
// TODO: Refactor the warnForMissingKey calls to happen after fiber creation
// so that we can get access to the fiber that will eventually be created.
// That way the log can show up associated with the right instance in DevTools.

}

var fiber = createFiberFromElement(child, returnFiber.mode, 0);
fiber.return = returnFiber;
runWithFiberInDEV(fiber, function () {
runWithFiberInDEV(workInProgress, function () {
error('Each child in a list should have a unique "key" prop.' + '%s%s See https://react.dev/link/warning-keys for more information.', currentComponentErrorInfo, childOwnerAppendix);
});
};
Expand Down Expand Up @@ -6907,7 +6901,7 @@ function createChildReconciler(shouldTrackSideEffects) {
*/


function warnOnInvalidKey(child, knownKeys, returnFiber) {
function warnOnInvalidKey(returnFiber, workInProgress, child, knownKeys) {
{
if (typeof child !== 'object' || child === null) {
return knownKeys;
Expand All @@ -6916,7 +6910,7 @@ function createChildReconciler(shouldTrackSideEffects) {
switch (child.$$typeof) {
case REACT_ELEMENT_TYPE:
case REACT_PORTAL_TYPE:
warnForMissingKey(child, returnFiber);
warnForMissingKey(returnFiber, workInProgress, child);
var key = child.key;

if (typeof key !== 'string') {
Expand All @@ -6934,8 +6928,9 @@ function createChildReconciler(shouldTrackSideEffects) {
break;
}

error('Encountered two children with the same key, `%s`. ' + 'Keys should be unique so that components maintain their identity ' + 'across updates. Non-unique keys may cause children to be ' + 'duplicated and/or omitted — the behavior is unsupported and ' + 'could change in a future version.', key);

runWithFiberInDEV(workInProgress, function () {
error('Encountered two children with the same key, `%s`. ' + 'Keys should be unique so that components maintain their identity ' + 'across updates. Non-unique keys may cause children to be ' + 'duplicated and/or omitted — the behavior is unsupported and ' + 'could change in a future version.', key);
});
break;

case REACT_LAZY_TYPE:
Expand All @@ -6946,7 +6941,7 @@ function createChildReconciler(shouldTrackSideEffects) {
resolvedChild = callLazyInitInDEV(child);
}

warnOnInvalidKey(resolvedChild, knownKeys, returnFiber);
warnOnInvalidKey(returnFiber, workInProgress, resolvedChild, knownKeys);
break;
}
}
Expand All @@ -6971,16 +6966,7 @@ function createChildReconciler(shouldTrackSideEffects) {
// (adding everything to a Map) in for every insert/move.
// If you change this code, also update reconcileChildrenIterator() which
// uses the same algorithm.
{
// First, validate keys.
var knownKeys = null;

for (var i = 0; i < newChildren.length; i++) {
var child = newChildren[i];
knownKeys = warnOnInvalidKey(child, knownKeys, returnFiber);
}
}

var knownKeys = null;
var resultingFirstChild = null;
var previousNewFiber = null;
var oldFiber = currentFirstChild;
Expand Down Expand Up @@ -7010,6 +6996,10 @@ function createChildReconciler(shouldTrackSideEffects) {
break;
}

{
knownKeys = warnOnInvalidKey(returnFiber, newFiber, newChildren[newIdx], knownKeys);
}

if (shouldTrackSideEffects) {
if (oldFiber && newFiber.alternate === null) {
// We matched the slot, but we didn't reuse the existing fiber, so we
Expand Down Expand Up @@ -7052,6 +7042,10 @@ function createChildReconciler(shouldTrackSideEffects) {
continue;
}

{
knownKeys = warnOnInvalidKey(returnFiber, _newFiber, newChildren[newIdx], knownKeys);
}

lastPlacedIndex = placeChild(_newFiber, lastPlacedIndex, newIdx);

if (previousNewFiber === null) {
Expand All @@ -7074,6 +7068,10 @@ function createChildReconciler(shouldTrackSideEffects) {
var _newFiber2 = updateFromMap(existingChildren, returnFiber, newIdx, newChildren[newIdx], lanes, debugInfo);

if (_newFiber2 !== null) {
{
knownKeys = warnOnInvalidKey(returnFiber, _newFiber2, newChildren[newIdx], knownKeys);
}

if (shouldTrackSideEffects) {
if (_newFiber2.alternate !== null) {
// The new fiber is a work in progress, but if there exists a
Expand Down Expand Up @@ -7163,11 +7161,7 @@ function createChildReconciler(shouldTrackSideEffects) {
var knownKeys = null;
var step = newChildren.next();

{
knownKeys = warnOnInvalidKey(step.value, knownKeys, returnFiber);
}

for (; oldFiber !== null && !step.done; newIdx++, step = newChildren.next(), knownKeys = warnOnInvalidKey(step.value, knownKeys, returnFiber) ) {
for (; oldFiber !== null && !step.done; newIdx++, step = newChildren.next()) {
if (oldFiber.index > newIdx) {
nextOldFiber = oldFiber;
oldFiber = null;
Expand All @@ -7189,6 +7183,10 @@ function createChildReconciler(shouldTrackSideEffects) {
break;
}

{
knownKeys = warnOnInvalidKey(returnFiber, newFiber, step.value, knownKeys);
}

if (shouldTrackSideEffects) {
if (oldFiber && newFiber.alternate === null) {
// We matched the slot, but we didn't reuse the existing fiber, so we
Expand Down Expand Up @@ -7224,13 +7222,17 @@ function createChildReconciler(shouldTrackSideEffects) {
if (oldFiber === null) {
// If we don't have any more existing children we can choose a fast path
// since the rest will all be insertions.
for (; !step.done; newIdx++, step = newChildren.next(), knownKeys = warnOnInvalidKey(step.value, knownKeys, returnFiber) ) {
for (; !step.done; newIdx++, step = newChildren.next()) {
var _newFiber3 = createChild(returnFiber, step.value, lanes, debugInfo);

if (_newFiber3 === null) {
continue;
}

{
knownKeys = warnOnInvalidKey(returnFiber, _newFiber3, step.value, knownKeys);
}

lastPlacedIndex = placeChild(_newFiber3, lastPlacedIndex, newIdx);

if (previousNewFiber === null) {
Expand All @@ -7249,10 +7251,14 @@ function createChildReconciler(shouldTrackSideEffects) {

var existingChildren = mapRemainingChildren(oldFiber); // Keep scanning and use the map to restore deleted items as moves.

for (; !step.done; newIdx++, step = newChildren.next(), knownKeys = warnOnInvalidKey(step.value, knownKeys, returnFiber) ) {
for (; !step.done; newIdx++, step = newChildren.next()) {
var _newFiber4 = updateFromMap(existingChildren, returnFiber, newIdx, step.value, lanes, debugInfo);

if (_newFiber4 !== null) {
{
knownKeys = warnOnInvalidKey(returnFiber, _newFiber4, step.value, knownKeys);
}

if (shouldTrackSideEffects) {
if (_newFiber4.alternate !== null) {
// The new fiber is a work in progress, but if there exists a
Expand Down
Loading

0 comments on commit cdfa569

Please sign in to comment.