From e6941ff752142f822aa11851f00d07f642e0a561 Mon Sep 17 00:00:00 2001 From: Luke Dennis Date: Fri, 3 Mar 2023 18:21:45 -0700 Subject: [PATCH] fix for missing props, function props stub --- README.md | 3 ++- package.json | 2 +- src/components/ExampleInput.tsx | 7 ++++++- src/parseComponent.ts | 9 ++++++--- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index baa14b8..039af87 100644 --- a/README.md +++ b/README.md @@ -33,10 +33,11 @@ npm test -- -u # update snapshots ##### TODO: - Indexed access of pseudo-enum object constants +- Function props - Parsing plain JS in addition to TypeScript - Multiple files and directories on CLI - Settings for control prefences (`select` vs `radio`, etc) - More unit test coverage ##### TODONT: -- Not looking to add custom formatting; BYO linter/formatter. +- Not planning to add custom code formatting; BYO linter/formatter. diff --git a/package.json b/package.json index 0f31e33..18e2323 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ladlescoop", - "version": "1.0.2", + "version": "1.0.3", "description": "", "main": "src/index.ts", "bin": { diff --git a/src/components/ExampleInput.tsx b/src/components/ExampleInput.tsx index d294d97..4158271 100644 --- a/src/components/ExampleInput.tsx +++ b/src/components/ExampleInput.tsx @@ -38,6 +38,7 @@ export type ExampleInputProps = { labelString: string | null minValue?: -100 | 0 | 100 maxValue?: number + onChange: (updatedValue: number) => void roundToNearest?: "none" | "ten" | "hundred" startingValue?: number | string } @@ -51,6 +52,7 @@ export function ExampleInput({ labelString, minValue, maxValue = MAX_VALUE, + onChange, roundToNearest = "none", startingValue = 0, }: ExampleInputProps) { @@ -75,7 +77,10 @@ export function ExampleInput({ type="text" defaultValue={startingValue} onBlur={onBlur} - onChange={({target}) => setValue(target.value)} + onChange={({target}) => { + setValue(target.value) + onChange(target.value) + }} style={{fontSize, fontWeight}} value={value} /> diff --git a/src/parseComponent.ts b/src/parseComponent.ts index d82527a..d92ab3c 100644 --- a/src/parseComponent.ts +++ b/src/parseComponent.ts @@ -121,6 +121,9 @@ export function mutableAddProp( return set({kind, type: "string", defaultValue: "''"}) case ts.SyntaxKind.NumberKeyword: return set({kind, type: "number", defaultValue: "0"}) + case ts.SyntaxKind.FunctionType: + // TODO + return case ts.SyntaxKind.TypeReference: if (!ts.isTypeReferenceNode(typeNode)) break const enumName = typeNode.getText() @@ -278,7 +281,7 @@ export function handleFunction( if (!isExported(fn)) warn(`Warning: Component ${fnName} is not exported`) draft.componentsMap[fnName] = { ...draft.componentsMap[fnName], - isDefaultExport: !!fn.modifiers?.some(ts.isDefaultClause), + isDefaultExport: !!fn.modifiers?.some(m => m?.kind === ts.SyntaxKind.DefaultKeyword), hasFunction: true } @@ -306,9 +309,9 @@ export function mutableAddPropBinding( } if (bind.getChildCount() === 1) { const prop = draft.componentsMap[fnName].props[propName] - if (prop.kind === ts.SyntaxKind.NumberKeyword) + if (prop?.kind === ts.SyntaxKind.NumberKeyword) return set("0") - else if (prop.kind === ts.SyntaxKind.StringKeyword) + else if (prop?.kind === ts.SyntaxKind.StringKeyword) return set("''") } switch (token.kind) {