diff --git a/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/processor.js b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/processor.js index 302058036..c71ff6fe5 100644 --- a/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/processor.js +++ b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/processor.js @@ -747,8 +747,8 @@ export class TypeProcessor { * @private */ visitStructuredType(type, diagnosticNode, members) { - const symbol = type.getSymbol() ?? type.aliasSymbol; - const name = symbol?.name ?? this.checker.typeToString(type); + const symbol = type.aliasSymbol ?? type.getSymbol(); + const name = type.aliasSymbol?.name ?? symbol?.name ?? this.checker.typeToString(type); if (!name) return; if (this.emittedStructuredTypeNames.has(name)) return; this.emittedStructuredTypeNames.add(name); @@ -760,7 +760,7 @@ export class TypeProcessor { if (jsNameArg) args.push(jsNameArg); const annotation = this.renderMacroAnnotation("JSClass", args); const typeName = this.renderIdentifier(swiftName); - const docNode = symbol?.getDeclarations()?.[0] ?? diagnosticNode; + const docNode = type.aliasSymbol?.getDeclarations()?.[0] ?? symbol?.getDeclarations()?.[0] ?? diagnosticNode; if (docNode) { this.emitDocComment(docNode, { indent: "" }); } diff --git a/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/__snapshots__/ts2swift.test.js.snap b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/__snapshots__/ts2swift.test.js.snap index 343f8795b..49814a996 100644 --- a/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/__snapshots__/ts2swift.test.js.snap +++ b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/__snapshots__/ts2swift.test.js.snap @@ -426,6 +426,25 @@ exports[`ts2swift > snapshots Swift output for TypeAlias.d.ts > TypeAlias 1`] = " `; +exports[`ts2swift > snapshots Swift output for TypeAliasObject.d.ts > TypeAliasObject 1`] = ` +"// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, +// DO NOT EDIT. +// +// To update this file, just rebuild your project or run +// \`swift package bridge-js\`. + +@_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit + +@JSFunction func console() throws(JSException) -> Console + +/// Console from the environment. +@JSClass struct Console { + /// Log a message. + @JSFunction func log(_ message: String) throws(JSException) -> Void +} +" +`; + exports[`ts2swift > snapshots Swift output for TypeScriptClass.d.ts > TypeScriptClass 1`] = ` "// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, // DO NOT EDIT. diff --git a/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/TypeAliasObject.d.ts b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/TypeAliasObject.d.ts new file mode 100644 index 000000000..55ffdfa3a --- /dev/null +++ b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/TypeAliasObject.d.ts @@ -0,0 +1,11 @@ +/** + * Console from the environment. + */ +export type Console = { + /** + * Log a message. + */ + log(message: string): void; +}; + +export function console(): Console;