0

Mojo JS bindings: Use proper class declaration instead of assignment.

Prefer "export class Foo {...}" instead of "export const Foo = class
{...}" where possible.

The former is a proper class declaration, where a class named Foo is
defined, whereas the latter creates an anonymous class, and assigns it
to a variable.

This is a small step in making TypeScript better understand Mojo
generated code, since it allows consuming generated Mojo JS by
leveraging the "allowJs" Typescript compiler option.

Bug: 1189595
Change-Id: I599bfdb657f83bd9e6014071fb5ee1c33399f742
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2910189
Auto-Submit: dpapad <dpapad@chromium.org>
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#886129}
This commit is contained in:
dpapad
2021-05-25 00:37:40 +00:00
committed by Chromium LUCI CQ
parent bd369fab9e
commit 33b2ac349b
2 changed files with 14 additions and 14 deletions
mojo/public/tools/bindings/generators/js_templates/lite

@ -20,7 +20,7 @@
/**
* @implements {mojo.internal.interfaceSupport.PendingReceiver}
*/
export const {{interface.name}}PendingReceiver = class {
export class {{interface.name}}PendingReceiver {
/**
* @param {!MojoHandle|!mojo.internal.interfaceSupport.Endpoint} handle
*/
@ -34,10 +34,10 @@ export const {{interface.name}}PendingReceiver = class {
mojo.internal.interfaceSupport.bind(
this.handle, '{{mojom_namespace}}.{{interface.name}}', scope);
}
};
}
/** @interface */
export const {{interface.name}}Interface = class {
export class {{interface.name}}Interface {
{%- for method in interface.methods %}
{{generateMethodAnnotation(method)}}
{{method.name}}(
@ -46,12 +46,12 @@ export const {{interface.name}}Interface = class {
{%- endfor -%}
) {}
{%- endfor %}
};
}
/**
* @implements { {{interface.name}}Interface }
*/
export const {{interface.name}}Remote = class {
export class {{interface.name}}Remote {
/** @param {MojoHandle|mojo.internal.interfaceSupport.Endpoint=} handle */
constructor(handle = undefined) {
/**
@ -99,14 +99,14 @@ export const {{interface.name}}Remote = class {
]);
}
{%- endfor %}
};
}
/**
* An object which receives request messages for the {{interface.name}}
* mojom interface. Must be constructed over an object which implements that
* interface.
*/
export const {{interface.name}}Receiver = class {
export class {{interface.name}}Receiver {
/**
* @param {!{{interface.name}}Interface } impl
*/
@ -136,9 +136,9 @@ export const {{interface.name}}Receiver = class {
/** @public {!mojo.internal.interfaceSupport.ConnectionErrorEventRouter} */
this.onConnectionError = this.helper_internal_.getConnectionErrorEventRouter();
}
};
}
export const {{interface.name}} = class {
export class {{interface.name}} {
/**
* @return {!string}
*/
@ -158,7 +158,7 @@ export const {{interface.name}} = class {
remote.$.bindNewPipeAndPassReceiver().bindInBrowser();
return remote;
}
};
}
{#--- Enums #}
{% from "lite/enum_definition_for_module.tmpl" import enum_def with context %}
@ -172,7 +172,7 @@ export const {{interface.name}} = class {
* on this object for each message defined in the mojom interface, and each
* receiver can have any number of listeners added to it.
*/
export const {{interface.name}}CallbackRouter = class {
export class {{interface.name}}CallbackRouter {
constructor() {
this.helper_internal_ = new mojo.internal.interfaceSupport.InterfaceReceiverHelperInternal(
{{interface.name}}Remote);
@ -215,4 +215,4 @@ export const {{interface.name}}CallbackRouter = class {
removeListener(id) {
return this.router_.removeListener(id);
}
};
}

@ -44,11 +44,11 @@ export const {{struct.name}}_Deserialize =
/**
* @record
*/
export const {{struct.name}} = class {
export class {{struct.name}} {
constructor() {
{%- for packed_field in struct.packed.packed_fields %}
/** @type { {{packed_field.field.kind|field_type_in_js_module}} } */
this.{{packed_field.field.name}};
{%- endfor %}
}
};
}