Skip to content

Commit

Permalink
perf(generator): Remove duplicate checks in isMiscType (#506)
Browse files Browse the repository at this point in the history
  • Loading branch information
absidue authored Sep 15, 2023
1 parent f4bc850 commit 68df321
Showing 1 changed file with 29 additions and 27 deletions.
56 changes: 29 additions & 27 deletions src/parser/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 68df321

Please sign in to comment.