Skip to content

Commit ac72422

Browse files
Merge pull request #627 from swiftwasm/katei/bf1a-fix-ts2swift-for
Fix ts2swift alias struct naming and docs
1 parent a98e49d commit ac72422

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/processor.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -747,8 +747,8 @@ export class TypeProcessor {
747747
* @private
748748
*/
749749
visitStructuredType(type, diagnosticNode, members) {
750-
const symbol = type.getSymbol() ?? type.aliasSymbol;
751-
const name = symbol?.name ?? this.checker.typeToString(type);
750+
const symbol = type.aliasSymbol ?? type.getSymbol();
751+
const name = type.aliasSymbol?.name ?? symbol?.name ?? this.checker.typeToString(type);
752752
if (!name) return;
753753
if (this.emittedStructuredTypeNames.has(name)) return;
754754
this.emittedStructuredTypeNames.add(name);
@@ -760,7 +760,7 @@ export class TypeProcessor {
760760
if (jsNameArg) args.push(jsNameArg);
761761
const annotation = this.renderMacroAnnotation("JSClass", args);
762762
const typeName = this.renderIdentifier(swiftName);
763-
const docNode = symbol?.getDeclarations()?.[0] ?? diagnosticNode;
763+
const docNode = type.aliasSymbol?.getDeclarations()?.[0] ?? symbol?.getDeclarations()?.[0] ?? diagnosticNode;
764764
if (docNode) {
765765
this.emitDocComment(docNode, { indent: "" });
766766
}

Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/__snapshots__/ts2swift.test.js.snap

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,25 @@ exports[`ts2swift > snapshots Swift output for TypeAlias.d.ts > TypeAlias 1`] =
426426
"
427427
`;
428428
429+
exports[`ts2swift > snapshots Swift output for TypeAliasObject.d.ts > TypeAliasObject 1`] = `
430+
"// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit,
431+
// DO NOT EDIT.
432+
//
433+
// To update this file, just rebuild your project or run
434+
// \`swift package bridge-js\`.
435+
436+
@_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit
437+
438+
@JSFunction func console() throws(JSException) -> Console
439+
440+
/// Console from the environment.
441+
@JSClass struct Console {
442+
/// Log a message.
443+
@JSFunction func log(_ message: String) throws(JSException) -> Void
444+
}
445+
"
446+
`;
447+
429448
exports[`ts2swift > snapshots Swift output for TypeScriptClass.d.ts > TypeScriptClass 1`] = `
430449
"// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit,
431450
// DO NOT EDIT.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* Console from the environment.
3+
*/
4+
export type Console = {
5+
/**
6+
* Log a message.
7+
*/
8+
log(message: string): void;
9+
};
10+
11+
export function console(): Console;

0 commit comments

Comments
 (0)