rwsdk 0.1.17 → 0.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/dist/lib/compileTsModule.d.mts +0 -1
- package/dist/lib/compileTsModule.mjs +0 -27
- package/dist/runtime/entries/navigation.d.ts +0 -1
- package/dist/runtime/entries/navigation.js +0 -1
- package/dist/runtime/lib/db/typeInference/builders/table.d.ts +0 -10
- package/dist/runtime/lib/db/typeInference/builders/table.js +0 -1
- package/dist/runtime/render/injectRSCPayload.d.ts +0 -3
- package/dist/runtime/render/injectRSCPayload.js +0 -79
- package/dist/scripts/build-vendor-bundles.d.mts +0 -1
- package/dist/scripts/build-vendor-bundles.mjs +0 -92
- package/dist/vite/aliasByEnvPlugin.d.mts +0 -2
- package/dist/vite/aliasByEnvPlugin.mjs +0 -11
- package/dist/vite/asyncSetupPlugin.d.mts +0 -6
- package/dist/vite/asyncSetupPlugin.mjs +0 -23
- package/dist/vite/copyPrismaWasmPlugin.d.mts +0 -4
- package/dist/vite/copyPrismaWasmPlugin.mjs +0 -32
- package/dist/vite/customReactBuildPlugin.d.mts +0 -4
- package/dist/vite/customReactBuildPlugin.mjs +0 -61
- package/dist/vite/injectHmrPreambleJsxPlugin.d.mts +0 -2
- package/dist/vite/injectHmrPreambleJsxPlugin.mjs +0 -22
- package/dist/vite/miniflarePlugin.d.mts +0 -9
- package/dist/vite/miniflarePlugin.mjs +0 -135
- package/dist/vite/requestUtils.d.mts +0 -6
- package/dist/vite/requestUtils.mjs +0 -35
- package/dist/vite/setupEnvFiles.d.mts +0 -4
- package/dist/vite/setupEnvFiles.mjs +0 -31
- package/dist/vite/useClientPlugin.d.mts +0 -8
- package/dist/vite/useClientPlugin.mjs +0 -295
- package/dist/vite/useClientPlugin.test.d.mts +0 -1
- package/dist/vite/useClientPlugin.test.mjs +0 -1204
- package/dist/worker/__ssr_bridge.js +0 -8947
- package/dist/worker/__ssr_bridge.js.map +0 -1
|
@@ -1,1204 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
import { transformUseClientCode } from "./useClientPlugin.mjs";
|
|
3
|
-
describe("transformUseClientCode", () => {
|
|
4
|
-
async function transform(code) {
|
|
5
|
-
const result = await transformUseClientCode(code, "/test/file.tsx");
|
|
6
|
-
return result?.code;
|
|
7
|
-
}
|
|
8
|
-
it("transforms arrow function component", async () => {
|
|
9
|
-
expect(await transform(`"use client"
|
|
10
|
-
|
|
11
|
-
export const Component = () => {
|
|
12
|
-
return jsx('div', { children: 'Hello' });
|
|
13
|
-
}`)).toMatchInlineSnapshot(`
|
|
14
|
-
"import { registerClientReference } from "rwsdk/worker";
|
|
15
|
-
const ComponentSSR = () => {
|
|
16
|
-
return jsx('div', { children: 'Hello' });
|
|
17
|
-
}
|
|
18
|
-
const Component = registerClientReference("/test/file.tsx", "Component", ComponentSSR);
|
|
19
|
-
export { ComponentSSR, Component };"
|
|
20
|
-
`);
|
|
21
|
-
});
|
|
22
|
-
it("does nothing for irrelevant exports", async () => {
|
|
23
|
-
expect(await transform(`"use client"
|
|
24
|
-
|
|
25
|
-
export const foo = "bar"
|
|
26
|
-
export const baz = 23
|
|
27
|
-
}`)).toMatchInlineSnapshot(`
|
|
28
|
-
"import { registerClientReference } from "rwsdk/worker";
|
|
29
|
-
export const foo = "bar"
|
|
30
|
-
export const baz = 23
|
|
31
|
-
}"
|
|
32
|
-
`);
|
|
33
|
-
});
|
|
34
|
-
it("transforms async arrow function component", async () => {
|
|
35
|
-
expect(await transform(`"use client"
|
|
36
|
-
|
|
37
|
-
export const Component = async () => {
|
|
38
|
-
return jsx('div', { children: 'Hello' });
|
|
39
|
-
}`)).toMatchInlineSnapshot(`
|
|
40
|
-
"import { registerClientReference } from "rwsdk/worker";
|
|
41
|
-
const ComponentSSR = async () => {
|
|
42
|
-
return jsx('div', { children: 'Hello' });
|
|
43
|
-
}
|
|
44
|
-
const Component = registerClientReference("/test/file.tsx", "Component", ComponentSSR);
|
|
45
|
-
export { ComponentSSR, Component };"
|
|
46
|
-
`);
|
|
47
|
-
});
|
|
48
|
-
it("transforms function declaration component", async () => {
|
|
49
|
-
expect(await transform(`"use client"
|
|
50
|
-
|
|
51
|
-
export function Component() {
|
|
52
|
-
return jsx('div', { children: 'Hello' });
|
|
53
|
-
}`)).toMatchInlineSnapshot(`
|
|
54
|
-
"import { registerClientReference } from "rwsdk/worker";
|
|
55
|
-
|
|
56
|
-
function ComponentSSR() {
|
|
57
|
-
return jsx('div', { children: 'Hello' });
|
|
58
|
-
}
|
|
59
|
-
const Component = registerClientReference("/test/file.tsx", "Component", ComponentSSR);
|
|
60
|
-
export { ComponentSSR, Component };"
|
|
61
|
-
`);
|
|
62
|
-
});
|
|
63
|
-
it("transforms async function declaration component", async () => {
|
|
64
|
-
expect(await transform(`"use client"
|
|
65
|
-
|
|
66
|
-
export async function Component() {
|
|
67
|
-
return jsx('div', { children: 'Hello' });
|
|
68
|
-
}`)).toMatchInlineSnapshot(`
|
|
69
|
-
"import { registerClientReference } from "rwsdk/worker";
|
|
70
|
-
|
|
71
|
-
async function ComponentSSR() {
|
|
72
|
-
return jsx('div', { children: 'Hello' });
|
|
73
|
-
}
|
|
74
|
-
const Component = registerClientReference("/test/file.tsx", "Component", ComponentSSR);
|
|
75
|
-
export { ComponentSSR, Component };"
|
|
76
|
-
`);
|
|
77
|
-
});
|
|
78
|
-
it("transforms multiple arrow function components", async () => {
|
|
79
|
-
expect(await transform(`"use client"
|
|
80
|
-
|
|
81
|
-
export const First = () => {
|
|
82
|
-
return jsx('div', { children: 'First' });
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export const Second = () => {
|
|
86
|
-
return jsx('div', { children: 'Second' });
|
|
87
|
-
}`)).toMatchInlineSnapshot(`
|
|
88
|
-
"import { registerClientReference } from "rwsdk/worker";
|
|
89
|
-
const FirstSSR = () => {
|
|
90
|
-
return jsx('div', { children: 'First' });
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const SecondSSR = () => {
|
|
94
|
-
return jsx('div', { children: 'Second' });
|
|
95
|
-
}
|
|
96
|
-
const First = registerClientReference("/test/file.tsx", "First", FirstSSR);
|
|
97
|
-
const Second = registerClientReference("/test/file.tsx", "Second", SecondSSR);
|
|
98
|
-
export { FirstSSR, First };
|
|
99
|
-
export { SecondSSR, Second };"
|
|
100
|
-
`);
|
|
101
|
-
});
|
|
102
|
-
it("transforms multiple async arrow function components", async () => {
|
|
103
|
-
expect(await transform(`"use client"
|
|
104
|
-
|
|
105
|
-
export const First = async () => {
|
|
106
|
-
return jsx('div', { children: 'First' });
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export const Second = async () => {
|
|
110
|
-
return jsx('div', { children: 'Second' });
|
|
111
|
-
}`)).toMatchInlineSnapshot(`
|
|
112
|
-
"import { registerClientReference } from "rwsdk/worker";
|
|
113
|
-
const FirstSSR = async () => {
|
|
114
|
-
return jsx('div', { children: 'First' });
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const SecondSSR = async () => {
|
|
118
|
-
return jsx('div', { children: 'Second' });
|
|
119
|
-
}
|
|
120
|
-
const First = registerClientReference("/test/file.tsx", "First", FirstSSR);
|
|
121
|
-
const Second = registerClientReference("/test/file.tsx", "Second", SecondSSR);
|
|
122
|
-
export { FirstSSR, First };
|
|
123
|
-
export { SecondSSR, Second };"
|
|
124
|
-
`);
|
|
125
|
-
});
|
|
126
|
-
it("transforms multiple function declaration components", async () => {
|
|
127
|
-
expect(await transform(`"use client"
|
|
128
|
-
|
|
129
|
-
export function First() {
|
|
130
|
-
return jsx('div', { children: 'First' });
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
export function Second() {
|
|
134
|
-
return jsx('div', { children: 'Second' });
|
|
135
|
-
}`)).toMatchInlineSnapshot(`
|
|
136
|
-
"import { registerClientReference } from "rwsdk/worker";
|
|
137
|
-
|
|
138
|
-
function FirstSSR() {
|
|
139
|
-
return jsx('div', { children: 'First' });
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
function SecondSSR() {
|
|
143
|
-
return jsx('div', { children: 'Second' });
|
|
144
|
-
}
|
|
145
|
-
const First = registerClientReference("/test/file.tsx", "First", FirstSSR);
|
|
146
|
-
const Second = registerClientReference("/test/file.tsx", "Second", SecondSSR);
|
|
147
|
-
export { FirstSSR, First };
|
|
148
|
-
export { SecondSSR, Second };"
|
|
149
|
-
`);
|
|
150
|
-
});
|
|
151
|
-
it("transforms multiple async function declaration components", async () => {
|
|
152
|
-
expect(await transform(`"use client"
|
|
153
|
-
|
|
154
|
-
export async function First() {
|
|
155
|
-
return jsx('div', { children: 'First' });
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
export async function Second() {
|
|
159
|
-
return jsx('div', { children: 'Second' });
|
|
160
|
-
}`)).toMatchInlineSnapshot(`
|
|
161
|
-
"import { registerClientReference } from "rwsdk/worker";
|
|
162
|
-
|
|
163
|
-
async function FirstSSR() {
|
|
164
|
-
return jsx('div', { children: 'First' });
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
async function SecondSSR() {
|
|
168
|
-
return jsx('div', { children: 'Second' });
|
|
169
|
-
}
|
|
170
|
-
const First = registerClientReference("/test/file.tsx", "First", FirstSSR);
|
|
171
|
-
const Second = registerClientReference("/test/file.tsx", "Second", SecondSSR);
|
|
172
|
-
export { FirstSSR, First };
|
|
173
|
-
export { SecondSSR, Second };"
|
|
174
|
-
`);
|
|
175
|
-
});
|
|
176
|
-
it("transforms components with grouped exports (arrow functions)", async () => {
|
|
177
|
-
expect(await transform(`"use client"
|
|
178
|
-
|
|
179
|
-
const First = () => {
|
|
180
|
-
return jsx('div', { children: 'First' });
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
const Second = () => {
|
|
184
|
-
return jsx('div', { children: 'Second' });
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
export { First, Second }`)).toMatchInlineSnapshot(`
|
|
188
|
-
"import { registerClientReference } from "rwsdk/worker";
|
|
189
|
-
const FirstSSR = () => {
|
|
190
|
-
return jsx('div', { children: 'First' });
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
const SecondSSR = () => {
|
|
194
|
-
return jsx('div', { children: 'Second' });
|
|
195
|
-
}
|
|
196
|
-
const First = registerClientReference("/test/file.tsx", "First", FirstSSR);
|
|
197
|
-
const Second = registerClientReference("/test/file.tsx", "Second", SecondSSR);
|
|
198
|
-
export { FirstSSR, First };
|
|
199
|
-
export { SecondSSR, Second };"
|
|
200
|
-
`);
|
|
201
|
-
});
|
|
202
|
-
it("transforms complex grouped export cases", async () => {
|
|
203
|
-
expect(await transform(`
|
|
204
|
-
"use client";
|
|
205
|
-
|
|
206
|
-
import * as React from "react"
|
|
207
|
-
import { Slot } from "@radix-ui/react-slot"
|
|
208
|
-
import { cva, type VariantProps } from "class-variance-authority"
|
|
209
|
-
import { jsx, jsxs } from "react/jsx-runtime"
|
|
210
|
-
|
|
211
|
-
import { cn } from "@/lib/utils"
|
|
212
|
-
|
|
213
|
-
const buttonVariants = cva(
|
|
214
|
-
"font-bold inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
|
|
215
|
-
{
|
|
216
|
-
variants: {
|
|
217
|
-
variant: {
|
|
218
|
-
default:
|
|
219
|
-
"bg-primary text-primary-foreground shadow-xs hover:bg-primary/90",
|
|
220
|
-
destructive:
|
|
221
|
-
"bg-destructive text-white shadow-xs hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
|
|
222
|
-
outline:
|
|
223
|
-
"border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",
|
|
224
|
-
secondary:
|
|
225
|
-
"bg-secondary text-secondary-foreground shadow-xs hover:bg-secondary/80",
|
|
226
|
-
ghost:
|
|
227
|
-
"hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
|
|
228
|
-
link: "text-primary underline-offset-4 hover:underline",
|
|
229
|
-
},
|
|
230
|
-
size: {
|
|
231
|
-
default: "h-9 px-4 py-2 has-[>svg]:px-3",
|
|
232
|
-
sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
|
|
233
|
-
lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
|
|
234
|
-
icon: "size-9",
|
|
235
|
-
},
|
|
236
|
-
},
|
|
237
|
-
defaultVariants: {
|
|
238
|
-
variant: "default",
|
|
239
|
-
size: "default",
|
|
240
|
-
},
|
|
241
|
-
}
|
|
242
|
-
)
|
|
243
|
-
|
|
244
|
-
function Button({
|
|
245
|
-
className,
|
|
246
|
-
variant,
|
|
247
|
-
size,
|
|
248
|
-
asChild = false,
|
|
249
|
-
...props
|
|
250
|
-
}: React.ComponentProps<"button"> &
|
|
251
|
-
VariantProps<typeof buttonVariants> & {
|
|
252
|
-
asChild?: boolean
|
|
253
|
-
}) {
|
|
254
|
-
const Comp = asChild ? Slot : "button"
|
|
255
|
-
|
|
256
|
-
return jsx(
|
|
257
|
-
Comp,
|
|
258
|
-
{
|
|
259
|
-
"data-slot": "button",
|
|
260
|
-
className: cn(buttonVariants({ variant, size, className })),
|
|
261
|
-
...props
|
|
262
|
-
}
|
|
263
|
-
)
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
export { Button, buttonVariants }
|
|
267
|
-
`)).toMatchInlineSnapshot(`
|
|
268
|
-
"
|
|
269
|
-
import * as React from "react"
|
|
270
|
-
import { Slot } from "@radix-ui/react-slot"
|
|
271
|
-
import { cva, type VariantProps } from "class-variance-authority"
|
|
272
|
-
import { jsx, jsxs } from "react/jsx-runtime"
|
|
273
|
-
|
|
274
|
-
import { cn } from "@/lib/utils"
|
|
275
|
-
import { registerClientReference } from "rwsdk/worker";
|
|
276
|
-
|
|
277
|
-
const buttonVariants = cva(
|
|
278
|
-
"font-bold inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
|
|
279
|
-
{
|
|
280
|
-
variants: {
|
|
281
|
-
variant: {
|
|
282
|
-
default:
|
|
283
|
-
"bg-primary text-primary-foreground shadow-xs hover:bg-primary/90",
|
|
284
|
-
destructive:
|
|
285
|
-
"bg-destructive text-white shadow-xs hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
|
|
286
|
-
outline:
|
|
287
|
-
"border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",
|
|
288
|
-
secondary:
|
|
289
|
-
"bg-secondary text-secondary-foreground shadow-xs hover:bg-secondary/80",
|
|
290
|
-
ghost:
|
|
291
|
-
"hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
|
|
292
|
-
link: "text-primary underline-offset-4 hover:underline",
|
|
293
|
-
},
|
|
294
|
-
size: {
|
|
295
|
-
default: "h-9 px-4 py-2 has-[>svg]:px-3",
|
|
296
|
-
sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
|
|
297
|
-
lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
|
|
298
|
-
icon: "size-9",
|
|
299
|
-
},
|
|
300
|
-
},
|
|
301
|
-
defaultVariants: {
|
|
302
|
-
variant: "default",
|
|
303
|
-
size: "default",
|
|
304
|
-
},
|
|
305
|
-
}
|
|
306
|
-
)
|
|
307
|
-
|
|
308
|
-
function ButtonSSR({
|
|
309
|
-
className,
|
|
310
|
-
variant,
|
|
311
|
-
size,
|
|
312
|
-
asChild = false,
|
|
313
|
-
...props
|
|
314
|
-
}: React.ComponentProps<"button"> &
|
|
315
|
-
VariantProps<typeof buttonVariants> & {
|
|
316
|
-
asChild?: boolean
|
|
317
|
-
}) {
|
|
318
|
-
const Comp = asChild ? Slot : "button"
|
|
319
|
-
|
|
320
|
-
return jsx(
|
|
321
|
-
Comp,
|
|
322
|
-
{
|
|
323
|
-
"data-slot": "button",
|
|
324
|
-
className: cn(buttonVariants({ variant, size, className })),
|
|
325
|
-
...props
|
|
326
|
-
}
|
|
327
|
-
)
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
export { buttonVariants };
|
|
331
|
-
const Button = registerClientReference("/test/file.tsx", "Button", ButtonSSR);
|
|
332
|
-
export { ButtonSSR, Button };
|
|
333
|
-
"
|
|
334
|
-
`);
|
|
335
|
-
});
|
|
336
|
-
it("transforms components with grouped exports (async arrow functions)", async () => {
|
|
337
|
-
expect(await transform(`"use client"
|
|
338
|
-
|
|
339
|
-
const First = async () => {
|
|
340
|
-
return jsx('div', { children: 'First' });
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
const Second = async () => {
|
|
344
|
-
return jsx('div', { children: 'Second' });
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
export { First, Second }`)).toMatchInlineSnapshot(`
|
|
348
|
-
"import { registerClientReference } from "rwsdk/worker";
|
|
349
|
-
const FirstSSR = async () => {
|
|
350
|
-
return jsx('div', { children: 'First' });
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
const SecondSSR = async () => {
|
|
354
|
-
return jsx('div', { children: 'Second' });
|
|
355
|
-
}
|
|
356
|
-
const First = registerClientReference("/test/file.tsx", "First", FirstSSR);
|
|
357
|
-
const Second = registerClientReference("/test/file.tsx", "Second", SecondSSR);
|
|
358
|
-
export { FirstSSR, First };
|
|
359
|
-
export { SecondSSR, Second };"
|
|
360
|
-
`);
|
|
361
|
-
});
|
|
362
|
-
it("transforms components with grouped exports (function declarations)", async () => {
|
|
363
|
-
expect(await transform(`"use client"
|
|
364
|
-
|
|
365
|
-
function First() {
|
|
366
|
-
return jsx('div', { children: 'First' });
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
function Second() {
|
|
370
|
-
return jsx('div', { children: 'Second' });
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
export { First, Second }`)).toMatchInlineSnapshot(`
|
|
374
|
-
"import { registerClientReference } from "rwsdk/worker";
|
|
375
|
-
|
|
376
|
-
function FirstSSR() {
|
|
377
|
-
return jsx('div', { children: 'First' });
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
function SecondSSR() {
|
|
381
|
-
return jsx('div', { children: 'Second' });
|
|
382
|
-
}
|
|
383
|
-
const First = registerClientReference("/test/file.tsx", "First", FirstSSR);
|
|
384
|
-
const Second = registerClientReference("/test/file.tsx", "Second", SecondSSR);
|
|
385
|
-
export { FirstSSR, First };
|
|
386
|
-
export { SecondSSR, Second };"
|
|
387
|
-
`);
|
|
388
|
-
});
|
|
389
|
-
it("transforms components with grouped exports (async function declarations)", async () => {
|
|
390
|
-
expect(await transform(`"use client"
|
|
391
|
-
|
|
392
|
-
async function First() {
|
|
393
|
-
return jsx('div', { children: 'First' });
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
async function Second() {
|
|
397
|
-
return jsx('div', { children: 'Second' });
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
export { First, Second }`)).toMatchInlineSnapshot(`
|
|
401
|
-
"import { registerClientReference } from "rwsdk/worker";
|
|
402
|
-
|
|
403
|
-
async function FirstSSR() {
|
|
404
|
-
return jsx('div', { children: 'First' });
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
async function SecondSSR() {
|
|
408
|
-
return jsx('div', { children: 'Second' });
|
|
409
|
-
}
|
|
410
|
-
const First = registerClientReference("/test/file.tsx", "First", FirstSSR);
|
|
411
|
-
const Second = registerClientReference("/test/file.tsx", "Second", SecondSSR);
|
|
412
|
-
export { FirstSSR, First };
|
|
413
|
-
export { SecondSSR, Second };"
|
|
414
|
-
`);
|
|
415
|
-
});
|
|
416
|
-
it("transforms default export arrow function component", async () => {
|
|
417
|
-
expect(await transform(`"use client"
|
|
418
|
-
|
|
419
|
-
export default () => {
|
|
420
|
-
return jsx('div', { children: 'Hello' });
|
|
421
|
-
}`)).toMatchInlineSnapshot(`
|
|
422
|
-
"import { registerClientReference } from "rwsdk/worker";
|
|
423
|
-
const DefaultComponent0SSR = () => {
|
|
424
|
-
return jsx('div', { children: 'Hello' });
|
|
425
|
-
}
|
|
426
|
-
const DefaultComponent0 = registerClientReference("/test/file.tsx", "default", DefaultComponent0SSR);
|
|
427
|
-
export { DefaultComponent0 as default, DefaultComponent0SSR };"
|
|
428
|
-
`);
|
|
429
|
-
});
|
|
430
|
-
it("transforms default export async arrow function component", async () => {
|
|
431
|
-
expect(await transform(`"use client"
|
|
432
|
-
|
|
433
|
-
export default async () => {
|
|
434
|
-
return jsx('div', { children: 'Hello' });
|
|
435
|
-
}`)).toMatchInlineSnapshot(`
|
|
436
|
-
"import { registerClientReference } from "rwsdk/worker";
|
|
437
|
-
const DefaultComponent0SSR = async () => {
|
|
438
|
-
return jsx('div', { children: 'Hello' });
|
|
439
|
-
}
|
|
440
|
-
const DefaultComponent0 = registerClientReference("/test/file.tsx", "default", DefaultComponent0SSR);
|
|
441
|
-
export { DefaultComponent0 as default, DefaultComponent0SSR };"
|
|
442
|
-
`);
|
|
443
|
-
});
|
|
444
|
-
it("transforms complex default export cases", async () => {
|
|
445
|
-
expect(await transform(`
|
|
446
|
-
"use client";
|
|
447
|
-
import { jsxDEV } from "react/jsx-dev-runtime";
|
|
448
|
-
import { useState, useEffect, useRef } from "react";
|
|
449
|
-
import { ChevronDownIcon, CheckIcon } from "./icons";
|
|
450
|
-
export const MovieSelector = ({
|
|
451
|
-
label,
|
|
452
|
-
selectedMovie,
|
|
453
|
-
onSelect,
|
|
454
|
-
otherSelectedMovie,
|
|
455
|
-
movies,
|
|
456
|
-
error
|
|
457
|
-
}) => {
|
|
458
|
-
const [isOpen, setIsOpen] = useState(false);
|
|
459
|
-
const dropdownRef = useRef(null);
|
|
460
|
-
useEffect(() => {
|
|
461
|
-
const handleClickOutside = (event) => {
|
|
462
|
-
if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
|
|
463
|
-
setIsOpen(false);
|
|
464
|
-
}
|
|
465
|
-
};
|
|
466
|
-
document.addEventListener("mousedown", handleClickOutside);
|
|
467
|
-
return () => {
|
|
468
|
-
document.removeEventListener("mousedown", handleClickOutside);
|
|
469
|
-
};
|
|
470
|
-
}, []);
|
|
471
|
-
const selectedMovieObj = movies.find((movie) => movie.id === selectedMovie);
|
|
472
|
-
const availableMovies = movies.filter(
|
|
473
|
-
(movie) => !otherSelectedMovie || movie.id !== otherSelectedMovie
|
|
474
|
-
);
|
|
475
|
-
return /* @__PURE__ */ jsxDEV("div", { className: "relative", ref: dropdownRef, children: [
|
|
476
|
-
/* @__PURE__ */ jsxDEV("label", { className: "font-banner block text-sm font-medium text-gray-700 mb-1", children: label === "First Movie" ? "Mash ..." : "With ..." }, void 0, false, {
|
|
477
|
-
fileName: "/Users/justin/rw/blotter/ai-movie-mashup/src/app/pages/mashups/components/MovieSelector.tsx",
|
|
478
|
-
lineNumber: 49,
|
|
479
|
-
columnNumber: 7
|
|
480
|
-
}, this),
|
|
481
|
-
/* @__PURE__ */ jsxDEV(
|
|
482
|
-
"button",
|
|
483
|
-
{
|
|
484
|
-
type: "button",
|
|
485
|
-
className: "w-full p-2 border border-gray-300 rounded-md bg-white text-left flex items-center justify-between disabled:opacity-50 disabled:cursor-not-allowed",
|
|
486
|
-
onClick: () => setIsOpen(!isOpen),
|
|
487
|
-
disabled: !!error,
|
|
488
|
-
children: [
|
|
489
|
-
error ? /* @__PURE__ */ jsxDEV("span", { className: "text-red-500", children: "Error loading movies" }, void 0, false, {
|
|
490
|
-
fileName: "/Users/justin/rw/blotter/ai-movie-mashup/src/app/pages/mashups/components/MovieSelector.tsx",
|
|
491
|
-
lineNumber: 59,
|
|
492
|
-
columnNumber: 11
|
|
493
|
-
}, this) : selectedMovieObj ? /* @__PURE__ */ jsxDEV("div", { className: "flex items-center", children: [
|
|
494
|
-
/* @__PURE__ */ jsxDEV(
|
|
495
|
-
"img",
|
|
496
|
-
{
|
|
497
|
-
src: \`https://image.tmdb.org/t/p/w500/\${selectedMovieObj.photo}\`,
|
|
498
|
-
alt: selectedMovieObj.title,
|
|
499
|
-
className: "size-6 shrink-0 rounded-sm mr-2"
|
|
500
|
-
},
|
|
501
|
-
void 0,
|
|
502
|
-
false,
|
|
503
|
-
{
|
|
504
|
-
fileName: "/Users/justin/rw/blotter/ai-movie-mashup/src/app/pages/mashups/components/MovieSelector.tsx",
|
|
505
|
-
lineNumber: 62,
|
|
506
|
-
columnNumber: 13
|
|
507
|
-
},
|
|
508
|
-
this
|
|
509
|
-
),
|
|
510
|
-
/* @__PURE__ */ jsxDEV("span", { children: selectedMovieObj.title }, void 0, false, {
|
|
511
|
-
fileName: "/Users/justin/rw/blotter/ai-movie-mashup/src/app/pages/mashups/components/MovieSelector.tsx",
|
|
512
|
-
lineNumber: 67,
|
|
513
|
-
columnNumber: 13
|
|
514
|
-
}, this)
|
|
515
|
-
] }, void 0, true, {
|
|
516
|
-
fileName: "/Users/justin/rw/blotter/ai-movie-mashup/src/app/pages/mashups/components/MovieSelector.tsx",
|
|
517
|
-
lineNumber: 61,
|
|
518
|
-
columnNumber: 11
|
|
519
|
-
}, this) : /* @__PURE__ */ jsxDEV("span", { className: "text-gray-500", children: label }, void 0, false, {
|
|
520
|
-
fileName: "/Users/justin/rw/blotter/ai-movie-mashup/src/app/pages/mashups/components/MovieSelector.tsx",
|
|
521
|
-
lineNumber: 70,
|
|
522
|
-
columnNumber: 11
|
|
523
|
-
}, this),
|
|
524
|
-
/* @__PURE__ */ jsxDEV(ChevronDownIcon, { isOpen }, void 0, false, {
|
|
525
|
-
fileName: "/Users/justin/rw/blotter/ai-movie-mashup/src/app/pages/mashups/components/MovieSelector.tsx",
|
|
526
|
-
lineNumber: 72,
|
|
527
|
-
columnNumber: 9
|
|
528
|
-
}, this)
|
|
529
|
-
]
|
|
530
|
-
},
|
|
531
|
-
void 0,
|
|
532
|
-
true,
|
|
533
|
-
{
|
|
534
|
-
fileName: "/Users/justin/rw/blotter/ai-movie-mashup/src/app/pages/mashups/components/MovieSelector.tsx",
|
|
535
|
-
lineNumber: 52,
|
|
536
|
-
columnNumber: 7
|
|
537
|
-
},
|
|
538
|
-
this
|
|
539
|
-
),
|
|
540
|
-
isOpen && !error && /* @__PURE__ */ jsxDEV("div", { className: "absolute z-10 mt-1 w-full bg-white shadow-lg max-h-60 rounded-md py-1 text-base overflow-auto focus:outline-none sm:text-sm", children: availableMovies.map((movie) => /* @__PURE__ */ jsxDEV(
|
|
541
|
-
"div",
|
|
542
|
-
{
|
|
543
|
-
className: "cursor-pointer select-none relative py-2 pl-3 pr-9 hover:bg-purple-50",
|
|
544
|
-
onClick: () => {
|
|
545
|
-
onSelect(movie.id);
|
|
546
|
-
setIsOpen(false);
|
|
547
|
-
},
|
|
548
|
-
children: [
|
|
549
|
-
/* @__PURE__ */ jsxDEV("div", { className: "flex items-center", children: [
|
|
550
|
-
/* @__PURE__ */ jsxDEV(
|
|
551
|
-
"img",
|
|
552
|
-
{
|
|
553
|
-
src: \`https://image.tmdb.org/t/p/w500/\${movie.photo}\`,
|
|
554
|
-
alt: movie.title,
|
|
555
|
-
className: "size-10 shrink-0 rounded-sm mr-2"
|
|
556
|
-
},
|
|
557
|
-
void 0,
|
|
558
|
-
false,
|
|
559
|
-
{
|
|
560
|
-
fileName: "/Users/justin/rw/blotter/ai-movie-mashup/src/app/pages/mashups/components/MovieSelector.tsx",
|
|
561
|
-
lineNumber: 87,
|
|
562
|
-
columnNumber: 17
|
|
563
|
-
},
|
|
564
|
-
this
|
|
565
|
-
),
|
|
566
|
-
/* @__PURE__ */ jsxDEV("span", { className: "block truncate text-base font-medium", children: movie.title }, void 0, false, {
|
|
567
|
-
fileName: "/Users/justin/rw/blotter/ai-movie-mashup/src/app/pages/mashups/components/MovieSelector.tsx",
|
|
568
|
-
lineNumber: 92,
|
|
569
|
-
columnNumber: 17
|
|
570
|
-
}, this)
|
|
571
|
-
] }, void 0, true, {
|
|
572
|
-
fileName: "/Users/justin/rw/blotter/ai-movie-mashup/src/app/pages/mashups/components/MovieSelector.tsx",
|
|
573
|
-
lineNumber: 86,
|
|
574
|
-
columnNumber: 15
|
|
575
|
-
}, this),
|
|
576
|
-
selectedMovie === movie.id && /* @__PURE__ */ jsxDEV("span", { className: "absolute inset-y-0 right-0 flex items-center pr-4 text-purple-600", children: /* @__PURE__ */ jsxDEV(CheckIcon, {}, void 0, false, {
|
|
577
|
-
fileName: "/Users/justin/rw/blotter/ai-movie-mashup/src/app/pages/mashups/components/MovieSelector.tsx",
|
|
578
|
-
lineNumber: 99,
|
|
579
|
-
columnNumber: 19
|
|
580
|
-
}, this) }, void 0, false, {
|
|
581
|
-
fileName: "/Users/justin/rw/blotter/ai-movie-mashup/src/app/pages/mashups/components/MovieSelector.tsx",
|
|
582
|
-
lineNumber: 98,
|
|
583
|
-
columnNumber: 17
|
|
584
|
-
}, this)
|
|
585
|
-
]
|
|
586
|
-
},
|
|
587
|
-
movie.id,
|
|
588
|
-
true,
|
|
589
|
-
{
|
|
590
|
-
fileName: "/Users/justin/rw/blotter/ai-movie-mashup/src/app/pages/mashups/components/MovieSelector.tsx",
|
|
591
|
-
lineNumber: 78,
|
|
592
|
-
columnNumber: 13
|
|
593
|
-
},
|
|
594
|
-
this
|
|
595
|
-
)) }, void 0, false, {
|
|
596
|
-
fileName: "/Users/justin/rw/blotter/ai-movie-mashup/src/app/pages/mashups/components/MovieSelector.tsx",
|
|
597
|
-
lineNumber: 76,
|
|
598
|
-
columnNumber: 9
|
|
599
|
-
}, this)
|
|
600
|
-
] }, void 0, true, {
|
|
601
|
-
fileName: "/Users/justin/rw/blotter/ai-movie-mashup/src/app/pages/mashups/components/MovieSelector.tsx",
|
|
602
|
-
lineNumber: 48,
|
|
603
|
-
columnNumber: 5
|
|
604
|
-
}, this);
|
|
605
|
-
};
|
|
606
|
-
|
|
607
|
-
`)).toMatchInlineSnapshot(`
|
|
608
|
-
"
|
|
609
|
-
import { jsxDEV } from "react/jsx-dev-runtime";
|
|
610
|
-
import { useState, useEffect, useRef } from "react";
|
|
611
|
-
import { ChevronDownIcon, CheckIcon } from "./icons";
|
|
612
|
-
import { registerClientReference } from "rwsdk/worker";
|
|
613
|
-
|
|
614
|
-
const MovieSelectorSSR = ({
|
|
615
|
-
label,
|
|
616
|
-
selectedMovie,
|
|
617
|
-
onSelect,
|
|
618
|
-
otherSelectedMovie,
|
|
619
|
-
movies,
|
|
620
|
-
error
|
|
621
|
-
}) => {
|
|
622
|
-
const [isOpen, setIsOpen] = useState(false);
|
|
623
|
-
const dropdownRef = useRef(null);
|
|
624
|
-
useEffect(() => {
|
|
625
|
-
const handleClickOutside = (event) => {
|
|
626
|
-
if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
|
|
627
|
-
setIsOpen(false);
|
|
628
|
-
}
|
|
629
|
-
};
|
|
630
|
-
document.addEventListener("mousedown", handleClickOutside);
|
|
631
|
-
return () => {
|
|
632
|
-
document.removeEventListener("mousedown", handleClickOutside);
|
|
633
|
-
};
|
|
634
|
-
}, []);
|
|
635
|
-
const selectedMovieObj = movies.find((movie) => movie.id === selectedMovie);
|
|
636
|
-
const availableMovies = movies.filter(
|
|
637
|
-
(movie) => !otherSelectedMovie || movie.id !== otherSelectedMovie
|
|
638
|
-
);
|
|
639
|
-
return /* @__PURE__ */ jsxDEV("div", { className: "relative", ref: dropdownRef, children: [
|
|
640
|
-
/* @__PURE__ */ jsxDEV("label", { className: "font-banner block text-sm font-medium text-gray-700 mb-1", children: label === "First Movie" ? "Mash ..." : "With ..." }, void 0, false, {
|
|
641
|
-
fileName: "/Users/justin/rw/blotter/ai-movie-mashup/src/app/pages/mashups/components/MovieSelector.tsx",
|
|
642
|
-
lineNumber: 49,
|
|
643
|
-
columnNumber: 7
|
|
644
|
-
}, this),
|
|
645
|
-
/* @__PURE__ */ jsxDEV(
|
|
646
|
-
"button",
|
|
647
|
-
{
|
|
648
|
-
type: "button",
|
|
649
|
-
className: "w-full p-2 border border-gray-300 rounded-md bg-white text-left flex items-center justify-between disabled:opacity-50 disabled:cursor-not-allowed",
|
|
650
|
-
onClick: () => setIsOpen(!isOpen),
|
|
651
|
-
disabled: !!error,
|
|
652
|
-
children: [
|
|
653
|
-
error ? /* @__PURE__ */ jsxDEV("span", { className: "text-red-500", children: "Error loading movies" }, void 0, false, {
|
|
654
|
-
fileName: "/Users/justin/rw/blotter/ai-movie-mashup/src/app/pages/mashups/components/MovieSelector.tsx",
|
|
655
|
-
lineNumber: 59,
|
|
656
|
-
columnNumber: 11
|
|
657
|
-
}, this) : selectedMovieObj ? /* @__PURE__ */ jsxDEV("div", { className: "flex items-center", children: [
|
|
658
|
-
/* @__PURE__ */ jsxDEV(
|
|
659
|
-
"img",
|
|
660
|
-
{
|
|
661
|
-
src: \`https://image.tmdb.org/t/p/w500/\${selectedMovieObj.photo}\`,
|
|
662
|
-
alt: selectedMovieObj.title,
|
|
663
|
-
className: "size-6 shrink-0 rounded-sm mr-2"
|
|
664
|
-
},
|
|
665
|
-
void 0,
|
|
666
|
-
false,
|
|
667
|
-
{
|
|
668
|
-
fileName: "/Users/justin/rw/blotter/ai-movie-mashup/src/app/pages/mashups/components/MovieSelector.tsx",
|
|
669
|
-
lineNumber: 62,
|
|
670
|
-
columnNumber: 13
|
|
671
|
-
},
|
|
672
|
-
this
|
|
673
|
-
),
|
|
674
|
-
/* @__PURE__ */ jsxDEV("span", { children: selectedMovieObj.title }, void 0, false, {
|
|
675
|
-
fileName: "/Users/justin/rw/blotter/ai-movie-mashup/src/app/pages/mashups/components/MovieSelector.tsx",
|
|
676
|
-
lineNumber: 67,
|
|
677
|
-
columnNumber: 13
|
|
678
|
-
}, this)
|
|
679
|
-
] }, void 0, true, {
|
|
680
|
-
fileName: "/Users/justin/rw/blotter/ai-movie-mashup/src/app/pages/mashups/components/MovieSelector.tsx",
|
|
681
|
-
lineNumber: 61,
|
|
682
|
-
columnNumber: 11
|
|
683
|
-
}, this) : /* @__PURE__ */ jsxDEV("span", { className: "text-gray-500", children: label }, void 0, false, {
|
|
684
|
-
fileName: "/Users/justin/rw/blotter/ai-movie-mashup/src/app/pages/mashups/components/MovieSelector.tsx",
|
|
685
|
-
lineNumber: 70,
|
|
686
|
-
columnNumber: 11
|
|
687
|
-
}, this),
|
|
688
|
-
/* @__PURE__ */ jsxDEV(ChevronDownIcon, { isOpen }, void 0, false, {
|
|
689
|
-
fileName: "/Users/justin/rw/blotter/ai-movie-mashup/src/app/pages/mashups/components/MovieSelector.tsx",
|
|
690
|
-
lineNumber: 72,
|
|
691
|
-
columnNumber: 9
|
|
692
|
-
}, this)
|
|
693
|
-
]
|
|
694
|
-
},
|
|
695
|
-
void 0,
|
|
696
|
-
true,
|
|
697
|
-
{
|
|
698
|
-
fileName: "/Users/justin/rw/blotter/ai-movie-mashup/src/app/pages/mashups/components/MovieSelector.tsx",
|
|
699
|
-
lineNumber: 52,
|
|
700
|
-
columnNumber: 7
|
|
701
|
-
},
|
|
702
|
-
this
|
|
703
|
-
),
|
|
704
|
-
isOpen && !error && /* @__PURE__ */ jsxDEV("div", { className: "absolute z-10 mt-1 w-full bg-white shadow-lg max-h-60 rounded-md py-1 text-base overflow-auto focus:outline-none sm:text-sm", children: availableMovies.map((movie) => /* @__PURE__ */ jsxDEV(
|
|
705
|
-
"div",
|
|
706
|
-
{
|
|
707
|
-
className: "cursor-pointer select-none relative py-2 pl-3 pr-9 hover:bg-purple-50",
|
|
708
|
-
onClick: () => {
|
|
709
|
-
onSelect(movie.id);
|
|
710
|
-
setIsOpen(false);
|
|
711
|
-
},
|
|
712
|
-
children: [
|
|
713
|
-
/* @__PURE__ */ jsxDEV("div", { className: "flex items-center", children: [
|
|
714
|
-
/* @__PURE__ */ jsxDEV(
|
|
715
|
-
"img",
|
|
716
|
-
{
|
|
717
|
-
src: \`https://image.tmdb.org/t/p/w500/\${movie.photo}\`,
|
|
718
|
-
alt: movie.title,
|
|
719
|
-
className: "size-10 shrink-0 rounded-sm mr-2"
|
|
720
|
-
},
|
|
721
|
-
void 0,
|
|
722
|
-
false,
|
|
723
|
-
{
|
|
724
|
-
fileName: "/Users/justin/rw/blotter/ai-movie-mashup/src/app/pages/mashups/components/MovieSelector.tsx",
|
|
725
|
-
lineNumber: 87,
|
|
726
|
-
columnNumber: 17
|
|
727
|
-
},
|
|
728
|
-
this
|
|
729
|
-
),
|
|
730
|
-
/* @__PURE__ */ jsxDEV("span", { className: "block truncate text-base font-medium", children: movie.title }, void 0, false, {
|
|
731
|
-
fileName: "/Users/justin/rw/blotter/ai-movie-mashup/src/app/pages/mashups/components/MovieSelector.tsx",
|
|
732
|
-
lineNumber: 92,
|
|
733
|
-
columnNumber: 17
|
|
734
|
-
}, this)
|
|
735
|
-
] }, void 0, true, {
|
|
736
|
-
fileName: "/Users/justin/rw/blotter/ai-movie-mashup/src/app/pages/mashups/components/MovieSelector.tsx",
|
|
737
|
-
lineNumber: 86,
|
|
738
|
-
columnNumber: 15
|
|
739
|
-
}, this),
|
|
740
|
-
selectedMovie === movie.id && /* @__PURE__ */ jsxDEV("span", { className: "absolute inset-y-0 right-0 flex items-center pr-4 text-purple-600", children: /* @__PURE__ */ jsxDEV(CheckIcon, {}, void 0, false, {
|
|
741
|
-
fileName: "/Users/justin/rw/blotter/ai-movie-mashup/src/app/pages/mashups/components/MovieSelector.tsx",
|
|
742
|
-
lineNumber: 99,
|
|
743
|
-
columnNumber: 19
|
|
744
|
-
}, this) }, void 0, false, {
|
|
745
|
-
fileName: "/Users/justin/rw/blotter/ai-movie-mashup/src/app/pages/mashups/components/MovieSelector.tsx",
|
|
746
|
-
lineNumber: 98,
|
|
747
|
-
columnNumber: 17
|
|
748
|
-
}, this)
|
|
749
|
-
]
|
|
750
|
-
},
|
|
751
|
-
movie.id,
|
|
752
|
-
true,
|
|
753
|
-
{
|
|
754
|
-
fileName: "/Users/justin/rw/blotter/ai-movie-mashup/src/app/pages/mashups/components/MovieSelector.tsx",
|
|
755
|
-
lineNumber: 78,
|
|
756
|
-
columnNumber: 13
|
|
757
|
-
},
|
|
758
|
-
this
|
|
759
|
-
)) }, void 0, false, {
|
|
760
|
-
fileName: "/Users/justin/rw/blotter/ai-movie-mashup/src/app/pages/mashups/components/MovieSelector.tsx",
|
|
761
|
-
lineNumber: 76,
|
|
762
|
-
columnNumber: 9
|
|
763
|
-
}, this)
|
|
764
|
-
] }, void 0, true, {
|
|
765
|
-
fileName: "/Users/justin/rw/blotter/ai-movie-mashup/src/app/pages/mashups/components/MovieSelector.tsx",
|
|
766
|
-
lineNumber: 48,
|
|
767
|
-
columnNumber: 5
|
|
768
|
-
}, this);
|
|
769
|
-
};
|
|
770
|
-
const MovieSelector = registerClientReference("/test/file.tsx", "MovieSelector", MovieSelectorSSR);
|
|
771
|
-
export { MovieSelectorSSR, MovieSelector };
|
|
772
|
-
|
|
773
|
-
"
|
|
774
|
-
`);
|
|
775
|
-
});
|
|
776
|
-
it("transforms default export function declaration component", async () => {
|
|
777
|
-
expect(await transform(`"use client"
|
|
778
|
-
|
|
779
|
-
export default function Component({ prop1, prop2 }) {
|
|
780
|
-
return jsx('div', { children: 'Hello' });
|
|
781
|
-
}`)).toMatchInlineSnapshot(`
|
|
782
|
-
"import { registerClientReference } from "rwsdk/worker";
|
|
783
|
-
|
|
784
|
-
function ComponentSSR({ prop1, prop2 }) {
|
|
785
|
-
return jsx('div', { children: 'Hello' });
|
|
786
|
-
}
|
|
787
|
-
const Component = registerClientReference("/test/file.tsx", "default", ComponentSSR);
|
|
788
|
-
export { Component as default, ComponentSSR };"
|
|
789
|
-
`);
|
|
790
|
-
});
|
|
791
|
-
it("transforms default export async function declaration component", async () => {
|
|
792
|
-
expect(await transform(`"use client"
|
|
793
|
-
|
|
794
|
-
export default async function Component() {
|
|
795
|
-
return jsx('div', { children: 'Hello' });
|
|
796
|
-
}`)).toMatchInlineSnapshot(`
|
|
797
|
-
"import { registerClientReference } from "rwsdk/worker";
|
|
798
|
-
|
|
799
|
-
async function ComponentSSR() {
|
|
800
|
-
return jsx('div', { children: 'Hello' });
|
|
801
|
-
}
|
|
802
|
-
const Component = registerClientReference("/test/file.tsx", "default", ComponentSSR);
|
|
803
|
-
export { Component as default, ComponentSSR };"
|
|
804
|
-
`);
|
|
805
|
-
});
|
|
806
|
-
it("transforms complex component with multiple computations", async () => {
|
|
807
|
-
expect(await transform(`"use client"
|
|
808
|
-
|
|
809
|
-
export function ComplexComponent({ initialCount = 0 }) {
|
|
810
|
-
const [count, setCount] = useState(initialCount);
|
|
811
|
-
const [items, setItems] = useState([]);
|
|
812
|
-
const doubledCount = useMemo(() => count * 2, [count]);
|
|
813
|
-
|
|
814
|
-
useEffect(() => {
|
|
815
|
-
const timer = setInterval(() => {
|
|
816
|
-
setCount(c => c + 1);
|
|
817
|
-
}, 1000);
|
|
818
|
-
return () => clearInterval(timer);
|
|
819
|
-
}, []);
|
|
820
|
-
|
|
821
|
-
const handleAddItem = useCallback(() => {
|
|
822
|
-
const newItem = {
|
|
823
|
-
id: Math.random().toString(36),
|
|
824
|
-
value: Math.floor(Math.random() * 100)
|
|
825
|
-
};
|
|
826
|
-
setItems(prev => [...prev, newItem]);
|
|
827
|
-
}, []);
|
|
828
|
-
|
|
829
|
-
const filteredItems = items.filter(item => item.value > 50);
|
|
830
|
-
const total = filteredItems.reduce((sum, item) => sum + item.value, 0);
|
|
831
|
-
|
|
832
|
-
if (items.length === 0) {
|
|
833
|
-
return jsx('div', { children: 'No items yet' });
|
|
834
|
-
}
|
|
835
|
-
|
|
836
|
-
return jsxs('div', {
|
|
837
|
-
className: 'complex-component',
|
|
838
|
-
children: [
|
|
839
|
-
jsxs('div', {
|
|
840
|
-
className: 'counter-section',
|
|
841
|
-
children: [
|
|
842
|
-
jsx('h2', { children: 'Counter' }),
|
|
843
|
-
jsxs('p', {
|
|
844
|
-
children: [
|
|
845
|
-
'Count: ',
|
|
846
|
-
jsx('span', { children: count }),
|
|
847
|
-
' (Doubled: ',
|
|
848
|
-
jsx('span', { children: doubledCount }),
|
|
849
|
-
')'
|
|
850
|
-
]
|
|
851
|
-
})
|
|
852
|
-
]
|
|
853
|
-
}),
|
|
854
|
-
jsxs('div', {
|
|
855
|
-
className: 'items-section',
|
|
856
|
-
children: [
|
|
857
|
-
jsx('h2', { children: 'Items' }),
|
|
858
|
-
jsx('button', {
|
|
859
|
-
onClick: handleAddItem,
|
|
860
|
-
children: 'Add Random Item'
|
|
861
|
-
}),
|
|
862
|
-
jsxs('div', {
|
|
863
|
-
children: [
|
|
864
|
-
'Total value of filtered items: ',
|
|
865
|
-
jsx('span', { children: total })
|
|
866
|
-
]
|
|
867
|
-
}),
|
|
868
|
-
jsx('ul', {
|
|
869
|
-
children: filteredItems.map(item =>
|
|
870
|
-
jsx('li', {
|
|
871
|
-
key: item.id,
|
|
872
|
-
children: \`Item \${item.id}: \${item.value}\`
|
|
873
|
-
})
|
|
874
|
-
)
|
|
875
|
-
})
|
|
876
|
-
]
|
|
877
|
-
})
|
|
878
|
-
]
|
|
879
|
-
});
|
|
880
|
-
}`)).toMatchInlineSnapshot(`
|
|
881
|
-
"import { registerClientReference } from "rwsdk/worker";
|
|
882
|
-
|
|
883
|
-
function ComplexComponentSSR({ initialCount = 0 }) {
|
|
884
|
-
const [count, setCount] = useState(initialCount);
|
|
885
|
-
const [items, setItems] = useState([]);
|
|
886
|
-
const doubledCount = useMemo(() => count * 2, [count]);
|
|
887
|
-
|
|
888
|
-
useEffect(() => {
|
|
889
|
-
const timer = setInterval(() => {
|
|
890
|
-
setCount(c => c + 1);
|
|
891
|
-
}, 1000);
|
|
892
|
-
return () => clearInterval(timer);
|
|
893
|
-
}, []);
|
|
894
|
-
|
|
895
|
-
const handleAddItem = useCallback(() => {
|
|
896
|
-
const newItem = {
|
|
897
|
-
id: Math.random().toString(36),
|
|
898
|
-
value: Math.floor(Math.random() * 100)
|
|
899
|
-
};
|
|
900
|
-
setItems(prev => [...prev, newItem]);
|
|
901
|
-
}, []);
|
|
902
|
-
|
|
903
|
-
const filteredItems = items.filter(item => item.value > 50);
|
|
904
|
-
const total = filteredItems.reduce((sum, item) => sum + item.value, 0);
|
|
905
|
-
|
|
906
|
-
if (items.length === 0) {
|
|
907
|
-
return jsx('div', { children: 'No items yet' });
|
|
908
|
-
}
|
|
909
|
-
|
|
910
|
-
return jsxs('div', {
|
|
911
|
-
className: 'complex-component',
|
|
912
|
-
children: [
|
|
913
|
-
jsxs('div', {
|
|
914
|
-
className: 'counter-section',
|
|
915
|
-
children: [
|
|
916
|
-
jsx('h2', { children: 'Counter' }),
|
|
917
|
-
jsxs('p', {
|
|
918
|
-
children: [
|
|
919
|
-
'Count: ',
|
|
920
|
-
jsx('span', { children: count }),
|
|
921
|
-
' (Doubled: ',
|
|
922
|
-
jsx('span', { children: doubledCount }),
|
|
923
|
-
')'
|
|
924
|
-
]
|
|
925
|
-
})
|
|
926
|
-
]
|
|
927
|
-
}),
|
|
928
|
-
jsxs('div', {
|
|
929
|
-
className: 'items-section',
|
|
930
|
-
children: [
|
|
931
|
-
jsx('h2', { children: 'Items' }),
|
|
932
|
-
jsx('button', {
|
|
933
|
-
onClick: handleAddItem,
|
|
934
|
-
children: 'Add Random Item'
|
|
935
|
-
}),
|
|
936
|
-
jsxs('div', {
|
|
937
|
-
children: [
|
|
938
|
-
'Total value of filtered items: ',
|
|
939
|
-
jsx('span', { children: total })
|
|
940
|
-
]
|
|
941
|
-
}),
|
|
942
|
-
jsx('ul', {
|
|
943
|
-
children: filteredItems.map(item =>
|
|
944
|
-
jsx('li', {
|
|
945
|
-
key: item.id,
|
|
946
|
-
children: \`Item \${item.id}: \${item.value}\`
|
|
947
|
-
})
|
|
948
|
-
)
|
|
949
|
-
})
|
|
950
|
-
]
|
|
951
|
-
})
|
|
952
|
-
]
|
|
953
|
-
});
|
|
954
|
-
}
|
|
955
|
-
const ComplexComponent = registerClientReference("/test/file.tsx", "ComplexComponent", ComplexComponentSSR);
|
|
956
|
-
export { ComplexComponentSSR, ComplexComponent };"
|
|
957
|
-
`);
|
|
958
|
-
});
|
|
959
|
-
it("transforms mixed export styles (inline, grouped, and default)", async () => {
|
|
960
|
-
expect(await transform(`"use client"
|
|
961
|
-
|
|
962
|
-
export const First = () => {
|
|
963
|
-
return jsx('div', { children: 'First' });
|
|
964
|
-
}
|
|
965
|
-
|
|
966
|
-
const Second = () => {
|
|
967
|
-
return jsx('div', { children: 'Second' });
|
|
968
|
-
}
|
|
969
|
-
|
|
970
|
-
function Third() {
|
|
971
|
-
return jsx('div', { children: 'Third' });
|
|
972
|
-
}
|
|
973
|
-
|
|
974
|
-
const Fourth = () => {
|
|
975
|
-
return jsx('div', { children: 'Fourth' });
|
|
976
|
-
}
|
|
977
|
-
|
|
978
|
-
export default function Main() {
|
|
979
|
-
return jsx('div', { children: 'Main' });
|
|
980
|
-
}
|
|
981
|
-
|
|
982
|
-
export { Second, Third }
|
|
983
|
-
export { Fourth as AnotherName }`)).toMatchInlineSnapshot(`
|
|
984
|
-
"import { registerClientReference } from "rwsdk/worker";
|
|
985
|
-
const FirstSSR = () => {
|
|
986
|
-
return jsx('div', { children: 'First' });
|
|
987
|
-
}
|
|
988
|
-
|
|
989
|
-
const SecondSSR = () => {
|
|
990
|
-
return jsx('div', { children: 'Second' });
|
|
991
|
-
}
|
|
992
|
-
|
|
993
|
-
function ThirdSSR() {
|
|
994
|
-
return jsx('div', { children: 'Third' });
|
|
995
|
-
}
|
|
996
|
-
|
|
997
|
-
const FourthSSR = () => {
|
|
998
|
-
return jsx('div', { children: 'Fourth' });
|
|
999
|
-
}
|
|
1000
|
-
|
|
1001
|
-
function MainSSR() {
|
|
1002
|
-
return jsx('div', { children: 'Main' });
|
|
1003
|
-
}
|
|
1004
|
-
const Third = registerClientReference("/test/file.tsx", "Third", ThirdSSR);
|
|
1005
|
-
const Main = registerClientReference("/test/file.tsx", "default", MainSSR);
|
|
1006
|
-
const First = registerClientReference("/test/file.tsx", "First", FirstSSR);
|
|
1007
|
-
const Second = registerClientReference("/test/file.tsx", "Second", SecondSSR);
|
|
1008
|
-
const Fourth = registerClientReference("/test/file.tsx", "Fourth", FourthSSR);
|
|
1009
|
-
export { ThirdSSR, Third };
|
|
1010
|
-
export { Main as default, MainSSR };
|
|
1011
|
-
export { FirstSSR, First };
|
|
1012
|
-
export { SecondSSR, Second };
|
|
1013
|
-
export { FourthSSR, Fourth };"
|
|
1014
|
-
`);
|
|
1015
|
-
});
|
|
1016
|
-
it("transforms function declaration that is exported default separately", async () => {
|
|
1017
|
-
expect(await transform(`
|
|
1018
|
-
"use client"
|
|
1019
|
-
|
|
1020
|
-
function Component({ prop1, prop2 }) {
|
|
1021
|
-
return jsx('div', { children: 'Hello' });
|
|
1022
|
-
}
|
|
1023
|
-
|
|
1024
|
-
export default Component;`)).toMatchInlineSnapshot(`
|
|
1025
|
-
"import { registerClientReference } from "rwsdk/worker";
|
|
1026
|
-
|
|
1027
|
-
function ComponentSSR({ prop1, prop2 }) {
|
|
1028
|
-
return jsx('div', { children: 'Hello' });
|
|
1029
|
-
}
|
|
1030
|
-
const Component = registerClientReference("/test/file.tsx", "default", ComponentSSR);
|
|
1031
|
-
export { Component as default, ComponentSSR };"
|
|
1032
|
-
`);
|
|
1033
|
-
});
|
|
1034
|
-
it("Works in dev", async () => {
|
|
1035
|
-
expect(await transform(`"use client"
|
|
1036
|
-
import { jsxDEV } from "react/jsx-dev-runtime";
|
|
1037
|
-
import { sendMessage } from "./functions";
|
|
1038
|
-
import { useState } from "react";
|
|
1039
|
-
import { consumeEventStream } from "rwsdk/client";
|
|
1040
|
-
|
|
1041
|
-
export function Chat() {
|
|
1042
|
-
const [message, setMessage] = useState("");
|
|
1043
|
-
const [reply, setReply] = useState("");
|
|
1044
|
-
const onClick = async () => {
|
|
1045
|
-
setReply("");
|
|
1046
|
-
(await sendMessage(message)).pipeTo(
|
|
1047
|
-
consumeEventStream({
|
|
1048
|
-
onChunk: (event) => {
|
|
1049
|
-
setReply(
|
|
1050
|
-
(prev) => prev + (event.data === "[DONE]" ? "" : JSON.parse(event.data).response)
|
|
1051
|
-
);
|
|
1052
|
-
}
|
|
1053
|
-
})
|
|
1054
|
-
);
|
|
1055
|
-
};
|
|
1056
|
-
return /* @__PURE__ */ jsxDEV("div", { children: [
|
|
1057
|
-
/* @__PURE__ */ jsxDEV(
|
|
1058
|
-
"input",
|
|
1059
|
-
{
|
|
1060
|
-
type: "text",
|
|
1061
|
-
value: message,
|
|
1062
|
-
placeholder: "Type a message...",
|
|
1063
|
-
onChange: (e) => setMessage(e.target.value),
|
|
1064
|
-
style: {
|
|
1065
|
-
width: "80%",
|
|
1066
|
-
padding: "10px",
|
|
1067
|
-
marginRight: "8px",
|
|
1068
|
-
borderRadius: "4px",
|
|
1069
|
-
border: "1px solid #ccc"
|
|
1070
|
-
}
|
|
1071
|
-
},
|
|
1072
|
-
void 0,
|
|
1073
|
-
false,
|
|
1074
|
-
{
|
|
1075
|
-
fileName: "/Users/justin/rw/sdk/experiments/ai-stream/src/app/pages/Chat/Chat.tsx",
|
|
1076
|
-
lineNumber: 28,
|
|
1077
|
-
columnNumber: 7
|
|
1078
|
-
},
|
|
1079
|
-
this
|
|
1080
|
-
),
|
|
1081
|
-
/* @__PURE__ */ jsxDEV(
|
|
1082
|
-
"button",
|
|
1083
|
-
{
|
|
1084
|
-
onClick,
|
|
1085
|
-
style: {
|
|
1086
|
-
padding: "10px 20px",
|
|
1087
|
-
borderRadius: "4px",
|
|
1088
|
-
border: "none",
|
|
1089
|
-
backgroundColor: "#007bff",
|
|
1090
|
-
color: "white",
|
|
1091
|
-
cursor: "pointer"
|
|
1092
|
-
},
|
|
1093
|
-
children: "Send"
|
|
1094
|
-
},
|
|
1095
|
-
void 0,
|
|
1096
|
-
false,
|
|
1097
|
-
{
|
|
1098
|
-
fileName: "/Users/justin/rw/sdk/experiments/ai-stream/src/app/pages/Chat/Chat.tsx",
|
|
1099
|
-
lineNumber: 41,
|
|
1100
|
-
columnNumber: 7
|
|
1101
|
-
},
|
|
1102
|
-
this
|
|
1103
|
-
),
|
|
1104
|
-
/* @__PURE__ */ jsxDEV("div", { children: reply }, void 0, false, {
|
|
1105
|
-
fileName: "/Users/justin/rw/sdk/experiments/ai-stream/src/app/pages/Chat/Chat.tsx",
|
|
1106
|
-
lineNumber: 54,
|
|
1107
|
-
columnNumber: 7
|
|
1108
|
-
}, this)
|
|
1109
|
-
] }, void 0, true, {
|
|
1110
|
-
fileName: "/Users/justin/rw/sdk/experiments/ai-stream/src/app/pages/Chat/Chat.tsx",
|
|
1111
|
-
lineNumber: 27,
|
|
1112
|
-
columnNumber: 5
|
|
1113
|
-
}, this);
|
|
1114
|
-
}
|
|
1115
|
-
`)).toMatchInlineSnapshot(`
|
|
1116
|
-
"import { jsxDEV } from "react/jsx-dev-runtime";
|
|
1117
|
-
import { sendMessage } from "./functions";
|
|
1118
|
-
import { useState } from "react";
|
|
1119
|
-
import { consumeEventStream } from "rwsdk/client";
|
|
1120
|
-
import { registerClientReference } from "rwsdk/worker";
|
|
1121
|
-
|
|
1122
|
-
function ChatSSR() {
|
|
1123
|
-
const [message, setMessage] = useState("");
|
|
1124
|
-
const [reply, setReply] = useState("");
|
|
1125
|
-
const onClick = async () => {
|
|
1126
|
-
setReply("");
|
|
1127
|
-
(await sendMessage(message)).pipeTo(
|
|
1128
|
-
consumeEventStream({
|
|
1129
|
-
onChunk: (event) => {
|
|
1130
|
-
setReply(
|
|
1131
|
-
(prev) => prev + (event.data === "[DONE]" ? "" : JSON.parse(event.data).response)
|
|
1132
|
-
);
|
|
1133
|
-
}
|
|
1134
|
-
})
|
|
1135
|
-
);
|
|
1136
|
-
};
|
|
1137
|
-
return /* @__PURE__ */ jsxDEV("div", { children: [
|
|
1138
|
-
/* @__PURE__ */ jsxDEV(
|
|
1139
|
-
"input",
|
|
1140
|
-
{
|
|
1141
|
-
type: "text",
|
|
1142
|
-
value: message,
|
|
1143
|
-
placeholder: "Type a message...",
|
|
1144
|
-
onChange: (e) => setMessage(e.target.value),
|
|
1145
|
-
style: {
|
|
1146
|
-
width: "80%",
|
|
1147
|
-
padding: "10px",
|
|
1148
|
-
marginRight: "8px",
|
|
1149
|
-
borderRadius: "4px",
|
|
1150
|
-
border: "1px solid #ccc"
|
|
1151
|
-
}
|
|
1152
|
-
},
|
|
1153
|
-
void 0,
|
|
1154
|
-
false,
|
|
1155
|
-
{
|
|
1156
|
-
fileName: "/Users/justin/rw/sdk/experiments/ai-stream/src/app/pages/Chat/Chat.tsx",
|
|
1157
|
-
lineNumber: 28,
|
|
1158
|
-
columnNumber: 7
|
|
1159
|
-
},
|
|
1160
|
-
this
|
|
1161
|
-
),
|
|
1162
|
-
/* @__PURE__ */ jsxDEV(
|
|
1163
|
-
"button",
|
|
1164
|
-
{
|
|
1165
|
-
onClick,
|
|
1166
|
-
style: {
|
|
1167
|
-
padding: "10px 20px",
|
|
1168
|
-
borderRadius: "4px",
|
|
1169
|
-
border: "none",
|
|
1170
|
-
backgroundColor: "#007bff",
|
|
1171
|
-
color: "white",
|
|
1172
|
-
cursor: "pointer"
|
|
1173
|
-
},
|
|
1174
|
-
children: "Send"
|
|
1175
|
-
},
|
|
1176
|
-
void 0,
|
|
1177
|
-
false,
|
|
1178
|
-
{
|
|
1179
|
-
fileName: "/Users/justin/rw/sdk/experiments/ai-stream/src/app/pages/Chat/Chat.tsx",
|
|
1180
|
-
lineNumber: 41,
|
|
1181
|
-
columnNumber: 7
|
|
1182
|
-
},
|
|
1183
|
-
this
|
|
1184
|
-
),
|
|
1185
|
-
/* @__PURE__ */ jsxDEV("div", { children: reply }, void 0, false, {
|
|
1186
|
-
fileName: "/Users/justin/rw/sdk/experiments/ai-stream/src/app/pages/Chat/Chat.tsx",
|
|
1187
|
-
lineNumber: 54,
|
|
1188
|
-
columnNumber: 7
|
|
1189
|
-
}, this)
|
|
1190
|
-
] }, void 0, true, {
|
|
1191
|
-
fileName: "/Users/justin/rw/sdk/experiments/ai-stream/src/app/pages/Chat/Chat.tsx",
|
|
1192
|
-
lineNumber: 27,
|
|
1193
|
-
columnNumber: 5
|
|
1194
|
-
}, this);
|
|
1195
|
-
}
|
|
1196
|
-
const Chat = registerClientReference("/test/file.tsx", "Chat", ChatSSR);
|
|
1197
|
-
export { ChatSSR, Chat };
|
|
1198
|
-
"
|
|
1199
|
-
`);
|
|
1200
|
-
});
|
|
1201
|
-
it("Does not transform when 'use client' is not directive", async () => {
|
|
1202
|
-
expect(await transform(`const message = "use client";`)).toMatchInlineSnapshot(`undefined`);
|
|
1203
|
-
});
|
|
1204
|
-
});
|