summaryrefslogtreecommitdiff
path: root/vendor/wasm-bindgen-shared/src
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2025-07-02 18:36:06 -0600
committermo khan <mo@mokhan.ca>2025-07-02 18:36:06 -0600
commit8cdfa445d6629ffef4cb84967ff7017654045bc2 (patch)
tree22f0b0907c024c78d26a731e2e1f5219407d8102 /vendor/wasm-bindgen-shared/src
parent4351c74c7c5f97156bc94d3a8549b9940ac80e3f (diff)
chore: add vendor directory
Diffstat (limited to 'vendor/wasm-bindgen-shared/src')
-rw-r--r--vendor/wasm-bindgen-shared/src/identifier.rs42
-rw-r--r--vendor/wasm-bindgen-shared/src/lib.rs239
-rw-r--r--vendor/wasm-bindgen-shared/src/schema_hash_approval.rs16
3 files changed, 297 insertions, 0 deletions
diff --git a/vendor/wasm-bindgen-shared/src/identifier.rs b/vendor/wasm-bindgen-shared/src/identifier.rs
new file mode 100644
index 00000000..51ebcc81
--- /dev/null
+++ b/vendor/wasm-bindgen-shared/src/identifier.rs
@@ -0,0 +1,42 @@
+/// Returns whether a character has the Unicode `ID_Start` properly.
+///
+/// This is only ever-so-slightly different from `XID_Start` in a few edge
+/// cases, so we handle those edge cases manually and delegate everything else
+/// to `unicode-ident`.
+fn is_id_start(c: char) -> bool {
+ match c {
+ '\u{037A}' | '\u{0E33}' | '\u{0EB3}' | '\u{309B}' | '\u{309C}' | '\u{FC5E}'
+ | '\u{FC5F}' | '\u{FC60}' | '\u{FC61}' | '\u{FC62}' | '\u{FC63}' | '\u{FDFA}'
+ | '\u{FDFB}' | '\u{FE70}' | '\u{FE72}' | '\u{FE74}' | '\u{FE76}' | '\u{FE78}'
+ | '\u{FE7A}' | '\u{FE7C}' | '\u{FE7E}' | '\u{FF9E}' | '\u{FF9F}' => true,
+ _ => unicode_ident::is_xid_start(c),
+ }
+}
+
+/// Returns whether a character has the Unicode `ID_Continue` properly.
+///
+/// This is only ever-so-slightly different from `XID_Continue` in a few edge
+/// cases, so we handle those edge cases manually and delegate everything else
+/// to `unicode-ident`.
+fn is_id_continue(c: char) -> bool {
+ match c {
+ '\u{037A}' | '\u{309B}' | '\u{309C}' | '\u{FC5E}' | '\u{FC5F}' | '\u{FC60}'
+ | '\u{FC61}' | '\u{FC62}' | '\u{FC63}' | '\u{FDFA}' | '\u{FDFB}' | '\u{FE70}'
+ | '\u{FE72}' | '\u{FE74}' | '\u{FE76}' | '\u{FE78}' | '\u{FE7A}' | '\u{FE7C}'
+ | '\u{FE7E}' => true,
+ _ => unicode_ident::is_xid_continue(c),
+ }
+}
+
+/// Returns whether a string is a valid JavaScript identifier.
+/// Defined at https://tc39.es/ecma262/#prod-IdentifierName.
+pub fn is_valid_ident(name: &str) -> bool {
+ !name.is_empty()
+ && name.chars().enumerate().all(|(i, char)| {
+ if i == 0 {
+ is_id_start(char) || char == '$' || char == '_'
+ } else {
+ is_id_continue(char) || char == '$' || char == '\u{200C}' || char == '\u{200D}'
+ }
+ })
+}
diff --git a/vendor/wasm-bindgen-shared/src/lib.rs b/vendor/wasm-bindgen-shared/src/lib.rs
new file mode 100644
index 00000000..20b1164e
--- /dev/null
+++ b/vendor/wasm-bindgen-shared/src/lib.rs
@@ -0,0 +1,239 @@
+#![doc(html_root_url = "https://docs.rs/wasm-bindgen-shared/0.2")]
+
+pub mod identifier;
+#[cfg(test)]
+mod schema_hash_approval;
+
+// This gets changed whenever our schema changes.
+// At this time versions of wasm-bindgen and wasm-bindgen-cli are required to have the exact same
+// SCHEMA_VERSION in order to work together.
+pub const SCHEMA_VERSION: &str = "0.2.100";
+
+#[macro_export]
+macro_rules! shared_api {
+ ($mac:ident) => {
+ $mac! {
+ struct Program<'a> {
+ exports: Vec<Export<'a>>,
+ enums: Vec<Enum<'a>>,
+ imports: Vec<Import<'a>>,
+ structs: Vec<Struct<'a>>,
+ // NOTE: Originally typescript_custom_sections are just some strings
+ // But the expression type can only be parsed into a string during compilation
+ // So when encoding, LitOrExpr contains two types, one is that expressions are parsed into strings during compilation, and the other is can be parsed directly.
+ // When decoding, LitOrExpr can be decoded as a string.
+ typescript_custom_sections: Vec<LitOrExpr<'a>>,
+ local_modules: Vec<LocalModule<'a>>,
+ inline_js: Vec<&'a str>,
+ unique_crate_identifier: &'a str,
+ package_json: Option<&'a str>,
+ linked_modules: Vec<LinkedModule<'a>>,
+ }
+
+ struct Import<'a> {
+ module: Option<ImportModule<'a>>,
+ js_namespace: Option<Vec<String>>,
+ kind: ImportKind<'a>,
+ }
+
+ struct LinkedModule<'a> {
+ module: ImportModule<'a>,
+ link_function_name: &'a str,
+ }
+
+ enum ImportModule<'a> {
+ Named(&'a str),
+ RawNamed(&'a str),
+ Inline(u32),
+ }
+
+ enum ImportKind<'a> {
+ Function(ImportFunction<'a>),
+ Static(ImportStatic<'a>),
+ String(ImportString<'a>),
+ Type(ImportType<'a>),
+ Enum(StringEnum<'a>),
+ }
+
+ struct ImportFunction<'a> {
+ shim: &'a str,
+ catch: bool,
+ variadic: bool,
+ assert_no_shim: bool,
+ method: Option<MethodData<'a>>,
+ structural: bool,
+ function: Function<'a>,
+ }
+
+ struct MethodData<'a> {
+ class: &'a str,
+ kind: MethodKind<'a>,
+ }
+
+ enum MethodKind<'a> {
+ Constructor,
+ Operation(Operation<'a>),
+ }
+
+ struct Operation<'a> {
+ is_static: bool,
+ kind: OperationKind<'a>,
+ }
+
+ enum OperationKind<'a> {
+ Regular,
+ Getter(&'a str),
+ Setter(&'a str),
+ IndexingGetter,
+ IndexingSetter,
+ IndexingDeleter,
+ }
+
+ struct ImportStatic<'a> {
+ name: &'a str,
+ shim: &'a str,
+ }
+
+ struct ImportString<'a> {
+ shim: &'a str,
+ string: &'a str,
+ }
+
+ struct ImportType<'a> {
+ name: &'a str,
+ instanceof_shim: &'a str,
+ vendor_prefixes: Vec<&'a str>,
+ }
+
+ struct StringEnum<'a> {
+ name: &'a str,
+ variant_values: Vec<&'a str>,
+ comments: Vec<&'a str>,
+ generate_typescript: bool,
+ }
+
+ struct Export<'a> {
+ class: Option<&'a str>,
+ comments: Vec<&'a str>,
+ consumed: bool,
+ function: Function<'a>,
+ method_kind: MethodKind<'a>,
+ start: bool,
+ }
+
+ struct Enum<'a> {
+ name: &'a str,
+ signed: bool,
+ variants: Vec<EnumVariant<'a>>,
+ comments: Vec<&'a str>,
+ generate_typescript: bool,
+ }
+
+ struct EnumVariant<'a> {
+ name: &'a str,
+ value: u32,
+ comments: Vec<&'a str>,
+ }
+
+ struct Function<'a> {
+ args: Vec<FunctionArgumentData<'a>>,
+ asyncness: bool,
+ name: &'a str,
+ generate_typescript: bool,
+ generate_jsdoc: bool,
+ variadic: bool,
+ ret_ty_override: Option<&'a str>,
+ ret_desc: Option<&'a str>,
+ }
+
+ struct FunctionArgumentData<'a> {
+ name: String,
+ ty_override: Option<&'a str>,
+ desc: Option<&'a str>,
+ }
+
+ struct Struct<'a> {
+ name: &'a str,
+ fields: Vec<StructField<'a>>,
+ comments: Vec<&'a str>,
+ is_inspectable: bool,
+ generate_typescript: bool,
+ }
+
+ struct StructField<'a> {
+ name: &'a str,
+ readonly: bool,
+ comments: Vec<&'a str>,
+ generate_typescript: bool,
+ generate_jsdoc: bool,
+ }
+
+ struct LocalModule<'a> {
+ identifier: &'a str,
+ contents: &'a str,
+ linked_module: bool,
+ }
+ }
+ }; // end of mac case
+} // end of mac definition
+
+pub fn new_function(struct_name: &str) -> String {
+ let mut name = "__wbg_".to_string();
+ name.extend(struct_name.chars().flat_map(|s| s.to_lowercase()));
+ name.push_str("_new");
+ name
+}
+
+pub fn free_function(struct_name: &str) -> String {
+ let mut name = "__wbg_".to_string();
+ name.extend(struct_name.chars().flat_map(|s| s.to_lowercase()));
+ name.push_str("_free");
+ name
+}
+
+pub fn unwrap_function(struct_name: &str) -> String {
+ let mut name = "__wbg_".to_string();
+ name.extend(struct_name.chars().flat_map(|s| s.to_lowercase()));
+ name.push_str("_unwrap");
+ name
+}
+
+pub fn free_function_export_name(function_name: &str) -> String {
+ function_name.to_string()
+}
+
+pub fn struct_function_export_name(struct_: &str, f: &str) -> String {
+ let mut name = struct_
+ .chars()
+ .flat_map(|s| s.to_lowercase())
+ .collect::<String>();
+ name.push('_');
+ name.push_str(f);
+ name
+}
+
+pub fn struct_field_get(struct_: &str, f: &str) -> String {
+ let mut name = String::from("__wbg_get_");
+ name.extend(struct_.chars().flat_map(|s| s.to_lowercase()));
+ name.push('_');
+ name.push_str(f);
+ name
+}
+
+pub fn struct_field_set(struct_: &str, f: &str) -> String {
+ let mut name = String::from("__wbg_set_");
+ name.extend(struct_.chars().flat_map(|s| s.to_lowercase()));
+ name.push('_');
+ name.push_str(f);
+ name
+}
+
+pub fn version() -> String {
+ let mut v = env!("CARGO_PKG_VERSION").to_string();
+ if let Some(s) = option_env!("WBG_VERSION") {
+ v.push_str(" (");
+ v.push_str(s);
+ v.push(')');
+ }
+ v
+}
diff --git a/vendor/wasm-bindgen-shared/src/schema_hash_approval.rs b/vendor/wasm-bindgen-shared/src/schema_hash_approval.rs
new file mode 100644
index 00000000..16747438
--- /dev/null
+++ b/vendor/wasm-bindgen-shared/src/schema_hash_approval.rs
@@ -0,0 +1,16 @@
+// Whenever the lib.rs changes, the SCHEMA_FILE_HASH environment variable will change and the
+// schema_version test below will fail.
+// Proceed as follows:
+//
+// If the schema in this library has changed then:
+// 1. Change this APPROVED_SCHEMA_FILE_HASH to the new hash.
+//
+// If the schema in this library has changed then:
+// 1. Bump the version in `crates/shared/Cargo.toml`
+// 2. Change the `SCHEMA_VERSION` in this library to this new Cargo.toml version
+const APPROVED_SCHEMA_FILE_HASH: &str = "6242250402756688161";
+
+#[test]
+fn schema_version() {
+ assert_eq!(env!("SCHEMA_FILE_HASH"), APPROVED_SCHEMA_FILE_HASH)
+}