@@ -6,7 +6,7 @@ import { leadingComment } from './comments';
66import type { Object , Schema } from './ir' ;
77import type { DerefFn } from './knownImports' ;
88import type { Project } from './project' ;
9- import { findSymbolInitializer , resolveLiteralOrIdentifier } from './resolveInit' ;
9+ import { findSymbolInitializer } from './resolveInit' ;
1010import type { SourceFile } from './sourceFile' ;
1111
1212import type { KnownCodec } from './knownImports' ;
@@ -181,30 +181,31 @@ function parseObjectExpression(
181181 result . required . push ( name ) ;
182182 continue ;
183183 } else if ( property . type === 'SpreadElement' ) {
184- const initE = resolveLiteralOrIdentifier ( project , source , property . arguments ) ;
185- if ( E . isLeft ( initE ) ) {
186- return initE ;
187- }
188- let [ newSourceFile , init ] = initE . right ;
189- if ( init . type === 'TsAsExpression' || init . type === 'TsConstAssertion' ) {
190- init = init . expression ;
184+ const schemaE = parsePlainInitializer ( project , source , property . arguments ) ;
185+ if ( E . isLeft ( schemaE ) ) {
186+ return schemaE ;
191187 }
192- if ( init . type !== 'ObjectExpression' ) {
193- return E . left ( 'Spread element must be object' ) ;
188+ let schema = schemaE . right ;
189+ if ( schema . type === 'ref' ) {
190+ const realInitE = findSymbolInitializer ( project , source , schema . name ) ;
191+ if ( E . isLeft ( realInitE ) ) {
192+ return realInitE ;
193+ }
194+ const schemaE = parsePlainInitializer (
195+ project ,
196+ realInitE . right [ 0 ] ,
197+ realInitE . right [ 1 ] ,
198+ ) ;
199+ if ( E . isLeft ( schemaE ) ) {
200+ return schemaE ;
201+ }
202+ schema = schemaE . right ;
194203 }
195- const valueE = parseObjectExpression (
196- project ,
197- newSourceFile ,
198- init . span . start ,
199- init ,
200- ) ;
201- if ( E . isLeft ( valueE ) ) {
202- return valueE ;
203- } else if ( valueE . right . type !== 'object' ) {
204- return E . left ( 'Spread element must be object' ) ;
204+ if ( schema . type !== 'object' ) {
205+ return E . left ( `Spread element must be object` ) ;
205206 }
206- result . properties = { ... result . properties , ... valueE . right . properties } ;
207- result . required = [ ... result . required , ... valueE . right . required ] ;
207+ Object . assign ( result . properties , schema . properties ) ;
208+ result . required . push ( ... schema . required ) ;
208209 continue ;
209210 } else if ( property . type !== 'KeyValueProperty' ) {
210211 return E . left ( `Unimplemented property type ${ property . type } ` ) ;
0 commit comments