Skip to content

Commit 42c1cdd

Browse files
authored
Merge branch 'master' into reexporting_in_2018
2 parents 69bbf59 + 2177dee commit 42c1cdd

File tree

29 files changed

+260
-54
lines changed

29 files changed

+260
-54
lines changed

crates/backend/src/ast.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ pub struct Import {
7979
pub enum ImportModule {
8080
None,
8181
Named(String, Span),
82+
RawNamed(String, Span),
8283
Inline(usize, Span),
8384
}
8485

@@ -96,6 +97,10 @@ impl Hash for ImportModule {
9697
2u8.hash(h);
9798
idx.hash(h);
9899
}
100+
ImportModule::RawNamed(name, _) => {
101+
3u8.hash(h);
102+
name.hash(h);
103+
}
99104
}
100105
}
101106
}

crates/backend/src/codegen.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,18 @@ impl ToTokens for ast::ImportEnum {
844844
}
845845
}
846846

847+
#[allow(clippy::all)]
848+
impl wasm_bindgen::convert::OptionIntoWasmAbi for #name {
849+
#[inline]
850+
fn none() -> Self::Abi { Object::none() }
851+
}
852+
853+
#[allow(clippy::all)]
854+
impl wasm_bindgen::convert::OptionFromWasmAbi for #name {
855+
#[inline]
856+
fn is_none(abi: &Self::Abi) -> bool { Object::is_none(abi) }
857+
}
858+
847859
#[allow(clippy::all)]
848860
impl From<#name> for wasm_bindgen::JsValue {
849861
fn from(obj: #name) -> wasm_bindgen::JsValue {

crates/backend/src/encode.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ fn shared_import<'a>(i: &'a ast::Import, intern: &'a Interner) -> Result<Import<
208208
ast::ImportModule::Named(m, span) => {
209209
ImportModule::Named(intern.resolve_import_module(m, *span)?)
210210
}
211+
ast::ImportModule::RawNamed(m, _span) => ImportModule::RawNamed(intern.intern_str(m)),
211212
ast::ImportModule::Inline(idx, _) => ImportModule::Inline(*idx as u32),
212213
ast::ImportModule::None => ImportModule::None,
213214
},

crates/cli-support/src/js/mod.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2836,6 +2836,7 @@ impl<'a, 'b> SubContext<'a, 'b> {
28362836
// not sure how to import them.
28372837
let is_local_snippet = match import.module {
28382838
decode::ImportModule::Named(s) => self.cx.local_modules.contains_key(s),
2839+
decode::ImportModule::RawNamed(_) => false,
28392840
decode::ImportModule::Inline(_) => true,
28402841
decode::ImportModule::None => false,
28412842
};
@@ -2921,11 +2922,13 @@ impl<'a, 'b> SubContext<'a, 'b> {
29212922
name,
29222923
field,
29232924
},
2924-
decode::ImportModule::Named(module) => Import::Module {
2925-
module,
2926-
name,
2927-
field,
2928-
},
2925+
decode::ImportModule::Named(module) | decode::ImportModule::RawNamed(module) => {
2926+
Import::Module {
2927+
module,
2928+
name,
2929+
field,
2930+
}
2931+
}
29292932
decode::ImportModule::Inline(idx) => {
29302933
let offset = *self
29312934
.cx

crates/macro-support/src/parser.rs

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ macro_rules! attrgen {
3333
(static_method_of, StaticMethodOf(Span, Ident)),
3434
(js_namespace, JsNamespace(Span, Ident)),
3535
(module, Module(Span, String, Span)),
36+
(raw_module, RawModule(Span, String, Span)),
3637
(inline_js, InlineJs(Span, String, Span)),
3738
(getter, Getter(Span, Option<Ident>)),
3839
(setter, Setter(Span, Option<Ident>)),
@@ -1085,24 +1086,28 @@ impl MacroParse<BindgenAttrs> for syn::ItemForeignMod {
10851086
));
10861087
}
10871088
}
1088-
let module = match opts.module() {
1089-
Some((name, span)) => {
1090-
if opts.inline_js().is_some() {
1091-
let msg = "cannot specify both `module` and `inline_js`";
1092-
errors.push(Diagnostic::span_error(span, msg));
1093-
}
1094-
ast::ImportModule::Named(name.to_string(), span)
1089+
let module = if let Some((name, span)) = opts.module() {
1090+
if opts.inline_js().is_some() {
1091+
let msg = "cannot specify both `module` and `inline_js`";
1092+
errors.push(Diagnostic::span_error(span, msg));
10951093
}
1096-
None => {
1097-
match opts.inline_js() {
1098-
Some((js, span)) => {
1099-
let i = program.inline_js.len();
1100-
program.inline_js.push(js.to_string());
1101-
ast::ImportModule::Inline(i, span)
1102-
}
1103-
None => ast::ImportModule::None
1104-
}
1094+
if opts.raw_module().is_some() {
1095+
let msg = "cannot specify both `module` and `raw_module`";
1096+
errors.push(Diagnostic::span_error(span, msg));
11051097
}
1098+
ast::ImportModule::Named(name.to_string(), span)
1099+
} else if let Some((name, span)) = opts.raw_module() {
1100+
if opts.inline_js().is_some() {
1101+
let msg = "cannot specify both `raw_module` and `inline_js`";
1102+
errors.push(Diagnostic::span_error(span, msg));
1103+
}
1104+
ast::ImportModule::RawNamed(name.to_string(), span)
1105+
} else if let Some((js, span)) = opts.inline_js() {
1106+
let i = program.inline_js.len();
1107+
program.inline_js.push(js.to_string());
1108+
ast::ImportModule::Inline(i, span)
1109+
} else {
1110+
ast::ImportModule::None
11061111
};
11071112
for item in self.items.into_iter() {
11081113
if let Err(e) = item.macro_parse(program, module.clone()) {

crates/shared/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ macro_rules! shared_api {
2828
enum ImportModule<'a> {
2929
None,
3030
Named(&'a str),
31+
RawNamed(&'a str),
3132
Inline(u32),
3233
}
3334

crates/typescript-tests/index.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
use wasm_bindgen::prelude::*;
2+
3+
#[wasm_bindgen(typescript_custom_section)]
4+
const TS_INTERFACE_EXPORT: &'static str = r"
5+
interface Height { height: number; }
6+
";
7+
8+
#[wasm_bindgen]
9+
pub struct Person {
10+
pub height: u32,
11+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import * as wbg from '../pkg/typescript_tests';
2+
3+
const height: wbg.Height = new wbg.Person();

crates/typescript-tests/src/lib.rs

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,4 @@
1-
use wasm_bindgen::prelude::*;
2-
3-
#[wasm_bindgen]
4-
pub fn greet(_: &str) {}
5-
6-
#[wasm_bindgen]
7-
struct A {
8-
}
9-
10-
#[wasm_bindgen]
11-
impl A {
12-
#[wasm_bindgen(constructor)]
13-
pub fn new() -> A {
14-
A {}
15-
}
16-
17-
pub fn other() {}
18-
19-
pub fn foo(&self) {}
20-
}
1+
mod custom_section;
2+
mod opt_args_and_ret;
3+
mod simple_fn;
4+
mod simple_struct;

0 commit comments

Comments
 (0)