From 6efebe44890ca2c9548c55ab015b5ee382b9509f Mon Sep 17 00:00:00 2001 From: Liz Looney Date: Thu, 6 Nov 2025 20:58:36 -0800 Subject: [PATCH 1/5] In mrc_class_method_def.ts: Added constants for NO_RETURN_VALUE and UNTYPED_RETURN_VALUE. Added upgrade_004_to_005 to change mrcReturnType from 'Any' to UNTYPED_RETURN_VALUE. Changed createCustomMethodBlockWithReturn to use UNTYPED_RETURN_VALUE instead of 'Any'. In upgrade_project.ts: Incremented CURRENT_VERSION to 0.0.5. Changed switch statement in upgradeProjectIfNecessary to have the default case at the top. All other cases have @ts-ignore and blank lines so it is more clear that the @ts-ignore goes with the case after it. Added upgradeBlocksFiles function that can be called from other upgradeFrom_..._to_... functions. Added upgradeFrom_004_to_005. --- src/blocks/mrc_class_method_def.ts | 34 ++++++++++++--- src/storage/upgrade_project.ts | 69 ++++++++++++++++++++++++++---- 2 files changed, 89 insertions(+), 14 deletions(-) diff --git a/src/blocks/mrc_class_method_def.ts b/src/blocks/mrc_class_method_def.ts index d6b8126f..b8a2897f 100644 --- a/src/blocks/mrc_class_method_def.ts +++ b/src/blocks/mrc_class_method_def.ts @@ -37,6 +37,9 @@ import * as paramContainer from './mrc_param_container' export const BLOCK_NAME = 'mrc_class_method_def'; +const NO_RETURN_VALUE = 'None'; +const UNTYPED_RETURN_VALUE = ''; + const INPUT_TITLE = 'TITLE'; export const FIELD_METHOD_NAME = 'NAME'; const FIELD_PARAM_PREFIX = 'PARAM_'; @@ -82,8 +85,8 @@ type ClassMethodDefExtraState = { canBeCalledOutsideClass: boolean, /** * The return type of the function. - * Use 'None' for no return value. - * Use '' for an untyped return value. + * Use NO_RETURN_VALUE for no return value. + * Use UNTYPED_RETURN_VALUE for an untyped return value. */ returnType: string, /** @@ -252,8 +255,8 @@ const CLASS_METHOD_DEF = { this.removeInput(INPUT_RETURN); } - // Add return input if return type is not 'None' - if (this.mrcReturnType && this.mrcReturnType !== 'None') { + // Add return input if return type is not NO_RETURN_VALUE + if (this.mrcReturnType !== undefined && this.mrcReturnType !== NO_RETURN_VALUE) { this.appendValueInput(INPUT_RETURN) .setAlign(Blockly.inputs.Align.RIGHT) .appendField(Blockly.Msg.PROCEDURES_DEFRETURN_RETURN); @@ -348,6 +351,11 @@ const CLASS_METHOD_DEF = { methodBlock.mrcParameters = filteredParams; } }, + upgrade_004_to_005: function(this: ClassMethodDefBlock) { + if (this.mrcReturnType === 'Any') { + this.mrcReturnType = UNTYPED_RETURN_VALUE; + } + }, }; /** @@ -508,7 +516,7 @@ export function createCustomMethodBlock(): toolboxItems.Block { canChangeSignature: true, canBeCalledWithinClass: true, canBeCalledOutsideClass: true, - returnType: 'None', + returnType: NO_RETURN_VALUE, params: [], }; const fields: {[key: string]: any} = {}; @@ -521,7 +529,7 @@ export function createCustomMethodBlockWithReturn(): toolboxItems.Block { canChangeSignature: true, canBeCalledWithinClass: true, canBeCalledOutsideClass: true, - returnType: 'Any', + returnType: UNTYPED_RETURN_VALUE, params: [], }; const fields: {[key: string]: any} = {}; @@ -609,3 +617,17 @@ export function getMethodNamesAlreadyOverriddenInWorkspace( } }); } + +/** + * Upgrades the ClassMethodDefBlocks in the given workspace from version 004 to 005. + * This function should only be called when upgrading old projects. + */ +export function upgrade_004_to_005(workspace: Blockly.Workspace): void { + // Make sure the workspace is headless. + if (workspace.rendered) { + throw new Error('upgrade_004_to_005 should never be called with a rendered workspace.'); + } + workspace.getBlocksByType(BLOCK_NAME).forEach(block => { + (block as ClassMethodDefBlock).upgrade_004_to_005(); + }); +} diff --git a/src/storage/upgrade_project.ts b/src/storage/upgrade_project.ts index 53a057ee..55c2fe1c 100644 --- a/src/storage/upgrade_project.ts +++ b/src/storage/upgrade_project.ts @@ -28,39 +28,83 @@ import * as storageModule from './module'; import * as storageModuleContent from './module_content'; import * as storageNames from './names'; import * as storageProject from './project'; -import { ClassMethodDefBlock, BLOCK_NAME as MRC_CLASS_METHOD_DEF_BLOCK_NAME } from '../blocks/mrc_class_method_def'; +import { ClassMethodDefBlock, BLOCK_NAME as MRC_CLASS_METHOD_DEF_BLOCK_NAME, upgrade_004_to_005 } from '../blocks/mrc_class_method_def'; import * as workspaces from '../blocks/utils/workspaces'; export const NO_VERSION = '0.0.0'; -export const CURRENT_VERSION = '0.0.4'; +export const CURRENT_VERSION = '0.0.5'; export async function upgradeProjectIfNecessary( storage: commonStorage.Storage, projectName: string): Promise { const projectInfo = await storageProject.fetchProjectInfo(storage, projectName); if (semver.lt(projectInfo.version, CURRENT_VERSION)) { switch (projectInfo.version) { + default: + throw new Error('Unrecognized project version: ' + projectInfo.version); + + // Intentional fallthrough after case '0.0.0' // @ts-ignore case '0.0.0': upgradeFrom_000_to_001(storage, projectName, projectInfo) - // Intentional fallthrough + + // Intentional fallthrough after case '0.0.1' // @ts-ignore case '0.0.1': upgradeFrom_001_to_002(storage, projectName, projectInfo); - // Intentional fallthrough + + // Intentional fallthrough after case '0.0.2' // @ts-ignore case '0.0.2': - upgradeFrom_002_to_003(storage, projectName, projectInfo); + upgradeFrom_002_to_003(storage, projectName, projectInfo); + + // Intentional fallthrough after case '0.0.3' + // @ts-ignore case '0.0.3': upgradeFrom_003_to_004(storage, projectName, projectInfo); - break; - default: - throw new Error('Unrecognized project version: ' + projectInfo.version); + // Intentional fallthrough after case '0.0.4' + // @ts-ignore + case '0.0.4': + upgradeFrom_004_to_005(storage, projectName, projectInfo); } await storageProject.saveProjectInfo(storage, projectName); } } +async function upgradeBlocksFiles( + storage: commonStorage.Storage, + projectName: string, + upgradeFunc: (w: Blockly.Workspace) => void +): Promise { + const projectFileNames: string[] = await storage.list( + storageNames.makeProjectDirectoryPath(projectName)); + for (const projectFileName of projectFileNames) { + const modulePath = storageNames.makeFilePath(projectName, projectFileName); + const moduleType = storageNames.getModuleType(modulePath); + + let moduleContentText = await storage.fetchFileContentText(modulePath); + const moduleContent = storageModuleContent.parseModuleContentText(moduleContentText); + let blocks = moduleContent.getBlocks(); + + // Create a temporary workspace to upgrade the blocks. + const headlessWorkspace = workspaces.createHeadlessWorkspace(moduleType); + + try { + Blockly.serialization.workspaces.load(blocks, headlessWorkspace); + + upgradeFunc(headlessWorkspace); + + blocks = Blockly.serialization.workspaces.save(headlessWorkspace); + } finally { + workspaces.destroyHeadlessWorkspace(headlessWorkspace); + } + + moduleContent.setBlocks(blocks); + moduleContentText = moduleContent.getModuleContentText(); + await storage.saveFile(modulePath, moduleContentText); + } +} + async function upgradeFrom_000_to_001( _storage: commonStorage.Storage, _projectName: string, @@ -157,3 +201,12 @@ async function upgradeFrom_003_to_004( // from loading a project with an older version of software. projectInfo.version = '0.0.4'; } + +async function upgradeFrom_004_to_005( + storage: commonStorage.Storage, + projectName: string, + projectInfo: storageProject.ProjectInfo): Promise { + // mrc_class_method_def blocks that return a value need to have returnType changed from 'Any' to ''. + await upgradeBlocksFiles(storage, projectName, upgrade_004_to_005); + projectInfo.version = '0.0.5'; +} From d7a0d12e536c607c991ee0a4189a05465dbace7e Mon Sep 17 00:00:00 2001 From: Liz Looney Date: Thu, 6 Nov 2025 22:11:00 -0800 Subject: [PATCH 2/5] In mrc_class_method_def.ts: Added upgrade_002_to_003 function. In upgrade_project.ts: Modified upgradeBlocksFiles to take a predicate function. Added anyModuleType and isOpMode functions that can be passed to upgradeBlocksFiles as the predicate function. Modified upgradeFrom_002_to_003 to call upgradeBlocksFiles. Modified upgradeFrom_004_to_005 to pass anyModuleType to upgradeBlocksFiles. --- src/blocks/mrc_class_method_def.ts | 14 +++++ src/storage/upgrade_project.ts | 89 ++++++++++++++---------------- 2 files changed, 54 insertions(+), 49 deletions(-) diff --git a/src/blocks/mrc_class_method_def.ts b/src/blocks/mrc_class_method_def.ts index b8a2897f..7a184e79 100644 --- a/src/blocks/mrc_class_method_def.ts +++ b/src/blocks/mrc_class_method_def.ts @@ -618,6 +618,20 @@ export function getMethodNamesAlreadyOverriddenInWorkspace( }); } +/** + * Upgrades the ClassMethodDefBlocks in the given workspace from version 002 to 003. + * This function should only be called when upgrading old projects. + */ +export function upgrade_002_to_003(workspace: Blockly.Workspace): void { + // Make sure the workspace is headless. + if (workspace.rendered) { + throw new Error('upgrade_002_to_003 should never be called with a rendered workspace.'); + } + workspace.getBlocksByType(BLOCK_NAME).forEach(block => { + (block as ClassMethodDefBlock).upgrade_002_to_003(); + }); +} + /** * Upgrades the ClassMethodDefBlocks in the given workspace from version 004 to 005. * This function should only be called when upgrading old projects. diff --git a/src/storage/upgrade_project.ts b/src/storage/upgrade_project.ts index 55c2fe1c..fa04c079 100644 --- a/src/storage/upgrade_project.ts +++ b/src/storage/upgrade_project.ts @@ -28,7 +28,7 @@ import * as storageModule from './module'; import * as storageModuleContent from './module_content'; import * as storageNames from './names'; import * as storageProject from './project'; -import { ClassMethodDefBlock, BLOCK_NAME as MRC_CLASS_METHOD_DEF_BLOCK_NAME, upgrade_004_to_005 } from '../blocks/mrc_class_method_def'; +import { upgrade_002_to_003, upgrade_004_to_005 } from '../blocks/mrc_class_method_def'; import * as workspaces from '../blocks/utils/workspaces'; export const NO_VERSION = '0.0.0'; @@ -74,6 +74,7 @@ export async function upgradeProjectIfNecessary( async function upgradeBlocksFiles( storage: commonStorage.Storage, projectName: string, + upgradePredicate: (moduleType: storageModule.ModuleType) => boolean, upgradeFunc: (w: Blockly.Workspace) => void ): Promise { const projectFileNames: string[] = await storage.list( @@ -81,30 +82,50 @@ async function upgradeBlocksFiles( for (const projectFileName of projectFileNames) { const modulePath = storageNames.makeFilePath(projectName, projectFileName); const moduleType = storageNames.getModuleType(modulePath); + const originalModuleContentText = await storage.fetchFileContentText(modulePath); + let moduleContentText = originalModuleContentText; - let moduleContentText = await storage.fetchFileContentText(modulePath); - const moduleContent = storageModuleContent.parseModuleContentText(moduleContentText); - let blocks = moduleContent.getBlocks(); - - // Create a temporary workspace to upgrade the blocks. - const headlessWorkspace = workspaces.createHeadlessWorkspace(moduleType); + if (upgradePredicate(moduleType)) { + const moduleContent = storageModuleContent.parseModuleContentText(moduleContentText); + let blocks = moduleContent.getBlocks(); - try { - Blockly.serialization.workspaces.load(blocks, headlessWorkspace); + // Create a temporary workspace to upgrade the blocks. + const headlessWorkspace = workspaces.createHeadlessWorkspace(moduleType); - upgradeFunc(headlessWorkspace); + try { + Blockly.serialization.workspaces.load(blocks, headlessWorkspace); + upgradeFunc(headlessWorkspace); + blocks = Blockly.serialization.workspaces.save(headlessWorkspace); + } finally { + workspaces.destroyHeadlessWorkspace(headlessWorkspace); + } - blocks = Blockly.serialization.workspaces.save(headlessWorkspace); - } finally { - workspaces.destroyHeadlessWorkspace(headlessWorkspace); + moduleContent.setBlocks(blocks); + moduleContentText = moduleContent.getModuleContentText(); } - moduleContent.setBlocks(blocks); - moduleContentText = moduleContent.getModuleContentText(); - await storage.saveFile(modulePath, moduleContentText); + if (moduleContentText !== originalModuleContentText) { + await storage.saveFile(modulePath, moduleContentText); + } } } +/** + * Predicate function that can be passed to upgradeBlocksFiles indicating that all modules should be + * affected. + */ +function anyModuleType(_moduleType: storageModule.ModuleType): boolean { + return true; +} + +/** + * Predicate function that can be passed to upgradeBlocksFiles indicating that only OpMode modules + * should be affected. + */ +function isOpMode(moduleType: storageModule.ModuleType): boolean { + return moduleType === storageModule.ModuleType.OPMODE; +} + async function upgradeFrom_000_to_001( _storage: commonStorage.Storage, _projectName: string, @@ -158,38 +179,8 @@ async function upgradeFrom_002_to_003( storage: commonStorage.Storage, projectName: string, projectInfo: storageProject.ProjectInfo): Promise { - // Opmodes had robot as a parameter to init method - const projectFileNames: string[] = await storage.list( - storageNames.makeProjectDirectoryPath(projectName)); - - for (const projectFileName of projectFileNames) { - const modulePath = storageNames.makeFilePath(projectName, projectFileName); - - if (storageNames.getModuleType(modulePath) === storageModule.ModuleType.OPMODE) { - let moduleContentText = await storage.fetchFileContentText(modulePath); - const moduleContent = storageModuleContent.parseModuleContentText(moduleContentText); - let blocks = moduleContent.getBlocks(); - - // Create a temporary workspace to upgrade the blocks. - const headlessWorkspace = workspaces.createHeadlessWorkspace(storageModule.ModuleType.ROBOT); - - try { - Blockly.serialization.workspaces.load(blocks, headlessWorkspace); - - // Method blocks need to be upgraded - headlessWorkspace.getBlocksByType(MRC_CLASS_METHOD_DEF_BLOCK_NAME, false).forEach(block => { - (block as ClassMethodDefBlock).upgrade_002_to_003(); - }); - blocks = Blockly.serialization.workspaces.save(headlessWorkspace); - } finally { - workspaces.destroyHeadlessWorkspace(headlessWorkspace); - } - - moduleContent.setBlocks(blocks); - moduleContentText = moduleContent.getModuleContentText(); - await storage.saveFile(modulePath, moduleContentText); - } - } + // OpModes had robot as a parameter to init method. + await upgradeBlocksFiles(storage, projectName, isOpMode, upgrade_002_to_003); projectInfo.version = '0.0.3'; } @@ -207,6 +198,6 @@ async function upgradeFrom_004_to_005( projectName: string, projectInfo: storageProject.ProjectInfo): Promise { // mrc_class_method_def blocks that return a value need to have returnType changed from 'Any' to ''. - await upgradeBlocksFiles(storage, projectName, upgrade_004_to_005); + await upgradeBlocksFiles(storage, projectName, anyModuleType, upgrade_004_to_005); projectInfo.version = '0.0.5'; } From ec1377b15af868fcbfaa03e3fbf0096349ee2462 Mon Sep 17 00:00:00 2001 From: Liz Looney Date: Thu, 6 Nov 2025 23:19:57 -0800 Subject: [PATCH 3/5] Added preupgradePredicate and preupgradeFunc parameters to upgradeBlocksFiles. Modified upgradeFrom_001_to_002 to call upgradeBlocksFiles. --- src/storage/upgrade_project.ts | 74 +++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 33 deletions(-) diff --git a/src/storage/upgrade_project.ts b/src/storage/upgrade_project.ts index fa04c079..49adc787 100644 --- a/src/storage/upgrade_project.ts +++ b/src/storage/upgrade_project.ts @@ -74,6 +74,8 @@ export async function upgradeProjectIfNecessary( async function upgradeBlocksFiles( storage: commonStorage.Storage, projectName: string, + preupgradePredicate: (moduleType: storageModule.ModuleType) => boolean, + preupgradeFunc: (moduleContentText: string) => string, upgradePredicate: (moduleType: storageModule.ModuleType) => boolean, upgradeFunc: (w: Blockly.Workspace) => void ): Promise { @@ -85,6 +87,10 @@ async function upgradeBlocksFiles( const originalModuleContentText = await storage.fetchFileContentText(modulePath); let moduleContentText = originalModuleContentText; + if (preupgradePredicate(moduleType)) { + moduleContentText = preupgradeFunc(moduleContentText); + } + if (upgradePredicate(moduleType)) { const moduleContent = storageModuleContent.parseModuleContentText(moduleContentText); let blocks = moduleContent.getBlocks(); @@ -126,6 +132,29 @@ function isOpMode(moduleType: storageModule.ModuleType): boolean { return moduleType === storageModule.ModuleType.OPMODE; } +/** + * Predicate function that can be passed to upgradeBlocksFiles indicating that only Robot modules + * should be affected. + */ +function isRobot(moduleType: storageModule.ModuleType): boolean { + return moduleType === storageModule.ModuleType.ROBOT; +} + +/** + * Predicate function that can be passed to upgradeBlocksFiles indicating that no modules should be + * affected. + */ +function noModuleTypes(_moduleType: storageModule.ModuleType): boolean { + return false; +} + +/** + * Preupgrade function that makes no changes to moduleContentText. + */ +function noPreupgrade(moduleContentText: string): string { + return moduleContentText; +} + async function upgradeFrom_000_to_001( _storage: commonStorage.Storage, _projectName: string, @@ -141,37 +170,10 @@ async function upgradeFrom_001_to_002( projectInfo: storageProject.ProjectInfo): Promise { // Modules were saved without private components. // The Robot's mrc_mechanism_component_holder block was saved without hidePrivateComponents. - const projectFileNames: string[] = await storage.list( - storageNames.makeProjectDirectoryPath(projectName)); - for (const projectFileName of projectFileNames) { - const modulePath = storageNames.makeFilePath(projectName, projectFileName); - let moduleContentText = await storage.fetchFileContentText(modulePath); - - // Add private components to the module content. - moduleContentText = storageModuleContent.addPrivateComponents(moduleContentText); - - if (storageNames.getModuleType(modulePath) === storageModule.ModuleType.ROBOT) { - // If this module is the robot, hide the private components part of the - // mrc_mechanism_component_holder block. - const moduleContent = storageModuleContent.parseModuleContentText(moduleContentText); - let blocks = moduleContent.getBlocks(); - - // Create a temporary workspace to upgrade the blocks. - const headlessWorkspace = workspaces.createHeadlessWorkspace(storageModule.ModuleType.ROBOT); - - try { - Blockly.serialization.workspaces.load(blocks, headlessWorkspace); - mechanismComponentHolder.hidePrivateComponents(headlessWorkspace); - blocks = Blockly.serialization.workspaces.save(headlessWorkspace); - } finally { - workspaces.destroyHeadlessWorkspace(headlessWorkspace); - } - moduleContent.setBlocks(blocks); - moduleContentText = moduleContent.getModuleContentText(); - } - - await storage.saveFile(modulePath, moduleContentText); - } + await upgradeBlocksFiles( + storage, projectName, + anyModuleType, storageModuleContent.addPrivateComponents, + isRobot, mechanismComponentHolder.hidePrivateComponents); projectInfo.version = '0.0.2'; } @@ -180,7 +182,10 @@ async function upgradeFrom_002_to_003( projectName: string, projectInfo: storageProject.ProjectInfo): Promise { // OpModes had robot as a parameter to init method. - await upgradeBlocksFiles(storage, projectName, isOpMode, upgrade_002_to_003); + await upgradeBlocksFiles( + storage, projectName, + noModuleTypes, noPreupgrade, + isOpMode, upgrade_002_to_003); projectInfo.version = '0.0.3'; } @@ -198,6 +203,9 @@ async function upgradeFrom_004_to_005( projectName: string, projectInfo: storageProject.ProjectInfo): Promise { // mrc_class_method_def blocks that return a value need to have returnType changed from 'Any' to ''. - await upgradeBlocksFiles(storage, projectName, anyModuleType, upgrade_004_to_005); + await upgradeBlocksFiles( + storage, projectName, + noModuleTypes, noPreupgrade, + anyModuleType, upgrade_004_to_005); projectInfo.version = '0.0.5'; } From 84df4d391644cbed7445f671ecff1d1f36d5bfa5 Mon Sep 17 00:00:00 2001 From: Liz Looney Date: Thu, 6 Nov 2025 23:40:19 -0800 Subject: [PATCH 4/5] In mrc_mechanism_component_holder.ts: Renamed function hidePrivateComponents to upgrade_001_to_002 and added code to check that the module type is ROBOT. In module_content.ts: Renamed addPrivateComponents to preupgrade_001_to_002. In upgrade_project.ts: Updated upgradeFrom_001_to_002. --- src/blocks/mrc_mechanism_component_holder.ts | 12 +++++++++--- src/storage/module_content.ts | 6 +++--- src/storage/upgrade_project.ts | 6 +++--- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/blocks/mrc_mechanism_component_holder.ts b/src/blocks/mrc_mechanism_component_holder.ts index 0c59c273..ee71bf80 100644 --- a/src/blocks/mrc_mechanism_component_holder.ts +++ b/src/blocks/mrc_mechanism_component_holder.ts @@ -36,6 +36,7 @@ import { ComponentBlock } from './mrc_component'; import { BLOCK_NAME as MRC_EVENT_NAME } from './mrc_event'; import { OUTPUT_NAME as EVENT_OUTPUT } from './mrc_event'; import { EventBlock } from './mrc_event'; +import { getModuleTypeForWorkspace } from './utils/workspaces'; export const BLOCK_NAME = 'mrc_mechanism_component_holder'; @@ -520,13 +521,18 @@ export function mrcDescendantsMayHaveChanged(workspace: Blockly.Workspace): void } /** - * Hide private components. + * Upgrades the MechanismComponentHolderBlock in the given workspace from version 001 to 002 by + * setting mrcHidePrivateComponents to true. * This function should only be called when upgrading old projects. */ -export function hidePrivateComponents(workspace: Blockly.Workspace) { +export function upgrade_001_to_002(workspace: Blockly.Workspace) { // Make sure the workspace is headless. if (workspace.rendered) { - throw new Error('hidePrivateComponents should never be called with a rendered workspace.'); + throw new Error('upgrade_001_to_002 should never be called with a rendered workspace.'); + } + // Make sure the module type is ROBOT. + if (getModuleTypeForWorkspace(workspace) !== storageModule.ModuleType.ROBOT) { + throw new Error('upgrade_001_to_002 should only be called for a robot module.'); } workspace.getBlocksByType(BLOCK_NAME).forEach(block => { (block as MechanismComponentHolderBlock).mrcHidePrivateComponents = true; diff --git a/src/storage/module_content.ts b/src/storage/module_content.ts index 8969e774..1fa3f7ed 100644 --- a/src/storage/module_content.ts +++ b/src/storage/module_content.ts @@ -270,10 +270,10 @@ export class ModuleContent { } /** - * Add privateComponents field. - * This function should only called when upgrading old projects. + * Preupgrades the module content text by adding the privateComponents field. + * This function should only be called when upgrading old projects. */ -export function addPrivateComponents(moduleContentText: string): string { +export function preupgrade_001_to_002(moduleContentText: string): string { const parsedContent = JSON.parse(moduleContentText); if (!('privateComponents' in parsedContent)) { parsedContent.privateComponents = []; diff --git a/src/storage/upgrade_project.ts b/src/storage/upgrade_project.ts index 49adc787..e85bd084 100644 --- a/src/storage/upgrade_project.ts +++ b/src/storage/upgrade_project.ts @@ -22,12 +22,12 @@ import * as semver from 'semver'; import * as Blockly from 'blockly/core'; -import * as mechanismComponentHolder from '../blocks/mrc_mechanism_component_holder'; import * as commonStorage from './common_storage'; import * as storageModule from './module'; import * as storageModuleContent from './module_content'; import * as storageNames from './names'; import * as storageProject from './project'; +import { upgrade_001_to_002 } from '../blocks/mrc_mechanism_component_holder'; import { upgrade_002_to_003, upgrade_004_to_005 } from '../blocks/mrc_class_method_def'; import * as workspaces from '../blocks/utils/workspaces'; @@ -172,8 +172,8 @@ async function upgradeFrom_001_to_002( // The Robot's mrc_mechanism_component_holder block was saved without hidePrivateComponents. await upgradeBlocksFiles( storage, projectName, - anyModuleType, storageModuleContent.addPrivateComponents, - isRobot, mechanismComponentHolder.hidePrivateComponents); + anyModuleType, storageModuleContent.preupgrade_001_to_002, + isRobot, upgrade_001_to_002); projectInfo.version = '0.0.2'; } From 9602df4ab08291be3aabc807c1a3b59a7b9c832e Mon Sep 17 00:00:00 2001 From: Liz Looney Date: Fri, 7 Nov 2025 20:16:20 -0800 Subject: [PATCH 5/5] Removed code that checks that the workspace is headless in upgrade functions. --- src/blocks/mrc_class_method_def.ts | 8 -------- src/blocks/mrc_mechanism_component_holder.ts | 4 ---- 2 files changed, 12 deletions(-) diff --git a/src/blocks/mrc_class_method_def.ts b/src/blocks/mrc_class_method_def.ts index 7a184e79..7e314cbb 100644 --- a/src/blocks/mrc_class_method_def.ts +++ b/src/blocks/mrc_class_method_def.ts @@ -623,10 +623,6 @@ export function getMethodNamesAlreadyOverriddenInWorkspace( * This function should only be called when upgrading old projects. */ export function upgrade_002_to_003(workspace: Blockly.Workspace): void { - // Make sure the workspace is headless. - if (workspace.rendered) { - throw new Error('upgrade_002_to_003 should never be called with a rendered workspace.'); - } workspace.getBlocksByType(BLOCK_NAME).forEach(block => { (block as ClassMethodDefBlock).upgrade_002_to_003(); }); @@ -637,10 +633,6 @@ export function upgrade_002_to_003(workspace: Blockly.Workspace): void { * This function should only be called when upgrading old projects. */ export function upgrade_004_to_005(workspace: Blockly.Workspace): void { - // Make sure the workspace is headless. - if (workspace.rendered) { - throw new Error('upgrade_004_to_005 should never be called with a rendered workspace.'); - } workspace.getBlocksByType(BLOCK_NAME).forEach(block => { (block as ClassMethodDefBlock).upgrade_004_to_005(); }); diff --git a/src/blocks/mrc_mechanism_component_holder.ts b/src/blocks/mrc_mechanism_component_holder.ts index ee71bf80..9c7c70b7 100644 --- a/src/blocks/mrc_mechanism_component_holder.ts +++ b/src/blocks/mrc_mechanism_component_holder.ts @@ -526,10 +526,6 @@ export function mrcDescendantsMayHaveChanged(workspace: Blockly.Workspace): void * This function should only be called when upgrading old projects. */ export function upgrade_001_to_002(workspace: Blockly.Workspace) { - // Make sure the workspace is headless. - if (workspace.rendered) { - throw new Error('upgrade_001_to_002 should never be called with a rendered workspace.'); - } // Make sure the module type is ROBOT. if (getModuleTypeForWorkspace(workspace) !== storageModule.ModuleType.ROBOT) { throw new Error('upgrade_001_to_002 should only be called for a robot module.');