Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add enums.rs #12

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions crates/cli/tests/reference/enums.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* tslint:disable */
/* eslint-disable */
/**
* @param {Color} color
* @returns {Color}
*/
export function enum_echo(color: Color): Color;
/**
* @param {Color | undefined} [color]
* @returns {Color | undefined}
*/
export function option_enum_echo(color?: Color): Color | undefined;
/**
*/
export enum Color {
Green = 0,
Yellow = 1,
Red = 2,
}
54 changes: 54 additions & 0 deletions crates/cli/tests/reference/enums.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
let wasm;
export function __wbg_set_wasm(val) {
wasm = val;
}


const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder;

let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true });

cachedTextDecoder.decode();

let cachedUint8Memory0 = null;

function getUint8Memory0() {
if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) {
cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
}
return cachedUint8Memory0;
}

function getStringFromWasm0(ptr, len) {
ptr = ptr >>> 0;
return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
}
/**
* @param {Color} color
* @returns {Color}
*/
export function enum_echo(color) {
const ret = wasm.enum_echo(color);
return ret;
}

function isLikeNone(x) {
return x === undefined || x === null;
}
/**
* @param {Color | undefined} [color]
* @returns {Color | undefined}
*/
export function option_enum_echo(color) {
const ret = wasm.option_enum_echo(isLikeNone(color) ? 3 : color);
return ret === 3 ? undefined : ret;
}

/**
*/
export const Color = Object.freeze({ Green:0,"0":"Green",Yellow:1,"1":"Yellow",Red:2,"2":"Red", });

export function __wbindgen_throw(arg0, arg1) {
throw new Error(getStringFromWasm0(arg0, arg1));
};

19 changes: 19 additions & 0 deletions crates/cli/tests/reference/enums.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use wasm_bindgen::prelude::*;

#[wasm_bindgen]
#[derive(PartialEq, Debug)]
pub enum Color {
Green,
Yellow,
Red,
}

#[wasm_bindgen]
pub fn enum_echo(color: Color) -> Color {
color
}

#[wasm_bindgen]
pub fn option_enum_echo(color: Option<Color>) -> Option<Color> {
color
}
9 changes: 9 additions & 0 deletions crates/cli/tests/reference/enums.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(module
(type (;0;) (func (param i32) (result i32)))
(func $enum_echo (;0;) (type 0) (param i32) (result i32))
(func $option_enum_echo (;1;) (type 0) (param i32) (result i32))
(memory (;0;) 17)
(export "memory" (memory 0))
(export "enum_echo" (func $enum_echo))
(export "option_enum_echo" (func $option_enum_echo))
)