Skip to main content

Class: Names

Defined in: packages/blockly/core/names.ts:26

Class for a database of entity names (variables, procedures, etc).

Properties index​

PropertyDescription
DEVELOPER_VARIABLE_TYPE-

Methods index​

MethodDescription
resetEmpty the database and start from scratch. The reserved words are kept.
setVariableMapSet the variable map that maps from variable name to variable object.
populateVariablesGenerate names for user variables, but only ones that are being used.
populateProceduresGenerate names for procedures.
getNameConvert a Blockly entity name to a legal exportable entity name.
getUserNamesReturn a list of all known user-created names of a specified name type.
getDistinctNameConvert a Blockly entity name to a legal exportable entity name. Ensure that this is a new name not overlapping any previously defined name. Also check against list of reserved words for the current language and ensure name doesn't collide.
equalsDo the given two entity names refer to the same entity? Blockly names are case-insensitive.

Constructors​

Constructor​

new Names(reservedWordsList, opt_variablePrefix?): Names;

Defined in: packages/blockly/core/names.ts:54

Parameters​

ParameterTypeDescription
reservedWordsListstringA comma-separated string of words that are illegal for use as names in a language (e.g. 'new,if,this,...').
opt_variablePrefix?stringSome languages need a '$' or a namespace before all variable names (but not procedure names).

Returns​

Names

Properties​

DEVELOPER_VARIABLE_TYPE​

static DEVELOPER_VARIABLE_TYPE: NameType;

Defined in: packages/blockly/core/names.ts:27

Methods​

reset()​

reset(): void;

Defined in: packages/blockly/core/names.ts:66

Empty the database and start from scratch. The reserved words are kept.

Returns​

void


setVariableMap()​

setVariableMap(map): void;

Defined in: packages/blockly/core/names.ts:77

Set the variable map that maps from variable name to variable object.

Parameters​

ParameterTypeDescription
mapIVariableMap<IVariableModel<IVariableState>>The map to track.

Returns​

void


populateVariables()​

populateVariables(workspace): void;

Defined in: packages/blockly/core/names.ts:112

Generate names for user variables, but only ones that are being used.

Parameters​

ParameterTypeDescription
workspaceWorkspaceWorkspace to generate variables from.

Returns​

void


populateProcedures()​

populateProcedures(workspace): void;

Defined in: packages/blockly/core/names.ts:125

Generate names for procedures.

Parameters​

ParameterTypeDescription
workspaceWorkspaceWorkspace to generate procedures from.

Returns​

void


getName()​

getName(nameOrId, type): string;

Defined in: packages/blockly/core/names.ts:140

Convert a Blockly entity name to a legal exportable entity name.

Parameters​

ParameterTypeDescription
nameOrIdstringThe Blockly entity name (no constraints) or variable ID.
typestringThe type of the name in Blockly ('VARIABLE', 'PROCEDURE', 'DEVELOPER_VARIABLE', etc...).

Returns​

string

An entity name that is legal in the exported language.


getUserNames()​

getUserNames(type): string[];

Defined in: packages/blockly/core/names.ts:174

Return a list of all known user-created names of a specified name type.

Parameters​

ParameterTypeDescription
typestringThe type of entity in Blockly ('VARIABLE', 'PROCEDURE', 'DEVELOPER_VARIABLE', etc...).

Returns​

string[]

A list of Blockly entity names (no constraints).


getDistinctName()​

getDistinctName(name, type): string;

Defined in: packages/blockly/core/names.ts:190

Convert a Blockly entity name to a legal exportable entity name. Ensure that this is a new name not overlapping any previously defined name. Also check against list of reserved words for the current language and ensure name doesn't collide.

Parameters​

ParameterTypeDescription
namestringThe Blockly entity name (no constraints).
typestringThe type of entity in Blockly ('VARIABLE', 'PROCEDURE', 'DEVELOPER_VARIABLE', etc...).

Returns​

string

An entity name that is legal in the exported language.


equals()​

static equals(name1, name2): boolean;

Defined in: packages/blockly/core/names.ts:240

Do the given two entity names refer to the same entity? Blockly names are case-insensitive.

Parameters​

ParameterTypeDescription
name1stringFirst name.
name2stringSecond name.

Returns​

boolean

True if names are the same.