* 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)
| 470 | * @returns The resolved path part name of the child |
| 471 | */ |
| 472 | private addChild(child: Construct, childName: string) { |
| 473 | if (this.locked) { |
| 474 | |
| 475 | // special error if root is locked |
| 476 | if (!this.path) { |
| 477 | throw new Error('Cannot add children during synthesis'); |
| 478 | } |
| 479 | |
| 480 | throw new Error(`Cannot add children to "${this.path}" during synthesis`); |
| 481 | } |
| 482 | |
| 483 | if (!this._children) { |
| 484 | this._children = {}; |
| 485 | } |
| 486 | |
| 487 | if (this._children[childName]) { |
| 488 | const name = this.id ?? ''; |
| 489 | const typeName = this.host.constructor.name; |
| 490 | throw new Error(`There is already a Construct with name '${childName}' in ${typeName}${name.length > 0 ? ' [' + name + ']' : ''}`); |
| 491 | } |
| 492 | |
| 493 | this._children[childName] = child; |
| 494 | } |
| 495 | } |
| 496 | |
| 497 | /** |