forked from lib-ruby-parser/wasm-bindings
-
Notifications
You must be signed in to change notification settings - Fork 0
/
messages.rs.liquid
56 lines (51 loc) · 1.67 KB
/
messages.rs.liquid
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// This field is autogenerated by {{ template }}
use wasm_bindgen::prelude::*;
use crate::IntoJs;
{%- for message in messages %}
#[wasm_bindgen(raw_module = "./messages")]
extern "C" {
#[wasm_bindgen(js_name = {{ message.camelcase_name }})]
pub type Js{{ message.camelcase_name }};
#[wasm_bindgen(constructor, js_namespace = messages, js_class = {{ message.camelcase_name }})]
fn new(
{% for field in message.fields %}
{{ field.comment | render_comment: "///", 8 }}
{{ field.snakecase_name }}:
{%- case field.field_type -%}
{%- when "Str" -%}
String,
{%- when "Byte" -%}
u8,
{%- endcase -%}
{% endfor %}
) -> Js{{ message.camelcase_name }};
}
{%- endfor %}
#[wasm_bindgen(raw_module = "./messages")]
extern "C" {
#[wasm_bindgen(js_name = DiagnosticMessage)]
pub type JsDiagnosticMessage;
#[wasm_bindgen(constructor, js_class = DiagnosticMessage)]
fn new(v: JsValue) -> JsDiagnosticMessage;
}
use lib_ruby_parser::DiagnosticMessage as RustDiagnosticMessage;
impl IntoJs for RustDiagnosticMessage {
type Output = JsDiagnosticMessage;
fn into_js(self) -> JsDiagnosticMessage {
match self {
{%- for message in messages %}
Self::{{ message.camelcase_name }} { {%- for field in message.fields %}{{ field.snakecase_name }}, {%- endfor %} } => {
JsDiagnosticMessage::from(
JsValue::from(
Js{{ message.camelcase_name }}::new(
{%- for field in message.fields %}
{{ field.snakecase_name }}.into_js(),
{%- endfor %}
)
)
)
},
{%- endfor %}
}
}
}