@@ -206,12 +206,13 @@ export class Resource extends Referenceable {
206
206
*/
207
207
public toCloudFormation ( ) : object {
208
208
try {
209
- if ( Resource . isTaggable ( this ) ) {
210
- const tags = this . tags . renderTags ( ) ;
211
- this . properties . tags = tags === undefined ? this . properties . tags : tags ;
212
- }
213
209
// merge property overrides onto properties and then render (and validate).
214
- const properties = this . renderProperties ( deepMerge ( this . properties || { } , this . untypedPropertyOverrides ) ) ;
210
+ const tags = Resource . isTaggable ( this ) ? this . tags . renderTags ( ) : undefined ;
211
+ const properties = this . renderProperties ( deepMerge (
212
+ this . properties || { } ,
213
+ { tags } ,
214
+ this . untypedPropertyOverrides
215
+ ) ) ;
215
216
216
217
return {
217
218
Resources : {
@@ -254,7 +255,6 @@ export class Resource extends Referenceable {
254
255
protected renderProperties ( properties : any ) : { [ key : string ] : any } {
255
256
return properties ;
256
257
}
257
-
258
258
}
259
259
260
260
export enum TagType {
@@ -312,33 +312,35 @@ export interface ResourceOptions {
312
312
* Merges `source` into `target`, overriding any existing values.
313
313
* `null`s will cause a value to be deleted.
314
314
*/
315
- export function deepMerge ( target : any , source : any ) {
316
- if ( typeof ( source ) !== 'object' || typeof ( target ) !== 'object' ) {
317
- throw new Error ( `Invalid usage. Both source (${ JSON . stringify ( source ) } ) and target (${ JSON . stringify ( target ) } ) must be objects` ) ;
318
- }
315
+ export function deepMerge ( target : any , ...sources : any [ ] ) {
316
+ for ( const source of sources ) {
317
+ if ( typeof ( source ) !== 'object' || typeof ( target ) !== 'object' ) {
318
+ throw new Error ( `Invalid usage. Both source (${ JSON . stringify ( source ) } ) and target (${ JSON . stringify ( target ) } ) must be objects` ) ;
319
+ }
319
320
320
- for ( const key of Object . keys ( source ) ) {
321
- const value = source [ key ] ;
322
- if ( typeof ( value ) === 'object' && value != null && ! Array . isArray ( value ) ) {
323
- // if the value at the target is not an object, override it with an
324
- // object so we can continue the recursion
325
- if ( typeof ( target [ key ] ) !== 'object' ) {
326
- target [ key ] = { } ;
327
- }
321
+ for ( const key of Object . keys ( source ) ) {
322
+ const value = source [ key ] ;
323
+ if ( typeof ( value ) === 'object' && value != null && ! Array . isArray ( value ) ) {
324
+ // if the value at the target is not an object, override it with an
325
+ // object so we can continue the recursion
326
+ if ( typeof ( target [ key ] ) !== 'object' ) {
327
+ target [ key ] = { } ;
328
+ }
328
329
329
- deepMerge ( target [ key ] , value ) ;
330
+ deepMerge ( target [ key ] , value ) ;
330
331
331
- // if the result of the merge is an empty object, it's because the
332
- // eventual value we assigned is `undefined`, and there are no
333
- // sibling concrete values alongside, so we can delete this tree.
334
- const output = target [ key ] ;
335
- if ( typeof ( output ) === 'object' && Object . keys ( output ) . length === 0 ) {
332
+ // if the result of the merge is an empty object, it's because the
333
+ // eventual value we assigned is `undefined`, and there are no
334
+ // sibling concrete values alongside, so we can delete this tree.
335
+ const output = target [ key ] ;
336
+ if ( typeof ( output ) === 'object' && Object . keys ( output ) . length === 0 ) {
337
+ delete target [ key ] ;
338
+ }
339
+ } else if ( value === undefined ) {
336
340
delete target [ key ] ;
341
+ } else {
342
+ target [ key ] = value ;
337
343
}
338
- } else if ( value === undefined ) {
339
- delete target [ key ] ;
340
- } else {
341
- target [ key ] = value ;
342
344
}
343
345
}
344
346
0 commit comments