mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-19 07:51:26 +00:00
Generate enum js code
This commit is contained in:
@ -978,6 +978,9 @@ impl<'a, 'b> SubContext<'a, 'b> {
|
||||
for f in self.program.imports.iter() {
|
||||
self.generate_import(f);
|
||||
}
|
||||
for e in self.program.enums.iter() {
|
||||
self.generate_enum(e);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn generate_export(&mut self, export: &shared::Export) {
|
||||
@ -1424,6 +1427,19 @@ impl<'a, 'b> SubContext<'a, 'b> {
|
||||
self.cx.globals.push_str(&dst);
|
||||
self.cx.globals.push_str("\n");
|
||||
}
|
||||
|
||||
pub fn generate_enum(&mut self, enum_: &shared::Enum) {
|
||||
let mut variants = String::new();
|
||||
|
||||
let mut value = 0;
|
||||
for variant in enum_.variants.iter() {
|
||||
variants.push_str(&format!("{}:{},", variant.name, value));
|
||||
value = value + 1;
|
||||
}
|
||||
self.cx.globals.push_str(&format!("export const {} = {{", enum_.name));
|
||||
self.cx.globals.push_str(&variants);
|
||||
self.cx.globals.push_str("}\n");
|
||||
}
|
||||
}
|
||||
|
||||
struct VectorType {
|
||||
|
Reference in New Issue
Block a user