Skip to content

Commit 76beb64

Browse files
committed
[compiler] loosen computed key restriction for compiler (#34902)
We have a whole ton of compiler errors due to us using a helper to return breakpoints for CSS-in-js, which results in code like: ``` const styles = { [responsive.up('xl')]: { ... } } ``` this results in TONS of bailouts due to `(BuildHIR::lowerExpression) Expected Identifier, got CallExpression key in ObjectExpression`. I was looking into what it would take to fix it and why we don't allow it, and following the paper trail is seems like the gotchas have been fixed with the new mutability aliasing model that is fully rolled out. It looks like this is the same pattern/issue that was fixed (see https://github.com/facebook/react/blob/main/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/repro-object-expression-computed-key-modified-during-after-construction-hoisted-sequence-expr.js and the old bug in https://github.com/facebook/react/blob/d58c07b563a79bd706531278cb4afec6292b84a8/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/bug-object-expression-computed-key-modified-during-after-construction-hoisted-sequence-expr.expect.md). @josephsavona can you confirm if that's the case and if we're able to drop this restriction now? (or alternatively, is there another case we can ignore?) DiffTrain build for [ea0c17b](ea0c17b)
1 parent c157c76 commit 76beb64

35 files changed

+88
-97
lines changed

compiled/eslint-plugin-react-hooks/index.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24151,7 +24151,7 @@ function lowerObjectMethod(builder, property) {
2415124151
};
2415224152
}
2415324153
function lowerObjectPropertyKey(builder, property) {
24154-
var _a, _b;
24154+
var _a;
2415524155
const key = property.get('key');
2415624156
if (key.isStringLiteral()) {
2415724157
return {
@@ -24160,15 +24160,6 @@ function lowerObjectPropertyKey(builder, property) {
2416024160
};
2416124161
}
2416224162
else if (property.node.computed && key.isExpression()) {
24163-
if (!key.isIdentifier() && !key.isMemberExpression()) {
24164-
builder.errors.push({
24165-
reason: `(BuildHIR::lowerExpression) Expected Identifier, got ${key.type} key in ObjectExpression`,
24166-
category: ErrorCategory.Todo,
24167-
loc: (_a = key.node.loc) !== null && _a !== void 0 ? _a : null,
24168-
suggestions: null,
24169-
});
24170-
return null;
24171-
}
2417224163
const place = lowerExpressionToTemporary(builder, key);
2417324164
return {
2417424165
kind: 'computed',
@@ -24190,7 +24181,7 @@ function lowerObjectPropertyKey(builder, property) {
2419024181
builder.errors.push({
2419124182
reason: `(BuildHIR::lowerExpression) Expected Identifier, got ${key.type} key in ObjectExpression`,
2419224183
category: ErrorCategory.Todo,
24193-
loc: (_b = key.node.loc) !== null && _b !== void 0 ? _b : null,
24184+
loc: (_a = key.node.loc) !== null && _a !== void 0 ? _a : null,
2419424185
suggestions: null,
2419524186
});
2419624187
return null;

compiled/facebook-www/REVISION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2bcbf254f168ddec567156f802d19315e64e4aa8
1+
ea0c17b0952e2b866a1f0dd4b5ac28c7df9d8518
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2bcbf254f168ddec567156f802d19315e64e4aa8
1+
ea0c17b0952e2b866a1f0dd4b5ac28c7df9d8518

compiled/facebook-www/React-dev.classic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1499,7 +1499,7 @@ __DEV__ &&
14991499
exports.useTransition = function () {
15001500
return resolveDispatcher().useTransition();
15011501
};
1502-
exports.version = "19.3.0-www-classic-2bcbf254-20251020";
1502+
exports.version = "19.3.0-www-classic-ea0c17b0-20251020";
15031503
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
15041504
"function" ===
15051505
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled/facebook-www/React-dev.modern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1499,7 +1499,7 @@ __DEV__ &&
14991499
exports.useTransition = function () {
15001500
return resolveDispatcher().useTransition();
15011501
};
1502-
exports.version = "19.3.0-www-modern-2bcbf254-20251020";
1502+
exports.version = "19.3.0-www-modern-ea0c17b0-20251020";
15031503
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
15041504
"function" ===
15051505
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled/facebook-www/React-prod.classic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,4 +606,4 @@ exports.useSyncExternalStore = function (
606606
exports.useTransition = function () {
607607
return ReactSharedInternals.H.useTransition();
608608
};
609-
exports.version = "19.3.0-www-classic-2bcbf254-20251020";
609+
exports.version = "19.3.0-www-classic-ea0c17b0-20251020";

compiled/facebook-www/React-prod.modern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,4 +606,4 @@ exports.useSyncExternalStore = function (
606606
exports.useTransition = function () {
607607
return ReactSharedInternals.H.useTransition();
608608
};
609-
exports.version = "19.3.0-www-modern-2bcbf254-20251020";
609+
exports.version = "19.3.0-www-modern-ea0c17b0-20251020";

compiled/facebook-www/React-profiling.classic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ exports.useSyncExternalStore = function (
610610
exports.useTransition = function () {
611611
return ReactSharedInternals.H.useTransition();
612612
};
613-
exports.version = "19.3.0-www-classic-2bcbf254-20251020";
613+
exports.version = "19.3.0-www-classic-ea0c17b0-20251020";
614614
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
615615
"function" ===
616616
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled/facebook-www/React-profiling.modern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ exports.useSyncExternalStore = function (
610610
exports.useTransition = function () {
611611
return ReactSharedInternals.H.useTransition();
612612
};
613-
exports.version = "19.3.0-www-modern-2bcbf254-20251020";
613+
exports.version = "19.3.0-www-modern-ea0c17b0-20251020";
614614
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
615615
"function" ===
616616
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled/facebook-www/ReactART-dev.classic.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20371,10 +20371,10 @@ __DEV__ &&
2037120371
(function () {
2037220372
var internals = {
2037320373
bundleType: 1,
20374-
version: "19.3.0-www-classic-2bcbf254-20251020",
20374+
version: "19.3.0-www-classic-ea0c17b0-20251020",
2037520375
rendererPackageName: "react-art",
2037620376
currentDispatcherRef: ReactSharedInternals,
20377-
reconcilerVersion: "19.3.0-www-classic-2bcbf254-20251020"
20377+
reconcilerVersion: "19.3.0-www-classic-ea0c17b0-20251020"
2037820378
};
2037920379
internals.overrideHookState = overrideHookState;
2038020380
internals.overrideHookStateDeletePath = overrideHookStateDeletePath;
@@ -20409,7 +20409,7 @@ __DEV__ &&
2040920409
exports.Shape = Shape;
2041020410
exports.Surface = Surface;
2041120411
exports.Text = Text;
20412-
exports.version = "19.3.0-www-classic-2bcbf254-20251020";
20412+
exports.version = "19.3.0-www-classic-ea0c17b0-20251020";
2041320413
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
2041420414
"function" ===
2041520415
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

0 commit comments

Comments
 (0)