mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-13 04:51:23 +00:00
Implement the local JS snippets RFC
This commit is an implementation of [RFC 6] which enables crates to inline local JS snippets into the final output artifact of `wasm-bindgen`. This is accompanied with a few minor breaking changes which are intended to be relatively minor in practice: * The `module` attribute disallows paths starting with `./` and `../`. It requires paths starting with `/` to actually exist on the filesystem. * The `--browser` flag no longer emits bundler-compatible code, but rather emits an ES module that can be natively loaded into a browser. Otherwise be sure to check out [the RFC][RFC 6] for more details, and otherwise this should implement at least the MVP version of the RFC! Notably at this time JS snippets with `--nodejs` or `--no-modules` are not supported and will unconditionally generate an error. [RFC 6]: https://github.com/rustwasm/rfcs/pull/6 Closes #1311
This commit is contained in:
@ -14,16 +14,22 @@ macro_rules! shared_api {
|
||||
imports: Vec<Import<'a>>,
|
||||
structs: Vec<Struct<'a>>,
|
||||
typescript_custom_sections: Vec<&'a str>,
|
||||
// version: &'a str,
|
||||
// schema_version: &'a str,
|
||||
local_modules: Vec<LocalModule<'a>>,
|
||||
inline_js: Vec<&'a str>,
|
||||
}
|
||||
|
||||
struct Import<'a> {
|
||||
module: Option<&'a str>,
|
||||
module: ImportModule<'a>,
|
||||
js_namespace: Option<&'a str>,
|
||||
kind: ImportKind<'a>,
|
||||
}
|
||||
|
||||
enum ImportModule<'a> {
|
||||
None,
|
||||
Named(&'a str),
|
||||
Inline(u32),
|
||||
}
|
||||
|
||||
enum ImportKind<'a> {
|
||||
Function(ImportFunction<'a>),
|
||||
Static(ImportStatic<'a>),
|
||||
@ -113,6 +119,11 @@ macro_rules! shared_api {
|
||||
readonly: bool,
|
||||
comments: Vec<&'a str>,
|
||||
}
|
||||
|
||||
struct LocalModule<'a> {
|
||||
identifier: &'a str,
|
||||
contents: &'a str,
|
||||
}
|
||||
}
|
||||
}; // end of mac case
|
||||
} // end of mac definition
|
||||
|
Reference in New Issue
Block a user