From aeb17feaf4a09d33a97a11b6000f068f1d4b229d Mon Sep 17 00:00:00 2001 From: absidue <48293849+absidue@users.noreply.github.com> Date: Fri, 15 Sep 2023 17:56:53 +0200 Subject: [PATCH] perf(generator): Remove duplicate checks in `isMiscType` --- src/parser/generator.ts | 56 +++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/src/parser/generator.ts b/src/parser/generator.ts index 3bf8ad004..931af51b4 100644 --- a/src/parser/generator.ts +++ b/src/parser/generator.ts @@ -134,33 +134,35 @@ export function isRendererList(value: unknown) { * @returns If it is a misc type, return the InferenceType. Otherwise, return false. */ export function isMiscType(key: string, value: unknown): MiscInferenceType | false { - // NavigationEndpoint - if ((key.endsWith('Endpoint') || key.endsWith('Command') || key === 'endpoint') && typeof value === 'object' && value !== null) { - return { - type: 'misc', - endpoint: new NavigationEndpoint(value), - optional: false, - misc_type: 'NavigationEndpoint' - }; - } - // Text - if (typeof value === 'object' && value !== null && (Reflect.has(value, 'simpleText') || Reflect.has(value, 'runs'))) { - const textNode = new Text(value); - return { - type: 'misc', - misc_type: 'Text', - optional: false, - endpoint: textNode.endpoint, - text: textNode.toString() - }; - } - // Thumbnail - if (typeof value === 'object' && value !== null && Reflect.has(value, 'thumbnails') && Array.isArray(Reflect.get(value, 'thumbnails'))) { - return { - type: 'misc', - misc_type: 'Thumbnail', - optional: false - }; + if (typeof value === 'object' && value !== null) { + // NavigationEndpoint + if (key.endsWith('Endpoint') || key.endsWith('Command') || key === 'endpoint') { + return { + type: 'misc', + endpoint: new NavigationEndpoint(value), + optional: false, + misc_type: 'NavigationEndpoint' + }; + } + // Text + if (Reflect.has(value, 'simpleText') || Reflect.has(value, 'runs')) { + const textNode = new Text(value); + return { + type: 'misc', + misc_type: 'Text', + optional: false, + endpoint: textNode.endpoint, + text: textNode.toString() + }; + } + // Thumbnail + if (Reflect.has(value, 'thumbnails') && Array.isArray(Reflect.get(value, 'thumbnails'))) { + return { + type: 'misc', + misc_type: 'Thumbnail', + optional: false + }; + } } return false; }