From 8c867ae00a45c1953f24b6ebcbb58b9652ddb93e Mon Sep 17 00:00:00 2001 From: absidue <48293849+absidue@users.noreply.github.com> Date: Sat, 2 Dec 2023 17:00:28 +0100 Subject: [PATCH] fix(generator): Output Parser.parseItem() calls with one valid type, without the array --- src/parser/generator.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/parser/generator.ts b/src/parser/generator.ts index 931af51b4..9f8628db3 100644 --- a/src/parser/generator.ts +++ b/src/parser/generator.ts @@ -448,12 +448,12 @@ export function toParser(key: string, inference_type: InferenceType, key_path: s switch (inference_type.type) { case 'renderer': { - parser = `Parser.parseItem(${key_path.join('.')}.${key}, [ ${inference_type.renderers.map((type) => `YTNodes.${type}`).join(', ')} ])`; + parser = `Parser.parseItem(${key_path.join('.')}.${key}, ${toParserValidTypes(inference_type.renderers)})`; } break; case 'renderer_list': { - parser = `Parser.parse(${key_path.join('.')}.${key}, true, [ ${inference_type.renderers.map((type) => `YTNodes.${type}`).join(', ')} ])`; + parser = `Parser.parse(${key_path.join('.')}.${key}, true, ${toParserValidTypes(inference_type.renderers)})`; } break; case 'object': @@ -491,6 +491,14 @@ export function toParser(key: string, inference_type: InferenceType, key_path: s return parser; } +function toParserValidTypes(types: string[]) { + if (types.length === 1) { + return `YTNodes.${types[0]}`; + } + + return `[ ${types.map((type) => `YTNodes.${type}`).join(', ')} ]`; +} + function accessDataFromKeyPath(root: any, key_path: string[]) { let data = root; for (const key of key_path)