Skip to content

Commit d6551ac

Browse files
BridgeJS: Add te2swift unit tests
1 parent 6a230da commit d6551ac

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ export class TypeProcessor {
691691
if (nonNullableTypes.length === 1 && (hasNull || hasUndefined)) {
692692
const wrapped = this.visitType(nonNullableTypes[0], node);
693693
if (hasNull && hasUndefined) {
694-
return `JSUndefinedOr<Optional<${wrapped}>>`;
694+
return "JSObject";
695695
}
696696
if (hasNull) {
697697
return `Optional<${wrapped}>`;

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,47 @@ exports[`ts2swift > snapshots Swift output for MultipleImportedTypes.d.ts > Mult
145145
"
146146
`;
147147
148+
exports[`ts2swift > snapshots Swift output for OptionalNullUndefined.d.ts > OptionalNullUndefined 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 roundTripNumberNull(_ value: Optional<Double>) throws(JSException) -> Optional<Double>
158+
159+
@JSFunction func roundTripNumberUndefined(_ value: JSUndefinedOr<Double>) throws(JSException) -> JSUndefinedOr<Double>
160+
161+
@JSFunction func roundTripStringNull(_ value: Optional<String>) throws(JSException) -> Optional<String>
162+
163+
@JSFunction func roundTripStringUndefined(_ value: JSUndefinedOr<String>) throws(JSException) -> JSUndefinedOr<String>
164+
165+
@JSFunction func roundTripBooleanNull(_ value: JSObject) throws(JSException) -> JSObject
166+
167+
@JSFunction func roundTripBooleanUndefined(_ value: JSObject) throws(JSException) -> JSObject
168+
169+
@JSFunction func optionalNumberParamNull(_ x: Double, _ maybe: Optional<Double>) throws(JSException) -> Double
170+
171+
@JSFunction func optionalNumberParamUndefined(_ x: Double, _ maybe: JSUndefinedOr<Double>) throws(JSException) -> Double
172+
173+
@JSFunction func roundTripMyInterfaceNull(_ value: Optional<MyInterface>) throws(JSException) -> Optional<MyInterface>
174+
175+
@JSClass struct MyInterface {
176+
}
177+
178+
@JSFunction func roundTripMyInterfaceUndefined(_ value: JSUndefinedOr<MyInterface>) throws(JSException) -> JSUndefinedOr<MyInterface>
179+
180+
@JSClass struct WithOptionalFields {
181+
@JSGetter var valueOrNull: Optional<MyInterface>
182+
@JSSetter func setValueOrNull(_ value: Optional<MyInterface>) throws(JSException)
183+
@JSGetter var valueOrUndefined: JSUndefinedOr<MyInterface>
184+
@JSSetter func setValueOrUndefined(_ value: JSUndefinedOr<MyInterface>) throws(JSException)
185+
}
186+
"
187+
`;
188+
148189
exports[`ts2swift > snapshots Swift output for PrimitiveParameters.d.ts > PrimitiveParameters 1`] = `
149190
"// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit,
150191
// DO NOT EDIT.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export function roundTripNumberNull(value: number | null): number | null;
2+
export function roundTripNumberUndefined(value: number | undefined): number | undefined;
3+
4+
export function roundTripStringNull(value: string | null): string | null;
5+
export function roundTripStringUndefined(value: string | undefined): string | undefined;
6+
7+
export function roundTripBooleanNull(value: boolean | null): boolean | null;
8+
export function roundTripBooleanUndefined(value: boolean | undefined): boolean | undefined;
9+
10+
export function optionalNumberParamNull(x: number, maybe: number | null): number;
11+
export function optionalNumberParamUndefined(x: number, maybe: number | undefined): number;
12+
13+
export interface MyInterface {}
14+
export function roundTripMyInterfaceNull(value: MyInterface | null): MyInterface | null;
15+
export function roundTripMyInterfaceUndefined(value: MyInterface | undefined): MyInterface | undefined;
16+
17+
export class WithOptionalFields {
18+
valueOrNull: MyInterface | null;
19+
valueOrUndefined: MyInterface | undefined;
20+
}

0 commit comments

Comments
 (0)