Skip to content

Commit 773471f

Browse files
TS2Swift: skip enum types when emitting string literal unions
1 parent 9527aa5 commit 773471f

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,11 @@ export class TypeProcessor {
324324
*/
325325
getStringLiteralUnionLiterals(type) {
326326
if ((type.flags & ts.TypeFlags.Union) === 0) return null;
327+
const symbol = type.getSymbol() ?? type.aliasSymbol;
328+
// Skip enums so we don't double-generate real enum declarations.
329+
if (symbol && (symbol.flags & ts.SymbolFlags.Enum) !== 0) {
330+
return null;
331+
}
327332
/** @type {ts.UnionType} */
328333
// @ts-ignore
329334
const unionType = type;

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -355,12 +355,6 @@ extension FeatureFlag: _BridgedSwiftEnumNoPayload, _BridgedSwiftRawValueEnum {}
355355
356356
@JSFunction func takesFeatureFlag(_ flag: FeatureFlag) throws(JSException) -> Void
357357
358-
enum FeatureFlag: String {
359-
case foo = "foo"
360-
case bar = "bar"
361-
}
362-
extension FeatureFlag: _BridgedSwiftEnumNoPayload, _BridgedSwiftRawValueEnum {}
363-
364358
@JSFunction func returnsFeatureFlag() throws(JSException) -> FeatureFlag
365359
"
366360
`;

0 commit comments

Comments
 (0)