mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-13 09:32:12 +00:00
fix(generator): Output Parser.parseItem() calls with one valid type, without the array (#551)
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user