@@ -212,8 +212,9 @@ const DIRECTIVE_INTERVAL = {
212212
213213class VersionedTypedefNode < T > implements Iterable < [ ValidFor , T ] > {
214214 constructor (
215- public vBase ?: T ,
216- public vOverride ?: T ,
215+ public vBase : T | undefined ,
216+ public vOverride : T | undefined ,
217+ readonly allowSharing : boolean
217218 ) { }
218219
219220 * [ Symbol . iterator ] ( ) : Iterator < [ ValidFor , T ] > {
@@ -223,20 +224,29 @@ class VersionedTypedefNode<T> implements Iterable<[ValidFor, T]> {
223224 } else if ( this . vOverride != null ) {
224225 yield [ ValidFor . PoE2 , this . vOverride ] ;
225226 } else if ( this . vBase != null ) {
226- yield [ ValidFor . Common , this . vBase ] ;
227+ if ( this . allowSharing ) {
228+ yield [ ValidFor . Common , this . vBase ] ;
229+ } else {
230+ yield [ ValidFor . PoE1 , this . vBase ] ;
231+ }
227232 }
228233 }
229234}
230235
231236class VersionedTypedefMap < T extends TypeDefinitionNode > {
232237 readonly data = new Map < string , VersionedTypedefNode < T > > ( ) ;
233238
239+ constructor (
240+ readonly allowSharing : boolean
241+ ) { }
242+
234243 add ( typeNode : T , override : boolean ) : boolean {
235244 const existingNode = this . data . get ( typeNode . name . value ) ;
236245 if ( ! existingNode ) {
237246 this . data . set ( typeNode . name . value , new VersionedTypedefNode (
238247 ! override ? typeNode : undefined ,
239248 override ? typeNode : undefined ,
249+ this . allowSharing
240250 ) ) ;
241251 } else if ( override ) {
242252 if ( existingNode . vOverride != null ) return false ;
@@ -265,7 +275,11 @@ class ScopedTypedefMap<T> {
265275 if ( this . ver === ValidFor . PoE1 ) {
266276 return node . vBase ;
267277 } else {
268- return node . vOverride ?? node . vBase ;
278+ if ( node . allowSharing ) {
279+ return node . vOverride ?? node . vBase ;
280+ } else {
281+ return node . vOverride ;
282+ }
269283 }
270284 }
271285 }
@@ -281,10 +295,11 @@ interface Context {
281295}
282296
283297export function readSchemaSources (
284- sources : readonly Source [ ]
298+ sources : readonly Source [ ] ,
299+ allowSharingSchemas : boolean
285300) : Pick < SchemaFile , 'tables' | 'enumerations' > {
286- const typeDefsMap = new VersionedTypedefMap < ObjectTypeDefinitionNode > ( ) ;
287- const enumDefsMap = new VersionedTypedefMap < EnumTypeDefinitionNode > ( ) ;
301+ const typeDefsMap = new VersionedTypedefMap < ObjectTypeDefinitionNode > ( allowSharingSchemas ) ;
302+ const enumDefsMap = new VersionedTypedefMap < EnumTypeDefinitionNode > ( allowSharingSchemas ) ;
288303
289304 for ( const source of sources ) {
290305 const doc = parse ( source , { noLocation : false } ) ;
0 commit comments