Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2089,7 +2089,7 @@ function computeSignatureForInstruction(
effects.push({
kind: 'Freeze',
value: operand,
reason: ValueReason.Other,
reason: ValueReason.HookCaptured,
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,8 @@ function codegenTerminal(
if (terminal.targetKind === 'implicit') {
return null;
}
return t.breakStatement(
return createBreakStatement(
terminal.loc,
terminal.targetKind === 'labeled'
? t.identifier(codegenLabel(terminal.target))
: null,
Expand All @@ -955,14 +956,16 @@ function codegenTerminal(
if (terminal.targetKind === 'implicit') {
return null;
}
return t.continueStatement(
return createContinueStatement(
terminal.loc,
terminal.targetKind === 'labeled'
? t.identifier(codegenLabel(terminal.target))
: null,
);
}
case 'for': {
return t.forStatement(
return createForStatement(
terminal.loc,
codegenForInit(cx, terminal.init),
codegenInstructionValueToExpression(cx, terminal.test),
terminal.update !== null
Expand Down Expand Up @@ -1047,7 +1050,8 @@ function codegenTerminal(
`Unhandled lvalue kind: ${iterableItem.value.lvalue.kind}`,
);
}
return t.forInStatement(
return createForInStatement(
terminal.loc,
/*
* Special handling here since we only want the VariableDeclarators without any inits
* This needs to be updated when we handle non-trivial ForOf inits
Expand Down Expand Up @@ -1140,7 +1144,8 @@ function codegenTerminal(
`Unhandled lvalue kind: ${iterableItem.value.lvalue.kind}`,
);
}
return t.forOfStatement(
return createForOfStatement(
terminal.loc,
/*
* Special handling here since we only want the VariableDeclarators without any inits
* This needs to be updated when we handle non-trivial ForOf inits
Expand All @@ -1162,7 +1167,7 @@ function codegenTerminal(
alternate = block;
}
}
return t.ifStatement(test, consequent, alternate);
return createIfStatement(terminal.loc, test, consequent, alternate);
}
case 'return': {
const value = codegenPlaceToExpression(cx, terminal.value);
Expand All @@ -1173,7 +1178,8 @@ function codegenTerminal(
return t.returnStatement(value);
}
case 'switch': {
return t.switchStatement(
return createSwitchStatement(
terminal.loc,
codegenPlaceToExpression(cx, terminal.test),
terminal.cases.map(case_ => {
const test =
Expand All @@ -1186,15 +1192,26 @@ function codegenTerminal(
);
}
case 'throw': {
return t.throwStatement(codegenPlaceToExpression(cx, terminal.value));
return createThrowStatement(
terminal.loc,
codegenPlaceToExpression(cx, terminal.value),
);
}
case 'do-while': {
const test = codegenInstructionValueToExpression(cx, terminal.test);
return t.doWhileStatement(test, codegenBlock(cx, terminal.loop));
return createDoWhileStatement(
terminal.loc,
test,
codegenBlock(cx, terminal.loop),
);
}
case 'while': {
const test = codegenInstructionValueToExpression(cx, terminal.test);
return t.whileStatement(test, codegenBlock(cx, terminal.loop));
return createWhileStatement(
terminal.loc,
test,
codegenBlock(cx, terminal.loop),
);
}
case 'label': {
return codegenBlock(cx, terminal.block);
Expand All @@ -1205,7 +1222,8 @@ function codegenTerminal(
catchParam = convertIdentifier(terminal.handlerBinding.identifier);
cx.temp.set(terminal.handlerBinding.identifier.declarationId, null);
}
return t.tryStatement(
return createTryStatement(
terminal.loc,
codegenBlock(cx, terminal.block),
t.catchClause(catchParam, codegenBlock(cx, terminal.handler)),
);
Expand Down Expand Up @@ -1543,7 +1561,13 @@ const createExpressionStatement = withLoc(t.expressionStatement);
const _createLabelledStatement = withLoc(t.labeledStatement);
const createVariableDeclaration = withLoc(t.variableDeclaration);
const createFunctionDeclaration = withLoc(t.functionDeclaration);
const _createWhileStatement = withLoc(t.whileStatement);
const createWhileStatement = withLoc(t.whileStatement);
const createDoWhileStatement = withLoc(t.doWhileStatement);
const createSwitchStatement = withLoc(t.switchStatement);
const createIfStatement = withLoc(t.ifStatement);
const createForStatement = withLoc(t.forStatement);
const createForOfStatement = withLoc(t.forOfStatement);
const createForInStatement = withLoc(t.forInStatement);
const createTaggedTemplateExpression = withLoc(t.taggedTemplateExpression);
const createLogicalExpression = withLoc(t.logicalExpression);
const createSequenceExpression = withLoc(t.sequenceExpression);
Expand All @@ -1558,6 +1582,10 @@ const createJsxText = withLoc(t.jsxText);
const createJsxClosingElement = withLoc(t.jsxClosingElement);
const createJsxOpeningElement = withLoc(t.jsxOpeningElement);
const createStringLiteral = withLoc(t.stringLiteral);
const createThrowStatement = withLoc(t.throwStatement);
const createTryStatement = withLoc(t.tryStatement);
const createBreakStatement = withLoc(t.breakStatement);
const createContinueStatement = withLoc(t.continueStatement);

function createHookGuard(
guard: ExternalFunction,
Expand Down Expand Up @@ -2314,6 +2342,9 @@ function codegenInstructionValue(
);
}
}
if (instrValue.loc != null && instrValue.loc != GeneratedSource) {
value.loc = instrValue.loc;
}
return value;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ class CollectDependenciesVisitor extends ReactiveFunctionVisitor<
* memoization. Note: we may still prune primitive-producing scopes if
* they don't ultimately escape at all.
*/
const level = MemoizationLevel.Memoized;
const level = MemoizationLevel.Conditional;
return {
lvalues: lvalue !== null ? [{place: lvalue, level}] : [],
rvalues: [...eachReactiveValueOperand(value)],
Expand Down Expand Up @@ -701,9 +701,7 @@ class CollectDependenciesVisitor extends ReactiveFunctionVisitor<
}
case 'ComputedLoad':
case 'PropertyLoad': {
const level = options.forceMemoizePrimitives
? MemoizationLevel.Memoized
: MemoizationLevel.Conditional;
const level = MemoizationLevel.Conditional;
return {
// Indirection for the inner value, memoized if the value is
lvalues: lvalue !== null ? [{place: lvalue, level}] : [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ function useFoo(t0) {
t1 = null;
break bb0;
}

if (cond2) {
mutate(s);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ function useFoo(t0) {
if ($[0] !== cond || $[1] !== value) {
bb0: {
items = [];

if (cond) {
break bb0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function Foo() {
if (cond) {
thing = makeObject_Primitives();
}

if (CONST_TRUE) {
mutate(thing);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { c as _c } from "react/compiler-runtime";
function useBar(props) {
const $ = _c(1);
let z;

if (props.a) {
if (props.b) {
let t0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ function getNativeLogFunction(level) {
) {
logLevel = LOG_LEVELS.warn;
}

if (global.__inspectorLog) {
global.__inspectorLog(
INSPECTOR_LEVELS[logLevel],
Expand All @@ -75,6 +76,7 @@ function getNativeLogFunction(level) {
INSPECTOR_FRAMES_TO_SKIP,
);
}

if (groupStack.length) {
str = groupFormat("", str);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ function useKeyCommand() {
};

const moveLeft = { handler: handleKey("left") };

const moveRight = { handler: handleKey("right") };

t0 = [moveLeft, moveRight];
$[0] = t0;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ function Component() {
let y;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
y = x = {};

const foo = () => {
x = makeArray();
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ function ComponentA(props) {
if (b) {
a.push(props.p0);
}

if (props.p1) {
b.push(props.p2);
}
Expand All @@ -68,6 +69,7 @@ function ComponentB(props) {
if (mayMutate(b)) {
a.push(props.p0);
}

if (props.p1) {
b.push(props.p2);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ function Component(props) {
const foo = () => {
setX(1);
};

if (props.cond) {
setX(2);
foo();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ function Foo() {
return identity(1);
},
};

t0 = x.foo();
$[0] = t0;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ function foo() {
value={[
true,
true,

"a\nb",
"\n",
"a1b",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ function foo() {
true,
-Infinity,
-NaN,

-1 * NaN,
-1 * Infinity,
-1 * -Infinity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function Component(props) {
const a = [];
const b = {};
new Foo(a, b);

new Foo(b);
t0 = <div a={a} b={b} />;
$[0] = t0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ function Component(t0) {
}
},
};

invoke(obj.method, cond);
$[0] = cond;
$[1] = x;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const FIXTURE_ENTRYPOINT = {
```javascript
function Component(props) {
debugger;

if (props.cond) {
debugger;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ function Component(props) {
let x;
if ($[0] !== props.a || $[1] !== props.b) {
x = { a: props.a, b: props.b };

delete x["b"];
$[0] = props.a;
$[1] = props.b;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ function foo(a, b) {
if (x.length) {
y.push(x);
}

if (b) {
y.push(b);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ function foo(x, y, z) {
} else {
items2 = $[2];
}

if (y) {
items.push(x);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ function Component(t0) {
let y;
if ($[0] !== a || $[1] !== b || $[2] !== c) {
x = [];

if (a) {
let t1;
if ($[5] !== b) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function foo(a, b, c) {
} else {
x = $[3];
}

if (x.length) {
return x;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function Component(props) {
let items;
if ($[0] !== props.items) {
items = [];

for (let i = 0, length = props.items.length; i < length; i++) {
items.push(props.items[i]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function Component(props) {
for (const x of items) {
lastItem = x;
}

if (lastItem != null) {
lastItem.a = lastItem.a + 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function Component(props) {
for (const x of items) {
lastItem = x;
}

if (lastItem != null) {
lastItem.a = lastItem.a + 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ function Component(props) {
t1 = $[1];
}
const onChange = t1;

if (props.cond) {
}
let t2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const Foo = isForgetEnabled_Fixtures()
if (DEV && shouldInstrument)
useRenderCounter("Foo", "/codegen-instrument-forget-gating-test.ts");
const $ = _c(3);

if (props.bar < 0) {
return props.children;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const Foo = isForgetEnabled_Fixtures()
? function Foo(props) {
"use forget";
const $ = _c(3);

if (props.bar < 0) {
return props.children;
}
Expand Down
Loading
Loading