diff --git a/core/variable_map.ts b/core/variable_map.ts index 45f562618..7ef809b53 100644 --- a/core/variable_map.ts +++ b/core/variable_map.ts @@ -44,10 +44,18 @@ export class VariableMap { /** @param workspace The workspace this map belongs to. */ constructor(public workspace: Workspace) {} - /** Clear the variable map. */ + /** Clear the variable map. Fires events for every deletion. */ clear() { - this.variableMap.clear(); + for (const variables of this.variableMap.values()) { + while (variables.length > 0) { + this.deleteVariable(variables[0]); + } + } + if (this.variableMap.size !== 0) { + throw Error('Non-empty variable map'); + } } + /* Begin functions for renaming variables. */ /** * Rename the given variable by updating its name in the variable map. @@ -142,6 +150,7 @@ export class VariableMap { // And remove it from the list. arrayUtils.removeElem(this.variableMap.get(type)!, variable); } + /* End functions for renaming variables. */ /** * Create a variable with a given name, optional type, and optional ID. @@ -187,6 +196,7 @@ export class VariableMap { return variable; } + /* Begin functions for variable deletion. */ /** * Delete a variable. @@ -203,6 +213,9 @@ export class VariableMap { variableList.splice(i, 1); eventUtils.fire( new (eventUtils.get(eventUtils.VAR_DELETE))(variable)); + if (variableList.length === 0) { + this.variableMap.delete(variable.type); + } return; } } @@ -306,7 +319,7 @@ export class VariableMap { * @returns The variable with the given ID. */ getVariableById(id: string): VariableModel|null { - for (const [_key, variables] of this.variableMap) { + for (const variables of this.variableMap.values()) { for (const variable of variables) { if (variable.getId() === id) { return variable; diff --git a/scripts/gulpfiles/release_tasks.js b/scripts/gulpfiles/release_tasks.js index 58717985c..5a0eb9f0e 100644 --- a/scripts/gulpfiles/release_tasks.js +++ b/scripts/gulpfiles/release_tasks.js @@ -102,7 +102,7 @@ function checkReleaseDir(done) { // Check with the user that the version number is correct, then login and publish to npm. function loginAndPublish_(done, isBeta) { const { version } = getPackageJson(); - if(readlineSync.keyInYN(`You are about to publish blockly with the version number:${version}. Do you want to continue?`)) { + if (readlineSync.keyInYN(`You are about to publish blockly with the version number:${version}. Do you want to continue?`)) { execSync(`npm login --registry https://wombat-dressing-room.appspot.com`, {stdio: 'inherit'}); execSync(`npm publish --registry https://wombat-dressing-room.appspot.com ${isBeta ? '--tag beta' : ''}`, {cwd: RELEASE_DIR, stdio: 'inherit'}); done(); @@ -129,7 +129,7 @@ function updateBetaVersion(done) { const blocklyVersions = JSON.parse(execSync('npm view blockly versions --json').toString()); const re = new RegExp(/-beta\.(\d)/); const latestBetaVersion = execSync('npm show blockly version --tag beta').toString().trim(); - while(!isValid) { + while (!isValid) { newVersion = readlineSync.question(`What is the new beta version? (latest beta version: ${latestBetaVersion})`); const existsOnNpm = blocklyVersions.indexOf(newVersion) > -1; const isFormatted = newVersion.search(re) > -1;