Files
blockly/core/variable_model.ts
T
Beka Westberg 29e1f0cb03 fix: tsc errors picked up from develop (#6224)
* fix: relative path for deprecation utils

* fix: checking if properties exist in svg_math

* fix: set all timeout PIDs to AnyDuringMigration

* fix: make nullability errors explicity in block drag surface

* fix: make null check in events_block_change explicit

* fix: make getEventWorkspace_ internal so we can access it from CommentCreateDeleteHelper

* fix: rename DIV -> containerDiv in tooltip

* fix: ignore backwards compat check in category

* fix: set block styles to AnyDuringMigration

* fix: type typo in KeyboardShortcut

* fix: constants name in row measurables

* fix: typecast in mutator

* fix: populateProcedures type of flattened array

* fix: ignore errors related to workspace comment deserialization

* chore: format files

* fix: renaming imports missing file extensions

* fix: remove check for sound.play

* fix: temporarily remove bad requireType.

All `export type` statements are stripped when tsc is run. This means
that when we attempt to require BlockDefinition from the block files, we
get an error because it does not exist.

We decided to temporarily remove the require, because this will no
longer be a problem when we conver the blocks to typescript, and
everything gets compiled together.

* fix: bad jsdoc in array

* fix: silence missing property errors

Closure was complaining about inexistant properties, but they actually
do exist, they're just not being transpiled by tsc in a way that closure
understands.

I.E. if things are initialized in a function called by the constructor,
rather than in a class field or in the custructor itself, closure would
error.

It would also error on enums, because they are transpiled to a weird
IIFE.

* fix: context menu action handler not knowing the type of this.

this: TypeX information gets stripped when tsc is run, so closure could
not know that this was not global. Fixed this by reorganizing to use the
option object directly instead of passing it to onAction to be bound to
this.

* fix: readd getDeveloperVars checks (should not be part of migration)

This was found because ALL_DEVELOPER_VARS_WARNINGS_BY_BLOCK_TYPE was no
longer being accessed.

* fix: silence closure errors about overriding supertype props

We propertly define the overrides in typescript, but these get removed
from the compiled output, so closure doesn't know they exist.

* fix: silence globalThis errors

this: TypeX annotations get stripped from the compiled output, so
closure can't know that we're accessing the correct things. However,
typescript makes sure that this always has the correct properties, so
silencing this should be fine.

* fix: bad jsdoc name

* chore: attempt compiling with blockly.js

* fix: attempt moving the import statement above the namespace line

* chore: add todo comments to block def files

* chore: remove todo from context menu

* chore: add comments abotu disabled errors
2022-06-27 09:25:56 -07:00

84 lines
2.5 KiB
TypeScript

/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @fileoverview Components for the variable model.
*/
/**
* Components for the variable model.
* @class
*/
import * as goog from '../closure/goog/goog.js';
goog.declareModuleId('Blockly.VariableModel');
// Unused import preserved for side-effects. Remove if unneeded.
import './events/events_var_create.js';
import * as eventUtils from './events/utils.js';
import * as idGenerator from './utils/idgenerator.js';
/* eslint-disable-next-line no-unused-vars */
import {Workspace} from './workspace.js';
/**
* Class for a variable model.
* Holds information for the variable including name, ID, and type.
* @see {Blockly.FieldVariable}
* @alias Blockly.VariableModel
*/
export class VariableModel {
type: string;
private readonly id_: string;
/**
* @param workspace The variable's workspace.
* @param name The name of the variable. This is the user-visible name (e.g.
* 'my var' or '私の変数'), not the generated name.
* @param opt_type The type of the variable like 'int' or 'string'.
* Does not need to be unique. Field_variable can filter variables based
* on their type. This will default to '' which is a specific type.
* @param opt_id The unique ID of the variable. This will default to a UUID.
*/
constructor(
public workspace: Workspace, public name: string, opt_type?: string,
opt_id?: string) {
/**
* The type of the variable, such as 'int' or 'sound_effect'. This may be
* used to build a list of variables of a specific type. By default this is
* the empty string '', which is a specific type.
* @see {Blockly.FieldVariable}
*/
this.type = opt_type || '';
/**
* A unique ID for the variable. This should be defined at creation and
* not change, even if the name changes. In most cases this should be a
* UUID.
*/
this.id_ = opt_id || idGenerator.genUid();
eventUtils.fire(new (eventUtils.get(eventUtils.VAR_CREATE))!(this));
}
/** @return The ID for the variable. */
getId(): string {
return this.id_;
}
/**
* A custom compare function for the VariableModel objects.
* @param var1 First variable to compare.
* @param var2 Second variable to compare.
* @return -1 if name of var1 is less than name of var2, 0 if equal, and 1 if
* greater.
* @internal
*/
static compareByName(var1: VariableModel, var2: VariableModel): number {
return var1.name.localeCompare(var2.name, undefined, {sensitivity: 'base'});
}
}