wasm-bindgen/tests/headless/main.rs
Alex Crichton b762948456 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
2019-03-05 08:00:47 -08:00

42 lines
812 B
Rust

#![cfg(target_arch = "wasm32")]
extern crate wasm_bindgen;
extern crate wasm_bindgen_test;
use wasm_bindgen::prelude::*;
use wasm_bindgen_test::*;
wasm_bindgen_test_configure!(run_in_browser);
#[wasm_bindgen]
pub struct ConsumeRetString;
#[wasm_bindgen]
impl ConsumeRetString {
// https://github.com/rustwasm/wasm-bindgen/issues/329#issuecomment-411082013
//
// This used to cause two `const ptr = ...` declarations, which is invalid
// JS.
pub fn consume(self) -> String {
String::new()
}
}
#[wasm_bindgen_test]
fn works() {
ConsumeRetString.consume();
}
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(js_namespace = console)]
pub fn log(s: &str);
}
#[wasm_bindgen_test]
fn can_log_html_strings() {
log("<script>alert('lol')</script>");
}
pub mod snippets;