[compiler] Add missing source locations to statements, expressions (#34406)
Adds missing locations to all the statement kinds that we produce in codegenInstruction(), and adds generic handling of source locations for the nodes produced by codegenInstructionValue(). There are definitely some places where we are still missing a location, but this should address some of the known issues we've seen such as missing location on `throw`. --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/react/pull/34406). * #34394 * __->__ #34406 * #34346
Joseph Savona committed
Sep 6, 2025 at 11:14 UTC
f5e96b974073d3ba80dc844d095c49d5b019afe0
92 files changed
+164
-59
compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/CodegenReactiveFunction.ts
+43
-12
@@ -982,7 +982,8 @@ function codegenTerminal(
982
if (terminal.targetKind === 'implicit') {
983
return null;
984
}
985
- return t.breakStatement(
985
+ return createBreakStatement(
986
+ terminal.loc,
987
terminal.targetKind === 'labeled'
988
? t.identifier(codegenLabel(terminal.target))
989
: null,
@@ -992,14 +993,16 @@ function codegenTerminal(
993
if (terminal.targetKind === 'implicit') {
994
return null;
995
}
995
- return t.continueStatement(
996
+ return createContinueStatement(
997
+ terminal.loc,
998
terminal.targetKind === 'labeled'
999
? t.identifier(codegenLabel(terminal.target))
1000
: null,
1001
);
1002
}
1003
case 'for': {
1002
- return t.forStatement(
1004
+ return createForStatement(
1005
+ terminal.loc,
1006
codegenForInit(cx, terminal.init),
1007
codegenInstructionValueToExpression(cx, terminal.test),
1008
terminal.update !== null
@@ -1108,7 +1111,8 @@ function codegenTerminal(
1111
`Unhandled lvalue kind: ${iterableItem.value.lvalue.kind}`,
1112
);
1113
}
1111
- return t.forInStatement(
1114
+ return createForInStatement(
1115
+ terminal.loc,
1116
/*
1117
* Special handling here since we only want the VariableDeclarators without any inits
1118
* This needs to be updated when we handle non-trivial ForOf inits
@@ -1225,7 +1229,8 @@ function codegenTerminal(
1229
`Unhandled lvalue kind: ${iterableItem.value.lvalue.kind}`,
1230
);
1231
}
1228
- return t.forOfStatement(
1232
+ return createForOfStatement(
1233
+ terminal.loc,
1234
/*
1235
* Special handling here since we only want the VariableDeclarators without any inits
1236
* This needs to be updated when we handle non-trivial ForOf inits
@@ -1247,7 +1252,7 @@ function codegenTerminal(
1252
alternate = block;
1253
}
1254
}
1250
- return t.ifStatement(test, consequent, alternate);
1255
+ return createIfStatement(terminal.loc, test, consequent, alternate);
1256
}
1257
case 'return': {
1258
const value = codegenPlaceToExpression(cx, terminal.value);
@@ -1258,7 +1263,8 @@ function codegenTerminal(
1263
return t.returnStatement(value);
1264
}
1265
case 'switch': {
1261
- return t.switchStatement(
1266
+ return createSwitchStatement(
1267
+ terminal.loc,
1268
codegenPlaceToExpression(cx, terminal.test),
1269
terminal.cases.map(case_ => {
1270
const test =
@@ -1271,15 +1277,26 @@ function codegenTerminal(
1277
);
1278
}
1279
case 'throw': {
1274
- return t.throwStatement(codegenPlaceToExpression(cx, terminal.value));
1280
+ return createThrowStatement(
1281
+ terminal.loc,
1282
+ codegenPlaceToExpression(cx, terminal.value),
1283
+ );
1284
}
1285
case 'do-while': {
1286
const test = codegenInstructionValueToExpression(cx, terminal.test);
1278
- return t.doWhileStatement(test, codegenBlock(cx, terminal.loop));
1287
+ return createDoWhileStatement(
1288
+ terminal.loc,
1289
+ test,
1290
+ codegenBlock(cx, terminal.loop),
1291
+ );
1292
}
1293
case 'while': {
1294
const test = codegenInstructionValueToExpression(cx, terminal.test);
1282
- return t.whileStatement(test, codegenBlock(cx, terminal.loop));
1295
+ return createWhileStatement(
1296
+ terminal.loc,
1297
+ test,
1298
+ codegenBlock(cx, terminal.loop),
1299
+ );
1300
}
1301
case 'label': {
1302
return codegenBlock(cx, terminal.block);
@@ -1290,7 +1307,8 @@ function codegenTerminal(
1307
catchParam = convertIdentifier(terminal.handlerBinding.identifier);
1308
cx.temp.set(terminal.handlerBinding.identifier.declarationId, null);
1309
}
1293
- return t.tryStatement(
1310
+ return createTryStatement(
1311
+ terminal.loc,
1312
codegenBlock(cx, terminal.block),
1313
t.catchClause(catchParam, codegenBlock(cx, terminal.handler)),
1314
);
@@ -1695,7 +1713,13 @@ const createExpressionStatement = withLoc(t.expressionStatement);
1713
const _createLabelledStatement = withLoc(t.labeledStatement);
1714
const createVariableDeclaration = withLoc(t.variableDeclaration);
1715
const createFunctionDeclaration = withLoc(t.functionDeclaration);
1698
-const _createWhileStatement = withLoc(t.whileStatement);
1716
+const createWhileStatement = withLoc(t.whileStatement);
1717
+const createDoWhileStatement = withLoc(t.doWhileStatement);
1718
+const createSwitchStatement = withLoc(t.switchStatement);
1719
+const createIfStatement = withLoc(t.ifStatement);
1720
+const createForStatement = withLoc(t.forStatement);
1721
+const createForOfStatement = withLoc(t.forOfStatement);
1722
+const createForInStatement = withLoc(t.forInStatement);
1723
const createTaggedTemplateExpression = withLoc(t.taggedTemplateExpression);
1724
const createLogicalExpression = withLoc(t.logicalExpression);
1725
const createSequenceExpression = withLoc(t.sequenceExpression);
@@ -1710,6 +1734,10 @@ const createJsxText = withLoc(t.jsxText);
1734
const createJsxClosingElement = withLoc(t.jsxClosingElement);
1735
const createJsxOpeningElement = withLoc(t.jsxOpeningElement);
1736
const createStringLiteral = withLoc(t.stringLiteral);
1737
+const createThrowStatement = withLoc(t.throwStatement);
1738
+const createTryStatement = withLoc(t.tryStatement);
1739
+const createBreakStatement = withLoc(t.breakStatement);
1740
+const createContinueStatement = withLoc(t.continueStatement);
1741
1742
function createHookGuard(
1743
guard: ExternalFunction,
@@ -2524,6 +2552,9 @@ function codegenInstructionValue(
2552
);
2553
}
2554
}
2555
+ if (instrValue.loc != null && instrValue.loc != GeneratedSource) {
2556
+ value.loc = instrValue.loc;
2557
+ }
2558
return value;
2559
}
2560
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/align-scopes-nested-block-structure.expect.md
+1
@@ -129,6 +129,7 @@ function useFoo(t0) {
129
t1 = null;
130
break bb0;
131
}
132
+
133
if (cond2) {
134
mutate(s);
135
}
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/align-scopes-reactive-scope-overlaps-label.expect.md
+1
@@ -43,6 +43,7 @@ function useFoo(t0) {
43
if ($[0] !== cond || $[1] !== value) {
44
bb0: {
45
items = [];
46
+
47
if (cond) {
48
break bb0;
49
}
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/align-scopes-trycatch-nested-overlapping-range.expect.md
+1
@@ -39,6 +39,7 @@ function Foo() {
39
if (cond) {
40
thing = makeObject_Primitives();
41
}
42
+
43
if (CONST_TRUE) {
44
mutate(thing);
45
}
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/assignment-in-nested-if.expect.md
+1
@@ -23,6 +23,7 @@ import { c as _c } from "react/compiler-runtime";
23
function useBar(props) {
24
const $ = _c(1);
25
let z;
26
+
27
if (props.a) {
28
if (props.b) {
29
let t0;
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capture-param-mutate.expect.md
+2
@@ -67,6 +67,7 @@ function getNativeLogFunction(level) {
67
) {
68
logLevel = LOG_LEVELS.warn;
69
}
70
+
71
if (global.__inspectorLog) {
72
global.__inspectorLog(
73
INSPECTOR_LEVELS[logLevel],
@@ -75,6 +76,7 @@ function getNativeLogFunction(level) {
76
INSPECTOR_FRAMES_TO_SKIP,
77
);
78
}
79
+
80
if (groupStack.length) {
81
str = groupFormat("", str);
82
}
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capture-ref-for-later-mutation.expect.md
-2
@@ -47,9 +47,7 @@ function useKeyCommand() {
47
};
48
49
const moveLeft = { handler: handleKey("left") };
50
-
50
const moveRight = { handler: handleKey("right") };
52
-
51
t0 = [moveLeft, moveRight];
52
$[0] = t0;
53
} else {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/chained-assignment-context-variable.expect.md
-1
@@ -33,7 +33,6 @@ function Component() {
33
let y;
34
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
35
y = x = {};
36
-
36
const foo = () => {
37
x = makeArray();
38
};
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/conditional-on-mutable.expect.md
+2
@@ -44,6 +44,7 @@ function ComponentA(props) {
44
if (b) {
45
a.push(props.p0);
46
}
47
+
48
if (props.p1) {
49
b.push(props.p2);
50
}
@@ -68,6 +69,7 @@ function ComponentB(props) {
69
if (mayMutate(b)) {
70
a.push(props.p0);
71
}
72
+
73
if (props.p1) {
74
b.push(props.p2);
75
}
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/conditional-set-state-in-render.expect.md
+1
@@ -34,6 +34,7 @@ function Component(props) {
34
const foo = () => {
35
setX(1);
36
};
37
+
38
if (props.cond) {
39
setX(2);
40
foo();
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/constant-prop-to-object-method.expect.md
-1
@@ -36,7 +36,6 @@ function Foo() {
36
return identity(1);
37
},
38
};
39
-
39
t0 = x.foo();
40
$[0] = t0;
41
} else {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/constant-propagation-template-literal.expect.md
-1
@@ -79,7 +79,6 @@ function foo() {
79
value={[
80
true,
81
true,
82
-
82
"a\nb",
83
"\n",
84
"a1b",
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/constant-propagation-unary-number.expect.md
-1
@@ -48,7 +48,6 @@ function foo() {
48
true,
49
-Infinity,
50
-NaN,
51
-
51
-1 * NaN,
52
-1 * Infinity,
53
-1 * -Infinity,
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/constructor.expect.md
+1
@@ -28,6 +28,7 @@ function Component(props) {
28
const a = [];
29
const b = {};
30
new Foo(a, b);
31
+
32
new Foo(b);
33
t0 = <div a={a} b={b} />;
34
$[0] = t0;
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/context-variable-reassigned-objectmethod.expect.md
-1
@@ -43,7 +43,6 @@ function Component(t0) {
43
}
44
},
45
};
46
-
46
invoke(obj.method, cond);
47
$[0] = cond;
48
$[1] = x;
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/debugger.expect.md
+1
@@ -27,6 +27,7 @@ export const FIXTURE_ENTRYPOINT = {
27
```javascript
28
function Component(props) {
29
debugger;
30
+
31
if (props.cond) {
32
debugger;
33
} else {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/delete-computed-property.expect.md
+1
@@ -26,6 +26,7 @@ function Component(props) {
26
let x;
27
if ($[0] !== props.a || $[1] !== props.b) {
28
x = { a: props.a, b: props.b };
29
+
30
delete x["b"];
31
$[0] = props.a;
32
$[1] = props.b;
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/dependencies-outputs.expect.md
+1
@@ -46,6 +46,7 @@ function foo(a, b) {
46
if (x.length) {
47
y.push(x);
48
}
49
+
50
if (b) {
51
y.push(b);
52
}
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/dependencies.expect.md
+1
@@ -46,6 +46,7 @@ function foo(x, y, z) {
46
} else {
47
items2 = $[2];
48
}
49
+
50
if (y) {
51
items.push(x);
52
}
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/dont-merge-if-dep-is-inner-declaration-of-previous-scope.expect.md
+1
@@ -57,6 +57,7 @@ function Component(t0) {
57
let y;
58
if ($[0] !== a || $[1] !== b || $[2] !== c) {
59
x = [];
60
+
61
if (a) {
62
let t1;
63
if ($[5] !== b) {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/extend-scopes-if.expect.md
+1
@@ -48,6 +48,7 @@ function foo(a, b, c) {
48
} else {
49
x = $[3];
50
}
51
+
52
if (x.length) {
53
return x;
54
}
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/for-multiple-variable-declarations-in-initializer.expect.md
+1
@@ -28,6 +28,7 @@ function Component(props) {
28
let items;
29
if ($[0] !== props.items) {
30
items = [];
31
+
32
for (let i = 0, length = props.items.length; i < length; i++) {
33
items.push(props.items[i]);
34
}
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/for-of-capture-item-of-local-collection-mutate-later-value-initially-null.expect.md
+1
@@ -39,6 +39,7 @@ function Component(props) {
39
for (const x of items) {
40
lastItem = x;
41
}
42
+
43
if (lastItem != null) {
44
lastItem.a = lastItem.a + 1;
45
}
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/for-of-capture-item-of-local-collection-mutate-later.expect.md
+1
@@ -39,6 +39,7 @@ function Component(props) {
39
for (const x of items) {
40
lastItem = x;
41
}
42
+
43
if (lastItem != null) {
44
lastItem.a = lastItem.a + 1;
45
}
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/function-expression-captures-value-later-frozen-jsx.expect.md
+1
@@ -41,6 +41,7 @@ function Component(props) {
41
t1 = $[1];
42
}
43
const onChange = t1;
44
+
45
if (props.cond) {
46
}
47
let t2;
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/codegen-instrument-forget-gating-test.expect.md
+1
@@ -69,6 +69,7 @@ const Foo = isForgetEnabled_Fixtures()
69
if (DEV && shouldInstrument)
70
useRenderCounter("Foo", "/codegen-instrument-forget-gating-test.ts");
71
const $ = _c(3);
72
+
73
if (props.bar < 0) {
74
return props.children;
75
}
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/gating-test-export-function-and-default.expect.md
+1
@@ -63,6 +63,7 @@ const Foo = isForgetEnabled_Fixtures()
63
? function Foo(props) {
64
"use forget";
65
const $ = _c(3);
66
+
67
if (props.bar < 0) {
68
return props.children;
69
}
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hoisting-object-method.expect.md
-1
@@ -35,7 +35,6 @@ function hoisting() {
35
return bar();
36
},
37
};
38
-
38
const bar = _temp;
39
40
t0 = x.foo();
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/iife-return-modified-later-phi.expect.md
+1
@@ -30,6 +30,7 @@ function Component(props) {
30
let items;
31
if ($[0] !== props.a || $[1] !== props.cond) {
32
let t0;
33
+
34
if (props.cond) {
35
t0 = [];
36
} else {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/inline-jsx-transform.expect.md
+1
@@ -390,6 +390,7 @@ function ConditionalJsx(t0) {
390
t1 = $[0];
391
}
392
let content = t1;
393
+
394
if (shouldWrap) {
395
const t2 = content;
396
let t3;
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/jsx-local-memberexpr-tag-conditional.expect.md
+1
@@ -27,6 +27,7 @@ import * as SharedRuntime from "shared-runtime";
27
function useFoo(t0) {
28
const $ = _c(1);
29
const { cond } = t0;
30
+
31
if (cond) {
32
let t1;
33
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/merge-consecutive-nested-scopes.expect.md
+1
@@ -30,6 +30,7 @@ const { getNumber } = require("shared-runtime");
30
function Component(props) {
31
const $ = _c(1);
32
let x;
33
+
34
if (props.cond) {
35
let t0;
36
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/module-scoped-bindings.expect.md
-1
@@ -75,7 +75,6 @@ function Component() {
75
if ($[0] !== state) {
76
t0 = [
77
React,
78
-
78
state,
79
CONST,
80
NON_REASSIGNED_LET,
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/mutable-lifetime-loops.expect.md
+4
@@ -94,12 +94,16 @@ function testFunction(props) {
94
break;
95
}
96
}
97
+
98
if (a) {
99
}
100
+
101
if (b) {
102
}
103
+
104
if (c) {
105
}
106
+
107
if (d) {
108
}
109
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/mutable-lifetime-with-aliasing.expect.md
+5
@@ -78,14 +78,19 @@ function Component(props) {
78
x = {};
79
x.b = b;
80
const y = mutate(x, d);
81
+
82
if (a) {
83
}
84
+
85
if (b) {
86
}
87
+
88
if (c) {
89
}
90
+
91
if (d) {
92
}
93
+
94
if (y) {
95
}
96
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/mutable-liverange-loop.expect.md
+4
@@ -51,12 +51,16 @@ function Component(props) {
51
break;
52
}
53
}
54
+
55
if (a) {
56
}
57
+
58
if (b) {
59
}
60
+
61
if (c) {
62
}
63
+
64
if (d) {
65
}
66
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/capture-backedge-phi-with-later-mutation.expect.md
+2
@@ -53,8 +53,10 @@ function Component(t0) {
53
let z;
54
if ($[0] !== prop1 || $[1] !== prop2) {
55
let x = [{ value: prop1 }];
56
+
57
while (x.length < 2) {
58
arrayPush(x, { value: prop2 });
59
+
60
if (x[0].value === prop1) {
61
x = [{ value: prop2 }];
62
const y = x;
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/iife-return-modified-later-phi.expect.md
+1
@@ -30,6 +30,7 @@ function Component(props) {
30
let items;
31
if ($[0] !== props.a || $[1] !== props.cond) {
32
let t0;
33
+
34
if (props.cond) {
35
t0 = [];
36
} else {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/object-expression-computed-key-object-mutated-later.expect.md
-1
@@ -33,7 +33,6 @@ function Component(props) {
33
if ($[0] !== props.value) {
34
const key = {};
35
context = { [key]: identity([props.value]) };
36
-
36
mutate(key);
37
$[0] = props.value;
38
$[1] = context;
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/object-expression-computed-member.expect.md
-1
@@ -44,7 +44,6 @@ function Component(props) {
44
t2 = $[3];
45
}
46
context = t2;
47
-
47
mutate(key);
48
$[0] = props.value;
49
$[1] = context;
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/repro-compiler-infinite-loop.expect.md
+1
@@ -32,6 +32,7 @@ import fbt from "fbt";
32
function Component() {
33
const $ = _c(1);
34
const sections = Object.keys(items);
35
+
36
for (let i = 0; i < sections.length; i = i + 3, i) {
37
chunks.push(sections.slice(i, i + 3).map(_temp));
38
}
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/useCallback-reordering-depslist-assignment.expect.md
-1
@@ -51,7 +51,6 @@ function useFoo(arr1, arr2) {
51
if ($[2] !== arr2 || $[3] !== x) {
52
let y;
53
t1 = () => ({ y });
54
-
54
(y = x.concat(arr2)), y;
55
$[2] = arr2;
56
$[3] = x;
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/nonmutating-capture-in-unsplittable-memo-block.expect.md
+1
@@ -89,6 +89,7 @@ function useFoo(t0) {
89
y = $[2];
90
z = $[3];
91
}
92
+
93
if (z[0] !== y) {
94
throw new Error("oh no!");
95
}
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-expression-computed-key-object-mutated-later.expect.md
-1
@@ -32,7 +32,6 @@ function Component(props) {
32
if ($[0] !== props.value) {
33
const key = {};
34
context = { [key]: identity([props.value]) };
35
-
35
mutate(key);
36
$[0] = props.value;
37
$[1] = context;
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-expression-computed-member.expect.md
-1
@@ -43,7 +43,6 @@ function Component(props) {
43
t2 = $[3];
44
}
45
context = t2;
46
-
46
mutate(key);
47
$[0] = props.value;
48
$[1] = context;
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-method-maybe-alias.expect.md
-2
@@ -38,13 +38,11 @@ function useHook(props) {
38
return props;
39
},
40
};
41
-
41
const y = {
42
getY() {
43
return "y";
44
},
45
};
47
-
46
t0 = setProperty(x, y);
47
$[0] = props;
48
$[1] = t0;
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-method-shorthand-3.expect.md
-1
@@ -39,7 +39,6 @@ function useHook(a) {
39
return x;
40
},
41
};
42
-
42
t0 = obj.method();
43
$[0] = a;
44
$[1] = t0;
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-method-shorthand-aliased-mutate-after.expect.md
-1
@@ -37,7 +37,6 @@ function useHook(t0) {
37
return value;
38
},
39
};
40
-
40
mutate(x);
41
$[0] = value;
42
$[1] = obj;
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-method-shorthand-mutated-after.expect.md
-1
@@ -37,7 +37,6 @@ function useHook(t0) {
37
return x;
38
},
39
};
40
-
40
mutate(obj);
41
$[0] = value;
42
$[1] = obj;
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-method-shorthand.expect.md
-1
@@ -31,7 +31,6 @@ function Component() {
31
return 1;
32
},
33
};
34
-
34
t0 = obj.method();
35
$[0] = t0;
36
} else {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/original-reactive-scopes-fork/capture-ref-for-later-mutation.expect.md
-2
@@ -48,9 +48,7 @@ function useKeyCommand() {
48
};
49
50
const moveLeft = { handler: handleKey("left") };
51
-
51
const moveRight = { handler: handleKey("right") };
53
-
52
t0 = [moveLeft, moveRight];
53
$[0] = t0;
54
} else {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/overlapping-scopes-interleaved-by-terminal.expect.md
+1
@@ -27,6 +27,7 @@ export const FIXTURE_ENTRYPOINT = {
27
function foo(a, b, c) {
28
const x = [];
29
const y = [];
30
+
31
if (x) {
32
}
33
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/maybe-invalid-useMemo-no-memoblock-sideeffect.expect.md
+1
@@ -36,6 +36,7 @@ import { useMemo } from "react";
36
// (i.e. inferred non-mutable or non-escaping values don't get memoized)
37
function useFoo(t0) {
38
const { minWidth, styles, setStyles } = t0;
39
+
40
if (styles.width > minWidth) {
41
setStyles(styles);
42
}
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/prune-nonescaping-useMemo-mult-returns-primitive.expect.md
+1
@@ -34,6 +34,7 @@ import { identity } from "shared-runtime";
34
35
function useFoo(cond) {
36
let t0;
37
+
38
if (cond) {
39
t0 = 2;
40
} else {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/prune-nonescaping-useMemo-mult-returns.expect.md
+1
@@ -34,6 +34,7 @@ import { identity } from "shared-runtime";
34
35
function useFoo(cond) {
36
let t0;
37
+
38
if (cond) {
39
t0 = identity(10);
40
} else {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-nonescaping.expect.md
+1
@@ -41,6 +41,7 @@ function Component(t0) {
41
const { entity, children } = t0;
42
43
const showMessage = () => entity != null;
44
+
45
if (!showMessage()) {
46
return children;
47
}
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-reordering-depslist-assignment.expect.md
-1
@@ -50,7 +50,6 @@ function useFoo(arr1, arr2) {
50
if ($[2] !== arr2 || $[3] !== x) {
51
let y;
52
t1 = () => ({ y });
53
-
53
(y = x.concat(arr2)), y;
54
$[2] = arr2;
55
$[3] = x;
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/conditional-on-mutable.expect.md
+2
@@ -45,6 +45,7 @@ function ComponentA(props) {
45
if (b) {
46
a.push(props.p0);
47
}
48
+
49
if (props.p1) {
50
b.push(props.p2);
51
}
@@ -69,6 +70,7 @@ function ComponentB(props) {
70
if (mayMutate(b)) {
71
a.push(props.p0);
72
}
73
+
74
if (props.p1) {
75
b.push(props.p2);
76
}
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/iife-return-modified-later-phi.expect.md
+1
@@ -31,6 +31,7 @@ function Component(props) {
31
let items;
32
if ($[0] !== props.a || $[1] !== props.cond) {
33
let t0;
34
+
35
if (props.cond) {
36
t0 = [];
37
} else {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-object-method-uncond-access.expect.md
-1
@@ -40,7 +40,6 @@ function useFoo(t0) {
40
return identity(a.b.c);
41
},
42
};
43
-
43
t1 = <Stringify x={x} shouldInvokeFns={true} />;
44
$[0] = a;
45
$[1] = t1;
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/switch-non-final-default.expect.md
-1
@@ -61,7 +61,6 @@ function Component(props) {
61
y = x;
62
}
63
}
64
-
64
t0 = <Component data={x} />;
65
$[0] = props.p0;
66
$[1] = props.p2;
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/switch.expect.md
+1
-1
@@ -34,6 +34,7 @@ function Component(props) {
34
let y;
35
if ($[0] !== props.p0 || $[1] !== props.p2 || $[2] !== props.p3) {
36
const x = [];
37
+
38
switch (props.p0) {
39
case true: {
40
x.push(props.p2);
@@ -43,7 +44,6 @@ function Component(props) {
44
y = x;
45
}
46
}
46
-
47
t0 = <Component data={x} />;
48
$[0] = props.p0;
49
$[1] = props.p2;
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/useMemo-multiple-if-else.expect.md
+1
@@ -47,6 +47,7 @@ function Component(props) {
47
if (props.cond) {
48
y.push(props.a);
49
}
50
+
51
if (props.cond2) {
52
t0 = y;
53
break bb0;
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-dependency-fixpoint.expect.md
+1
@@ -33,6 +33,7 @@ function Component(props) {
33
const $ = _c(2);
34
let x = 0;
35
let y = 0;
36
+
37
while (x === 0) {
38
x = y;
39
y = props.value;
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassignment-conditional.expect.md
+1
@@ -29,6 +29,7 @@ function Component(props) {
29
let x = [];
30
x.push(props.p0);
31
const y = x;
32
+
33
if (props.p1) {
34
let t1;
35
if ($[4] === Symbol.for("react.memo_cache_sentinel")) {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/rename-source-variables-nested-object-method.expect.md
-1
@@ -59,7 +59,6 @@ function useFoo(props) {
59
return b;
60
},
61
};
62
-
62
t1 = a.foo().bar();
63
$0[0] = props;
64
$0[1] = t1;
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/repro-backedge-reference-effect.expect.md
+1
@@ -43,6 +43,7 @@ function Foo(t0) {
43
<Stringify
44
fn={() => {
45
const arr = [];
46
+
47
for (const selectedUser of userIds) {
48
arr.push(selectedUser);
49
}
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/repro-false-positive-ref-validation-in-use-effect.expect.md
-1
@@ -49,7 +49,6 @@ function Component() {
49
if ($[0] !== params) {
50
t0 = (partialParams) => {
51
const nextParams = { ...params, ...partialParams };
52
-
52
nextParams.param = "value";
53
console.log(nextParams);
54
};
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/repro-invalid-reactivity-value-block.expect.md
+1
@@ -82,6 +82,7 @@ function Foo() {
82
const result = t1;
83
84
useNoAlias(result, obj);
85
+
86
if (shouldCaptureObj && result[0] !== obj) {
87
throw new Error("Unexpected");
88
}
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/repro-mutate-ref-in-function-passed-to-hook.expect.md
+1
@@ -52,6 +52,7 @@ function Example() {
52
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
53
t0 = function updateStyles() {
54
const foo = fooRef.current;
55
+
56
if (barRef.current == null || foo == null) {
57
return;
58
}
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/repro-object-expression-computed-key-modified-during-after-construction-hoisted-sequence-expr.expect.md
-1
@@ -67,7 +67,6 @@ function Component(props) {
67
const key = {};
68
const tmp = (mutate(key), key);
69
const context = { [tmp]: identity([props.value]) };
70
-
70
mutate(key);
71
t0 = [context, key];
72
$[0] = props.value;
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/repro-renaming-conflicting-decls.expect.md
-1
@@ -72,7 +72,6 @@ function Component(props) {
72
let t2;
73
if ($[3] !== t0) {
74
const linkProps = { url: t0 };
75
-
75
const x = {};
76
let t3;
77
let t4;
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/repro-slow-validate-preserve-memo.expect.md
+1
-5
@@ -40,11 +40,7 @@ function useTest(t0) {
40
t1 = Builder.makeBuilder(isNull, "hello world")
41
?.push("1", 2)
42
?.push(3, { a: 4, b: 5, c: data })
43
- ?.push(
44
- 6,
45
-
46
- data,
47
- )
43
+ ?.push(6, data)
44
?.push(7, "8")
45
?.push("8", Builder.makeBuilder(!isNull)?.push(9).vals)?.vals;
46
$[0] = data;
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/repro-unreachable-code-early-return-in-useMemo.expect.md
+1
@@ -53,6 +53,7 @@ function Component(t0) {
53
t1 = null;
54
break bb0;
55
}
56
+
57
try {
58
let t3;
59
if ($[0] !== value) {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/return-ref-callback-structure.expect.md
+1
@@ -44,6 +44,7 @@ function Foo(t0) {
44
t1 = $[0];
45
}
46
const s = t1;
47
+
48
if (cond) {
49
let t2;
50
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/rules-of-hooks/rules-of-hooks-93dc5d5e538a.expect.md
+1
@@ -20,6 +20,7 @@ function RegressionTest() {
20
// Valid because the loop doesn't change the order of hooks calls.
21
function RegressionTest() {
22
const res = [];
23
+
24
for (let i = 0; i !== 10 && true; ++i) {
25
res.push(i);
26
}
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/rules-of-hooks/rules-of-hooks-c1e8c7f4c191.expect.md
+39
@@ -148,82 +148,121 @@ function MyComponent() {
148
function MyComponent() {
149
if (c) {
150
}
151
+
152
if (c) {
153
}
154
+
155
if (c) {
156
}
157
+
158
if (c) {
159
}
160
+
161
if (c) {
162
}
163
+
164
if (c) {
165
}
166
+
167
if (c) {
168
}
169
+
170
if (c) {
171
}
172
+
173
if (c) {
174
}
175
+
176
if (c) {
177
}
178
+
179
if (c) {
180
}
181
+
182
if (c) {
183
}
184
+
185
if (c) {
186
}
187
+
188
if (c) {
189
}
190
+
191
if (c) {
192
}
193
+
194
if (c) {
195
}
196
+
197
if (c) {
198
}
199
+
200
if (c) {
201
}
202
+
203
if (c) {
204
}
205
+
206
if (c) {
207
}
208
+
209
if (c) {
210
}
211
+
212
if (c) {
213
}
214
+
215
if (c) {
216
}
217
+
218
if (c) {
219
}
220
+
221
if (c) {
222
}
223
+
224
if (c) {
225
}
226
+
227
if (c) {
228
}
229
+
230
if (c) {
231
}
232
+
233
if (c) {
234
}
235
+
236
if (c) {
237
}
238
+
239
if (c) {
240
}
241
+
242
if (c) {
243
}
244
+
245
if (c) {
246
}
247
+
248
if (c) {
249
}
250
+
251
if (c) {
252
}
253
+
254
if (c) {
255
}
256
+
257
if (c) {
258
}
259
+
260
if (c) {
261
}
262
+
263
if (c) {
264
}
265
+
266
if (c) {
267
}
268
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/rules-of-hooks/todo.bail.rules-of-hooks-6949b255e7eb.expect.md
+1
@@ -97,6 +97,7 @@ const SomeName = () => {
97
(FILLER ?? FILLER, FILLER) ?? FILLER;
98
99
useSomeHook();
100
+
101
if (anyConditionCanEvenBeFalse) {
102
return null;
103
}
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/switch-non-final-default.expect.md
-1
@@ -60,7 +60,6 @@ function Component(props) {
60
y = x;
61
}
62
}
63
-
63
t0 = <Component data={x} />;
64
$[0] = props.p0;
65
$[1] = props.p2;
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/switch.expect.md
+1
-1
@@ -33,6 +33,7 @@ function Component(props) {
33
let y;
34
if ($[0] !== props.p0 || $[1] !== props.p2 || $[2] !== props.p3) {
35
const x = [];
36
+
37
switch (props.p0) {
38
case true: {
39
x.push(props.p2);
@@ -42,7 +43,6 @@ function Component(props) {
43
y = x;
44
}
45
}
45
-
46
t0 = <Component data={x} />;
47
$[0] = props.p0;
48
$[1] = props.p2;
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/todo-function-expression-captures-value-later-frozen.expect.md
+1
@@ -32,6 +32,7 @@ function Component(props) {
32
const onChange = (e) => {
33
maybeMutate(x, e.target.value);
34
};
35
+
36
if (props.cond) {
37
}
38
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/transform-fire/bailout-retry/infer-deps-on-retry.expect.md
+1
@@ -46,6 +46,7 @@ function useFoo(t0) {
46
() => {
47
log(derived);
48
},
49
+
50
[derived],
51
[derived],
52
);
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/transform-fire/bailout-validate-conditional-hook.expect.md
+1
@@ -39,6 +39,7 @@ import { Stringify } from "shared-runtime";
39
*/
40
function Component(props) {
41
const foo = _temp;
42
+
43
if (props.cond) {
44
const t0 = useFire(foo);
45
useEffect(() => {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/try-catch-within-object-method-returns-caught-value.expect.md
-1
@@ -44,7 +44,6 @@ function Component(props) {
44
}
45
},
46
};
47
-
47
t0 = object.foo();
48
$[0] = props;
49
$[1] = t0;
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/try-catch-within-object-method.expect.md
-1
@@ -39,7 +39,6 @@ function Component(props) {
39
}
40
},
41
};
42
-
42
t0 = object.foo();
43
$[0] = t0;
44
} else {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/unlabeled-break-within-label-loop.expect.md
+1
@@ -35,6 +35,7 @@ function useHook(end) {
35
log = [];
36
for (let i = 0; i < end + 1; i++) {
37
log.push(`${i} @A`);
38
+
39
if (i === end) {
40
break;
41
}
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/unlabeled-break-within-label-switch.expect.md
+1
@@ -41,6 +41,7 @@ function useHook(cond) {
41
bb0: switch (CONST_STRING0) {
42
case CONST_STRING0: {
43
log.push("@A");
44
+
45
if (cond) {
46
break bb0;
47
}
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/use-effect-cleanup-reassigns.expect.md
+10
-6
@@ -65,12 +65,16 @@ function Component(t0) {
65
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
66
t1 = () => {
67
let cleanedUp = false;
68
- setTimeout(() => {
69
- if (!cleanedUp) {
70
- cleanedUp = true;
71
- setCleanupCount(_temp);
72
- }
73
- }, 0);
68
+ setTimeout(
69
+ () => {
70
+ if (!cleanedUp) {
71
+ cleanedUp = true;
72
+ setCleanupCount(_temp);
73
+ }
74
+ },
75
+
76
+ 0,
77
+ );
78
return () => {
79
if (!cleanedUp) {
80
cleanedUp = true;
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/useImperativeHandle-ref-mutate.expect.md
-1
@@ -43,7 +43,6 @@ function Component(t0) {
43
const precomputed = prop + ref2.current;
44
return { foo: () => prop + ref2.current + precomputed };
45
};
46
-
46
t2 = [prop];
47
$[0] = prop;
48
$[1] = t1;
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/useMemo-multiple-if-else.expect.md
+1
@@ -46,6 +46,7 @@ function Component(props) {
46
if (props.cond) {
47
y.push(props.a);
48
}
49
+
50
if (props.cond2) {
51
t0 = y;
52
break bb0;
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/useMemo-switch-return.expect.md
-1
@@ -50,7 +50,6 @@ function Component(props) {
50
y = props.y;
51
}
52
}
53
-
53
t0 = y;
54
}
55
const x = t0;
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/validate-no-set-state-in-render-uncalled-function-with-mutable-range-is-valid.expect.md
+1
@@ -50,6 +50,7 @@ function Component(props) {
50
t0 = $[1];
51
}
52
const onSubmit = t0;
53
+
54
switch (currentStep) {
55
case 0: {
56
let t1;