Skip to content

Commit 3c3fa81

Browse files
committed
don't re-wrap when or unless in derive
1 parent 4e03a45 commit 3c3fa81

File tree

3 files changed

+8
-39
lines changed

3 files changed

+8
-39
lines changed

packages/ts-transformers/src/transformers/opaque-ref/helpers.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,14 @@ export function createComputedCallForExpression(
247247
): ts.Expression | undefined {
248248
if (plan.entries.length === 0) return undefined;
249249

250-
// Don't wrap expressions that are already derive or computed calls
250+
// Don't wrap expressions that are already derive, computed, when, or unless calls
251+
// These are already reactive and wrapping them would create unnecessary nesting
251252
if (ts.isCallExpression(expression)) {
252253
const callKind = detectCallKind(expression, context.checker);
253254
if (
254255
callKind?.kind === "derive" ||
256+
callKind?.kind === "when" ||
257+
callKind?.kind === "unless" ||
255258
(callKind?.kind === "builder" && callKind.builderName === "computed")
256259
) {
257260
return undefined;

packages/ts-transformers/test/fixtures/jsx-expressions/map-nested-conditional-no-name.expected.tsx

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -410,24 +410,7 @@ export default recipe(false as const satisfies __ctHelpers.JSONSchema, {
410410
}
411411
}
412412
} as const satisfies __ctHelpers.JSONSchema, ({ element: item, params: {} }) => (<div>
413-
{__ctHelpers.derive({
414-
type: "object",
415-
properties: {
416-
item: {
417-
type: "object",
418-
properties: {
419-
name: {
420-
type: "string",
421-
asOpaque: true
422-
}
423-
},
424-
required: ["name"]
425-
}
426-
},
427-
required: ["item"]
428-
} as const satisfies __ctHelpers.JSONSchema, true as const satisfies __ctHelpers.JSONSchema, { item: {
429-
name: item.name
430-
} }, ({ item }) => __ctHelpers.when({
413+
{__ctHelpers.when({
431414
type: "string",
432415
asOpaque: true
433416
} as const satisfies __ctHelpers.JSONSchema, {
@@ -596,7 +579,7 @@ export default recipe(false as const satisfies __ctHelpers.JSONSchema, {
596579
}
597580
}
598581
}
599-
} as const satisfies __ctHelpers.JSONSchema, item.name, <span>{item.name}</span>))}
582+
} as const satisfies __ctHelpers.JSONSchema, item.name, <span>{item.name}</span>)}
600583
</div>)), {})}
601584
</div>)}
602585
</div>),

packages/ts-transformers/test/fixtures/jsx-expressions/map-nested-conditional.expected.tsx

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -410,24 +410,7 @@ export default recipe(false as const satisfies __ctHelpers.JSONSchema, {
410410
}
411411
}
412412
} as const satisfies __ctHelpers.JSONSchema, ({ element: item, params: {} }) => (<div>
413-
{__ctHelpers.derive({
414-
type: "object",
415-
properties: {
416-
item: {
417-
type: "object",
418-
properties: {
419-
name: {
420-
type: "string",
421-
asOpaque: true
422-
}
423-
},
424-
required: ["name"]
425-
}
426-
},
427-
required: ["item"]
428-
} as const satisfies __ctHelpers.JSONSchema, true as const satisfies __ctHelpers.JSONSchema, { item: {
429-
name: item.name
430-
} }, ({ item }) => __ctHelpers.when({
413+
{__ctHelpers.when({
431414
type: "string",
432415
asOpaque: true
433416
} as const satisfies __ctHelpers.JSONSchema, {
@@ -596,7 +579,7 @@ export default recipe(false as const satisfies __ctHelpers.JSONSchema, {
596579
}
597580
}
598581
}
599-
} as const satisfies __ctHelpers.JSONSchema, item.name, <span>{item.name}</span>))}
582+
} as const satisfies __ctHelpers.JSONSchema, item.name, <span>{item.name}</span>)}
600583
</div>)), {})}
601584
</div>)}
602585
</div>),

0 commit comments

Comments
 (0)