File tree Expand file tree Collapse file tree 2 files changed +55
-1
lines changed
packages/openapi-ts/src/generate Expand file tree Collapse file tree 2 files changed +55
-1
lines changed Original file line number Diff line number Diff line change
1
+ import { describe , expect , it } from 'vitest' ;
2
+
3
+ import { TypeScriptRenderer } from '../renderer' ;
4
+
5
+ describe ( 'TypeScriptRenderer' , ( ) => {
6
+ describe ( 'default import placeholder replacement' , ( ) => {
7
+ it ( 'should replace placeholders in default imports correctly' , ( ) => {
8
+ const renderer = new TypeScriptRenderer ( ) ;
9
+
10
+ // Create a mock project with symbols that have placeholders
11
+ const project = {
12
+ symbolIdToFiles : ( ) => [ ] ,
13
+ symbols : new Map ( ) ,
14
+ } as any ;
15
+
16
+ // Create a symbol with a placeholder
17
+ const symbolId = 95 ;
18
+ const symbol = {
19
+ id : symbolId ,
20
+ name : 'foo' ,
21
+ placeholder : '_heyapi_95_' ,
22
+ } ;
23
+ project . symbols . set ( symbolId , symbol ) ;
24
+
25
+ // Create a mock file
26
+ const file = {
27
+ resolvedNames : new Map ( [ [ symbolId , 'foo' ] ] ) ,
28
+ } as any ;
29
+
30
+ // Create bindings with a default import that has a placeholder
31
+ const bindings = new Map ( ) ;
32
+ bindings . set ( 'foo' , {
33
+ aliases : { } ,
34
+ defaultBinding : '_heyapi_95_' , // Contains placeholder that should be replaced
35
+ from : 'foo' ,
36
+ names : [ ] ,
37
+ typeNames : [ ] ,
38
+ } ) ;
39
+
40
+ // Generate import lines
41
+ const importLines = renderer [ 'getImportLines' ] ( bindings , file , project ) ;
42
+
43
+ // The import should use 'foo' not '_heyapi_95_'
44
+ expect ( importLines ) . toEqual ( [ "import foo from 'foo';" ] ) ;
45
+ } ) ;
46
+ } ) ;
47
+ } ) ;
Original file line number Diff line number Diff line change @@ -281,7 +281,14 @@ export class TypeScriptRenderer implements Renderer {
281
281
let isTypeOnly = false ;
282
282
283
283
if ( value . defaultBinding ) {
284
- defaultBinding = tsc . identifier ( { text : value . defaultBinding } ) ;
284
+ const processedDefaultBinding = renderIds (
285
+ value . defaultBinding ,
286
+ ( symbolId ) => {
287
+ const symbol = project . symbols . get ( symbolId ) ;
288
+ return this . replacerFn ( { file, project, symbol } ) ;
289
+ } ,
290
+ ) ;
291
+ defaultBinding = tsc . identifier ( { text : processedDefaultBinding } ) ;
285
292
if ( value . typeDefaultBinding ) {
286
293
isTypeOnly = true ;
287
294
}
You can’t perform that action at this time.
0 commit comments