Blockly. Names
Constructor
Names
new Names(reservedWords, opt_variablePrefix)
Class for a database of entity names (variables, functions, etc).
Parameter |
|
---|---|
reservedWords |
string A comma-separated string of words that are illegal for use as names in a language (e.g. 'new,if,this,...'). |
opt_variablePrefix |
Optional string Some languages need a '$' or a namespace before all variable names. |
Property
DEVELOPER_VARIABLE_TYPE
Constant to separate developer variable names from user-defined variable names when running generators. A developer variable will be declared as a global in the generated code, but will never be shown to the user in the workspace or stored in the variable map.
Methods
equals
equals(name1, name2) returns boolean
Do the given two entity names refer to the same entity? Blockly names are case-insensitive.
Parameter |
|
---|---|
name1 |
string First name. |
name2 |
string Second name. |
- Returns
-
boolean
True if names are the same.
getDistinctName
getDistinctName(name, type) returns string
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.
Parameter |
|
---|---|
name |
string The Blockly entity name (no constraints). |
type |
string The type of entity in Blockly ('VARIABLE', 'PROCEDURE', 'BUILTIN', etc...). |
- Returns
-
string
An entity name that is legal in the exported language.
getName
getName(name, type) returns string
Convert a Blockly entity name to a legal exportable entity name.
Parameter |
|
---|---|
name |
string The Blockly entity name (no constraints). |
type |
string The type of entity in Blockly ('VARIABLE', 'PROCEDURE', 'BUILTIN', etc...). |
- Returns
-
string
An entity name that is legal in the exported language.
reset
reset()
Empty the database and start from scratch. The reserved words are kept.
setVariableMap
setVariableMap(map)
Set the variable map that maps from variable name to variable object.
Parameter |
|
---|---|
map |
The map to track. Value must not be null. |