Implement static imports

This allows importing static objects like `document`, `window`, or an arbitrary
JS object from a module
This commit is contained in:
Alex Crichton
2018-03-21 08:09:59 -07:00
parent eebe23649a
commit 8e894fcfc5
7 changed files with 189 additions and 3 deletions

View File

@ -11,7 +11,8 @@ pub const SCHEMA_VERSION: &str = "0";
pub struct Program {
pub exports: Vec<Export>,
pub enums: Vec<Enum>,
pub imports: Vec<Import>,
pub imported_functions: Vec<Import>,
pub imported_fields: Vec<ImportField>,
pub custom_type_names: Vec<CustomTypeName>,
pub version: String,
pub schema_version: String,
@ -30,6 +31,12 @@ pub struct Import {
pub function: Function,
}
#[derive(Deserialize)]
pub struct ImportField {
pub module: Option<String>,
pub name: String,
}
#[derive(Deserialize)]
pub struct Export {
pub class: Option<String>,
@ -148,3 +155,9 @@ pub fn version() -> String {
}
return v
}
impl ImportField {
pub fn shim_name(&self) -> String {
format!("__wbg_field_import_shim_{}", self.name)
}
}