File tree Expand file tree Collapse file tree
codegen-core/src/__tests__
shared/src/plugins/shared/utils Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -106,4 +106,22 @@ describe('SymbolRegistry', () => {
106106 const result = r . query ( meta ( { a : { b : { c : 123 } } } ) ) ;
107107 expect ( result ) . toEqual ( [ a ] ) ;
108108 } ) ;
109+
110+ it ( 'query() returns all symbols sharing the same meta but with different names' , ( ) => {
111+ const r = new SymbolRegistry ( ) ;
112+
113+ const sharedMeta = meta ( { category : 'external' , resource : '@shared/types' } ) ;
114+
115+ const a = r . register ( { meta : sharedMeta , name : 'CustomNumber' } ) ;
116+ const b = r . register ( { meta : sharedMeta , name : 'FlakeIdString' } ) ;
117+
118+ const results = r . query ( sharedMeta ) ;
119+ expect ( results ) . toHaveLength ( 2 ) ;
120+ expect ( results ) . toContain ( a ) ;
121+ expect ( results ) . toContain ( b ) ;
122+
123+ // filtering by name correctly identifies each symbol independently
124+ expect ( results . find ( ( s ) => s . name === 'CustomNumber' ) ) . toBe ( a ) ;
125+ expect ( results . find ( ( s ) => s . name === 'FlakeIdString' ) ) . toBe ( b ) ;
126+ } ) ;
109127} ) ;
Original file line number Diff line number Diff line change @@ -399,7 +399,8 @@ export class PluginInstance<T extends Plugin.Types = Plugin.Types> {
399399
400400 /**
401401 * Registers a symbol only if it does not already exist based on the provided
402- * metadata. This prevents duplicate symbols from being created in the project.
402+ * name and metadata. This prevents duplicate symbols from being created in
403+ * the project.
403404 */
404405 symbolOnce ( name : SymbolIn [ 'name' ] , symbol ?: Omit < SymbolIn , 'name' > ) : Symbol {
405406 const meta = {
@@ -409,7 +410,7 @@ export class PluginInstance<T extends Plugin.Types = Plugin.Types> {
409410 meta . category = 'external' ;
410411 meta . resource = symbol . external ;
411412 }
412- const existing = this . querySymbol ( meta ) ;
413+ const existing = this . gen . symbols . query ( meta ) . find ( ( s ) => s . name === name ) ;
413414 if ( existing ) return existing ;
414415 return this . symbol ( name , { ...symbol , meta } ) ;
415416 }
You can’t perform that action at this time.
0 commit comments