Skip to content

Commit 3397899

Browse files
authored
Revert "[tsgen] Handle different get/set types for value_objects too. (#22439)"
This reverts commit bdf5b0d.
1 parent 50e0b07 commit 3397899

File tree

6 files changed

+37
-54
lines changed

6 files changed

+37
-54
lines changed

src/embind/embind_gen.js

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -243,18 +243,6 @@ var LibraryEmbind = {
243243
}
244244

245245
},
246-
$printProperty: (prop, nameMap, out) => {
247-
const setType = nameMap(prop.type, false);
248-
const getType = nameMap(prop.type, true);
249-
if (prop.readonly || setType === getType) {
250-
out.push(`${prop.readonly ? 'readonly ' : ''}${prop.name}: ${getType}`);
251-
return;
252-
}
253-
// The getter/setter types don't match, so generate each get/set definition.
254-
out.push(`get ${prop.name}(): ${getType}`);
255-
out.push(`set ${prop.name}(value: ${setType})`);
256-
},
257-
$ClassProperty__deps: ['$printProperty'],
258246
$ClassProperty: class {
259247
constructor(type, name, readonly) {
260248
this.type = type;
@@ -263,7 +251,15 @@ var LibraryEmbind = {
263251
}
264252

265253
print(nameMap, out) {
266-
printProperty(this, nameMap, out);
254+
const setType = nameMap(this.type, false);
255+
const getType = nameMap(this.type, true);
256+
if (this.readonly || setType === getType) {
257+
out.push(`${this.readonly ? 'readonly ' : ''}${this.name}: ${getType}`);
258+
return;
259+
}
260+
// The getter/setter types don't match, so generate each get/set definition.
261+
out.push(`get ${this.name}(): ${getType}`);
262+
out.push(`set ${this.name}(value: ${setType})`);
267263
}
268264
},
269265
$ConstantDefinition: class {
@@ -329,7 +325,6 @@ var LibraryEmbind = {
329325
out.push(' ];\n\n');
330326
}
331327
},
332-
$ValueObjectDefinition__deps: ['$printProperty'],
333328
$ValueObjectDefinition: class {
334329
constructor(typeId, name) {
335330
this.typeId = typeId;
@@ -341,14 +336,12 @@ var LibraryEmbind = {
341336
}
342337

343338
print(nameMap, out) {
344-
out.push(`export type ${this.name} = {\n `);
339+
out.push(`export type ${this.name} = {\n`);
345340
const outFields = [];
346-
for (const field of this.fields) {
347-
const property = [];
348-
printProperty(field, nameMap, property);
349-
outFields.push(...property);
341+
for (const {name, type} of this.fields) {
342+
outFields.push(` ${name}: ${nameMap(type)}`);
350343
}
351-
out.push(outFields.join(',\n '))
344+
out.push(outFields.join(',\n'))
352345
out.push('\n};\n\n');
353346
}
354347
},

test/other/embind_tsgen.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ EMSCRIPTEN_DECLARE_VAL_TYPE(CallbackType);
6060
struct ValObj {
6161
Foo foo;
6262
Bar bar;
63-
std::string str;
6463
CallbackType callback;
6564
ValObj() : callback(val::undefined()) {}
6665
};
@@ -179,7 +178,6 @@ EMSCRIPTEN_BINDINGS(Test) {
179178
value_object<ValObj>("ValObj")
180179
.field("foo", &ValObj::foo)
181180
.field("bar", &ValObj::bar)
182-
.field("str", &ValObj::str)
183181
.field("callback", &ValObj::callback);
184182

185183
register_vector<int>("IntVec");

test/other/embind_tsgen.d.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ export interface ClassWithSmartPtrConstructor {
8585
delete(): void;
8686
}
8787

88+
export type ValObj = {
89+
foo: Foo,
90+
bar: Bar,
91+
callback: (message: string) => void
92+
};
93+
8894
export interface BaseClass {
8995
fn(_0: number): number;
9096
delete(): void;
@@ -97,14 +103,6 @@ export interface DerivedClass extends BaseClass {
97103

98104
export type ValArr = [ number, number, number ];
99105

100-
export type ValObj = {
101-
foo: Foo,
102-
bar: Bar,
103-
get str(): string,
104-
set str(value: EmbindString),
105-
callback: (message: string) => void
106-
};
107-
108106
interface EmbindModule {
109107
Test: {
110108
staticFunction(_0: number): number;

test/other/embind_tsgen_ignore_1.d.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ export interface ClassWithSmartPtrConstructor {
9494
delete(): void;
9595
}
9696

97+
export type ValObj = {
98+
foo: Foo,
99+
bar: Bar,
100+
callback: (message: string) => void
101+
};
102+
97103
export interface BaseClass {
98104
fn(_0: number): number;
99105
delete(): void;
@@ -106,14 +112,6 @@ export interface DerivedClass extends BaseClass {
106112

107113
export type ValArr = [ number, number, number ];
108114

109-
export type ValObj = {
110-
foo: Foo,
111-
bar: Bar,
112-
get str(): string,
113-
set str(value: EmbindString),
114-
callback: (message: string) => void
115-
};
116-
117115
interface EmbindModule {
118116
Test: {
119117
staticFunction(_0: number): number;

test/other/embind_tsgen_ignore_2.d.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ export interface ClassWithSmartPtrConstructor {
7171
delete(): void;
7272
}
7373

74+
export type ValObj = {
75+
foo: Foo,
76+
bar: Bar,
77+
callback: (message: string) => void
78+
};
79+
7480
export interface BaseClass {
7581
fn(_0: number): number;
7682
delete(): void;
@@ -83,14 +89,6 @@ export interface DerivedClass extends BaseClass {
8389

8490
export type ValArr = [ number, number, number ];
8591

86-
export type ValObj = {
87-
foo: Foo,
88-
bar: Bar,
89-
get str(): string,
90-
set str(value: EmbindString),
91-
callback: (message: string) => void
92-
};
93-
9492
interface EmbindModule {
9593
Test: {
9694
staticFunction(_0: number): number;

test/other/embind_tsgen_ignore_3.d.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ export interface ClassWithSmartPtrConstructor {
8585
delete(): void;
8686
}
8787

88+
export type ValObj = {
89+
foo: Foo,
90+
bar: Bar,
91+
callback: (message: string) => void
92+
};
93+
8894
export interface BaseClass {
8995
fn(_0: number): number;
9096
delete(): void;
@@ -97,14 +103,6 @@ export interface DerivedClass extends BaseClass {
97103

98104
export type ValArr = [ number, number, number ];
99105

100-
export type ValObj = {
101-
foo: Foo,
102-
bar: Bar,
103-
get str(): string,
104-
set str(value: EmbindString),
105-
callback: (message: string) => void
106-
};
107-
108106
interface EmbindModule {
109107
Test: {
110108
staticFunction(_0: number): number;

0 commit comments

Comments
 (0)