@samitouri / QOS-React-2 / commits / 6efd1f99d7

Make function name a string not an identifier

Fixes #1751. Function ids can be plain strings, and we can refer to them as globals rather than via a local identifier. In addition to the bug from $1751 this also cleans up an existing todo.

Joe Savona committed Jun 20, 2023 at 15:16 UTC 6efd1f99d77e50ef26d94c411a1e0336a39b64ca
55 files changed +125 -163
compiler/forget/packages/babel-plugin-react-forget/src/HIR/BuildHIR.ts
+2 -3
@@ -23,7 +23,6 @@ import {
23 GeneratedSource,
24 GotoVariant,
25 HIRFunction,
26 - Identifier,
26 IfTerminal,
27 InstructionKind,
28 InstructionValue,
@@ -77,9 +76,9 @@ export function lower(
76 // Internal babel is on an older version that does not have hasNode (v7.17)
77 // See https://github.com/babel/babel/pull/13940/files for impl
78 // TODO: write helper function for NodePath.node != null
80 - let id: Identifier | null = null;
79 + let id: string | null = null;
80 if (func.isFunctionDeclaration() && func.get("id").node != null) {
82 - id = builder.resolveIdentifier(func.get("id") as NodePath<t.Identifier>);
81 + id = (func.get("id") as NodePath<t.Identifier>).node.name;
82 }
83 const params: Array<Place> = [];
84 func.get("params").forEach((param) => {
compiler/forget/packages/babel-plugin-react-forget/src/HIR/HIR.ts
+2 -2
@@ -48,7 +48,7 @@ export type SourceLocation = t.SourceLocation | typeof GeneratedSource;
48 */
49 export type ReactiveFunction = {
50 loc: SourceLocation;
51 - id: Identifier | null;
51 + id: string | null;
52 params: Array<Place>;
53 generator: boolean;
54 async: boolean;
@@ -216,7 +216,7 @@ export type ReactiveLabelTerminal = {
216 */
217 export type HIRFunction = {
218 loc: SourceLocation;
219 - id: Identifier | null;
219 + id: string | null;
220 env: Environment;
221 params: Array<Place>;
222 context: Array<Place>;
compiler/forget/packages/babel-plugin-react-forget/src/HIR/HIRBuilder.ts
+2 -14
@@ -171,23 +171,11 @@ export default class HIRBuilder {
171 if (binding == null) {
172 return null;
173 }
174 - // If the binding is from the parent function's outer scope, then
175 - // we treat it equivalently to a global.
176 - //
177 - // TODO: remove the exception that resolves references to the
178 - // parent function itself. We don't need to support self-recursion,
179 - // so we can treat such references as globals.
174 + // Check if the binding is from module scope, if so return null
175 const outerBinding =
176 this.parentFunction.scope.parent.getBinding(originalName);
177 if (binding === outerBinding) {
183 - const func = this.parentFunction;
184 - const isParentFunctionReference =
185 - func.isFunctionDeclaration() &&
186 - func.get("id").node != null &&
187 - func.get("id").node!.name === originalName;
188 - if (!isParentFunctionReference) {
189 - return null;
190 - }
178 + return null;
179 }
180 return binding;
181 }
compiler/forget/packages/babel-plugin-react-forget/src/Inference/InferReferenceEffects.ts
-9
@@ -96,15 +96,6 @@ export default function inferReferenceEffects(
96 value: undefined,
97 };
98 initialState.initialize(value, ValueKind.Frozen);
99 - if (fn.id !== null) {
100 - const id: Place = {
101 - kind: "Identifier",
102 - identifier: fn.id,
103 - loc: fn.loc,
104 - effect: Effect.Freeze,
105 - };
106 - initialState.define(id, value);
107 - }
99
100 for (const ref of fn.context) {
101 // TODO(gsn): This is a hack.
compiler/forget/packages/babel-plugin-react-forget/src/ReactiveScopes/CodegenReactiveFunction.ts
+2 -5
@@ -38,10 +38,7 @@ import { buildReactiveFunction } from "./BuildReactiveFunction";
38 export function codegenReactiveFunction(
39 fn: ReactiveFunction
40 ): Result<t.FunctionDeclaration, CompilerError> {
41 - const cx = new Context(fn.env, fn.id?.name ?? "[[ anonymous ]]");
42 - if (fn.id !== null) {
43 - cx.temp.set(fn.id.id, null);
44 - }
41 + const cx = new Context(fn.env, fn.id ?? "[[ anonymous ]]");
42 for (const param of fn.params) {
43 cx.temp.set(param.identifier.id, null);
44 }
@@ -77,7 +74,7 @@ export function codegenReactiveFunction(
74 return Ok(
75 createFunctionDeclaration(
76 fn.loc,
80 - fn.id !== null ? convertIdentifier(fn.id) : null,
77 + fn.id !== null ? t.identifier(fn.id) : null,
78 params,
79 body,
80 fn.generator,
compiler/forget/packages/babel-plugin-react-forget/src/ReactiveScopes/PrintReactiveFunction.ts
+1 -3
@@ -24,9 +24,7 @@ import { assertExhaustive } from "../Utils/utils";
24
25 export function printReactiveFunction(fn: ReactiveFunction): string {
26 const writer = new Writer();
27 - writer.writeLine(
28 - `function ${fn.id !== null ? printIdentifier(fn.id) : "<unknown>"}(`
29 - );
27 + writer.writeLine(`function ${fn.id !== null ? fn.id : "<unknown>"}(`);
28 writer.indented(() => {
29 for (const param of fn.params) {
30 writer.writeLine(`${printPlace(param)},`);
compiler/forget/packages/babel-plugin-react-forget/src/ReactiveScopes/PropagateScopeDependencies.ts
-6
@@ -49,12 +49,6 @@ export function propagateScopeDependencies(fn: ReactiveFunction): void {
49 visitReactiveFunction(fn, new FindPromotedTemporaries(), escapingTemporaries);
50
51 const context = new Context(escapingTemporaries.usedOutsideDeclaringScope);
52 - if (fn.id !== null) {
53 - context.declare(fn.id, {
54 - id: makeInstructionId(0),
55 - scope: empty(),
56 - });
57 - }
52 for (const param of fn.params) {
53 context.declare(param.identifier, {
54 id: makeInstructionId(0),
compiler/forget/packages/babel-plugin-react-forget/src/ReactiveScopes/PruneNonEscapingScopes.ts
-3
@@ -117,9 +117,6 @@ export function pruneNonEscapingScopes(
117 // First build up a map of which instructions are involved in creating which values,
118 // and which values are returned.
119 const state = new State(fn.env);
120 - if (fn.id !== null) {
121 - state.declare(fn.id.id);
122 - }
120 for (const param of fn.params) {
121 state.declare(param.identifier.id);
122 }
compiler/forget/packages/babel-plugin-react-forget/src/ReactiveScopes/RenameVariables.ts
-3
@@ -33,9 +33,6 @@ import {
33 export function renameVariables(fn: ReactiveFunction): void {
34 const scopes = new Scopes();
35 scopes.enter(() => {
36 - if (fn.id !== null) {
37 - scopes.visit(fn.id);
38 - }
36 for (const param of fn.params) {
37 scopes.visit(param.identifier);
38 }
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/array-pattern-params.expect.md
+2 -2
@@ -14,9 +14,9 @@ function component([a, b]) {
14
15 ```javascript
16 import { unstable_useMemoCache as useMemoCache } from "react";
17 -function component(t17) {
17 +function component(t16) {
18 const $ = useMemoCache(7);
19 - const [a, b] = t17;
19 + const [a, b] = t16;
20 const c_0 = $[0] !== a;
21 let t0;
22 if (c_0) {
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/babel-existing-react-import.expect.md
+4 -4
@@ -41,8 +41,8 @@ function Component(props) {
41 } else {
42 t0 = $[1];
43 }
44 - const t16 = t0;
45 - const expensiveNumber = t16;
44 + const t15 = t0;
45 + const expensiveNumber = t15;
46 const c_2 = $[2] !== expensiveNumber;
47 let t1;
48 if (c_2) {
@@ -67,8 +67,8 @@ function Component2(props) {
67 } else {
68 t0 = $[1];
69 }
70 - const t16 = t0;
71 - const expensiveNumber = t16;
70 + const t15 = t0;
71 + const expensiveNumber = t15;
72 const c_2 = $[2] !== expensiveNumber;
73 let t1;
74 if (c_2) {
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-function-member-expr-call.expect.md
+2 -2
@@ -20,9 +20,9 @@ function component({ mutator }) {
20
21 ```javascript
22 import { unstable_useMemoCache as useMemoCache } from "react";
23 -function component(t27) {
23 +function component(t26) {
24 const $ = useMemoCache(7);
25 - const { mutator } = t27;
25 + const { mutator } = t26;
26 const c_0 = $[0] !== mutator;
27 let t0;
28 if (c_0) {
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/destructuring-array-param-default.expect.md
+3 -3
@@ -11,9 +11,9 @@ function Component([a = 2]) {
11 ## Code
12
13 ```javascript
14 -function Component(t14) {
15 - const [t15] = t14;
16 - const a = t15 === undefined ? 2 : t15;
14 +function Component(t13) {
15 + const [t14] = t13;
16 + const a = t14 === undefined ? 2 : t14;
17 return a;
18 }
19
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/destructuring-assignment.expect.md
+8 -8
@@ -30,14 +30,14 @@ import { unstable_useMemoCache as useMemoCache } from "react";
30 function foo(a, b, c) {
31 const $ = useMemoCache(5);
32
33 - const [d, t47] = a;
34 - const [t49] = t47;
35 - const { e: t51 } = t49;
36 - const { f: g } = t51;
37 - const { l: t56, o } = b;
38 - const { m: t59 } = t56;
39 - const [t61] = t59;
40 - const [n] = t61;
33 + const [d, t46] = a;
34 + const [t48] = t46;
35 + const { e: t50 } = t48;
36 + const { f: g } = t50;
37 + const { l: t55, o } = b;
38 + const { m: t58 } = t55;
39 + const [t60] = t58;
40 + const [n] = t60;
41 const c_0 = $[0] !== d;
42 const c_1 = $[1] !== g;
43 const c_2 = $[2] !== n;
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/destructuring-mixed-scope-and-local-variables-with-default.expect.md
+2 -2
@@ -38,7 +38,7 @@ function Component(props) {
38 if (c_0) {
39 const allUrls = [];
40
41 - const { media: t0, comments: t2, urls: t82 } = post;
41 + const { media: t0, comments: t2, urls: t81 } = post;
42 const c_3 = $[3] !== t0;
43 let t1;
44 if (c_3) {
@@ -59,7 +59,7 @@ function Component(props) {
59 t3 = $[6];
60 }
61 const comments = t3;
62 - const urls = t82 === undefined ? [] : t82;
62 + const urls = t81 === undefined ? [] : t81;
63 const c_7 = $[7] !== comments.length;
64 let t4;
65 if (c_7) {
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/destructuring-mixed-scope-declarations-and-locals.expect.md
+2 -2
@@ -38,8 +38,8 @@ function Component(props) {
38 if (c_0) {
39 const allUrls = [];
40
41 - const { media: t85, comments, urls } = post;
42 - media = t85;
41 + const { media: t84, comments, urls } = post;
42 + media = t84;
43 const c_3 = $[3] !== comments.length;
44 let t0;
45 if (c_3) {
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/destructuring-object-param-default.expect.md
+3 -3
@@ -11,9 +11,9 @@ function Component({ a = 2 }) {
11 ## Code
12
13 ```javascript
14 -function Component(t14) {
15 - const { a: t15 } = t14;
16 - const a = t15 === undefined ? 2 : t15;
14 +function Component(t13) {
15 + const { a: t14 } = t13;
16 + const a = t14 === undefined ? 2 : t14;
17 return a;
18 }
19
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/destructuring.expect.md
+2 -2
@@ -59,8 +59,8 @@ function foo(a, b, c) {
59 g = $[6];
60 }
61 const { f } = t2;
62 - const { l: t52, p } = b;
63 - const { m: t3 } = t52;
62 + const { l: t51, p } = b;
63 + const { m: t3 } = t51;
64 const c_7 = $[7] !== t3;
65 let t4;
66 let o;
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error._bug.recursive-function-expr.expect.md deleted
-18
@@ -1,18 +0,0 @@
1 -
2 -## Input
3 -
4 -```javascript
5 -function foo() {
6 - (() => foo())();
7 -}
8 -
9 -```
10 -
11 -
12 -## Error
13 -
14 -```
15 -Expected value for identifier `0` to be initialized.
16 -```
17 -
18 -
\ No newline at end of file
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.hoisted-function-declaration.expect.md
+1 -1
@@ -17,7 +17,7 @@ function component(a) {
17 ## Error
18
19 ```
20 -[ReactForget] Invariant: EnterSSA: Expected identifier to be defined before being used. Identifier x$6 is undefined
20 +[ReactForget] Invariant: EnterSSA: Expected identifier to be defined before being used. Identifier x$5 is undefined
21 ```
22
23
\ No newline at end of file
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-access-ref-during-render.expect.md
+1 -1
@@ -15,7 +15,7 @@ function Component(props) {
15 ## Error
16
17 ```
18 -[ReactForget] InvalidInput: Ref values (the `current` property) may not be accessed during render. Cannot access ref value at freeze $23:TObject<BuiltInRefValue> (5:5)
18 +[ReactForget] InvalidInput: Ref values (the `current` property) may not be accessed during render. Cannot access ref value at freeze $22:TObject<BuiltInRefValue> (5:5)
19 ```
20
21
\ No newline at end of file
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-array-push-frozen.expect.md
+1 -1
@@ -15,7 +15,7 @@ function Component(props) {
15 ## Error
16
17 ```
18 -[ReactForget] InvalidInput: InferReferenceEffects: inferred mutation of known immutable value. Found mutation of $20:TObject<BuiltInArray> (frozen) (4:4)
18 +[ReactForget] InvalidInput: InferReferenceEffects: inferred mutation of known immutable value. Found mutation of $19:TObject<BuiltInArray> (frozen) (4:4)
19 ```
20
21
\ No newline at end of file
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-computed-store-to-frozen-value.expect.md
+1 -1
@@ -16,7 +16,7 @@ function Component(props) {
16 ## Error
17
18 ```
19 -[ReactForget] InvalidInput: InferReferenceEffects: inferred mutation of known immutable value. Found mutation of $22 (frozen) (5:5)
19 +[ReactForget] InvalidInput: InferReferenceEffects: inferred mutation of known immutable value. Found mutation of $21 (frozen) (5:5)
20 ```
21
22
\ No newline at end of file
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-delete-computed-property-of-frozen-value.expect.md
+1 -1
@@ -16,7 +16,7 @@ function Component(props) {
16 ## Error
17
18 ```
19 -[ReactForget] InvalidInput: InferReferenceEffects: inferred mutation of known immutable value. Found mutation of $20 (frozen) (5:5)
19 +[ReactForget] InvalidInput: InferReferenceEffects: inferred mutation of known immutable value. Found mutation of $19 (frozen) (5:5)
20 ```
21
22
\ No newline at end of file
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-delete-property-of-frozen-value.expect.md
+1 -1
@@ -16,7 +16,7 @@ function Component(props) {
16 ## Error
17
18 ```
19 -[ReactForget] InvalidInput: InferReferenceEffects: inferred mutation of known immutable value. Found mutation of $19 (frozen) (5:5)
19 +[ReactForget] InvalidInput: InferReferenceEffects: inferred mutation of known immutable value. Found mutation of $18 (frozen) (5:5)
20 ```
21
22
\ No newline at end of file
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-function-expression-mutates-immutable-value.expect.md
+1 -1
@@ -18,7 +18,7 @@ function Component(props) {
18 ## Error
19
20 ```
21 -[ReactForget] InvalidInput: InferReferenceEffects: inferred mutation of known immutable value. Found mutation of $40 (frozen) (5:5)
21 +[ReactForget] InvalidInput: InferReferenceEffects: inferred mutation of known immutable value. Found mutation of $39 (frozen) (5:5)
22 ```
23
24
\ No newline at end of file
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-mutate-after-aliased-freeze.expect.md
+1 -1
@@ -25,7 +25,7 @@ function Component(props) {
25 ## Error
26
27 ```
28 -[ReactForget] InvalidInput: InferReferenceEffects: inferred mutation of known immutable value. Found mutation of $46:TObject<BuiltInArray> (frozen) (13:13)
28 +[ReactForget] InvalidInput: InferReferenceEffects: inferred mutation of known immutable value. Found mutation of $44:TObject<BuiltInArray> (frozen) (13:13)
29 ```
30
31
\ No newline at end of file
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-mutate-after-freeze.expect.md
+1 -1
@@ -19,7 +19,7 @@ function Component(props) {
19 ## Error
20
21 ```
22 -[ReactForget] InvalidInput: InferReferenceEffects: inferred mutation of known immutable value. Found mutation of $27:TObject<BuiltInArray> (frozen) (7:7)
22 +[ReactForget] InvalidInput: InferReferenceEffects: inferred mutation of known immutable value. Found mutation of $26:TObject<BuiltInArray> (frozen) (7:7)
23 ```
24
25
\ No newline at end of file
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-pass-ref-to-function.expect.md
+1 -1
@@ -14,7 +14,7 @@ function Component(props) {
14 ## Error
15
16 ```
17 -[ReactForget] InvalidInput: Ref values may not be passed to functions because they could read the ref value (`current` property) during render. Cannot access ref object at mutate? $22[6:8]:TObject<BuiltInUseRefId> (3:3)
17 +[ReactForget] InvalidInput: Ref values may not be passed to functions because they could read the ref value (`current` property) during render. Cannot access ref object at mutate? $21[6:8]:TObject<BuiltInUseRefId> (3:3)
18 ```
19
20
\ No newline at end of file
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-property-store-to-frozen-value.expect.md
+1 -1
@@ -16,7 +16,7 @@ function Component(props) {
16 ## Error
17
18 ```
19 -[ReactForget] InvalidInput: InferReferenceEffects: inferred mutation of known immutable value. Found mutation of $21 (frozen) (5:5)
19 +[ReactForget] InvalidInput: InferReferenceEffects: inferred mutation of known immutable value. Found mutation of $20 (frozen) (5:5)
20 ```
21
22
\ No newline at end of file
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-ref-in-callback-invoked-during-render.expect.md
+1 -1
@@ -18,7 +18,7 @@ function Component(props) {
18 ## Error
19
20 ```
21 -[ReactForget] InvalidInput: Ref values (the `current` property) may not be accessed during render. Cannot access ref value at capture $43[6:16]:TObject<BuiltInRefValue> (5:5)
21 +[ReactForget] InvalidInput: Ref values (the `current` property) may not be accessed during render. Cannot access ref value at capture $42[6:16]:TObject<BuiltInRefValue> (5:5)
22 ```
23
24
\ No newline at end of file
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-ref-value-as-props.expect.md
+1 -1
@@ -13,7 +13,7 @@ function Component(props) {
13 ## Error
14
15 ```
16 -[ReactForget] InvalidInput: Ref values (the `current` property) may not be accessed during render. Cannot access ref value at freeze $20:TObject<BuiltInRefValue> (3:3)
16 +[ReactForget] InvalidInput: Ref values (the `current` property) may not be accessed during render. Cannot access ref value at freeze $19:TObject<BuiltInRefValue> (3:3)
17 ```
18
19
\ No newline at end of file
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-set-and-read-ref-during-render.expect.md
+2 -2
@@ -14,9 +14,9 @@ function Component(props) {
14 ## Error
15
16 ```
17 -[ReactForget] InvalidInput: Ref values may not be passed to functions because they could read the ref value (`current` property) during render. Cannot access ref object at store $22[7:9]:TObject<BuiltInUseRefId> (3:3)
17 +[ReactForget] InvalidInput: Ref values may not be passed to functions because they could read the ref value (`current` property) during render. Cannot access ref object at store $21[7:9]:TObject<BuiltInUseRefId> (3:3)
18
19 -[ReactForget] InvalidInput: Ref values (the `current` property) may not be accessed during render. Cannot access ref value at freeze $25:TObject<BuiltInRefValue> (4:4)
19 +[ReactForget] InvalidInput: Ref values (the `current` property) may not be accessed during render. Cannot access ref value at freeze $24:TObject<BuiltInRefValue> (4:4)
20 ```
21
22
\ No newline at end of file
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-use-ref-added-to-dep-without-type-info.expect.md
+1 -1
@@ -21,7 +21,7 @@ function Foo({ a }) {
21 ## Error
22
23 ```
24 -[ReactForget] InvalidInput: Ref values may not be passed to functions because they could read the ref value (`current` property) during render. Cannot access ref object at capture $30:TObject<BuiltInUseRefId> (4:4)
24 +[ReactForget] InvalidInput: Ref values may not be passed to functions because they could read the ref value (`current` property) during render. Cannot access ref object at capture $29:TObject<BuiltInUseRefId> (4:4)
25 ```
26
27
\ No newline at end of file
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.mutate-captured-arg-separately.expect.md
+1 -1
@@ -19,7 +19,7 @@ function component(a) {
19 ## Error
20
21 ```
22 -[ReactForget] Invariant: EnterSSA: Expected identifier to be defined before being used. Identifier x$2 is undefined (7:7)
22 +[ReactForget] Invariant: EnterSSA: Expected identifier to be defined before being used. Identifier x$1 is undefined (7:7)
23 ```
24
25
\ No newline at end of file
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/escape-analysis-destructured-rest-element.expect.md
+4 -4
@@ -21,8 +21,8 @@ function Component(props) {
21 const c_0 = $[0] !== props.a;
22 let b;
23 if (c_0) {
24 - const { a, ...t30 } = props.a;
25 - b = t30;
24 + const { a, ...t29 } = props.a;
25 + b = t29;
26 $[0] = props.a;
27 $[1] = b;
28 } else {
@@ -31,8 +31,8 @@ function Component(props) {
31 const c_2 = $[2] !== props.c;
32 let d;
33 if (c_2) {
34 - const [c, ...t31] = props.c;
35 - d = t31;
34 + const [c, ...t30] = props.c;
35 + d = t30;
36 $[2] = props.c;
37 $[3] = d;
38 } else {
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/function-param-assignment-pattern.expect.md
+2 -2
@@ -12,9 +12,9 @@ function Component(x = "default", y = [{}]) {
12
13 ```javascript
14 import { unstable_useMemoCache as useMemoCache } from "react";
15 -function Component(t24, t0) {
15 +function Component(t23, t0) {
16 const $ = useMemoCache(5);
17 - const x = t24 === undefined ? "default" : t24;
17 + const x = t23 === undefined ? "default" : t23;
18 const c_0 = $[0] !== t0;
19 let t1;
20 if (c_0) {
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/object-pattern-params.expect.md
+2 -2
@@ -14,9 +14,9 @@ function component({ a, b }) {
14
15 ```javascript
16 import { unstable_useMemoCache as useMemoCache } from "react";
17 -function component(t17) {
17 +function component(t16) {
18 const $ = useMemoCache(7);
19 - const { a, b } = t17;
19 + const { a, b } = t16;
20 const c_0 = $[0] !== a;
21 let t0;
22 if (c_0) {
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/recursive-function-expr.expect.md new
+19
@@ -0,0 +1,19 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +function foo() {
6 + (() => foo())();
7 +}
8 +
9 +```
10 +
11 +## Code
12 +
13 +```javascript
14 +function foo() {
15 + (() => foo())();
16 +}
17 +
18 +```
19 +
\ No newline at end of file
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/recursive-function-expr.js renamed
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/ref-current-aliased-not-added-to-dep-2.expect.md
+2 -2
@@ -17,9 +17,9 @@ function Foo({ a }) {
17
18 ```javascript
19 import { unstable_useMemoCache as useMemoCache } from "react"; // @validateRefAccessDuringRender false
20 -function Foo(t21) {
20 +function Foo(t20) {
21 const $ = useMemoCache(4);
22 - const { a } = t21;
22 + const { a } = t20;
23 const ref = useRef();
24 const val = ref.current;
25 const c_0 = $[0] !== a;
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/ref-current-not-added-to-dep-2.expect.md
+2 -2
@@ -16,9 +16,9 @@ function Foo({ a }) {
16
17 ```javascript
18 import { unstable_useMemoCache as useMemoCache } from "react"; // @validateRefAccessDuringRender false
19 -function Foo(t18) {
19 +function Foo(t17) {
20 const $ = useMemoCache(4);
21 - const { a } = t18;
21 + const { a } = t17;
22 const ref = useRef();
23 const c_0 = $[0] !== a;
24 let t0;
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/remove-memoization-kitchen-sink.expect.md
+2 -2
@@ -29,8 +29,8 @@ function Component(props) {
29 const object = { x, onChange };
30
31 const { x: x_0, onChange: onChange_0 } = object;
32 - const t44 = <input value={x_0} onChange={onChange_0} />;
33 - return t44;
32 + const t43 = <input value={x_0} onChange={onChange_0} />;
33 + return t43;
34 }
35
36 ```
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/unused-object-element-with-rest.expect.md
+2 -2
@@ -19,8 +19,8 @@ function Foo(props) {
19 const c_0 = $[0] !== props.a;
20 let rest;
21 if (c_0) {
22 - const { unused, ...t16 } = props.a;
23 - rest = t16;
22 + const { unused, ...t15 } = props.a;
23 + rest = t15;
24 $[0] = props.a;
25 $[1] = rest;
26 } else {
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/useMemo-if-else-multiple-return.expect.md
+4 -4
@@ -20,7 +20,7 @@ function Component(props) {
20 import { unstable_useMemoCache as useMemoCache } from "react";
21 function Component(props) {
22 const $ = useMemoCache(4);
23 - let t21 = undefined;
23 + let t20 = undefined;
24 bb7: {
25 if (props.cond) {
26 const c_0 = $[0] !== props.a;
@@ -32,7 +32,7 @@ function Component(props) {
32 } else {
33 t0 = $[1];
34 }
35 - t21 = t0;
35 + t20 = t0;
36 break bb7;
37 }
38 const c_2 = $[2] !== props.b;
@@ -44,9 +44,9 @@ function Component(props) {
44 } else {
45 t1 = $[3];
46 }
47 - t21 = t1;
47 + t20 = t1;
48 }
49 - const x = t21;
49 + const x = t20;
50 return x;
51 }
52
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/useMemo-independently-memoizeable.expect.md
+2 -2
@@ -51,8 +51,8 @@ function Component(props) {
51 } else {
52 t2 = $[6];
53 }
54 - const t27 = t2;
55 - const [a_0, b_0] = t27;
54 + const t26 = t2;
55 + const [a_0, b_0] = t26;
56 const c_7 = $[7] !== a_0;
57 const c_8 = $[8] !== b_0;
58 let t3;
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/useMemo-inlining-block-return.expect.md
+4 -4
@@ -19,7 +19,7 @@ function component(a, b) {
19 import { unstable_useMemoCache as useMemoCache } from "react";
20 function component(a, b) {
21 const $ = useMemoCache(2);
22 - let t14 = undefined;
22 + let t13 = undefined;
23 bb6: {
24 if (a) {
25 const c_0 = $[0] !== b;
@@ -31,12 +31,12 @@ function component(a, b) {
31 } else {
32 t0 = $[1];
33 }
34 - t14 = t0;
34 + t13 = t0;
35 break bb6;
36 }
37 - t14 = undefined;
37 + t13 = undefined;
38 }
39 - const x = t14;
39 + const x = t13;
40 return x;
41 }
42
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/useMemo-inverted-if.expect.md
+4 -4
@@ -21,20 +21,20 @@ function Component(props) {
21
22 ```javascript
23 function Component(props) {
24 - let t17 = undefined;
24 + let t16 = undefined;
25 bb10: {
26 bb5: {
27 if (props.cond) {
28 break bb5;
29 }
30
31 - t17 = props.a;
31 + t16 = props.a;
32 break bb10;
33 }
34
35 - t17 = props.b;
35 + t16 = props.b;
36 }
37 - const x = t17;
37 + const x = t16;
38 return x;
39 }
40
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/useMemo-labeled-statement-unconditional-return.expect.md
+2 -2
@@ -17,8 +17,8 @@ function Component(props) {
17
18 ```javascript
19 function Component(props) {
20 - const t9 = props.value;
21 - const x = t9;
20 + const t8 = props.value;
21 + const x = t8;
22 return x;
23 }
24
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/useMemo-logical.expect.md
+2 -2
@@ -13,8 +13,8 @@ function Component(props) {
13
14 ```javascript
15 function Component(props) {
16 - const t17 = props.a && props.b;
17 - const x = t17;
16 + const t16 = props.a && props.b;
17 + const x = t16;
18 return x;
19 }
20
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/useMemo-multiple-if-else.expect.md
+6 -6
@@ -25,7 +25,7 @@ function Component(props) {
25 import { unstable_useMemoCache as useMemoCache } from "react";
26 function Component(props) {
27 const $ = useMemoCache(3);
28 - let t32 = undefined;
28 + let t31 = undefined;
29 bb9: {
30 const c_0 = $[0] !== props;
31 let y;
@@ -35,21 +35,21 @@ function Component(props) {
35 y.push(props.a);
36 }
37 if (props.cond2) {
38 - t32 = y;
38 + t31 = y;
39 break bb9;
40 }
41
42 y.push(props.b);
43 $[0] = props;
44 $[1] = y;
45 - $[2] = t32;
45 + $[2] = t31;
46 } else {
47 y = $[1];
48 - t32 = $[2];
48 + t31 = $[2];
49 }
50 - t32 = y;
50 + t31 = y;
51 }
52 - const x = t32;
52 + const x = t31;
53 return x;
54 }
55
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/useMemo-simple.expect.md
+2 -2
@@ -24,8 +24,8 @@ function component(a) {
24 } else {
25 t0 = $[1];
26 }
27 - const t10 = t0;
28 - const x = t10;
27 + const t9 = t0;
28 + const x = t9;
29 const c_2 = $[2] !== x;
30 let t1;
31 if (c_2) {
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/useMemo-switch-no-fallthrough.expect.md
+4 -4
@@ -22,17 +22,17 @@ function Component(props) {
22
23 ```javascript
24 function Component(props) {
25 - let t18 = undefined;
25 + let t17 = undefined;
26 bb8: switch (props.key) {
27 case "key": {
28 - t18 = props.value;
28 + t17 = props.value;
29 break bb8;
30 }
31 default: {
32 - t18 = props.defaultValue;
32 + t17 = props.defaultValue;
33 }
34 }
35 - const x = t18;
35 + const x = t17;
36 return x;
37 }
38
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/useMemo-switch-return.expect.md
+4 -4
@@ -28,12 +28,12 @@ function Component(props) {
28
29 ```javascript
30 function Component(props) {
31 - let t22 = undefined;
31 + let t21 = undefined;
32 bb10: {
33 let y = undefined;
34 bb2: switch (props.switch) {
35 case "foo": {
36 - t22 = "foo";
36 + t21 = "foo";
37 break bb10;
38 }
39 case "bar": {
@@ -45,9 +45,9 @@ function Component(props) {
45 }
46 }
47
48 - t22 = y;
48 + t21 = y;
49 }
50 - const x = t22;
50 + const x = t21;
51 return x;
52 }
53
compiler/forget/packages/eslint-plugin-react-forget/__tests__/ReactForgetDiagnostics-test.ts
+2 -2
@@ -56,7 +56,7 @@ const tests: ForgetTestCases = {
56 errors: [
57 {
58 message:
59 - "[ReactForget] InvalidInput: Ref values (the `current` property) may not be accessed during render. Cannot access ref value at freeze $23:TObject<BuiltInRefValue> (6:6)",
59 + "[ReactForget] InvalidInput: Ref values (the `current` property) may not be accessed during render. Cannot access ref value at freeze $22:TObject<BuiltInRefValue> (6:6)",
60 line: 6,
61 column: 10,
62 endColumn: 15,
@@ -81,7 +81,7 @@ const tests: ForgetTestCases = {
81 errors: [
82 {
83 message:
84 - "[ReactForget] Invariant: EnterSSA: Expected identifier to be defined before being used. Identifier x$2 is undefined (8:8)",
84 + "[ReactForget] Invariant: EnterSSA: Expected identifier to be defined before being used. Identifier x$1 is undefined (8:8)",
85 line: 8,
86 column: 3,
87 endColumn: 17,