Skip to content

Commit

Permalink
revert some change
Browse files Browse the repository at this point in the history
  • Loading branch information
Elad Ben-Israel committed Apr 6, 2020
1 parent cc6b168 commit 344ede2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 26 deletions.
26 changes: 1 addition & 25 deletions packages/@aws-cdk/core/lib/cfn-element.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as cxapi from '@aws-cdk/cx-api';
import { Construct, IConstruct } from "./construct-compat";
import { Construct } from "./construct-compat";
import { Lazy } from "./lazy";
import { Token } from './token';

Expand All @@ -22,30 +22,6 @@ export abstract class CfnElement extends Construct {
return CFN_ELEMENT_SYMBOL in x;
}

/**
* Finds all CfnElements in a scope (does not recurse into sub-stacks).
*
* @param node Root node to collect all CfnElements from
* @param into Array to append CfnElements to
* @returns The same array as is being collected into
*
* @internal
*/
public static _findAll(node: IConstruct, into: CfnElement[] = []): CfnElement[] {
if (CfnElement.isCfnElement(node)) {
into.push(node);
}

for (const child of node.node.children) {
// Don't recurse into a substack
if (Stack.isStack(child)) { continue; }

this._findAll(child, into);
}

return into;
}

/**
* The logical ID for this CloudFormation stack element. The logical ID of the element
* is calculated from the path of the resource node in the construct tree.
Expand Down
24 changes: 23 additions & 1 deletion packages/@aws-cdk/core/lib/stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ export class Stack extends Construct implements ITaggable {
Metadata: this.templateOptions.metadata
};

const elements = CfnElement._findAll(this);
const elements = cfnElements(this);
const fragments = elements.map(e => this.resolve(e._toCloudFormation()));

// merge in all CloudFormation fragments collected from the tree
Expand Down Expand Up @@ -1001,6 +1001,28 @@ function merge(template: any, part: any) {
}
}

/**
* Collect all CfnElements from a Stack.
*
* @param node Root node to collect all CfnElements from
* @param into Array to append CfnElements to
* @returns The same array as is being collected into
*/
function cfnElements(node: IConstruct, into: CfnElement[] = []): CfnElement[] {
if (CfnElement.isCfnElement(node)) {
into.push(node);
}

for (const child of node.node.children) {
// Don't recurse into a substack
if (Stack.isStack(child)) { continue; }

cfnElements(child, into);
}

return into;
}

/**
* CloudFormation template options for a stack.
*/
Expand Down

0 comments on commit 344ede2

Please sign in to comment.