MCPcopy Create free account
hub / github.com/aws/constructs / addChild

Method addChild

src/construct.ts:499–521  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

497 * @returns The resolved path part name of the child
498 */
499 private addChild(child: Construct, childName: string) {
500 if (this.locked) {
501
502 // special error if root is locked
503 if (!this.path) {
504 throw new Error('Cannot add children during synthesis');
505 }
506
507 throw new Error(`Cannot add children to "${this.path}" during synthesis`);
508 }
509
510 if (!this._children) {
511 this._children = {};
512 }
513
514 if (this._children[childName]) {
515 const name = this.id ?? '';
516 const typeName = this.host.constructor.name;
517 throw new Error(`There is already a Construct with name '${childName}' in ${typeName}${name.length > 0 ? ' [' + name + ']' : ''}`);
518 }
519
520 this._children[childName] = child;
521 }
522}
523
524/**

Callers 1

constructorMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected