Skip to content

Commit e502920

Browse files
authored
embind_ts: handle empty enumerators case (#20398)
1 parent e18753e commit e502920

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

src/embind/embind_ts.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,15 @@ var LibraryEmbind = {
143143
out.push(`export interface ${this.name}Value<T extends number> {\n`);
144144
out.push(' value: T;\n}\n');
145145
out.push(`export type ${this.name} = `);
146-
const outItems = [];
147-
for (const [name, value] of this.items) {
148-
outItems.push(`${this.name}Value<${value}>`);
146+
if (this.items.length === 0) {
147+
out.push('never/* Empty Enumerator */');
148+
} else {
149+
const outItems = [];
150+
for (const [name, value] of this.items) {
151+
outItems.push(`${this.name}Value<${value}>`);
152+
}
153+
out.push(outItems.join('|'));
149154
}
150-
out.push(outItems.join('|'));
151155
out.push(';\n\n');
152156
}
153157

test/other/embind_tsgen.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class Foo {
4141

4242
enum Bar { kValueOne, kValueTwo, kValueThree };
4343

44+
enum EmptyEnum {};
45+
4446
Bar enum_returning_fn() { return kValueOne; }
4547

4648
struct ValArr {
@@ -120,6 +122,7 @@ EMSCRIPTEN_BINDINGS(Test) {
120122
.value("valueOne", Bar::kValueOne)
121123
.value("valueTwo", Bar::kValueTwo)
122124
.value("valueThree", Bar::kValueThree);
125+
enum_<EmptyEnum>("EmptyEnum");
123126

124127
function("enum_returning_fn", &enum_returning_fn);
125128

test/other/embind_tsgen.d.ts

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ export interface BarValue<T extends number> {
1616
}
1717
export type Bar = BarValue<0>|BarValue<1>|BarValue<2>;
1818

19+
export interface EmptyEnumValue<T extends number> {
20+
value: T;
21+
}
22+
export type EmptyEnum = never/* Empty Enumerator */;
23+
1924
export type ValArrIx = [ Bar, Bar, Bar, Bar ];
2025

2126
export interface IntVec {
@@ -66,6 +71,7 @@ export interface MainModule {
6671
a_class_instance: Test;
6772
an_enum: Bar;
6873
Bar: {valueOne: BarValue<0>, valueTwo: BarValue<1>, valueThree: BarValue<2>};
74+
EmptyEnum: {};
6975
enum_returning_fn(): Bar;
7076
IntVec: {new(): IntVec};
7177
Foo: {new(): Foo};

0 commit comments

Comments
 (0)