Array.prototype.join
Trivial
Joe Savona committed
May 25, 2023 at 15:57 UTC
3381ce7ea840786e76439e1cdc0cb5646fc265c0
3 files changed
+84
compiler/forget/src/HIR/ObjectShape.ts
+10
@@ -230,6 +230,16 @@ addObject(BUILTIN_SHAPES, BuiltInArrayId, [
230
returnValueKind: ValueKind.Mutable,
231
}),
232
],
233
+ [
234
+ "join",
235
+ addFunction(BUILTIN_SHAPES, [], {
236
+ positionalParams: [],
237
+ restParam: Effect.ConditionallyMutate,
238
+ returnType: PRIMITIVE_TYPE,
239
+ calleeEffect: Effect.Read,
240
+ returnValueKind: ValueKind.Immutable,
241
+ }),
242
+ ],
243
// TODO: rest of Array properties
244
]);
245
compiler/forget/src/__tests__/fixtures/compiler/array-join.expect.md
new
+68
@@ -0,0 +1,68 @@
1
+
2
+## Input
3
+
4
+```javascript
5
+function Component(props) {
6
+ const x = [{}, [], props.value];
7
+ const y = x.join(() => "this closure gets stringified, not called");
8
+ foo(y);
9
+ return [x, y];
10
+}
11
+
12
+```
13
+
14
+## Code
15
+
16
+```javascript
17
+import { unstable_useMemoCache as useMemoCache } from "react";
18
+function Component(props) {
19
+ const $ = useMemoCache(8);
20
+ let t0;
21
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
22
+ t0 = {};
23
+ $[0] = t0;
24
+ } else {
25
+ t0 = $[0];
26
+ }
27
+ let t1;
28
+ if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
29
+ t1 = [];
30
+ $[1] = t1;
31
+ } else {
32
+ t1 = $[1];
33
+ }
34
+ const c_2 = $[2] !== props.value;
35
+ let t2;
36
+ if (c_2) {
37
+ t2 = [t0, t1, props.value];
38
+ $[2] = props.value;
39
+ $[3] = t2;
40
+ } else {
41
+ t2 = $[3];
42
+ }
43
+ const x = t2;
44
+ let t3;
45
+ if ($[4] === Symbol.for("react.memo_cache_sentinel")) {
46
+ t3 = () => "this closure gets stringified, not called";
47
+ $[4] = t3;
48
+ } else {
49
+ t3 = $[4];
50
+ }
51
+ const y = x.join(t3);
52
+ foo(y);
53
+ const c_5 = $[5] !== x;
54
+ const c_6 = $[6] !== y;
55
+ let t4;
56
+ if (c_5 || c_6) {
57
+ t4 = [x, y];
58
+ $[5] = x;
59
+ $[6] = y;
60
+ $[7] = t4;
61
+ } else {
62
+ t4 = $[7];
63
+ }
64
+ return t4;
65
+}
66
+
67
+```
68
+
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/compiler/array-join.js
new
+6
@@ -0,0 +1,6 @@
1
+function Component(props) {
2
+ const x = [{}, [], props.value];
3
+ const y = x.join(() => "this closure gets stringified, not called");
4
+ foo(y);
5
+ return [x, y];
6
+}