Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 13 additions & 20 deletions src/embind/embind_gen.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,18 +243,6 @@ var LibraryEmbind = {
}

},
$printProperty: (prop, nameMap, out) => {
const setType = nameMap(prop.type, false);
const getType = nameMap(prop.type, true);
if (prop.readonly || setType === getType) {
out.push(`${prop.readonly ? 'readonly ' : ''}${prop.name}: ${getType}`);
return;
}
// The getter/setter types don't match, so generate each get/set definition.
out.push(`get ${prop.name}(): ${getType}`);
out.push(`set ${prop.name}(value: ${setType})`);
},
$ClassProperty__deps: ['$printProperty'],
$ClassProperty: class {
constructor(type, name, readonly) {
this.type = type;
Expand All @@ -263,7 +251,15 @@ var LibraryEmbind = {
}

print(nameMap, out) {
printProperty(this, nameMap, out);
const setType = nameMap(this.type, false);
const getType = nameMap(this.type, true);
if (this.readonly || setType === getType) {
out.push(`${this.readonly ? 'readonly ' : ''}${this.name}: ${getType}`);
return;
}
// The getter/setter types don't match, so generate each get/set definition.
out.push(`get ${this.name}(): ${getType}`);
out.push(`set ${this.name}(value: ${setType})`);
}
},
$ConstantDefinition: class {
Expand Down Expand Up @@ -329,7 +325,6 @@ var LibraryEmbind = {
out.push(' ];\n\n');
}
},
$ValueObjectDefinition__deps: ['$printProperty'],
$ValueObjectDefinition: class {
constructor(typeId, name) {
this.typeId = typeId;
Expand All @@ -341,14 +336,12 @@ var LibraryEmbind = {
}

print(nameMap, out) {
out.push(`export type ${this.name} = {\n `);
out.push(`export type ${this.name} = {\n`);
const outFields = [];
for (const field of this.fields) {
const property = [];
printProperty(field, nameMap, property);
outFields.push(...property);
for (const {name, type} of this.fields) {
outFields.push(` ${name}: ${nameMap(type)}`);
}
out.push(outFields.join(',\n '))
out.push(outFields.join(',\n'))
out.push('\n};\n\n');
}
},
Expand Down
2 changes: 0 additions & 2 deletions test/other/embind_tsgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ EMSCRIPTEN_DECLARE_VAL_TYPE(CallbackType);
struct ValObj {
Foo foo;
Bar bar;
std::string str;
CallbackType callback;
ValObj() : callback(val::undefined()) {}
};
Expand Down Expand Up @@ -179,7 +178,6 @@ EMSCRIPTEN_BINDINGS(Test) {
value_object<ValObj>("ValObj")
.field("foo", &ValObj::foo)
.field("bar", &ValObj::bar)
.field("str", &ValObj::str)
.field("callback", &ValObj::callback);

register_vector<int>("IntVec");
Expand Down
14 changes: 6 additions & 8 deletions test/other/embind_tsgen.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ export interface ClassWithSmartPtrConstructor {
delete(): void;
}

export type ValObj = {
foo: Foo,
bar: Bar,
callback: (message: string) => void
};

export interface BaseClass {
fn(_0: number): number;
delete(): void;
Expand All @@ -97,14 +103,6 @@ export interface DerivedClass extends BaseClass {

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

export type ValObj = {
foo: Foo,
bar: Bar,
get str(): string,
set str(value: EmbindString),
callback: (message: string) => void
};

interface EmbindModule {
Test: {
staticFunction(_0: number): number;
Expand Down
14 changes: 6 additions & 8 deletions test/other/embind_tsgen_ignore_1.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ export interface ClassWithSmartPtrConstructor {
delete(): void;
}

export type ValObj = {
foo: Foo,
bar: Bar,
callback: (message: string) => void
};

export interface BaseClass {
fn(_0: number): number;
delete(): void;
Expand All @@ -106,14 +112,6 @@ export interface DerivedClass extends BaseClass {

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

export type ValObj = {
foo: Foo,
bar: Bar,
get str(): string,
set str(value: EmbindString),
callback: (message: string) => void
};

interface EmbindModule {
Test: {
staticFunction(_0: number): number;
Expand Down
14 changes: 6 additions & 8 deletions test/other/embind_tsgen_ignore_2.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ export interface ClassWithSmartPtrConstructor {
delete(): void;
}

export type ValObj = {
foo: Foo,
bar: Bar,
callback: (message: string) => void
};

export interface BaseClass {
fn(_0: number): number;
delete(): void;
Expand All @@ -83,14 +89,6 @@ export interface DerivedClass extends BaseClass {

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

export type ValObj = {
foo: Foo,
bar: Bar,
get str(): string,
set str(value: EmbindString),
callback: (message: string) => void
};

interface EmbindModule {
Test: {
staticFunction(_0: number): number;
Expand Down
14 changes: 6 additions & 8 deletions test/other/embind_tsgen_ignore_3.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ export interface ClassWithSmartPtrConstructor {
delete(): void;
}

export type ValObj = {
foo: Foo,
bar: Bar,
callback: (message: string) => void
};

export interface BaseClass {
fn(_0: number): number;
delete(): void;
Expand All @@ -97,14 +103,6 @@ export interface DerivedClass extends BaseClass {

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

export type ValObj = {
foo: Foo,
bar: Bar,
get str(): string,
set str(value: EmbindString),
callback: (message: string) => void
};

interface EmbindModule {
Test: {
staticFunction(_0: number): number;
Expand Down
Loading