* Adds a child construct to this node. * * @param child The child construct * @param childName The type name of the child construct. * @returns The resolved path part name of the child
(child: Construct, childName: string)
| 510 | * @returns The resolved path part name of the child |
| 511 | */ |
| 512 | private addChild(child: Construct, childName: string) { |
| 513 | if (this.locked) { |
| 514 | |
| 515 | // special error if root is locked |
| 516 | if (!this.path) { |
| 517 | throw new Error('Cannot add children during synthesis'); |
| 518 | } |
| 519 | |
| 520 | throw new Error(`Cannot add children to "${this.path}" during synthesis`); |
| 521 | } |
| 522 | |
| 523 | if (!this._children) { |
| 524 | this._children = {}; |
| 525 | } |
| 526 | |
| 527 | if (this._children[childName]) { |
| 528 | const name = this.id ?? ''; |
| 529 | const typeName = this.host.constructor.name; |
| 530 | throw new Error(`There is already a Construct with name '${childName}' in ${typeName}${name.length > 0 ? ' [' + name + ']' : ''}`); |
| 531 | } |
| 532 | |
| 533 | this._children[childName] = child; |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | /** |