Commit 4224302f authored by Oksana Zhuravlova's avatar Oksana Zhuravlova Committed by Commit Bot

[mojo][JS][lite] Fix nested enums

This change exports a 'lite_closure_type' filter and modifies the
corresponding function to put an underscore instead of a dot for nested
enums. This new filter is now used in the enum template.

Bug: 939078
Change-Id: I0c4c1a7b08b6df09d460350a22f5b8cbcf318bc8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1538707
Commit-Queue: Oksana Zhuravlova <oksamyt@chromium.org>
Reviewed-by: default avatarKen Rockot <rockot@google.com>
Cr-Commit-Position: refs/heads/master@{#644678}
parent 15ebd34a
......@@ -11,6 +11,25 @@ struct TestStructA1 {
};
struct TestStructA2 {
enum NestedEnum {
A,
B,
};
TestStructA1 ax;
TestStructA1 ay;
NestedEnum enumField;
};
enum ModuleEnum {
THIRD,
};
interface ParentInterface {
enum NestedEnum {
FIRST,
SECOND,
};
SomeMethod(NestedEnum value);
};
......@@ -2,8 +2,10 @@
{# TODO: Less generic enum annotations would be nice. We do it this way because
the bindings generator is still too stupid to generate the right integral
constants directly. #}
{%- set enum_name = enum|lite_closure_type -%}
{% if generate_closure_exports -%}
goog.provide('{{enum_spec_parent}}.{{enum.name}}');
goog.provide('{{enum_name}}');
goog.provide('{{enum_spec_parent}}.{{enum.name}}Spec');
{%- endif %}
/**
......@@ -16,7 +18,7 @@ goog.provide('{{enum_spec_parent}}.{{enum.name}}Spec');
* @enum {number}
* @export
*/
{{enum_parent}}.{{enum.name}} = {
{{enum_name}} = {
{# Set up the enum here, but fill out the values later. #}
{%- for field in enum.fields %}
{{field.name}}: 0,
......@@ -32,11 +34,11 @@ goog.provide('{{enum_spec_parent}}.{{enum.name}}Spec');
{# Suppress type checks since we're assigning number into an enum. #}
/** @suppress {checkTypes} */
{%- if field.value %}
{{enum_parent}}.{{enum.name}}.{{field.name}} = {{field.value|expression_to_text_lite}};
{{enum_name}}.{{field.name}} = {{field.value|expression_to_text_lite}};
{%- elif loop.first %}
{{enum_parent}}.{{enum.name}}.{{field.name}} = 0;
{{enum_name}}.{{field.name}} = 0;
{%- else %}
{{enum_parent}}.{{enum.name}}.{{field.name}} = {{enum_parent}}.{{enum.name}}.{{enum.fields[loop.index0 - 1].name}} + 1;
{{enum_name}}.{{field.name}} = {{enum_name}}.{{enum.fields[loop.index0 - 1].name}} + 1;
{%- endif %}
{%- endfor %}
......
......@@ -306,6 +306,7 @@ class Generator(generator.Generator):
"namespace_declarations": self._NamespaceDeclarations,
"closure_type_with_nullability": self._ClosureTypeWithNullability,
"lite_closure_param_type": self._LiteClosureParamType,
"lite_closure_type": self._LiteClosureType,
"lite_closure_type_with_nullability":
self._LiteClosureTypeWithNullability,
"lite_closure_field_type": self._LiteClosureFieldType,
......@@ -442,6 +443,11 @@ class Generator(generator.Generator):
name.append(named_kind.module.namespace)
if named_kind.parent_kind:
name.append(named_kind.parent_kind.name)
if mojom.IsEnumKind(kind) and named_kind.parent_kind:
name = ".".join(name)
name += "_" + named_kind.name
else:
name.append("" + named_kind.name)
name = ".".join(name)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment