File tree Expand file tree Collapse file tree 3 files changed +57
-3
lines changed
Plugins/BridgeJS/Sources/TS2Swift/JavaScript Expand file tree Collapse file tree 3 files changed +57
-3
lines changed Original file line number Diff line number Diff line change @@ -692,12 +692,14 @@ export class TypeProcessor {
692692 "never" : "Void" ,
693693 "Promise" : "JSPromise" ,
694694 } ;
695- const typeString = type . getSymbol ( ) ?. name ?? this . checker . typeToString ( type ) ;
695+ const symbol = type . getSymbol ( ) ?? type . aliasSymbol ;
696+ const typeString = symbol ?. name ?? this . checker . typeToString ( type ) ;
696697 if ( typeMap [ typeString ] ) {
697698 return typeMap [ typeString ] ;
698699 }
699-
700- const symbol = type . getSymbol ( ) ?? type . aliasSymbol ;
700+ if ( isObjectType ( type ) && isTypeScriptLibSymbol ( symbol ) ) {
701+ return "JSObject" ;
702+ }
701703 if ( symbol && ( symbol . flags & ts . SymbolFlags . Enum ) !== 0 ) {
702704 const typeName = symbol . name ;
703705 this . seenTypes . set ( type , node ) ;
@@ -922,6 +924,17 @@ function isObjectType(type) {
922924 return typeof type . objectFlags === "number" ;
923925}
924926
927+ /**
928+ * @param {ts.Symbol | undefined } symbol
929+ * @returns {boolean }
930+ */
931+ function isTypeScriptLibSymbol ( symbol ) {
932+ if ( ! symbol ) return false ;
933+ const declarations = symbol . getDeclarations ( ) ?? [ ] ;
934+ if ( ! declarations . length ) return false ;
935+ return declarations . every ( decl => decl . getSourceFile ( ) . fileName . includes ( "node_modules/typescript/lib" ) ) ;
936+ }
937+
925938/**
926939 *
927940 * @param {ts.Type } type
Original file line number Diff line number Diff line change @@ -145,6 +145,37 @@ exports[`ts2swift > snapshots Swift output for MultipleImportedTypes.d.ts > Mult
145145"
146146` ;
147147
148+ exports [` ts2swift > snapshots Swift output for ObjectLikeTypes.d.ts > ObjectLikeTypes 1` ] = `
149+ "// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit,
150+ // DO NOT EDIT.
151+ //
152+ // To update this file, just rebuild your project or run
153+ // \` swift package bridge-js\` .
154+
155+ @_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit
156+
157+ @JSFunction func acceptObject(_ v: JSObject) throws(JSException) -> Void
158+
159+ @JSFunction func acceptFunction(_ v: JSObject) throws(JSException) -> Void
160+
161+ @JSFunction func acceptDate(_ v: JSObject) throws(JSException) -> JSObject
162+
163+ @JSFunction func acceptRegExp(_ v: JSObject) throws(JSException) -> JSObject
164+
165+ @JSFunction func acceptMap(_ v: JSObject) throws(JSException) -> JSObject
166+
167+ @JSFunction func acceptSet(_ v: JSObject) throws(JSException) -> JSObject
168+
169+ @JSFunction func acceptPromiseLike(_ v: JSObject) throws(JSException) -> JSObject
170+
171+ @JSFunction func acceptArrayBuffer(_ v: JSObject) throws(JSException) -> JSObject
172+
173+ @JSFunction func acceptArrayLike(_ v: JSObject) throws(JSException) -> JSObject
174+
175+ @JSFunction func acceptIterable(_ v: JSObject) throws(JSException) -> JSObject
176+ "
177+ ` ;
178+
148179exports [` ts2swift > snapshots Swift output for PrimitiveParameters.d.ts > PrimitiveParameters 1` ] = `
149180"// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit,
150181// DO NOT EDIT.
Original file line number Diff line number Diff line change 1+ export function acceptObject ( v : object ) : void ;
2+ export function acceptFunction ( v : Function ) : void ;
3+ export function acceptDate ( v : Date ) : Date ;
4+ export function acceptRegExp ( v : RegExp ) : RegExp ;
5+ export function acceptMap ( v : Map < string , number > ) : Map < string , number > ;
6+ export function acceptSet ( v : Set < string > ) : Set < string > ;
7+ export function acceptPromiseLike ( v : PromiseLike < string > ) : PromiseLike < string > ;
8+ export function acceptArrayBuffer ( v : ArrayBuffer ) : ArrayBuffer ;
9+ export function acceptArrayLike ( v : ArrayLike < string > ) : ArrayLike < string > ;
10+ export function acceptIterable ( v : Iterable < string > ) : Iterable < string > ;
You can’t perform that action at this time.
0 commit comments