Home > ts-morph-structures > ClassFieldStatementsMap
This is a map for specifying statements across several class members for a single class field.
For example, a field may require statements for: - defining a getter and/or a setter - initializing in a constructor - implementing a .toJSON() method
The field name specifies which field the statements are about. The statement group specifies where the statements go (what method, or an initializer).
Special field keys: ClassFieldStatementsMap.FIELD_HEAD_SUPER_CALL: These statements will appear at the head of the statement block. ClassFieldStatementsMap.FIELD_TAIL_FINAL_RETURN: These statements will appear at the tail of the statement block.
Special statement group keys: ClassFieldStatementsMap.GROUP_INITIALIZER_OR_PROPERTY: This represents an initializer for a property, or a value reference for a getter or setter. Field keys will have get
or set
stripped from them for this group key. Statement arrays for this group key should contain exactly one statement, and should be just a string.
Signature:
export default class ClassFieldStatementsMap
map.set("foo", ClassFieldStatementsMap.GROUP_INITIALIZER_OR_PROPERTY, ['this.#foo.value']);
map.set("foo", "toJSON", ["rv.foo = this.foo;"]);
// ...
map.set(ClassFieldsStatementsMap.FIELD_HEAD_SUPER_CALL, "toJSON", ["const rv = super.toJSON();"]);
map.set(ClassFieldsStatementsMap.FIELD_TAIL_FINAL_RETURN, "toJSON", ["return rv;"]);
Array.from(map.groupStatementsMap("toJSON")!.values())
// [["const rv = super.toJSON();"], ["rv.foo = this.foo;"], ["return rv;"]];
Constructor | Modifiers | Description |
---|---|---|
(constructor)(iterable) | Constructs a new instance of the ClassFieldStatementsMap class |
Property | Modifiers | Type | Description |
---|---|---|---|
[Symbol.toStringTag] | string | ||
FIELD_HEAD_SUPER_CALL | <p>static </p><p>readonly </p> |
(not declared) | A special field name for the start of a function. |
FIELD_TAIL_FINAL_RETURN | <p>static </p><p>readonly </p> |
(not declared) | A special field name for the end of a function. |
GROUP_INITIALIZER_OR_PROPERTY | <p>static </p><p>readonly </p> |
(not declared) | |
isBlockStatement | boolean | ||
purposeKey? | string | (Optional) | |
regionName? | string | (Optional) | |
size | readonly |
number | The number of elements in this collection. |
Method | Modifiers | Description |
---|---|---|
[Symbol.iterator]() | ||
clear() | Clear the collection. | |
delete(fieldName, statementGroup) | Delete an element from the collection by the given key sequence. | |
entries() | Yield the key-statements tuples of the collection. | |
fieldComparator(a, b) | static |
A convenience sorting function for fields. |
forEach(__callback__, __thisArg__) | Iterate over the keys and statementss. | |
get(fieldName, statementGroup) | Get a statements for a key set. | |
groupKeys() | ||
groupStatementsMap(statementGroup) | Get the current set of statements for each statement group, sorted by field name. | |
has(fieldName, statementGroup) | Report if the collection has a statements for a key set. | |
keys() | Yield the key sets of the collection. | |
normalizeKeys(fieldName, statementGroup) | static |
|
set(fieldName, statementGroup, statements) | Set a statements for a key set. | |
values() | Yield the statementss of the collection. |