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 @@ -451,6 +451,12 @@ export function compileProgram(
pass.code,
),
};
if (
!compileResult.compiledFn.hasFireRewrite &&
!compileResult.compiledFn.hasLoweredContextAccess
) {
return null;
}
} catch (err) {
// TODO: we might want to log error here, but this will also result in duplicate logging
if (err instanceof CompilerError) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
renameVariables,
} from '.';
import {CompilerError, ErrorSeverity} from '../CompilerError';
import {Environment, EnvironmentConfig, ExternalFunction} from '../HIR';
import {Environment, ExternalFunction} from '../HIR';
import {
ArrayPattern,
BlockId,
Expand Down Expand Up @@ -156,7 +156,7 @@ export function codegenFunction(
const compiled = compileResult.unwrap();

const hookGuard = fn.env.config.enableEmitHookGuards;
if (hookGuard != null) {
if (hookGuard != null && fn.env.isInferredMemoEnabled) {
compiled.body = t.blockStatement([
createHookGuard(
hookGuard,
Expand Down Expand Up @@ -250,7 +250,11 @@ export function codegenFunction(
}

const emitInstrumentForget = fn.env.config.enableEmitInstrumentForget;
if (emitInstrumentForget != null && fn.id != null) {
if (
emitInstrumentForget != null &&
fn.id != null &&
fn.env.isInferredMemoEnabled
) {
/*
* Technically, this is a conditional hook call. However, we expect
* __DEV__ and gating identifier to be runtime constants
Expand Down Expand Up @@ -548,7 +552,7 @@ function codegenBlockNoReset(
}

function wrapCacheDep(cx: Context, value: t.Expression): t.Expression {
if (cx.env.config.enableEmitFreeze != null) {
if (cx.env.config.enableEmitFreeze != null && cx.env.isInferredMemoEnabled) {
// The import declaration for emitFreeze is inserted in the Babel plugin
return t.conditionalExpression(
t.identifier('__DEV__'),
Expand Down Expand Up @@ -1553,7 +1557,7 @@ function createHookGuard(
* ```
*/
function createCallExpression(
config: EnvironmentConfig,
env: Environment,
callee: t.Expression,
args: Array<t.Expression | t.SpreadElement>,
loc: SourceLocation | null,
Expand All @@ -1564,8 +1568,8 @@ function createCallExpression(
callExpr.loc = loc;
}

const hookGuard = config.enableEmitHookGuards;
if (hookGuard != null && isHook) {
const hookGuard = env.config.enableEmitHookGuards;
if (hookGuard != null && isHook && env.isInferredMemoEnabled) {
const iife = t.functionExpression(
null,
[],
Expand Down Expand Up @@ -1701,7 +1705,7 @@ function codegenInstructionValue(
const callee = codegenPlaceToExpression(cx, instrValue.callee);
const args = instrValue.args.map(arg => codegenArgument(cx, arg));
value = createCallExpression(
cx.env.config,
cx.env,
callee,
args,
instrValue.loc,
Expand Down Expand Up @@ -1791,7 +1795,7 @@ function codegenInstructionValue(
);
const args = instrValue.args.map(arg => codegenArgument(cx, arg));
value = createCallExpression(
cx.env.config,
cx.env,
memberExpr,
args,
instrValue.loc,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

## Input

```javascript
// @flow @enableEmitHookGuards @panicThreshold(none) @enableFire

component Foo(useDynamicHook) {
useDynamicHook();
return <div>hello world</div>;
}

```

## Code

```javascript
function Foo({
useDynamicHook,
}: $ReadOnly<{ useDynamicHook: any }>): React.Node {
useDynamicHook();
return <div>hello world</div>;
}

```

### Eval output
(kind: exception) Fixture not implemented
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// @flow @enableEmitHookGuards @panicThreshold(none) @enableFire

component Foo(useDynamicHook) {
useDynamicHook();
return <div>hello world</div>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@

## Input

```javascript
// @flow @enableEmitHookGuards @panicThreshold(none) @enableFire
import {useEffect, fire} from 'react';

function Component(props, useDynamicHook) {
'use memo';
useDynamicHook();
const foo = props => {
console.log(props);
};
useEffect(() => {
fire(foo(props));
});

return <div>hello world</div>;
}

```

## Code

```javascript
import { $dispatcherGuard } from "react-compiler-runtime";
import { useFire } from "react/compiler-runtime";
import { useEffect, fire } from "react";

function Component(props, useDynamicHook) {
"use memo";

useDynamicHook();
const foo = _temp;
const t0 = useFire(foo);

useEffect(() => {
t0(props);
});
return <div>hello world</div>;
}
function _temp(props_0) {
console.log(props_0);
}

```

### Eval output
(kind: exception) Fixture not implemented
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// @flow @enableEmitHookGuards @panicThreshold(none) @enableFire
import {useEffect, fire} from 'react';

function Component(props, useDynamicHook) {
'use memo';
useDynamicHook();
const foo = props => {
console.log(props);
};
useEffect(() => {
fire(foo(props));
});

return <div>hello world</div>;
}
Loading