Rename static to namespace

This commit renames the `static` attribute to `namespace` and simultaneously
reduces and expands the scope. The `namespace` attribute can now be applied to
all imports in addition to functions, and it no longer recognizes full typed
paths but rather just a bare identifier. The `namespace` attribute will generate
a Rust namespace to invoke the item through if one doesn't already exist (aka
bindign a type).
This commit is contained in:
Alex Crichton
2018-03-21 09:55:16 -07:00
parent dd054fa357
commit 4a4f8b18b6
9 changed files with 267 additions and 176 deletions

View File

@ -11,8 +11,7 @@ pub const SCHEMA_VERSION: &str = "0";
pub struct Program {
pub exports: Vec<Export>,
pub enums: Vec<Enum>,
pub imported_functions: Vec<Import>,
pub imported_fields: Vec<ImportField>,
pub imports: Vec<Import>,
pub custom_type_names: Vec<CustomTypeName>,
pub version: String,
pub schema_version: String,
@ -20,11 +19,25 @@ pub struct Program {
#[derive(Deserialize)]
pub struct Import {
pub module: Option<String>,
pub namespace: Option<String>,
pub kind: ImportKind,
}
#[derive(Deserialize)]
#[serde(tag = "kind", rename_all = "lowercase")]
pub enum ImportKind {
Function(ImportFunction),
Static(ImportStatic),
Type(ImportType),
}
#[derive(Deserialize)]
pub struct ImportFunction {
pub module: Option<String>,
pub catch: bool,
pub method: bool,
pub js_new: bool,
pub statik: bool,
pub getter: Option<String>,
pub setter: Option<String>,
pub class: Option<String>,
@ -32,11 +45,15 @@ pub struct Import {
}
#[derive(Deserialize)]
pub struct ImportField {
pub struct ImportStatic {
pub module: Option<String>,
pub name: String,
}
#[derive(Deserialize)]
pub struct ImportType {
}
#[derive(Deserialize)]
pub struct Export {
pub class: Option<String>,
@ -99,6 +116,10 @@ pub fn mangled_import_name(struct_: Option<&str>, f: &str) -> String {
}
}
pub fn static_import_shim_name(statik: &str) -> String {
format!("__wbg_field_import_shim_{}", statik)
}
pub type Type = char;
pub const TYPE_VECTOR_JSVALUE: char = '\u{5b}';
@ -155,9 +176,3 @@ pub fn version() -> String {
}
return v
}
impl ImportField {
pub fn shim_name(&self) -> String {
format!("__wbg_field_import_shim_{}", self.name)
}
}