fix(generator): Output Parser.parseItem() calls with one valid type, without the array (#551)

This commit is contained in:
absidue
2023-12-04 19:45:38 +01:00
committed by GitHub
parent 48a5d4e7c3
commit bd487f8bef

View File

@@ -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)