diff options
Diffstat (limited to 'third_party/python/glean_parser/glean_parser/templates/javascript.jinja2')
-rw-r--r-- | third_party/python/glean_parser/glean_parser/templates/javascript.jinja2 | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/third_party/python/glean_parser/glean_parser/templates/javascript.jinja2 b/third_party/python/glean_parser/glean_parser/templates/javascript.jinja2 new file mode 100644 index 0000000000..4036e8922f --- /dev/null +++ b/third_party/python/glean_parser/glean_parser/templates/javascript.jinja2 @@ -0,0 +1,73 @@ +{# The final Javascript/Typescript code is autogenerated, but this +Jinja2 template is not. Please file bugs! #} +{% macro obj_declaration(obj) %} +new {{ obj.type|class_name }}{% if obj.extra_keys and lang == "typescript" %}<{ + {% for name, type in obj.allowed_extra_keys_with_types %} + {{ name }}?: {{ type|extra_type_name }}, + {% endfor %} +}>{% endif %}({ + {% for arg_name in (obj.type|args).common if obj[arg_name] is defined %} + {{ arg_name|camelize }}: {{ obj[arg_name]|js }}, + {% endfor %} +}{% for arg_name in (obj.type|args).extra if obj[arg_name] is defined %}, {{ obj[arg_name]|js }}{% endfor %}){% endmacro %} +{% macro labeled_obj_declaration(obj) %} +new {{ "labeled"|class_name }}({ + {% for arg_name in (obj.type|args).common if obj[arg_name] is defined %} + {{ arg_name|camelize }}: {{ obj[arg_name]|js }}, + {% endfor %} +}, {{ obj.type|class_name }}{% if obj.labels is not none %}, {{ obj.labels|js }}{% endif %}){% endmacro %} +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// AUTOGENERATED BY glean_parser v{{ parser_version }}. DO NOT EDIT. DO NOT COMMIT. + +{% if platform != "qt" %} +{% if has_labeled_metrics %} +import LabeledMetricType from "@mozilla/glean/private/metrics/labeled"; +{% endif %} +{% for type in types %} +import {{ type|class_name }} from "@mozilla/glean/private/{{ type|import_path }}"; +{% endfor %} +{% else %} +.import org.mozilla.Glean {{ version }} as Glean +{% endif %} + +{% for obj in objs.values() %} +/** + * {{ obj.description|wordwrap() | replace("\n", "\n * ") }} + * + * Generated from `{{ obj.identifier() }}`. + */ +{% if obj.labeled %} +{% if platform != "qt" %}export {% endif %}const {{ obj.name|camelize }} = {{ labeled_obj_declaration(obj) }}; +{% else %} +{% if platform != "qt" %}export {% endif %}const {{ obj.name|camelize }} = {{ obj_declaration(obj) }}; +{% endif %} + +{% if obj|attr("_generate_enums") %} +{% for name, suffix in obj["_generate_enums"] %} +{% if obj|attr(name)|length and name == "reason_codes" %} +/** + * Reason codes for `{{ obj.identifier() }}`. + * + * @readonly + * @enum {string} + */ +{% if lang == "typescript" %} +export enum {{ obj.name|Camelize }}{{ name|Camelize }} { + {% for key in obj|attr(name) %} + {{ key|Camelize }} = "{{ key }}", + {% endfor %} +} +{% else %} +{% if platform != "qt" %}export {% endif %}const {{ obj.name|Camelize }}{{ name|Camelize }} = { + {% for key in obj|attr(name) %} + "{{ key|Camelize }}": "{{ key }}", + {% endfor %} +} +{% endif %} +{% endif %} +{% endfor %} +{% endif %} +{% endfor %} |