Skip to content

Commit 85fe257

Browse files
committed
Remove support for the version attribute
First added in #161 this never ended up panning out, so let's remove the experimental suport which isn't actually used by anything today and hold off on any other changes until an RFC happens.
1 parent 7f8d510 commit 85fe257

39 files changed

+34
-237
lines changed

crates/backend/src/ast.rs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ pub enum MethodSelf {
5656
#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq))]
5757
pub struct Import {
5858
pub module: Option<String>,
59-
pub version: Option<String>,
6059
pub js_namespace: Option<Ident>,
6160
pub kind: ImportKind,
6261
}
@@ -301,33 +300,8 @@ impl Variant {
301300

302301
impl Import {
303302
fn shared(&self) -> Result<shared::Import, Diagnostic> {
304-
match (&self.module, &self.version) {
305-
(&Some(ref m), None) if m.starts_with("./") => {}
306-
(&Some(ref m), &Some(_)) if m.starts_with("./") => {
307-
panic!(
308-
"when a module path starts with `./` that indicates \
309-
that a local file is being imported so the `version` \
310-
key cannot also be specified"
311-
);
312-
}
313-
(&Some(_), &Some(_)) => {}
314-
(&Some(_), &None) => panic!(
315-
"when the `module` directive doesn't start with `./` \
316-
then it's interpreted as an NPM package which requires \
317-
a `version` to be specified as well, try using \
318-
#[wasm_bindgen(module = \"...\", version = \"...\")]"
319-
),
320-
(&None, &Some(_)) => {
321-
panic!(
322-
"the #[wasm_bindgen(version = \"...\")] attribute can only \
323-
be used when `module = \"...\"` is also specified"
324-
);
325-
}
326-
(&None, &None) => {}
327-
}
328303
Ok(shared::Import {
329304
module: self.module.clone(),
330-
version: self.version.clone(),
331305
js_namespace: self.js_namespace.as_ref().map(|s| s.to_string()),
332306
kind: self.kind.shared(),
333307
})

crates/backend/src/util.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ pub fn ident_ty(ident: Ident) -> syn::Type {
9494
pub fn wrap_import_function(function: ast::ImportFunction) -> ast::Import {
9595
ast::Import {
9696
module: None,
97-
version: None,
9897
js_namespace: None,
9998
kind: ast::ImportKind::Function(function),
10099
}

crates/cli-support/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ base64 = "0.9"
1515
failure = "0.1.2"
1616
parity-wasm = "0.31"
1717
serde = "1.0"
18-
serde_derive = "1.0"
1918
serde_json = "1.0"
2019
tempfile = "3.0"
2120
wasm-bindgen-shared = { path = "../shared", version = '=0.2.15' }

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

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use std::mem;
55
use failure::{Error, ResultExt};
66
use parity_wasm;
77
use parity_wasm::elements::*;
8-
use serde_json;
98
use shared;
109
use wasm_gc;
1110

@@ -43,7 +42,6 @@ pub struct Context<'a> {
4342
pub exported_classes: HashMap<String, ExportedClass>,
4443
pub function_table_needed: bool,
4544
pub run_descriptor: &'a Fn(&str) -> Option<Vec<u32>>,
46-
pub module_versions: Vec<(String, String)>,
4745
}
4846

4947
#[derive(Default)]
@@ -458,7 +456,6 @@ impl<'a> Context<'a> {
458456

459457
self.export_table();
460458
self.gc()?;
461-
self.add_wasm_pack_section();
462459

463460
while js.contains("\n\n\n") {
464461
js = js.replace("\n\n\n", "\n\n");
@@ -1629,28 +1626,6 @@ impl<'a> Context<'a> {
16291626
self.globals.push_str("\n");
16301627
}
16311628

1632-
fn add_wasm_pack_section(&mut self) {
1633-
if self.module_versions.len() == 0 {
1634-
return;
1635-
}
1636-
1637-
#[derive(Serialize)]
1638-
struct WasmPackSchema<'a> {
1639-
version: &'a str,
1640-
modules: &'a [(String, String)],
1641-
}
1642-
1643-
let contents = serde_json::to_string(&WasmPackSchema {
1644-
version: "0.0.1",
1645-
modules: &self.module_versions,
1646-
}).unwrap();
1647-
1648-
let mut section = CustomSection::default();
1649-
*section.name_mut() = "__wasm_pack_unstable".to_string();
1650-
*section.payload_mut() = contents.into_bytes();
1651-
self.module.sections_mut().push(Section::Custom(section));
1652-
}
1653-
16541629
fn use_node_require(&self) -> bool {
16551630
self.config.nodejs && !self.config.nodejs_experimental_modules
16561631
}
@@ -1766,7 +1741,6 @@ impl<'a, 'b> SubContext<'a, 'b> {
17661741
}
17671742

17681743
fn generate_import(&mut self, import: &shared::Import) -> Result<(), Error> {
1769-
self.validate_import_module(import)?;
17701744
match import.kind {
17711745
shared::ImportKind::Function(ref f) => {
17721746
self.generate_import_function(import, f).with_context(|_| {
@@ -1787,41 +1761,6 @@ impl<'a, 'b> SubContext<'a, 'b> {
17871761
Ok(())
17881762
}
17891763

1790-
fn validate_import_module(&mut self, import: &shared::Import) -> Result<(), Error> {
1791-
let version = match import.version {
1792-
Some(ref s) => s,
1793-
None => return Ok(()),
1794-
};
1795-
let module = match import.module {
1796-
Some(ref s) => s,
1797-
None => return Ok(()),
1798-
};
1799-
if module.starts_with("./") {
1800-
return Ok(());
1801-
}
1802-
let pkg = if module.starts_with("@") {
1803-
// Translate `@foo/bar/baz` to `@foo/bar` and `@foo/bar` to itself
1804-
let first_slash = match module.find('/') {
1805-
Some(i) => i,
1806-
None => bail!(
1807-
"packages starting with `@` must be of the form \
1808-
`@foo/bar`, but found: `{}`",
1809-
module
1810-
),
1811-
};
1812-
match module[first_slash + 1..].find('/') {
1813-
Some(i) => &module[..i],
1814-
None => module,
1815-
}
1816-
} else {
1817-
module.split('/').next().unwrap()
1818-
};
1819-
self.cx
1820-
.module_versions
1821-
.push((pkg.to_string(), version.clone()));
1822-
Ok(())
1823-
}
1824-
18251764
fn generate_import_static(
18261765
&mut self,
18271766
info: &shared::Import,

crates/cli-support/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
extern crate parity_wasm;
44
extern crate wasm_bindgen_shared as shared;
5-
#[macro_use]
6-
extern crate serde_derive;
75
extern crate serde_json;
86
extern crate wasm_gc;
97
extern crate wasmi;
@@ -203,7 +201,6 @@ impl Bindgen {
203201
config: &self,
204202
module: &mut module,
205203
function_table_needed: false,
206-
module_versions: Default::default(),
207204
run_descriptor: &|name| {
208205
let mut v = MyExternals(Vec::new());
209206
match instance.invoke_export(name, &[], &mut v) {

crates/js-sys/tests/wasm/Function.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fn apply() {
2929
assert_eq!(Array::from(&arr).length(), 1);
3030
}
3131

32-
#[wasm_bindgen(module = "tests/wasm/Function.js", version = "*")]
32+
#[wasm_bindgen(module = "tests/wasm/Function.js")]
3333
extern {
3434
fn get_function_to_bind() -> Function;
3535
fn get_value_to_bind_to() -> JsValue;

crates/js-sys/tests/wasm/Generator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use wasm_bindgen::prelude::*;
22
use wasm_bindgen_test::*;
33
use js_sys::*;
44

5-
#[wasm_bindgen(module = "tests/wasm/Generator.js", version = "*")]
5+
#[wasm_bindgen(module = "tests/wasm/Generator.js")]
66
extern {
77
fn one_two_generator() -> Generator;
88
fn dummy_generator() -> Generator;

crates/js-sys/tests/wasm/Object.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ extern {
1010
fn set_foo(this: &Foo42, val: JsValue);
1111
}
1212

13-
#[wasm_bindgen(module = "tests/wasm/Object.js", version = "*")]
13+
#[wasm_bindgen(module = "tests/wasm/Object.js")]
1414
extern {
1515
fn map_with_symbol_key() -> Object;
1616
fn symbol_key() -> JsValue;

crates/js-sys/tests/wasm/Proxy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use wasm_bindgen::prelude::*;
22
use wasm_bindgen_test::*;
33
use js_sys::*;
44

5-
#[wasm_bindgen(module = "tests/wasm/Proxy.js", version = "*")]
5+
#[wasm_bindgen(module = "tests/wasm/Proxy.js")]
66
extern {
77
fn proxy_target() -> JsValue;
88
fn proxy_handler() -> Object;

crates/js-sys/tests/wasm/Reflect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use wasm_bindgen::prelude::*;
22
use wasm_bindgen_test::*;
33
use js_sys::*;
44

5-
#[wasm_bindgen(module = "tests/wasm/Reflect.js", version = "*")]
5+
#[wasm_bindgen(module = "tests/wasm/Reflect.js")]
66
extern {
77
fn get_char_at() -> Function;
88

crates/js-sys/tests/wasm/Symbol.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use wasm_bindgen::prelude::*;
22
use wasm_bindgen_test::*;
33
use js_sys::*;
44

5-
#[wasm_bindgen(module = "tests/wasm/Symbol.js", version = "*")]
5+
#[wasm_bindgen(module = "tests/wasm/Symbol.js")]
66
extern {
77
fn test_has_instance(sym: &Symbol);
88
fn test_is_concat_spreadable(sym: &Symbol);

crates/macro-support/src/parser.rs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,6 @@ impl BindgenAttrs {
5353
.next()
5454
}
5555

56-
/// Get the first version attribute
57-
fn version(&self) -> Option<&str> {
58-
self.attrs
59-
.iter()
60-
.filter_map(|a| match a {
61-
BindgenAttr::Version(s) => Some(&s[..]),
62-
_ => None,
63-
})
64-
.next()
65-
}
66-
6756
/// Whether the catch attribute is present
6857
fn catch(&self) -> bool {
6958
self.attrs.iter().any(|a| match a {
@@ -195,7 +184,6 @@ pub enum BindgenAttr {
195184
StaticMethodOf(Ident),
196185
JsNamespace(Ident),
197186
Module(String),
198-
Version(String),
199187
Getter(Option<Ident>),
200188
Setter(Option<Ident>),
201189
Structural,
@@ -257,13 +245,6 @@ impl syn::synom::Synom for BindgenAttr {
257245
(s.value())
258246
)=> { BindgenAttr::Module }
259247
|
260-
do_parse!(
261-
call!(term, "version") >>
262-
punct!(=) >>
263-
s: syn!(syn::LitStr) >>
264-
(s.value())
265-
)=> { BindgenAttr::Version }
266-
|
267248
do_parse!(
268249
call!(term, "js_name") >>
269250
punct!(=) >>
@@ -909,10 +890,6 @@ impl<'a> MacroParse<&'a BindgenAttrs> for syn::ForeignItem {
909890
BindgenAttrs::find(attrs)?
910891
};
911892
let module = item_opts.module().or(opts.module()).map(|s| s.to_string());
912-
let version = item_opts
913-
.version()
914-
.or(opts.version())
915-
.map(|s| s.to_string());
916893
let js_namespace = item_opts.js_namespace().or(opts.js_namespace()).cloned();
917894
let kind = match self {
918895
syn::ForeignItem::Fn(f) => f.convert((item_opts, &module))?,
@@ -923,7 +900,6 @@ impl<'a> MacroParse<&'a BindgenAttrs> for syn::ForeignItem {
923900

924901
program.imports.push(ast::Import {
925902
module,
926-
version,
927903
js_namespace,
928904
kind,
929905
});

crates/shared/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ pub struct Program {
2424
#[derive(Deserialize, Serialize)]
2525
pub struct Import {
2626
pub module: Option<String>,
27-
pub version: Option<String>,
2827
pub js_namespace: Option<String>,
2928
pub kind: ImportKind,
3029
}

crates/webidl-tests/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ fn main() {
2828
use wasm_bindgen::prelude::*;
2929
use wasm_bindgen_test::*;
3030
31-
#[wasm_bindgen(module = "{}", version = "*")]
31+
#[wasm_bindgen(module = "{}")]
3232
extern {{
3333
fn not_actually_a_function{1}();
3434
}}

crates/webidl/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,6 @@ impl<'src> WebidlParse<'src, ()> for weedle::InterfaceDefinition<'src> {
240240

241241
program.imports.push(backend::ast::Import {
242242
module: None,
243-
version: None,
244243
js_namespace: None,
245244
kind: backend::ast::ImportKind::Type(backend::ast::ImportType {
246245
vis: public(),
@@ -718,7 +717,6 @@ impl<'src> WebidlParse<'src, ()> for weedle::EnumDefinition<'src> {
718717
let variants = &self.values.body.list;
719718
program.imports.push(backend::ast::Import {
720719
module: None,
721-
version: None,
722720
js_namespace: None,
723721
kind: backend::ast::ImportKind::Enum(backend::ast::ImportEnum {
724722
vis: public(),

guide/src/design/import-customization.md

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,6 @@ controlling precisely how imports are imported and what they map to in JS. This
55
section is intended to hopefully be an exhaustive reference of the
66
possibilities!
77

8-
* `module` and `version` - we've seen `module` so far indicating where we can
9-
import items from but `version` is also allowed:
10-
11-
```rust
12-
#[wasm_bindgen(module = "moment", version = "^2.0.0")]
13-
extern {
14-
type Moment;
15-
fn moment() -> Moment;
16-
#[wasm_bindgen(method)]
17-
fn format(this: &Moment) -> String;
18-
}
19-
```
20-
21-
The `module` key is used to configure the module that each item is imported
22-
from. The `version` key does not affect the generated wasm itself but rather
23-
it's an informative directive for tools like [wasm-pack]. Tools like wasm-pack
24-
will generate a `package.json` for you and the `version` listed here, when
25-
`module` is also an NPM package, will correspond to what to write down in
26-
`package.json`.
27-
28-
In other words the usage of `module` as the name of an NPM package and
29-
`version` as the version requirement allows you to, inline in Rust, depend on
30-
the NPM ecosystem and import functionality from those packages. When bundled
31-
with a tool like [wasm-pack] everything will automatically get wired up with
32-
bundlers and you should be good to go!
33-
34-
Note that the `version` is *required* if `module` doesn't start with `./`. If
35-
`module` starts with `./` then it is an error to provide a version.
36-
37-
[wasm-pack]: https://github.com/rustwasm/wasm-pack
38-
398
* `catch` - this attribute allows catching a JS exception. This can be attached
409
to any imported function and the function must return a `Result` where the
4110
`Err` payload is a `JsValue`, like so:

0 commit comments

Comments
 (0)