From 9f1ae01d913dca6e2315088d60723268fa174550 Mon Sep 17 00:00:00 2001
From: Misode
Date: Thu, 24 Oct 2024 15:24:04 +0200
Subject: [PATCH] Rename variables to be more consistent
---
.../components/generator/McdocRenderer.tsx | 54 +++++++++----------
1 file changed, 24 insertions(+), 30 deletions(-)
diff --git a/src/app/components/generator/McdocRenderer.tsx b/src/app/components/generator/McdocRenderer.tsx
index 6e3f3365..f2b9629f 100644
--- a/src/app/components/generator/McdocRenderer.tsx
+++ b/src/app/components/generator/McdocRenderer.tsx
@@ -26,7 +26,7 @@ export function McdocRoot({ node, makeEdit, ctx } : Props) {
const { locale } = useLocale()
const type = node?.typeDef ?? { kind: 'unsafe' }
- if (type.kind === 'struct' && JsonObjectNode.is(node)) {
+ if (type.kind === 'struct' && type.fields.length > 0 && JsonObjectNode.is(node)) {
return
}
@@ -373,13 +373,7 @@ function Body({ type, optional, node, makeEdit, ctx }: BodyProps) {
return
}
if (type.kind === 'struct') {
- if (!JsonObjectNode.is(node)) {
- return <>>
- }
- if (type.fields.length === 0) {
- return <>>
- }
- if (optional && !node) {
+ if (!JsonObjectNode.is(node) || optional || type.fields.length === 0) {
return <>>
}
return
@@ -434,21 +428,21 @@ function StructBody({ type: outerType, node, makeEdit, ctx }: StructBodyProps) {
return <>
{staticFields.map(field => {
const key = (field.key as LiteralType).value.value.toString()
- const childIndex = node.children.findIndex(p => p.key?.value === key)
- const child = childIndex === -1 ? undefined : node.children[childIndex]
- const childValue = child?.value
- const fieldType = simplifyType(field.type, ctx)
+ const index = node.children.findIndex(p => p.key?.value === key)
+ const pair = index === -1 ? undefined : node.children[index]
+ const child = pair?.value
+ const childType = simplifyType(field.type, ctx)
const makeFieldEdit: MakeEdit = (edit) => {
- if (child) {
+ if (pair) {
makeEdit(() => {
- const newChild = edit(childValue?.range ?? core.Range.create(child.range.end))
+ const newChild = edit(child?.range ?? core.Range.create(pair.range.end))
if (newChild === undefined) {
- node.children.splice(childIndex, 1)
+ node.children.splice(index, 1)
} else {
- node.children[childIndex] = {
+ node.children[index] = {
type: 'pair',
- range: child.range,
- key: child.key,
+ range: pair.range,
+ key: pair.key,
value: newChild,
}
}
@@ -477,12 +471,12 @@ function StructBody({ type: outerType, node, makeEdit, ctx }: StructBodyProps) {
}
return
+
-
+
})}
>
@@ -513,7 +507,7 @@ function ListBody({ type: outerType, node, makeEdit, ctx }: ListBodyProps) {
{node.children.map((item, index) => {
const child = item.value
const itemType = getItemType(type)
- const simplifiedItemType = simplifyType(itemType, ctx)
+ const childType = simplifyType(itemType, ctx)
const makeItemEdit: MakeEdit = (edit) => {
makeEdit(() => {
const newChild = edit(child?.range ?? item.range)
@@ -540,9 +534,9 @@ function ListBody({ type: outerType, node, makeEdit, ctx }: ListBodyProps) {
}
-
+
-
+
})}
>
@@ -556,10 +550,10 @@ function TupleBody({ type, node, makeEdit, ctx }: TupleBodyProps) {
return <>>
}
return <>
- {type.items.map((item, index) => {
- const itemNode = node?.children?.[index]
- const child = itemNode?.value
- const itemType = simplifyType(item, ctx)
+ {type.items.map((itemType, index) => {
+ const item = node?.children?.[index]
+ const child = item?.value
+ const childType = simplifyType(itemType, ctx)
const makeItemEdit: MakeEdit = (edit) => {
makeEdit(() => {
const newChild = edit(child?.range ?? node.range)
@@ -578,9 +572,9 @@ function TupleBody({ type, node, makeEdit, ctx }: TupleBodyProps) {
+
-
+
})}
>