* Validation function for component states. * This ensures that component states match their expected types.
(componentName: string, state: any)
| 1235 | * This ensures that component states match their expected types. |
| 1236 | */ |
| 1237 | function validateComponentState(componentName: string, state: any): boolean { |
| 1238 | // Basic validation - state must be an object |
| 1239 | if (typeof state !== 'object' || state === null) { |
| 1240 | return false; |
| 1241 | } |
| 1242 | |
| 1243 | switch (componentName) { |
| 1244 | case COMPILER_COMPONENT_NAME: |
| 1245 | // Compiler states can have various combinations of properties |
| 1246 | return ( |
| 1247 | (state.lang && state.source !== undefined) || |
| 1248 | (state.source !== undefined && state.compiler) || |
| 1249 | (state.lang && state.tree !== undefined) |
| 1250 | ); |
| 1251 | |
| 1252 | case EXECUTOR_COMPONENT_NAME: |
| 1253 | // Executor states require compilation panel booleans |
| 1254 | return typeof state.compilationPanelShown === 'boolean' && typeof state.compilerOutShown === 'boolean'; |
| 1255 | |
| 1256 | case EDITOR_COMPONENT_NAME: |
| 1257 | // Editor states are flexible but must have valid properties |
| 1258 | return true; |
| 1259 | |
| 1260 | case TREE_COMPONENT_NAME: |
| 1261 | // Tree states are flexible but must have valid properties |
| 1262 | return true; |
| 1263 | |
| 1264 | case OUTPUT_COMPONENT_NAME: |
| 1265 | // Output state needs specific numeric properties |
| 1266 | return ( |
| 1267 | typeof state.tree === 'number' && typeof state.compiler === 'number' && typeof state.editor === 'number' |
| 1268 | ); |
| 1269 | |
| 1270 | case TOOL_COMPONENT_NAME: |
| 1271 | // Tool state needs specific properties |
| 1272 | return ( |
| 1273 | typeof state.tree === 'number' && |
| 1274 | typeof state.toolId === 'string' && |
| 1275 | typeof state.id === 'number' && |
| 1276 | typeof state.editorid === 'number' |
| 1277 | ); |
| 1278 | |
| 1279 | // View components have diverse state requirements but must be valid objects |
| 1280 | case TOOL_INPUT_VIEW_COMPONENT_NAME: |
| 1281 | case DIFF_VIEW_COMPONENT_NAME: |
| 1282 | case OPT_VIEW_COMPONENT_NAME: |
| 1283 | case STACK_USAGE_VIEW_COMPONENT_NAME: |
| 1284 | case FLAGS_VIEW_COMPONENT_NAME: |
| 1285 | case PP_VIEW_COMPONENT_NAME: |
| 1286 | case AST_VIEW_COMPONENT_NAME: |
| 1287 | case GCC_DUMP_VIEW_COMPONENT_NAME: |
| 1288 | case CFG_VIEW_COMPONENT_NAME: |
| 1289 | case CONFORMANCE_VIEW_COMPONENT_NAME: |
| 1290 | case IR_VIEW_COMPONENT_NAME: |
| 1291 | case CLANGIR_VIEW_COMPONENT_NAME: |
| 1292 | case OPT_PIPELINE_VIEW_COMPONENT_NAME: |
| 1293 | case LLVM_OPT_PIPELINE_VIEW_COMPONENT_NAME: |
| 1294 | case RUST_MIR_VIEW_COMPONENT_NAME: |
no test coverage detected