mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-14 13:31:22 +00:00
@ -618,6 +618,14 @@ impl Import {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ImportKind {
|
impl ImportKind {
|
||||||
|
pub fn fits_on_impl(&self) -> bool {
|
||||||
|
match *self {
|
||||||
|
ImportKind::Function(_) => true,
|
||||||
|
ImportKind::Static(_) => false,
|
||||||
|
ImportKind::Type(_) => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn shared(&self) -> shared::ImportKind {
|
fn shared(&self) -> shared::ImportKind {
|
||||||
match *self {
|
match *self {
|
||||||
ImportKind::Function(ref f) => shared::ImportKind::Function(f.shared()),
|
ImportKind::Function(ref f) => shared::ImportKind::Function(f.shared()),
|
||||||
|
@ -44,14 +44,16 @@ impl ToTokens for ast::Program {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for i in self.imports.iter() {
|
for i in self.imports.iter() {
|
||||||
match i.js_namespace {
|
DescribeImport(&i.kind).to_tokens(tokens);
|
||||||
Some(ns) if types.contains(&ns) => {
|
|
||||||
|
if let Some(ns) = i.js_namespace {
|
||||||
|
if types.contains(&ns) && i.kind.fits_on_impl() {
|
||||||
let kind = &i.kind;
|
let kind = &i.kind;
|
||||||
(quote! { impl #ns { #kind } }).to_tokens(tokens);
|
(quote! { impl #ns { #kind } }).to_tokens(tokens);
|
||||||
}
|
}
|
||||||
_ => i.kind.to_tokens(tokens),
|
|
||||||
}
|
}
|
||||||
DescribeImport(&i.kind).to_tokens(tokens);
|
|
||||||
|
i.kind.to_tokens(tokens);
|
||||||
}
|
}
|
||||||
for e in self.enums.iter() {
|
for e in self.enums.iter() {
|
||||||
e.to_tokens(tokens);
|
e.to_tokens(tokens);
|
||||||
|
@ -464,3 +464,40 @@ fn rust_keyword() {
|
|||||||
"#)
|
"#)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn rust_keyword2() {
|
||||||
|
project()
|
||||||
|
.debug(false)
|
||||||
|
.file("src/lib.rs", r#"
|
||||||
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
|
extern crate wasm_bindgen;
|
||||||
|
|
||||||
|
use wasm_bindgen::prelude::*;
|
||||||
|
|
||||||
|
#[wasm_bindgen(module = "./test")]
|
||||||
|
extern {
|
||||||
|
pub type bar;
|
||||||
|
#[wasm_bindgen(js_namespace = bar, js_name = foo)]
|
||||||
|
static FOO: JsValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn run() {
|
||||||
|
assert_eq!(FOO.as_f64(), Some(3.0));
|
||||||
|
}
|
||||||
|
"#)
|
||||||
|
.file("test.ts", r#"
|
||||||
|
import { run } from "./out";
|
||||||
|
|
||||||
|
export const bar = {
|
||||||
|
foo: 3,
|
||||||
|
};
|
||||||
|
|
||||||
|
export function test() {
|
||||||
|
run();
|
||||||
|
}
|
||||||
|
"#)
|
||||||
|
.test();
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user