@@ -58,32 +58,29 @@ export function mergeBaseModel(model: Model) {
5858 . forEach ( ( decl ) => {
5959 const dataModel = decl as DataModel ;
6060
61- dataModel . superTypes . forEach ( ( superType ) => {
62- const superTypeDecl = superType . ref ;
63- if ( superTypeDecl ) {
64- superTypeDecl . fields . forEach ( ( field ) => {
65- const cloneField = Object . assign ( { } , field ) ;
66- const mutable = cloneField as Mutable < AstNode > ;
67- // update container
68- mutable . $container = dataModel ;
69- dataModel . fields . push ( mutable as DataModelField ) ;
70- } ) ;
71-
72- superTypeDecl . attributes . forEach ( ( attr ) => {
73- const cloneAttr = Object . assign ( { } , attr ) ;
74- const mutable = cloneAttr as Mutable < AstNode > ;
75- // update container
76- mutable . $container = dataModel ;
77- dataModel . attributes . push ( mutable as DataModelAttribute ) ;
78- } ) ;
79- }
80- } ) ;
61+ dataModel . fields = dataModel . superTypes
62+ . flatMap ( ( superType ) => updateContainer ( superType . ref ! . fields , dataModel ) )
63+ . concat ( dataModel . fields ) ;
64+
65+ dataModel . attributes = dataModel . superTypes
66+ . flatMap ( ( superType ) => updateContainer ( superType . ref ! . attributes , dataModel ) )
67+ . concat ( dataModel . attributes ) ;
8168 } ) ;
8269
8370 // remove abstract models
8471 model . declarations = model . declarations . filter ( ( x ) => ! ( x . $type == 'DataModel' && x . isAbstract ) ) ;
8572}
8673
74+ function updateContainer < T extends AstNode > ( nodes : T [ ] , container : AstNode ) : Mutable < T > [ ] {
75+ return nodes . map ( ( node ) => {
76+ const cloneField = Object . assign ( { } , node ) ;
77+ const mutable = cloneField as Mutable < T > ;
78+ // update container
79+ mutable . $container = container ;
80+ return mutable ;
81+ } ) ;
82+ }
83+
8784function toStaticPolicy (
8885 operation : PolicyOperationKind ,
8986 allows : DataModelAttribute [ ] ,
0 commit comments