Skip to content

Commit 002ffd9

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

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ export class TypeProcessor {
5656
this.emittedStructuredTypeNames = new Set();
5757
/** @type {Set<string>} */
5858
this.emittedStringLiteralUnionNames = new Set();
59-
/** @type {Set<string>} */
60-
this.emittedStringLiteralUnionNames = new Set();
6159

6260
/** @type {Set<string>} */
6361
this.visitedDeclarationKeys = new Set();
@@ -324,6 +322,11 @@ export class TypeProcessor {
324322
*/
325323
getStringLiteralUnionLiterals(type) {
326324
if ((type.flags & ts.TypeFlags.Union) === 0) return null;
325+
const symbol = type.getSymbol() ?? type.aliasSymbol;
326+
// Skip enums so we don't double-generate real enum declarations.
327+
if (symbol && (symbol.flags & ts.SymbolFlags.Enum) !== 0) {
328+
return null;
329+
}
327330
/** @type {ts.UnionType} */
328331
// @ts-ignore
329332
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)