Skip to content

Commit c6f2642

Browse files
committed
BridgeJS: Fix incorrect TypeScript type names for tsEnum-style enums and struct associated values
1 parent 60b9444 commit c6f2642

File tree

4 files changed

+22
-13
lines changed

4 files changed

+22
-13
lines changed

Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,6 +1470,9 @@ public struct BridgeJSLink {
14701470
case .namespaceEnum:
14711471
return enumDef.tsFullPath
14721472
default:
1473+
if enumDef.emitStyle == .tsEnum {
1474+
return enumDef.tsFullPath
1475+
}
14731476
return "\(enumDef.tsFullPath)Tag"
14741477
}
14751478
}
@@ -1786,7 +1789,7 @@ public struct BridgeJSLink {
17861789
]
17871790
for (associatedValueIndex, associatedValue) in enumCase.associatedValues.enumerated() {
17881791
let prop = associatedValue.label ?? "param\(associatedValueIndex)"
1789-
fields.append("\(prop): \(associatedValue.type.tsType)")
1792+
fields.append("\(prop): \(resolveTypeScriptType(associatedValue.type))")
17901793
}
17911794
unionParts.append("{ \(fields.joined(separator: "; ")) }")
17921795
}
@@ -2917,6 +2920,7 @@ extension BridgeJSLink {
29172920
depth: 1,
29182921
printer: printer,
29192922
exposeToGlobal: true,
2923+
exportedSkeletons: exportedSkeletons,
29202924
renderTSSignatureCallback: renderTSSignatureCallback
29212925
)
29222926
printer.unindent()
@@ -2935,6 +2939,7 @@ extension BridgeJSLink {
29352939
depth: 1,
29362940
printer: printer,
29372941
exposeToGlobal: false,
2942+
exportedSkeletons: exportedSkeletons,
29382943
renderTSSignatureCallback: renderTSSignatureCallback
29392944
)
29402945
}
@@ -2948,6 +2953,7 @@ extension BridgeJSLink {
29482953
depth: Int,
29492954
printer: CodeFragmentPrinter,
29502955
exposeToGlobal: Bool,
2956+
exportedSkeletons: [ExportedSkeleton],
29512957
renderTSSignatureCallback: @escaping ([Parameter], BridgeType, Effects) -> String
29522958
) {
29532959
func hasContent(node: NamespaceNode) -> Bool {
@@ -3102,7 +3108,9 @@ extension BridgeJSLink {
31023108
.enumerated()
31033109
{
31043110
let prop = associatedValue.label ?? "param\(associatedValueIndex)"
3105-
fields.append("\(prop): \(associatedValue.type.tsType)")
3111+
fields.append(
3112+
"\(prop): \(BridgeJSLink.resolveTypeScriptType(associatedValue.type, exportedSkeletons: exportedSkeletons))"
3113+
)
31063114
}
31073115
unionParts.append("{ \(fields.joined(separator: "; ")) }")
31083116
}
@@ -3136,6 +3144,7 @@ extension BridgeJSLink {
31363144
depth: depth + 1,
31373145
printer: printer,
31383146
exposeToGlobal: exposeToGlobal,
3147+
exportedSkeletons: exportedSkeletons,
31393148
renderTSSignatureCallback: renderTSSignatureCallback
31403149
)
31413150

Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export const AllTypesResultValues: {
8282
};
8383

8484
export type AllTypesResultTag =
85-
{ tag: typeof AllTypesResultValues.Tag.StructPayload; param0: PointTag } | { tag: typeof AllTypesResultValues.Tag.ClassPayload; param0: User } | { tag: typeof AllTypesResultValues.Tag.JsObjectPayload; param0: any } | { tag: typeof AllTypesResultValues.Tag.NestedEnum; param0: APIResultTag } | { tag: typeof AllTypesResultValues.Tag.ArrayPayload; param0: number[] } | { tag: typeof AllTypesResultValues.Tag.Empty }
85+
{ tag: typeof AllTypesResultValues.Tag.StructPayload; param0: Point } | { tag: typeof AllTypesResultValues.Tag.ClassPayload; param0: User } | { tag: typeof AllTypesResultValues.Tag.JsObjectPayload; param0: any } | { tag: typeof AllTypesResultValues.Tag.NestedEnum; param0: APIResultTag } | { tag: typeof AllTypesResultValues.Tag.ArrayPayload; param0: number[] } | { tag: typeof AllTypesResultValues.Tag.Empty }
8686

8787
export const OptionalAllTypesResultValues: {
8888
readonly Tag: {
@@ -96,7 +96,7 @@ export const OptionalAllTypesResultValues: {
9696
};
9797

9898
export type OptionalAllTypesResultTag =
99-
{ tag: typeof OptionalAllTypesResultValues.Tag.OptStruct; param0: PointTag | null } | { tag: typeof OptionalAllTypesResultValues.Tag.OptClass; param0: User | null } | { tag: typeof OptionalAllTypesResultValues.Tag.OptJSObject; param0: any | null } | { tag: typeof OptionalAllTypesResultValues.Tag.OptNestedEnum; param0: APIResultTag | null } | { tag: typeof OptionalAllTypesResultValues.Tag.OptArray; param0: number[] | null } | { tag: typeof OptionalAllTypesResultValues.Tag.Empty }
99+
{ tag: typeof OptionalAllTypesResultValues.Tag.OptStruct; param0: Point | null } | { tag: typeof OptionalAllTypesResultValues.Tag.OptClass; param0: User | null } | { tag: typeof OptionalAllTypesResultValues.Tag.OptJSObject; param0: any | null } | { tag: typeof OptionalAllTypesResultValues.Tag.OptNestedEnum; param0: APIResultTag | null } | { tag: typeof OptionalAllTypesResultValues.Tag.OptArray; param0: number[] | null } | { tag: typeof OptionalAllTypesResultValues.Tag.Empty }
100100

101101
export interface Point {
102102
x: number;

Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCase.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ export type Exports = {
4242
getDirection(): DirectionTag;
4343
processDirection(input: DirectionTag): StatusTag;
4444
roundTripOptionalDirection(input: DirectionTag | null): DirectionTag | null;
45-
setTSDirection(direction: TSDirectionTag): void;
46-
getTSDirection(): TSDirectionTag;
47-
roundTripOptionalTSDirection(input: TSDirectionTag | null): TSDirectionTag | null;
45+
setTSDirection(direction: TSDirection): void;
46+
getTSDirection(): TSDirection;
47+
roundTripOptionalTSDirection(input: TSDirection | null): TSDirection | null;
4848
Direction: DirectionObject
4949
Status: StatusObject
5050
PublicStatus: PublicStatusObject

Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumRawType.d.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,18 @@ export type Exports = {
113113
setTheme(theme: ThemeTag): void;
114114
getTheme(): ThemeTag;
115115
roundTripOptionalTheme(input: ThemeTag | null): ThemeTag | null;
116-
setTSTheme(theme: TSThemeTag): void;
117-
getTSTheme(): TSThemeTag;
118-
roundTripOptionalTSTheme(input: TSThemeTag | null): TSThemeTag | null;
116+
setTSTheme(theme: TSTheme): void;
117+
getTSTheme(): TSTheme;
118+
roundTripOptionalTSTheme(input: TSTheme | null): TSTheme | null;
119119
setFeatureFlag(flag: FeatureFlagTag): void;
120120
getFeatureFlag(): FeatureFlagTag;
121121
roundTripOptionalFeatureFlag(input: FeatureFlagTag | null): FeatureFlagTag | null;
122122
setHttpStatus(status: HttpStatusTag): void;
123123
getHttpStatus(): HttpStatusTag;
124124
roundTripOptionalHttpStatus(input: HttpStatusTag | null): HttpStatusTag | null;
125-
setTSHttpStatus(status: TSHttpStatusTag): void;
126-
getTSHttpStatus(): TSHttpStatusTag;
127-
roundTripOptionalHttpStatus(input: TSHttpStatusTag | null): TSHttpStatusTag | null;
125+
setTSHttpStatus(status: TSHttpStatus): void;
126+
getTSHttpStatus(): TSHttpStatus;
127+
roundTripOptionalHttpStatus(input: TSHttpStatus | null): TSHttpStatus | null;
128128
setPriority(priority: PriorityTag): void;
129129
getPriority(): PriorityTag;
130130
roundTripOptionalPriority(input: PriorityTag | null): PriorityTag | null;

0 commit comments

Comments
 (0)