From cffaac6395120044d9839f093e5c6abe7faaec55 Mon Sep 17 00:00:00 2001 From: sinclair Date: Sun, 9 Apr 2023 01:50:21 +0900 Subject: [PATCH] Workbench Compiler --- example/codegen/typescript-to-typebox.ts | 18 ++++++++++-------- example/index.ts | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/example/codegen/typescript-to-typebox.ts b/example/codegen/typescript-to-typebox.ts index 953f8a2..7f69b24 100644 --- a/example/codegen/typescript-to-typebox.ts +++ b/example/codegen/typescript-to-typebox.ts @@ -94,22 +94,24 @@ export namespace TypeScriptToTypeBox { // ------------------------------------------------------------------------- // TemplateLiteral // ------------------------------------------------------------------------- + // prettier-ignore function* TemplateLiteralTypeNode(node: ts.TemplateLiteralTypeNode) { - const collect = node.getChildren().map(node => Collect(node)) - yield `Type.TemplateLiteral([${collect.join('')}])` + const collect = node.getChildren().map(node => Collect(node)).join('') + yield `Type.TemplateLiteral([${collect.slice(0, collect.length - 2)}])` // can't remove trailing here } + // prettier-ignore function* TemplateLiteralTypeSpan(node: ts.TemplateLiteralTypeSpan) { - const collect = node.getChildren().map(node => Collect(node)) - yield collect.join(', ') + const collect = node.getChildren().map(node => Collect(node)).join(', ') + if(collect.length > 0) yield `${collect}` } function* TemplateHead(node: ts.TemplateHead) { - yield `Type.Literal('${node.text}'), ` + if (node.text.length > 0) yield `Type.Literal('${node.text}'), ` } function* TemplateMiddle(node: ts.TemplateMiddle) { - yield `Type.Literal('${node.text}'), ` + if (node.text.length > 0) yield `Type.Literal('${node.text}'), ` } function* TemplateTail(node: ts.TemplateTail) { - yield `Type.Literal('${node.text}')` + if (node.text.length > 0) yield `Type.Literal('${node.text}'), ` } function* IntersectionTypeNode(node: ts.IntersectionTypeNode): IterableIterator { const types = node.types.map((type) => Collect(type)).join(',\n') @@ -378,4 +380,4 @@ export namespace TypeScriptToTypeBox { const types = Formatter.Format(typeDeclarations) return [imports, '', types].join('\n') } -} \ No newline at end of file +} diff --git a/example/index.ts b/example/index.ts index c5ad5a1..ed52156 100644 --- a/example/index.ts +++ b/example/index.ts @@ -37,4 +37,4 @@ console.log(C.Code()) // Check: Value // ----------------------------------------------------------- -console.log(C.Check(V)) \ No newline at end of file +console.log(C.Check(V))