Commit Graph

2341 Commits

Author SHA1 Message Date
inottn
10a4c88f58
[compiler] Handle TSInstantiationExpression in lowerExpression (#32302)
Fix #31745
2025-02-03 08:41:04 -08:00
mofeiZ
152bfe3769
[compiler][rfc] Hacky retry pipeline for fire (#32164)
Hacky retry pipeline for when transforming `fire(...)` calls encounters
validation, todo, or memoization invariant bailouts. Would love feedback
on how we implement this to be extensible to other compiler
non-memoization features (e.g. inlineJSX)

Some observations:
- Compiler "front-end" passes (e.g. lower, type, effect, and mutability
inferences) should be shared for all compiler features -- memo and
otherwise
- Many passes (anything dealing with reactive scope ranges, scope blocks
/ dependencies, and optimizations such as ReactiveIR #31974) can be left
out of the retry pipeline. This PR hackily skips memoization features by
removing reactive scope creation, but we probably should restructure the
pipeline to skip these entirely on a retry
- We should maintain a canonical set of "validation flags"

Note the newly added fixtures are prefixed with `bailout-...` when the
retry fire pipeline is used. These fixture outputs contain correctly
inserted `useFire` calls and no memoization.
2025-01-31 15:57:26 -08:00
michael faith
a657bc5dee
build(eslint-plugin-react-hooks): add dev dependencies for typescript migration (#32279)
<!--
  Thanks for submitting a pull request!
We appreciate you spending the time to work on these changes. Please
provide enough information so that others can review your pull request.
The three fields below are mandatory.

Before submitting a pull request, please make sure the following is
done:

1. Fork [the repository](https://github.com/facebook/react) and create
your branch from `main`.
  2. Run `yarn` in the repository root.
3. If you've fixed a bug or added code that should be tested, add tests!
4. Ensure the test suite passes (`yarn test`). Tip: `yarn test --watch
TestName` is helpful in development.
5. Run `yarn test --prod` to test in the production environment. It
supports the same options as `yarn test`.
6. If you need a debugger, run `yarn test --debug --watch TestName`,
open `chrome://inspect`, and press "Inspect".
7. Format your code with
[prettier](https://github.com/prettier/prettier) (`yarn prettier`).
8. Make sure your code lints (`yarn lint`). Tip: `yarn linc` to only
check changed files.
  9. Run the [Flow](https://flowtype.org/) type checks (`yarn flow`).
  10. If you haven't already, complete the CLA.

Learn more about contributing:
https://reactjs.org/docs/how-to-contribute.html
-->

## Summary

Contributing to https://github.com/facebook/react/pull/32240, this
change adds the dev dependencies needed to support the migration of the
plugin to typescript.
2025-01-31 14:32:23 -05:00
Jeremy JIANG
dc44bca85b
fix(react-compiler-healthcheck): Add shebang to banner (#32225)
## Summary

PR https://github.com/facebook/react/pull/31963 migrated the bundler
from Rollup to esbuild, but the `react-compiler-healthcheck` script
lacks a shebang, leading to issues with `npx` not being able to execute
it.


dc7578290f/compiler/packages/react-compiler-healthcheck/rollup.config.js (L60-L78)


9eabb37338/compiler/packages/react-compiler-healthcheck/scripts/build.js (L38-L53)

## How did you test this change?

**Before**

(fail)

```shell
(main)> npx --version
10.5.0
(main)> npx react-compiler-healthcheck
/home/jeremy/.npm/_npx/67b118a83a29962c/node_modules/.bin/react-compiler-healthcheck: line 1: /bin: Is a directory
/home/jeremy/.npm/_npx/67b118a83a29962c/node_modules/.bin/react-compiler-healthcheck: line 2: syntax error near unexpected token `('
/home/jeremy/.npm/_npx/67b118a83a29962c/node_modules/.bin/react-compiler-healthcheck: line 2: ` * Copyright (c) Meta Platforms, Inc. and affiliates.'
```

**After**

```shell
(main)> npx react-compiler-healthcheck
Successfully compiled 108 out of 146 components.
StrictMode usage not found.
Found no usage of incompatible libraries.
```
2025-01-27 11:59:25 -05:00
Joe Savona
9eabb37338 [compiler][be] Remove unused experimental Rust port
I wrote this a couple summers back as an experiment to see how easily we could translate the compiler to Rust. We make extensive use of in-place mutation of the IR, and the experiment proved that this we can get reasonable ergonomics for this in Rust which was cool. We've since ended up using some of the code here for Relay, allowing Relay Compiler to parse JS files to do more fine-grained extraction of data. For React Compiler though, we plan to continue using JavaScript and explore lightweight native wrappers for things like OXC and SWC plugins. We're also working with the Hermes team to eventually compile the compiler with Static Hermes.

As Tomo always says: always bet on JavaScript.

ghstack-source-id: c5770a2efc
Pull Request resolved: https://github.com/facebook/react/pull/32219
2025-01-24 12:23:31 -08:00
Jordan Brown
ae9017ceab
Move effect dep inference tests to infer-effect-dependencies directory (#32161)
Summary: Grouping them to make it easy to see that they are all related

Test Plan:
2025-01-22 17:09:41 -05:00
mofeiZ
a0b91fbd65
[compiler][ez] Fix main (bad rebase / amend for #32095) (#32160)
See title: this fixes test cases broken by
https://github.com/facebook/react/pull/32095 adding instead of moving
new test fixtures
2025-01-22 16:21:53 -05:00
mofeiZ
b83090fca2
[compiler] Fix invalid Array.map type (#32095)
See test fixture
---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/32095).
* #32099
* #32104
* #32098
* #32097
* #32096
* __->__ #32095
* #32094
* #32093
2025-01-22 15:02:51 -05:00
mofeiZ
deba48a727
[compiler] Repro for invalid Array.map type (#32094)
See test fixture
---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/32094).
* #32099
* #32104
* #32098
* #32097
* #32096
* #32095
* __->__ #32094
* #32093
2025-01-22 14:58:52 -05:00
mofeiZ
b6b33bfb92
[compiler][ez] rewrite invariant in InferReferenceEffects (#32093)
Small patch to pass aliased context values into
`Object|ArrayExpression`s
---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/32093).
* #32099
* #32104
* #32098
* #32097
* #32096
* #32095
* #32094
* __->__ #32093
2025-01-22 14:34:08 -05:00
mofeiZ
7c864c9834
[compiler][ez] Patch for JSX escape sequences in @babel/generator (#32131)
Fall back to using JSXExpressionContainer for strings potentially
containing escape sequences (a single backslash) to fix
https://github.com/facebook/react/issues/32123. This is an extension of
https://github.com/facebook/react/pull/29079
2025-01-22 14:22:35 -05:00
mofeiZ
19557443c8
[compiler][repro] JSX escape sequences not printed correctly by @babel/generator (#32130)
Repro for https://github.com/facebook/react/issues/32123

Note that this is only a bug when calling `@babel/generator:generate()`
before transforming JSX.
---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/32130).
* #32131
* __->__ #32130
2025-01-22 13:52:05 -05:00
Alex Yang
e5a2062c80
fix(react-compiler): JSXText emits incorrect with bracket (#32138)
<!--
  Thanks for submitting a pull request!
We appreciate you spending the time to work on these changes. Please
provide enough information so that others can review your pull request.
The three fields below are mandatory.

Before submitting a pull request, please make sure the following is
done:

1. Fork [the repository](https://github.com/facebook/react) and create
your branch from `main`.
  2. Run `yarn` in the repository root.
3. If you've fixed a bug or added code that should be tested, add tests!
4. Ensure the test suite passes (`yarn test`). Tip: `yarn test --watch
TestName` is helpful in development.
5. Run `yarn test --prod` to test in the production environment. It
supports the same options as `yarn test`.
6. If you need a debugger, run `yarn test --debug --watch TestName`,
open `chrome://inspect`, and press "Inspect".
7. Format your code with
[prettier](https://github.com/prettier/prettier) (`yarn prettier`).
8. Make sure your code lints (`yarn lint`). Tip: `yarn linc` to only
check changed files.
  9. Run the [Flow](https://flowtype.org/) type checks (`yarn flow`).
  10. If you haven't already, complete the CLA.

Learn more about contributing:
https://reactjs.org/docs/how-to-contribute.html
-->

## Summary

Our [LlamaIndex](https://www.llamaindex.ai/) Product is blocked by this
bug

Fixes: https://github.com/facebook/react/issues/32137

<!--
Explain the **motivation** for making this change. What existing problem
does the pull request solve?
-->

## How did you test this change?

<!--
Demonstrate the code is solid. Example: The exact commands you ran and
their output, screenshots / videos if the pull request changes the user
interface.
How exactly did you verify that your PR solves the issue you wanted to
solve?
  If you leave this empty, your PR will very likely be closed.
-->
2025-01-22 12:04:59 -05:00
藍+85CD
9b62ee71f4
docs(eslint-plugin-react-compiler): fix typo (#32149) 2025-01-22 16:59:50 +01:00
Orta Therox
18eaf51bd5
Support eslint 8+ flat plugin syntax out of the box for eslint-plugin-react-compiler (#32120)
## Summary

The current docs for the react compiler eslint plugin is based on
integrating with the old-style eslint config format. This is generally
fine, but most plugins (and the [official
docs](https://eslint.org/docs/latest/use/configure/configuration-files#configuration-file))
are now describing themselves in the new format.

This PR has two changes:

- Update the exports to include a "flat configuration"
- Adds a README change describing how to handle both configs

The solution is semi-based on @guillaumebrunerie's answer in
https://github.com/reactwg/react-compiler/discussions/25 mixed with
reading the source code for
[eslint-plugin-react-refresh](https://github.com/ArnaudBarre/eslint-plugin-react-refresh/blob/main/src/index.ts)

## How did you test this change?

I faked this API in the most recent deploy:

![Screenshot 2025-01-18 at 19 58
44](https://github.com/user-attachments/assets/ae0e4bea-fb96-4073-a5f7-c886d087b6af)

Then used that in my app:

![Screenshot 2025-01-18 at 20 04
33](https://github.com/user-attachments/assets/21f77158-7535-453a-b988-49cf59d22d71)

and get myself some compiler messages:

```
/Users/orta/dev/app/apps/puzzmo.com/src/palette/HoverPopover.tsx
  31:37  error  Hooks must always be called in a consistent order, and may not be called conditionally. See the Rules of Hooks (https://react.dev/warnings/invalid-hook-call-warning)  react-compiler/react-compiler

/Users/orta/dev/app/apps/puzzmo.com/src/components/gameplay/PlayGamePauseOverlay.tsx
   33:7   error  Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)  react-compiler/react-compiler
   35:5   error  Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)  react-compiler/react-compiler
```
2025-01-18 17:41:34 -05:00
Joseph Savona
7f3826e8e4
[compiler] validation against calling impure functions (#31960)
For now we just reject all calls of impure functions, and the validation
is off by default. Going forward we can make this more precise and only
reject impure functions called during render.

Note that I was intentionally imprecise in the return type of these
functions in order to avoid changing output of existing code. We lie to
the compiler and say that Date.now, performance.now, and Math.random
return unknown mutable objects rather than primitives. Once the
validation is complete and vetted we can switch this to be more precise.
2025-01-17 09:04:02 -08:00
lauren
35dcf02b04
[rcr] Always target node (#32091)
Alternative to #32071. As a follow up to #31993, the `platform` target
was incorrectly being set to `browser` since it was the default argument
for the build script. This corrects it to `node` and `cjs` which I think
should resolve node 20 issues.
2025-01-16 13:37:13 -05:00
michael faith
b3a95caf61
fix(eslint-plugin-react-compiler): support v9 context api (#32045)
## Summary

This change fixes a gap in the plugin's support of eslint v9. In one
place that it's using the `SourceCode` api, it's correctly considering
v9's api. But in the other place where `SourceCode` is used, it's only
using the legacy api, which was removed in v9.
2025-01-13 13:49:31 -05:00
mofeiZ
af8532f251
[compiler][ez] Patch compilationMode:infer object method edge case (#32055)
Fix for  https://github.com/facebook/react/issues/31180
2025-01-13 12:18:59 -05:00
mofeiZ
d16fe4be5b
[compiler] Playground qol: shared compilation option directives with tests (#32012)
- Adds @compilationMode(all|infer|syntax|annotation) and
@panicMode(none) directives. This is now shared with our test infra
- Playground still defaults to `infer` mode while tests default to `all`
mode
- See added fixture tests
2025-01-09 12:38:16 -05:00
lauren
8932ca32f4
[playground] Partially revert #32009 (#32035)
I had forgotten that our default error reporting threshold was `none`
due to the fact that build pipelines should not throw errors. This
resets it back to throwing on all errors which mostly is the same as the
eslint plugin.

Closes #32014.
2025-01-09 12:21:05 -05:00
lauren
6efbc0897f
[playground] Use default compiler config (#32009)
The playground's compilation mode is currently set to 'all' along with
reporting all errors.

This tends to be misleading since people usually expect a 1:1 match
between how the playground works with what the compiler does in their
codebase, eg https://github.com/reactwg/react-compiler/discussions/51.
2025-01-07 11:53:27 -05:00
lauren
11df5224e6
[rcr] Generate ts defs (#31994)
This was accidentally removed in the esbuild transition.

---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/31994).
* #31995
* __->__ #31994
2025-01-06 11:01:38 -05:00
Cody Olsen
9627d71c50
fix: react-compiler-runtime should be cjs (#31993) 2025-01-06 09:06:09 -05:00
lauren
220dece92b
[compiler] Switch to esbuild (#31963)
This migrates the compiler's bundler to esbuild instead of rollup.
Unlike React, our bundling use cases are far simpler since the majority
of our packages are meant to be run on node. Rollup was adding
considerable build time overhead whereas esbuild remains fast and has
all the functionality we need out of the box.


### Before
```
time yarn workspaces run build
yarn workspaces v1.22.22

> babel-plugin-react-compiler
yarn run v1.22.22
$ rimraf dist && rollup --config --bundleConfigAsCjs

src/index.ts → dist/index.js...
(!) Circular dependencies
# ...
created dist/index.js in 15.5s
  Done in 16.45s.

> eslint-plugin-react-compiler
yarn run v1.22.22
$ rimraf dist && rollup --config --bundleConfigAsCjs

src/index.ts → dist/index.js...
(!) Circular dependencies
# ...
created dist/index.js in 9.1s
  Done in 10.11s.

> make-read-only-util
yarn run v1.22.22
warning package.json: No license field
$ tsc
  Done in 1.81s.

> react-compiler-healthcheck
yarn run v1.22.22
$ rimraf dist && rollup --config --bundleConfigAsCjs

src/index.ts → dist/index.js...
(!) Circular dependencies
# ...
created dist/index.js in 8.7s
  Done in 10.43s.

> react-compiler-runtime
yarn run v1.22.22
$ rimraf dist && rollup --config --bundleConfigAsCjs

src/index.ts → dist/index.js...
(!) src/index.ts (1:0): Module level directives cause errors when bundled, "use no memo" in "src/index.ts" was ignored.
# ...
created dist/index.js in 1.1s
  Done in 1.82s.

> snap
yarn run v1.22.22
$ rimraf dist && concurrently -n snap,runtime "tsc --build" "yarn --silent workspace react-compiler-runtime build --silent"
$ rimraf dist && rollup --config --bundleConfigAsCjs --silent
[runtime] yarn --silent workspace react-compiler-runtime build --silent exited with code 0
[snap] tsc --build exited with code 0
  Done in 5.73s.
  Done in 47.30s.
yarn workspaces run build  75.92s user 5.48s system 170% cpu 47.821 total
```

### After

```
time yarn workspaces run build
yarn workspaces v1.22.22

> babel-plugin-react-compiler
yarn run v1.22.22
$ rimraf dist && scripts/build.js
  Done in 1.02s.

> eslint-plugin-react-compiler
yarn run v1.22.22
$ rimraf dist && scripts/build.js
  Done in 0.93s.

> make-read-only-util
yarn run v1.22.22
warning package.json: No license field
$ rimraf dist && scripts/build.js
  Done in 0.89s.

> react-compiler-healthcheck
yarn run v1.22.22
$ rimraf dist && scripts/build.js
  Done in 0.58s.

> react-compiler-runtime
yarn run v1.22.22
$ rimraf dist && scripts/build.js
  Done in 0.48s.

> snap
yarn run v1.22.22
$ rimraf dist && concurrently -n snap,runtime "tsc --build" "yarn --silent workspace react-compiler-runtime build"
$ rimraf dist && scripts/build.js
[runtime] yarn --silent workspace react-compiler-runtime build exited with code 0
[snap] tsc --build exited with code 0
  Done in 4.69s.
  Done in 9.46s.
yarn workspaces run build  9.70s user 0.99s system 103% cpu 10.329 total
```
---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/31963).
* #31964
* __->__ #31963
* #31962
2025-01-02 16:59:56 -05:00
lauren
c784273bcc
[compiler] Update prettier-plugin-hermes-parser (#31962)
Just updating this package.
---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/31962).
* #31964
* #31963
* __->__ #31962
2025-01-02 16:59:45 -05:00
lauren
c8c89fab5b
[compiler] Update rollup plugins (#31919)
Update our various compiler rollup plugins.

---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/31919).
* #31927
* #31918
* #31917
* #31916
* __->__ #31919
2025-01-02 11:24:26 -05:00
lauren
4309bde2b4
[rcr] Relax react peer dep requirement (#31915)
There's no real reason to restrict the React peer dep to
non-experimental, so relax it.

---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/31915).
* #31919
* #31918
* #31917
* #31916
* __->__ #31915
* #31920
2024-12-27 14:27:43 -05:00
lauren
fc8a898dd1
[compiler] Fix broken fire snapshot (#31920)
This was not committed in #31811
---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/31920).
* #31919
* #31918
* #31917
* #31916
* #31915
* __->__ #31920
2024-12-26 14:58:37 -05:00
Jordan Brown
6907aa2a30
[compiler] Rewrite effect dep arrays that use fire (#31811)
If an effect uses a dep array, also rewrite the dep array to use the
fire binding

--
2024-12-20 17:16:59 -05:00
Jordan Brown
45a720f7c7
[compile] Error on fire outside of effects and ensure correct compilation, correct import (#31798)
Traverse the compiled functions to ensure there are no lingering fires
and that all
fire calls are inside an effect lambda.

Also corrects the import to import from the compiler runtime instead


--
2024-12-20 16:55:01 -05:00
Jordan Brown
ab27231dc5
[compiler] add fire imports (#31797)
Summary:

Adds import {useFire} from 'react' when fire syntax is used.

This is experimentation and may not become a stable feature in the
compiler.

--
---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/31797).
* #31811
* #31798
* __->__ #31797
2024-12-20 15:25:30 -05:00
Jordan Brown
03297e048d
[compiler] transform fire calls (#31796)
This is the diff with the meaningful changes. The approach is:
1. Collect fire callees and remove fire() calls, create a new binding
for the useFire result
2. Update LoadLocals for captured callees to point to the useFire result
3. Update function context to reference useFire results
4. Insert useFire calls after getting to the component scope

This approach aims to minimize the amount of new bindings we introduce
for the function expressions
to minimize bookkeeping for dependency arrays. We keep all of the
LoadLocals leading up to function
calls as they are and insert new instructions to load the originally
captured function, call useFire,
and store the result in a new promoted temporary. The lvalues that
referenced the original callee are
changed to point to the new useFire result.

This is the minimal diff to implement the expected behavior (up to
importing the useFire call, next diff)
and further stacked diffs implement error handling. The rules for fire
are:
1. If you use fire for a callee in the effect once you must use it for
every time you call it in that effect
2. You can only use fire in a useEffect lambda/functions defined inside
the useEffect lambda

There is still more work to do here, like updating the effect dependency
array and handling object methods

--
---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/31796).
* #31811
* #31798
* #31797
* __->__ #31796
2024-12-20 15:09:09 -05:00
Joseph Savona
6a3d6a4382
[compiler] Allow type cast expressions with refs (#31871)
We report a false positive for the combination of a ref-accessing
function placed inside an array which is they type-cast. Here we teach
ref validation about type casts. I also tried other variants like
`return ref as const` but those already worked.

Closes #31864
2024-12-20 08:56:48 -08:00
mofeiZ
8a7b30669a
[compiler][ez] Add shape for global Object.keys (#31583)
Add shape / type for global Object.keys. This is useful because
- it has an Effect.Read (not an Effect.Capture) as it cannot alias its
argument.
- Object.keys return an array
---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/31583).
* __->__ #31583
* #31582
2024-12-16 16:45:17 -05:00
mofeiZ
a78bbf9dbc
[compiler] Context variables as dependencies (#31582)
We previously didn't track context variables in the hoistable values
sidemap of `propagateScopeDependencies`. This was overly conservative as
we *do* track the mutable range of context variables, and it is safe to
hoist accesses to context variables after their last direct / aliased
maybe-assignment.

```js
function Component({value}) {
  // start of mutable range for `x`
  let x = DEFAULT;
  const setX = () => x = value;
  const aliasedSet = maybeAlias(setX);
  maybeCall(aliasedSet);
  // end of mutable range for `x`

  // here, we should be able to take x (and property reads
  // off of x) as dependencies
  return <Jsx value={x} />
}
```
---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/31582).
* #31583
* __->__ #31582
2024-12-16 16:45:05 -05:00
Jordan Brown
c869063f0d
[compiler] Add fire to known React APIs (#31795)
Makes `fire` a known export for type-based analysis

--
---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/31795).
* #31811
* #31798
* #31797
* #31796
* __->__ #31795
* #31794
2024-12-16 15:48:32 -05:00
Jordan Brown
308be6e8dc
[compiler] Add option for firing effect functions (#31794)
Config flag for `fire`

--
---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/31794).
* #31811
* #31798
* #31797
* #31796
* #31795
* __->__ #31794
2024-12-16 15:48:19 -05:00
mofeiZ
d325f872de
[compiler][be] Logger based debug printing in test runner (#31809)
Avoid mutable logging enabled state and writing to `process.stdout`
within our babel transform.
2024-12-16 15:15:13 -05:00
mofeiZ
ac17270652
[compiler][ez] Clean up duplicate code in propagateScopeDeps (#31581)
Clean up duplicate checks for when to skip processing values as
dependencies / hoistable temporaries.
---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/31581).
* #31583
* #31582
* __->__ #31581
2024-12-16 15:11:52 -05:00
mofeiZ
80b81fe563
[compiler] Repro for aliased captures within inner function expressions (#31770)
see fixture
2024-12-16 14:43:34 -05:00
mofeiZ
e30872a4e0
[compiler][be] Playground now compiles entire program (#31774)
Compiler playground now runs the entire program through
`babel-plugin-react-compiler` instead of a custom pipeline which
previously duplicated function inference logic from `Program.ts`. In
addition, the playground output reflects the tranformed file (instead of
a "virtual file" of manually concatenated functions).

This helps with the following:
- Reduce potential discrepencies between playground and babel plugin
behavior. See attached fixture output for an example where we previously
diverged.
- Let playground users see compiler-inserted imports (e.g. `_c` or
`useFire`)

This also helps us repurpose playground into a more general tool for
compiler-users instead of just for compiler engineers.
- imports and other functions are preserved.
We differentiate between imports and globals in many cases (e.g.
`inferEffectDeps`), so it may be misleading to omit imports in printed
output
- playground now shows other program-changing behavior like position of
outlined functions and hoisted declarations
- emitted compiled functions do not need synthetic names
---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/31774).
* #31809
* __->__ #31774
2024-12-16 14:43:21 -05:00
Joseph Savona
a1b3bd0da0
Optimize method calls w props receiver (#31775)
Redo of #31771 without ghstack
2024-12-13 17:10:07 -08:00
Jack Pope
16367ceb02
[compiler] Fix dropped ref with spread props in InlineJsxTransform (#31726)
When supporting ref as prop in
https://github.com/facebook/react/pull/31558, I missed fixing the
optimization to pass a spread-props-only props object in without an
additional object copy. In the case that we have only a ref along with a
spread, we cannot return only the spread object. This results in
dropping the ref.

In this example
```javascript
<Foo ref={ref} {...props} />
```

The bugged output is:
```javascript
{
  // ...
  props: props
}
```

With this change we now get the correct output:
```javascript
{
  // ...
  props: {ref: ref, ...props}
}
```
2024-12-10 16:11:17 -05:00
Mike Vitousek
76d603a72a [compiler] Support for non-declatation for in/of iterators
ghstack-source-id: a28801e022
Pull Request resolved: https://github.com/facebook/react/pull/31710
2024-12-09 12:04:00 -08:00
Mike Vitousek
226b85926a [compiler] Support for context variable loop iterators
Summary:
Fixing a compiler todo

ghstack-source-id: c4d9226b17
Pull Request resolved: https://github.com/facebook/react/pull/31709
2024-12-09 12:03:52 -08:00
Jordan Brown
6bcf0d20da
[compiler] Empty dep arrays for globals/module-scoped values/imports (#31666)
Any LoadGlobal in the "infer deps" position can safely use an empty dep
array. Globals have no reactive deps!

I just keep messing up sapling. This is the revised version of #31662
2024-12-03 13:54:08 -05:00
mofeiZ
b9b510df2a
Revert "Replace deprecated dependency in eslint-plugin-react-compiler" (#31665)
Reverts facebook/react#31629

`@babel/plugin-proposal-private-methods` is not compatible with
`@babel/traverse` versions < 7.25 (see
https://github.com/babel/babel/issues/16851). Internally we have
partners that use a less modern babel version, and we expect this to be
an issue for older codebases in OSS as well.
2024-12-03 11:46:08 -05:00
Jordan Brown
1b1283ade7
[compiler] Support default imports for autodep config (#31657)
## Summary

Allows us to add deps for things like `import useWrapperEffect from
'useWrapperEffect'`

---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/31657).
* __->__ #31657
* #31652
2024-12-03 07:42:53 -05:00
Jordan Brown
2ab471c8d2
[compiler] Don't include current field accesses in auto-deps (#31652)
## Summary

Drops .current field accesses in inferred dep arrays

---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/31652).
* #31657
* __->__ #31652
2024-12-03 07:42:28 -05:00