@@ -311,7 +311,7 @@ var LibraryEmbind = {
311
311
$TsPrinter : class {
312
312
constructor ( definitions ) {
313
313
this . definitions = definitions ;
314
- const jsString = 'ArrayBuffer|Uint8Array|Uint8ClampedArray|Int8Array|string' ;
314
+ const jsString = 'EmbindString' ; // Type alias for multiple types.
315
315
// The mapping is in the format of '<c++ name>' => ['toWireType', 'fromWireType']
316
316
// or if the to/from wire types are the same use a single element.
317
317
this . builtInToJsName = new Map ( [
@@ -334,6 +334,8 @@ var LibraryEmbind = {
334
334
[ 'std::u32string' , [ 'string' ] ] ,
335
335
[ 'emscripten::val' , [ 'any' ] ] ,
336
336
] ) ;
337
+ // Signal that the type alias for EmbindString is needed.
338
+ this . usedEmbindString = false ;
337
339
}
338
340
339
341
typeToJsName ( type , isFromWireType = false ) {
@@ -345,7 +347,11 @@ var LibraryEmbind = {
345
347
throw new Error ( `Missing primitive type to TS type for '${ type . name } '` ) ;
346
348
}
347
349
const [ toWireType , fromWireType = toWireType ] = this . builtInToJsName . get ( type . name ) ;
348
- return isFromWireType ? fromWireType : toWireType ;
350
+ const tsName = isFromWireType ? fromWireType : toWireType ;
351
+ if ( tsName === 'EmbindString' ) {
352
+ this . usedEmbindString = true ;
353
+ }
354
+ return tsName ;
349
355
}
350
356
if ( type instanceof PointerDefinition ) {
351
357
return this . typeToJsName ( type . classType ) ;
@@ -372,7 +378,10 @@ var LibraryEmbind = {
372
378
}
373
379
def . printModuleEntry ( this . typeToJsName . bind ( this ) , out ) ;
374
380
}
375
- out . push ( '}' ) ;
381
+ out . push ( '}\n' ) ;
382
+ if ( this . usedEmbindString ) {
383
+ out . unshift ( 'type EmbindString = ArrayBuffer|Uint8Array|Uint8ClampedArray|Int8Array|string;\n' ) ;
384
+ }
376
385
console . log ( out . join ( '' ) ) ;
377
386
}
378
387
} ,
0 commit comments