Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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: "" });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Console from the environment.
*/
export type Console = {
/**
* Log a message.
*/
log(message: string): void;
};

export function console(): Console;