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 @@ -716,12 +716,14 @@ export class TypeProcessor {
716716 "never" : "Void" ,
717717 "Promise" : "JSPromise" ,
718718 } ;
719- const typeString = type . getSymbol ( ) ?. name ?? this . checker . typeToString ( type ) ;
719+ const symbol = type . getSymbol ( ) ?? type . aliasSymbol ;
720+ const typeString = symbol ?. name ?? this . checker . typeToString ( type ) ;
720721 if ( typeMap [ typeString ] ) {
721722 return typeMap [ typeString ] ;
722723 }
723-
724- const symbol = type . getSymbol ( ) ?? type . aliasSymbol ;
724+ if ( isObjectType ( type ) && isTypeScriptLibSymbol ( symbol ) ) {
725+ return "JSObject" ;
726+ }
725727 if ( symbol && ( symbol . flags & ts . SymbolFlags . Enum ) !== 0 ) {
726728 const typeName = symbol . name ;
727729 this . seenTypes . set ( type , node ) ;
@@ -950,6 +952,17 @@ function isObjectType(type) {
950952 return typeof type . objectFlags === "number" ;
951953}
952954
955+ /**
956+ * @param {ts.Symbol | undefined } symbol
957+ * @returns {boolean }
958+ */
959+ function isTypeScriptLibSymbol ( symbol ) {
960+ if ( ! symbol ) return false ;
961+ const declarations = symbol . getDeclarations ( ) ?? [ ] ;
962+ if ( ! declarations . length ) return false ;
963+ return declarations . every ( decl => decl . getSourceFile ( ) . fileName . includes ( "node_modules/typescript/lib" ) ) ;
964+ }
965+
953966/**
954967 *
955968 * @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 OptionalNullUndefined.d.ts > OptionalNullUndefined 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