@@ -22,6 +22,10 @@ const { MetaModelNamespace } = require('@accordproject/concerto-metamodel');
2222const semver = require ( 'semver' ) ;
2323const DecoratorExtractor = require ( './decoratorextractor' ) ;
2424const { Warning, ErrorCodes } = require ( '@accordproject/concerto-util' ) ;
25+ const rfdc = require ( 'rfdc' ) ( {
26+ circles : true ,
27+ proto : false ,
28+ } ) ;
2529
2630// Types needed for TypeScript generation.
2731/* eslint-disable no-unused-vars */
@@ -349,9 +353,8 @@ class DecoratorManager {
349353 * @private
350354 */
351355 static pushMapValues ( array , map , key ) {
352- const targetCommands = map . get ( key ) ;
353- if ( targetCommands ) {
354- array . push ( ...targetCommands ) ;
356+ for ( const value of map . get ( key ) || [ ] ) {
357+ array . push ( value ) ;
355358 }
356359 }
357360
@@ -375,7 +378,7 @@ class DecoratorManager {
375378
376379 // we create synthetic imports for all decorator declarations
377380 // along with any of their type reference arguments
378- const decoratorImports = decoratorCommandSet . commands . map ( command => {
381+ const decoratorImports = decoratorCommandSet . commands . flatMap ( command => {
379382 return [ {
380383 $class : `${ MetaModelNamespace } .ImportType` ,
381384 name : command . decorator . name ,
@@ -389,21 +392,21 @@ class DecoratorManager {
389392 } ;
390393 } )
391394 : [ ] ) ;
392- } ) . flat ( ) . filter ( i => i . namespace ) ;
395+ } ) . filter ( i => i . namespace ) ;
393396 const { namespaceCommandsMap, declarationCommandsMap, propertyCommandsMap, mapElementCommandsMap, typeCommandsMap } = this . getDecoratorMaps ( decoratorCommandSet ) ;
394397 const ast = modelManager . getAst ( true , true ) ;
395- const decoratedAst = JSON . parse ( JSON . stringify ( ast ) ) ;
398+ const decoratedAst = rfdc ( ast ) ;
396399 decoratedAst . models . forEach ( ( model ) => {
397400 // remove the imports for types defined in this namespace
398401 const neededImports = decoratorImports . filter ( i => i . namespace !== model . namespace ) ;
399402 // add the imports for decorators, in case they get added below
400403 model . imports = model . imports ? model . imports . concat ( neededImports ) : neededImports ;
404+ const namespaceName = ModelUtil . parseNamespace ( model . namespace ) . name ;
401405 model . declarations . forEach ( ( decl ) => {
402406 const declarationDecoratorCommandSets = [ ] ;
403407 const { name : declarationName , $class : $classForDeclaration } = decl ;
404408 this . pushMapValues ( declarationDecoratorCommandSets , declarationCommandsMap , declarationName ) ;
405409 this . pushMapValues ( declarationDecoratorCommandSets , namespaceCommandsMap , model . namespace ) ;
406- const namespaceName = ModelUtil . parseNamespace ( model . namespace ) . name ;
407410 this . pushMapValues ( declarationDecoratorCommandSets , namespaceCommandsMap , namespaceName ) ;
408411 this . pushMapValues ( declarationDecoratorCommandSets , typeCommandsMap , $classForDeclaration ) ;
409412 const sortedDeclarationDecoratorCommandSets = declarationDecoratorCommandSets . sort ( ( declDcs1 , declDcs2 ) => declDcs1 . getIndex ( ) - declDcs2 . getIndex ( ) ) ;
0 commit comments