Skip to content

Commit

Permalink
fix(generator): Output Parser.parseItem() calls with one valid type, …
Browse files Browse the repository at this point in the history
…without the array
  • Loading branch information
absidue committed Dec 2, 2023
1 parent 37ae55a commit 8c867ae
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/parser/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 8c867ae

Please sign in to comment.