@samitouri / QOS-React / commits / 2c8725fdfd

[compiler] snap fails if nothing compiled, unless @expectNothingCompiled (#35615)

A few times an agent has constructed fixtures that are silently skipped because the component has no jsx or hook calls. This PR updates snap to ensure that for each fixture either: 1) There are at least one compile success/failure *and* the `@expectNothingCompiled` pragma is missing 2) OR there are zero success/failures *and* the `@expectNothingCompiled` pragma is present This ensures we are intentional about fixtures that are expected not to have compilation, and know if that expectation breaks.

Joseph Savona committed Jan 23, 2026 at 10:38 UTC 2c8725fdfd13705487d13dce008d62c605cd7f73
59 files changed +116 -81
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/class-component-with-render-helper.expect.md
+2 -2
@@ -2,7 +2,7 @@
2 ## Input
3
4 ```javascript
5 -// @compilationMode:"infer"
5 +// @expectNothingCompiled @compilationMode:"infer"
6 class Component {
7 _renderMessage = () => {
8 const Message = () => {
@@ -22,7 +22,7 @@ class Component {
22 ## Code
23
24 ```javascript
25 -// @compilationMode:"infer"
25 +// @expectNothingCompiled @compilationMode:"infer"
26 class Component {
27 _renderMessage = () => {
28 const Message = () => {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/class-component-with-render-helper.js
+1 -1
@@ -1,4 +1,4 @@
1 -// @compilationMode:"infer"
1 +// @expectNothingCompiled @compilationMode:"infer"
2 class Component {
3 _renderMessage = () => {
4 const Message = () => {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/custom-opt-out-directive.expect.md
+2 -2
@@ -2,7 +2,7 @@
2 ## Input
3
4 ```javascript
5 -// @customOptOutDirectives:["use todo memo"]
5 +// @expectNothingCompiled @customOptOutDirectives:["use todo memo"]
6 function Component() {
7 'use todo memo';
8 return <div>hello world!</div>;
@@ -18,7 +18,7 @@ export const FIXTURE_ENTRYPOINT = {
18 ## Code
19
20 ```javascript
21 -// @customOptOutDirectives:["use todo memo"]
21 +// @expectNothingCompiled @customOptOutDirectives:["use todo memo"]
22 function Component() {
23 "use todo memo";
24 return <div>hello world!</div>;
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/custom-opt-out-directive.tsx
+1 -1
@@ -1,4 +1,4 @@
1 -// @customOptOutDirectives:["use todo memo"]
1 +// @expectNothingCompiled @customOptOutDirectives:["use todo memo"]
2 function Component() {
3 'use todo memo';
4 return <div>hello world!</div>;
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/dont-memoize-primitive-function-call-non-escaping.expect.md
+2 -2
@@ -2,7 +2,7 @@
2 ## Input
3
4 ```javascript
5 -// @compilationMode:"infer" @enablePreserveExistingMemoizationGuarantees @validatePreserveExistingMemoizationGuarantees
5 +// @expectNothingCompiled @compilationMode:"infer" @enablePreserveExistingMemoizationGuarantees @validatePreserveExistingMemoizationGuarantees
6 import {useMemo} from 'react';
7 import {makeObject_Primitives, ValidateMemoization} from 'shared-runtime';
8
@@ -37,7 +37,7 @@ export const FIXTURE_ENTRYPOINT = {
37 ## Code
38
39 ```javascript
40 -// @compilationMode:"infer" @enablePreserveExistingMemoizationGuarantees @validatePreserveExistingMemoizationGuarantees
40 +// @expectNothingCompiled @compilationMode:"infer" @enablePreserveExistingMemoizationGuarantees @validatePreserveExistingMemoizationGuarantees
41 import { useMemo } from "react";
42 import { makeObject_Primitives, ValidateMemoization } from "shared-runtime";
43
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/dont-memoize-primitive-function-call-non-escaping.js
+1 -1
@@ -1,4 +1,4 @@
1 -// @compilationMode:"infer" @enablePreserveExistingMemoizationGuarantees @validatePreserveExistingMemoizationGuarantees
1 +// @expectNothingCompiled @compilationMode:"infer" @enablePreserveExistingMemoizationGuarantees @validatePreserveExistingMemoizationGuarantees
2 import {useMemo} from 'react';
3 import {makeObject_Primitives, ValidateMemoization} from 'shared-runtime';
4
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/repro-no-gating-import-without-compiled-functions.expect.md
+2 -2
@@ -2,7 +2,7 @@
2 ## Input
3
4 ```javascript
5 -// @gating
5 +// @expectNothingCompiled @gating
6 import {isForgetEnabled_Fixtures} from 'ReactForgetFeatureFlag';
7
8 export default 42;
@@ -12,7 +12,7 @@ export default 42;
12 ## Code
13
14 ```javascript
15 -// @gating
15 +// @expectNothingCompiled @gating
16 import { isForgetEnabled_Fixtures } from "ReactForgetFeatureFlag";
17
18 export default 42;
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/repro-no-gating-import-without-compiled-functions.js
+1 -1
@@ -1,4 +1,4 @@
1 -// @gating
1 +// @expectNothingCompiled @gating
2 import {isForgetEnabled_Fixtures} from 'ReactForgetFeatureFlag';
3
4 export default 42;
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/infer-dont-compile-components-with-multiple-params.expect.md
+2 -2
@@ -2,7 +2,7 @@
2 ## Input
3
4 ```javascript
5 -// @compilationMode:"infer"
5 +// @expectNothingCompiled @compilationMode:"infer"
6 // Takes multiple parameters - not a component!
7 function Component(foo, bar) {
8 return <div />;
@@ -18,7 +18,7 @@ export const FIXTURE_ENTRYPOINT = {
18 ## Code
19
20 ```javascript
21 -// @compilationMode:"infer"
21 +// @expectNothingCompiled @compilationMode:"infer"
22 // Takes multiple parameters - not a component!
23 function Component(foo, bar) {
24 return <div />;
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/infer-dont-compile-components-with-multiple-params.js
+1 -1
@@ -1,4 +1,4 @@
1 -// @compilationMode:"infer"
1 +// @expectNothingCompiled @compilationMode:"infer"
2 // Takes multiple parameters - not a component!
3 function Component(foo, bar) {
4 return <div />;
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/infer-no-component-annot.expect.md
+2 -2
@@ -2,7 +2,7 @@
2 ## Input
3
4 ```javascript
5 -// @compilationMode:"infer"
5 +// @expectNothingCompiled @compilationMode:"infer"
6 import {useIdentity, identity} from 'shared-runtime';
7
8 function Component(fakeProps: number) {
@@ -20,7 +20,7 @@ export const FIXTURE_ENTRYPOINT = {
20 ## Code
21
22 ```javascript
23 -// @compilationMode:"infer"
23 +// @expectNothingCompiled @compilationMode:"infer"
24 import { useIdentity, identity } from "shared-runtime";
25
26 function Component(fakeProps: number) {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/infer-no-component-annot.ts
+1 -1
@@ -1,4 +1,4 @@
1 -// @compilationMode:"infer"
1 +// @expectNothingCompiled @compilationMode:"infer"
2 import {useIdentity, identity} from 'shared-runtime';
3
4 function Component(fakeProps: number) {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/infer-no-component-nested-jsx.expect.md
+2 -2
@@ -2,7 +2,7 @@
2 ## Input
3
4 ```javascript
5 -// @compilationMode:"infer"
5 +// @expectNothingCompiled @compilationMode:"infer"
6 function Component(props) {
7 const result = f(props);
8 function helper() {
@@ -26,7 +26,7 @@ export const FIXTURE_ENTRYPOINT = {
26 ## Code
27
28 ```javascript
29 -// @compilationMode:"infer"
29 +// @expectNothingCompiled @compilationMode:"infer"
30 function Component(props) {
31 const result = f(props);
32 function helper() {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/infer-no-component-nested-jsx.js
+1 -1
@@ -1,4 +1,4 @@
1 -// @compilationMode:"infer"
1 +// @expectNothingCompiled @compilationMode:"infer"
2 function Component(props) {
3 const result = f(props);
4 function helper() {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/infer-no-component-obj-return.expect.md
+2 -2
@@ -2,7 +2,7 @@
2 ## Input
3
4 ```javascript
5 -// @compilationMode:"infer"
5 +// @expectNothingCompiled @compilationMode:"infer"
6 function Component(props) {
7 const ignore = <foo />;
8 return {foo: f(props)};
@@ -22,7 +22,7 @@ export const FIXTURE_ENTRYPOINT = {
22 ## Code
23
24 ```javascript
25 -// @compilationMode:"infer"
25 +// @expectNothingCompiled @compilationMode:"infer"
26 function Component(props) {
27 const ignore = <foo />;
28 return { foo: f(props) };
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/infer-no-component-obj-return.js
+1 -1
@@ -1,4 +1,4 @@
1 -// @compilationMode:"infer"
1 +// @expectNothingCompiled @compilationMode:"infer"
2 function Component(props) {
3 const ignore = <foo />;
4 return {foo: f(props)};
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/infer-skip-components-without-hooks-or-jsx.expect.md
+2 -2
@@ -2,7 +2,7 @@
2 ## Input
3
4 ```javascript
5 -// @compilationMode:"infer"
5 +// @expectNothingCompiled @compilationMode:"infer"
6 // This component is skipped bc it doesn't call any hooks or
7 // use JSX:
8 function Component(props) {
@@ -14,7 +14,7 @@ function Component(props) {
14 ## Code
15
16 ```javascript
17 -// @compilationMode:"infer"
17 +// @expectNothingCompiled @compilationMode:"infer"
18 // This component is skipped bc it doesn't call any hooks or
19 // use JSX:
20 function Component(props) {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/infer-skip-components-without-hooks-or-jsx.js
+1 -1
@@ -1,4 +1,4 @@
1 -// @compilationMode:"infer"
1 +// @expectNothingCompiled @compilationMode:"infer"
2 // This component is skipped bc it doesn't call any hooks or
3 // use JSX:
4 function Component(props) {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/rules-of-hooks/rules-of-hooks-0592bd574811.expect.md
+2 -2
@@ -2,7 +2,7 @@
2 ## Input
3
4 ```javascript
5 -// @compilationMode:"infer"
5 +// @expectNothingCompiled @compilationMode:"infer"
6 // Regression test for some internal code.
7 // This shows how the "callback rule" is more relaxed,
8 // and doesn't kick in unless we're confident we're in
@@ -20,7 +20,7 @@ function makeListener(instance) {
20 ## Code
21
22 ```javascript
23 -// @compilationMode:"infer"
23 +// @expectNothingCompiled @compilationMode:"infer"
24 // Regression test for some internal code.
25 // This shows how the "callback rule" is more relaxed,
26 // and doesn't kick in unless we're confident we're in
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/rules-of-hooks/rules-of-hooks-0592bd574811.js
+1 -1
@@ -1,4 +1,4 @@
1 -// @compilationMode:"infer"
1 +// @expectNothingCompiled @compilationMode:"infer"
2 // Regression test for some internal code.
3 // This shows how the "callback rule" is more relaxed,
4 // and doesn't kick in unless we're confident we're in
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/rules-of-hooks/rules-of-hooks-2bec02ac982b.expect.md
+2 -2
@@ -2,7 +2,7 @@
2 ## Input
3
4 ```javascript
5 -// @compilationMode:"infer"
5 +// @expectNothingCompiled @compilationMode:"infer"
6 // Valid because hooks can call hooks.
7 function createHook() {
8 return function useHook() {
@@ -16,7 +16,7 @@ function createHook() {
16 ## Code
17
18 ```javascript
19 -// @compilationMode:"infer"
19 +// @expectNothingCompiled @compilationMode:"infer"
20 // Valid because hooks can call hooks.
21 function createHook() {
22 return function useHook() {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/rules-of-hooks/rules-of-hooks-2bec02ac982b.js
+1 -1
@@ -1,4 +1,4 @@
1 -// @compilationMode:"infer"
1 +// @expectNothingCompiled @compilationMode:"infer"
2 // Valid because hooks can call hooks.
3 function createHook() {
4 return function useHook() {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/rules-of-hooks/rules-of-hooks-33a6e23edac1.expect.md
+2 -2
@@ -2,7 +2,7 @@
2 ## Input
3
4 ```javascript
5 -// @compilationMode:"infer"
5 +// @expectNothingCompiled @compilationMode:"infer"
6 // Valid because hooks can use hooks.
7 function createHook() {
8 return function useHookWithHook() {
@@ -15,7 +15,7 @@ function createHook() {
15 ## Code
16
17 ```javascript
18 -// @compilationMode:"infer"
18 +// @expectNothingCompiled @compilationMode:"infer"
19 // Valid because hooks can use hooks.
20 function createHook() {
21 return function useHookWithHook() {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/rules-of-hooks/rules-of-hooks-33a6e23edac1.js
+1 -1
@@ -1,4 +1,4 @@
1 -// @compilationMode:"infer"
1 +// @expectNothingCompiled @compilationMode:"infer"
2 // Valid because hooks can use hooks.
3 function createHook() {
4 return function useHookWithHook() {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/rules-of-hooks/rules-of-hooks-8f1c2c3f71c9.expect.md
+2 -2
@@ -2,7 +2,7 @@
2 ## Input
3
4 ```javascript
5 -// @compilationMode:"infer"
5 +// @expectNothingCompiled @compilationMode:"infer"
6 // Valid because components can use hooks.
7 function createComponentWithHook() {
8 return function ComponentWithHook() {
@@ -15,7 +15,7 @@ function createComponentWithHook() {
15 ## Code
16
17 ```javascript
18 -// @compilationMode:"infer"
18 +// @expectNothingCompiled @compilationMode:"infer"
19 // Valid because components can use hooks.
20 function createComponentWithHook() {
21 return function ComponentWithHook() {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/rules-of-hooks/rules-of-hooks-8f1c2c3f71c9.js
+1 -1
@@ -1,4 +1,4 @@
1 -// @compilationMode:"infer"
1 +// @expectNothingCompiled @compilationMode:"infer"
2 // Valid because components can use hooks.
3 function createComponentWithHook() {
4 return function ComponentWithHook() {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/rules-of-hooks/rules-of-hooks-df4d750736f3.expect.md
+2
@@ -2,6 +2,7 @@
2 ## Input
3
4 ```javascript
5 +// @expectNothingCompiled
6 // Valid because they're not matching use[A-Z].
7 fooState();
8 _use();
@@ -15,6 +16,7 @@ jest.useFakeTimer();
16 ## Code
17
18 ```javascript
19 +// @expectNothingCompiled
20 // Valid because they're not matching use[A-Z].
21 fooState();
22 _use();
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/rules-of-hooks/rules-of-hooks-df4d750736f3.js
+1
@@ -1,3 +1,4 @@
1 +// @expectNothingCompiled
2 // Valid because they're not matching use[A-Z].
3 fooState();
4 _use();
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/rules-of-hooks/rules-of-hooks-dfde14171fcd.expect.md
+2
@@ -2,6 +2,7 @@
2 ## Input
3
4 ```javascript
5 +// @expectNothingCompiled
6 // Valid because classes can call functions.
7 // We don't consider these to be hooks.
8 class C {
@@ -16,6 +17,7 @@ class C {
17 ## Code
18
19 ```javascript
20 +// @expectNothingCompiled
21 // Valid because classes can call functions.
22 // We don't consider these to be hooks.
23 class C {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/rules-of-hooks/rules-of-hooks-dfde14171fcd.js
+1
@@ -1,3 +1,4 @@
1 +// @expectNothingCompiled
2 // Valid because classes can call functions.
3 // We don't consider these to be hooks.
4 class C {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/rules-of-hooks/rules-of-hooks-fe6042f7628b.expect.md
+2 -2
@@ -2,7 +2,7 @@
2 ## Input
3
4 ```javascript
5 -// @compilationMode:"infer"
5 +// @expectNothingCompiled @compilationMode:"infer"
6 // This is valid because "use"-prefixed functions called in
7 // unnamed function arguments are not assumed to be hooks.
8 unknownFunction(function (foo, bar) {
@@ -16,7 +16,7 @@ unknownFunction(function (foo, bar) {
16 ## Code
17
18 ```javascript
19 -// @compilationMode:"infer"
19 +// @expectNothingCompiled @compilationMode:"infer"
20 // This is valid because "use"-prefixed functions called in
21 // unnamed function arguments are not assumed to be hooks.
22 unknownFunction(function (foo, bar) {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/rules-of-hooks/rules-of-hooks-fe6042f7628b.js
+1 -1
@@ -1,4 +1,4 @@
1 -// @compilationMode:"infer"
1 +// @expectNothingCompiled @compilationMode:"infer"
2 // This is valid because "use"-prefixed functions called in
3 // unnamed function arguments are not assumed to be hooks.
4 unknownFunction(function (foo, bar) {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/rules-of-hooks/todo.invalid.invalid-rules-of-hooks-191029ac48c8.expect.md
+2 -2
@@ -2,7 +2,7 @@
2 ## Input
3
4 ```javascript
5 -// @skip
5 +// @expectNothingCompiled @skip
6 // Passed but should have failed
7
8 // Invalid because it's dangerous.
@@ -22,7 +22,7 @@ useCustomHook();
22 ## Code
23
24 ```javascript
25 -// @skip
25 +// @expectNothingCompiled @skip
26 // Passed but should have failed
27
28 // Invalid because it's dangerous.
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/rules-of-hooks/todo.invalid.invalid-rules-of-hooks-191029ac48c8.js
+1 -1
@@ -1,4 +1,4 @@
1 -// @skip
1 +// @expectNothingCompiled @skip
2 // Passed but should have failed
3
4 // Invalid because it's dangerous.
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/rules-of-hooks/todo.invalid.invalid-rules-of-hooks-206e2811c87c.expect.md
+2 -2
@@ -2,7 +2,7 @@
2 ## Input
3
4 ```javascript
5 -// @skip
5 +// @expectNothingCompiled @skip
6 // Passed but should have failed
7
8 // This is a false positive (it's valid) that unfortunately
@@ -20,7 +20,7 @@ class Foo extends Component {
20 ## Code
21
22 ```javascript
23 -// @skip
23 +// @expectNothingCompiled @skip
24 // Passed but should have failed
25
26 // This is a false positive (it's valid) that unfortunately
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/rules-of-hooks/todo.invalid.invalid-rules-of-hooks-206e2811c87c.js
+1 -1
@@ -1,4 +1,4 @@
1 -// @skip
1 +// @expectNothingCompiled @skip
2 // Passed but should have failed
3
4 // This is a false positive (it's valid) that unfortunately
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/rules-of-hooks/todo.invalid.invalid-rules-of-hooks-28a7111f56a7.expect.md
+2 -2
@@ -2,7 +2,7 @@
2 ## Input
3
4 ```javascript
5 -// @skip
5 +// @expectNothingCompiled @skip
6 // Passed but should have failed
7
8 // Technically this is a false positive.
@@ -23,7 +23,7 @@ const browserHistory = useBasename(createHistory)({
23 ## Code
24
25 ```javascript
26 -// @skip
26 +// @expectNothingCompiled @skip
27 // Passed but should have failed
28
29 // Technically this is a false positive.
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/rules-of-hooks/todo.invalid.invalid-rules-of-hooks-28a7111f56a7.js
+1 -1
@@ -1,4 +1,4 @@
1 -// @skip
1 +// @expectNothingCompiled @skip
2 // Passed but should have failed
3
4 // Technically this is a false positive.
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/rules-of-hooks/todo.invalid.invalid-rules-of-hooks-2c51251df67a.expect.md
+2 -2
@@ -2,7 +2,7 @@
2 ## Input
3
4 ```javascript
5 -// @skip
5 +// @expectNothingCompiled @skip
6 // Passed but should have failed
7
8 (class {
@@ -16,7 +16,7 @@
16 ## Code
17
18 ```javascript
19 -// @skip
19 +// @expectNothingCompiled @skip
20 // Passed but should have failed
21
22 (class {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/rules-of-hooks/todo.invalid.invalid-rules-of-hooks-2c51251df67a.js
+1 -1
@@ -1,4 +1,4 @@
1 -// @skip
1 +// @expectNothingCompiled @skip
2 // Passed but should have failed
3
4 (class {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/rules-of-hooks/todo.invalid.invalid-rules-of-hooks-8303403b8e4c.expect.md
+2 -2
@@ -2,7 +2,7 @@
2 ## Input
3
4 ```javascript
5 -// @skip
5 +// @expectNothingCompiled @skip
6 // Passed but should have failed
7
8 class ClassComponentWithHook extends React.Component {
@@ -16,7 +16,7 @@ class ClassComponentWithHook extends React.Component {
16 ## Code
17
18 ```javascript
19 -// @skip
19 +// @expectNothingCompiled @skip
20 // Passed but should have failed
21
22 class ClassComponentWithHook extends React.Component {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/rules-of-hooks/todo.invalid.invalid-rules-of-hooks-8303403b8e4c.js
+1 -1
@@ -1,4 +1,4 @@
1 -// @skip
1 +// @expectNothingCompiled @skip
2 // Passed but should have failed
3
4 class ClassComponentWithHook extends React.Component {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/rules-of-hooks/todo.invalid.invalid-rules-of-hooks-99b5c750d1d1.expect.md
+2 -2
@@ -2,7 +2,7 @@
2 ## Input
3
4 ```javascript
5 -// @skip
5 +// @expectNothingCompiled @skip
6 // Passed but should have failed
7
8 class ClassComponentWithFeatureFlag extends React.Component {
@@ -18,7 +18,7 @@ class ClassComponentWithFeatureFlag extends React.Component {
18 ## Code
19
20 ```javascript
21 -// @skip
21 +// @expectNothingCompiled @skip
22 // Passed but should have failed
23
24 class ClassComponentWithFeatureFlag extends React.Component {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/rules-of-hooks/todo.invalid.invalid-rules-of-hooks-99b5c750d1d1.js
+1 -1
@@ -1,4 +1,4 @@
1 -// @skip
1 +// @expectNothingCompiled @skip
2 // Passed but should have failed
3
4 class ClassComponentWithFeatureFlag extends React.Component {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/rules-of-hooks/todo.invalid.invalid-rules-of-hooks-9c79feec4b9b.expect.md
+2 -2
@@ -2,7 +2,7 @@
2 ## Input
3
4 ```javascript
5 -// @skip
5 +// @expectNothingCompiled @skip
6 // Passed but should have failed
7
8 (class {
@@ -16,7 +16,7 @@
16 ## Code
17
18 ```javascript
19 -// @skip
19 +// @expectNothingCompiled @skip
20 // Passed but should have failed
21
22 (class {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/rules-of-hooks/todo.invalid.invalid-rules-of-hooks-9c79feec4b9b.js
+1 -1
@@ -1,4 +1,4 @@
1 -// @skip
1 +// @expectNothingCompiled @skip
2 // Passed but should have failed
3
4 (class {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/rules-of-hooks/todo.invalid.invalid-rules-of-hooks-acb56658fe7e.expect.md
+2 -2
@@ -2,7 +2,7 @@
2 ## Input
3
4 ```javascript
5 -// @skip
5 +// @expectNothingCompiled @skip
6 // Passed but should have failed
7
8 class C {
@@ -17,7 +17,7 @@ class C {
17 ## Code
18
19 ```javascript
20 -// @skip
20 +// @expectNothingCompiled @skip
21 // Passed but should have failed
22
23 class C {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/rules-of-hooks/todo.invalid.invalid-rules-of-hooks-acb56658fe7e.js
+1 -1
@@ -1,4 +1,4 @@
1 -// @skip
1 +// @expectNothingCompiled @skip
2 // Passed but should have failed
3
4 class C {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/rules-of-hooks/todo.invalid.invalid-rules-of-hooks-ddeca9708b63.expect.md
+2 -2
@@ -2,7 +2,7 @@
2 ## Input
3
4 ```javascript
5 -// @skip
5 +// @expectNothingCompiled @skip
6 // Passed but should have failed
7
8 (class {
@@ -16,7 +16,7 @@
16 ## Code
17
18 ```javascript
19 -// @skip
19 +// @expectNothingCompiled @skip
20 // Passed but should have failed
21
22 (class {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/rules-of-hooks/todo.invalid.invalid-rules-of-hooks-ddeca9708b63.js
+1 -1
@@ -1,4 +1,4 @@
1 -// @skip
1 +// @expectNothingCompiled @skip
2 // Passed but should have failed
3
4 (class {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/rules-of-hooks/todo.invalid.invalid-rules-of-hooks-e69ffce323c3.expect.md
+2 -2
@@ -2,7 +2,7 @@
2 ## Input
3
4 ```javascript
5 -// @skip
5 +// @expectNothingCompiled @skip
6 // Passed but should have failed
7
8 (class {
@@ -16,7 +16,7 @@
16 ## Code
17
18 ```javascript
19 -// @skip
19 +// @expectNothingCompiled @skip
20 // Passed but should have failed
21
22 (class {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/rules-of-hooks/todo.invalid.invalid-rules-of-hooks-e69ffce323c3.js
+1 -1
@@ -1,4 +1,4 @@
1 -// @skip
1 +// @expectNothingCompiled @skip
2 // Passed but should have failed
3
4 (class {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/skip-useMemoCache.expect.md
+2
@@ -2,6 +2,7 @@
2 ## Input
3
4 ```javascript
5 +// @expectNothingCompiled
6 import {c as useMemoCache} from 'react/compiler-runtime';
7
8 function Component(props) {
@@ -26,6 +27,7 @@ export const FIXTURE_ENTRYPOINT = {
27 ## Code
28
29 ```javascript
30 +// @expectNothingCompiled
31 import { c as useMemoCache } from "react/compiler-runtime";
32
33 function Component(props) {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/skip-useMemoCache.js
+1
@@ -1,3 +1,4 @@
1 +// @expectNothingCompiled
2 import {c as useMemoCache} from 'react/compiler-runtime';
3
4 function Component(props) {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/use-no-forget-with-no-errors.expect.md
+2
@@ -2,6 +2,7 @@
2 ## Input
3
4 ```javascript
5 +// @expectNothingCompiled
6 function Component() {
7 'use no forget';
8 return <div>Hello World</div>;
@@ -18,6 +19,7 @@ export const FIXTURE_ENTRYPOINT = {
19 ## Code
20
21 ```javascript
22 +// @expectNothingCompiled
23 function Component() {
24 "use no forget";
25 return <div>Hello World</div>;
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/use-no-forget-with-no-errors.js
+1
@@ -1,3 +1,4 @@
1 +// @expectNothingCompiled
2 function Component() {
3 'use no forget';
4 return <div>Hello World</div>;
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/use-no-memo-simple.expect.md
+2
@@ -2,6 +2,7 @@
2 ## Input
3
4 ```javascript
5 +// @expectNothingCompiled
6 function Component(props) {
7 'use no memo';
8 let x = [props.foo];
@@ -19,6 +20,7 @@ export const FIXTURE_ENTRYPOINT = {
20 ## Code
21
22 ```javascript
23 +// @expectNothingCompiled
24 function Component(props) {
25 "use no memo";
26 let x = [props.foo];
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/use-no-memo-simple.js
+1
@@ -1,3 +1,4 @@
1 +// @expectNothingCompiled
2 function Component(props) {
3 'use no memo';
4 let x = [props.foo];
compiler/packages/snap/src/compiler.ts
+29 -9
@@ -52,7 +52,11 @@ function makePluginOptions(
52 EffectEnum: typeof Effect,
53 ValueKindEnum: typeof ValueKind,
54 ValueReasonEnum: typeof ValueReason,
55 -): [PluginOptions, Array<{filename: string | null; event: LoggerEvent}>] {
55 +): {
56 + options: PluginOptions;
57 + loggerTestOnly: boolean;
58 + logs: Array<{filename: string | null; event: LoggerEvent}>;
59 +} {
60 // TODO(@mofeiZ) rewrite snap fixtures to @validatePreserveExistingMemo:false
61 let validatePreserveExistingMemoizationGuarantees = false;
62 let target: CompilerReactTarget = '19';
@@ -69,13 +73,12 @@ function makePluginOptions(
73 validatePreserveExistingMemoizationGuarantees = true;
74 }
75
76 + const loggerTestOnly = firstLine.includes('@loggerTestOnly');
77 const logs: Array<{filename: string | null; event: LoggerEvent}> = [];
78 const logger: Logger = {
74 - logEvent: firstLine.includes('@loggerTestOnly')
75 - ? (filename, event) => {
76 - logs.push({filename, event});
77 - }
78 - : () => {},
79 + logEvent: (filename, event) => {
80 + logs.push({filename, event});
81 + },
82 debugLogIRs: debugIRLogger,
83 };
84
@@ -96,7 +99,7 @@ function makePluginOptions(
99 enableReanimatedCheck: false,
100 target,
101 };
99 - return [options, logs];
102 + return {options, loggerTestOnly, logs};
103 }
104
105 export function parseInput(
@@ -245,7 +248,7 @@ export async function transformFixtureInput(
248 /**
249 * Get Forget compiled code
250 */
248 - const [options, logs] = makePluginOptions(
251 + const {options, loggerTestOnly, logs} = makePluginOptions(
252 firstLine,
253 parseConfigPragmaFn,
254 debugIRLogger,
@@ -342,7 +345,7 @@ export async function transformFixtureInput(
345 }
346 const forgetOutput = await format(forgetCode, language);
347 let formattedLogs = null;
345 - if (logs.length !== 0) {
348 + if (loggerTestOnly && logs.length !== 0) {
349 formattedLogs = logs
350 .map(({event}) => {
351 return JSON.stringify(event, (key, value) => {
@@ -358,6 +361,23 @@ export async function transformFixtureInput(
361 })
362 .join('\n');
363 }
364 + const expectNothingCompiled =
365 + firstLine.indexOf('@expectNothingCompiled') !== -1;
366 + const successFailures = logs.filter(
367 + log =>
368 + log.event.kind === 'CompileSuccess' || log.event.kind === 'CompileError',
369 + );
370 + if (successFailures.length === 0 && !expectNothingCompiled) {
371 + return {
372 + kind: 'err',
373 + msg: 'No success/failure events, add `// @expectNothingCompiled` to the first line if this is expected',
374 + };
375 + } else if (successFailures.length !== 0 && expectNothingCompiled) {
376 + return {
377 + kind: 'err',
378 + msg: 'Expected nothing to be compiled (from `// @expectNothingCompiled`), but some functions compiled or errored',
379 + };
380 + }
381 return {
382 kind: 'ok',
383 value: {