Skip to content

Commit

Permalink
Use conventional meta-item syntax for attributes
Browse files Browse the repository at this point in the history
Using the conventional form for attributes, which is compatible with
rustfmt and syn's meta-item parsing. This change is breaking and
substantial, but the necessary edits are largely mechanical.

With meta-items, it becomes possible to offload attribute parsing and
validation to `darling`. This offload fixes rustwasm#2874, as `darling` will
automatically generate errors for unexpected meta-item names. This also
makes it easier for people who are new to the codebase to understand
how to add new options.
  • Loading branch information
Ted Driggs committed Apr 28, 2022
1 parent e8ea739 commit 45030a1
Show file tree
Hide file tree
Showing 1,335 changed files with 55,408 additions and 11,247 deletions.
16 changes: 8 additions & 8 deletions benchmarks/src/lib.rs
Expand Up @@ -7,20 +7,20 @@ use web_sys::Node;

#[wasm_bindgen(raw_module = "../globals.js")]
extern "C" {
#[wasm_bindgen(js_name = jsthunk)]
#[wasm_bindgen(js_name = "jsthunk")]
fn js_thunk();
#[wasm_bindgen(js_name = add)]
#[wasm_bindgen(js_name = "add")]
fn js_add(a: i32, b: i32) -> i32;

pub type Foo;
#[wasm_bindgen(method, final, js_name = bar)]
#[wasm_bindgen(method, final, js_name = "bar")]
fn bar_final(this: &Foo);
#[wasm_bindgen(method, structural, js_name = bar)]
#[wasm_bindgen(method, structural, js_name = "bar")]
fn bar_structural(this: &Foo);

#[wasm_bindgen(js_name = jsthunk)]
#[wasm_bindgen(js_name = "jsthunk")]
fn doesnt_throw();
#[wasm_bindgen(catch, js_name = jsthunk)]
#[wasm_bindgen(catch, js_name = "jsthunk")]
fn doesnt_throw_catch() -> Result<(), JsValue>;
}

Expand Down Expand Up @@ -102,9 +102,9 @@ pub fn call_doesnt_throw_with_catch_n_times(n: usize) {
extern "C" {
pub type Element;

#[wasm_bindgen(method, js_name = firstChild, final, getter)]
#[wasm_bindgen(method, js_name = "firstChild", final, getter)]
fn first_child_final(this: &Element) -> Element;
#[wasm_bindgen(method, js_name = firstChild, structural, getter)]
#[wasm_bindgen(method, js_name = "firstChild", structural, getter)]
fn first_child_structural(this: &Element) -> Element;
}

Expand Down
1 change: 1 addition & 0 deletions crates/backend/Cargo.toml
Expand Up @@ -17,6 +17,7 @@ extra-traits = ["syn/extra-traits"]

[dependencies]
bumpalo = "3.0.0"
darling = "0.14.1"
lazy_static = "1.0.2"
log = "0.4"
proc-macro2 = "1.0"
Expand Down
6 changes: 6 additions & 0 deletions crates/backend/src/error.rs
Expand Up @@ -98,6 +98,12 @@ impl From<Error> for Diagnostic {
}
}

impl From<darling::Error> for Diagnostic {
fn from(err: darling::Error) -> Self {
Self::from(Error::from(err))
}
}

fn extract_spans(node: &dyn ToTokens) -> Option<(Span, Span)> {
let mut t = TokenStream::new();
node.to_tokens(&mut t);
Expand Down
6 changes: 3 additions & 3 deletions crates/cli/tests/wasm-bindgen/main.rs
Expand Up @@ -144,12 +144,12 @@ fn namespace_global_and_noglobal_works() {
use wasm_bindgen::prelude::*;
#[wasm_bindgen(module = "fs")]
extern "C" {
#[wasm_bindgen(js_namespace = window)]
#[wasm_bindgen(js_namespace = "window")]
fn t1();
}
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(js_namespace = window)]
#[wasm_bindgen(js_namespace = "window")]
fn t2();
}
#[wasm_bindgen]
Expand Down Expand Up @@ -189,7 +189,7 @@ fn bin_crate_works() {
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(js_namespace = console)]
#[wasm_bindgen(js_namespace = "console")]
fn log(data: &str);
}
Expand Down
6 changes: 3 additions & 3 deletions crates/futures/src/task/multithread.rs
Expand Up @@ -187,13 +187,13 @@ fn wait_async(ptr: &AtomicI32, current_value: i32) -> Option<js_sys::Promise> {
type Atomics;
type WaitAsyncResult;

#[wasm_bindgen(static_method_of = Atomics, js_name = waitAsync)]
#[wasm_bindgen(static_method_of = "Atomics", js_name = "waitAsync")]
fn wait_async(buf: &js_sys::Int32Array, index: i32, value: i32) -> WaitAsyncResult;

#[wasm_bindgen(static_method_of = Atomics, js_name = waitAsync, getter)]
#[wasm_bindgen(static_method_of = "Atomics", js_name = "waitAsync", getter)]
fn get_wait_async() -> JsValue;

#[wasm_bindgen(method, getter, structural, js_name = async)]
#[wasm_bindgen(method, getter, structural, js_name = "async")]
fn async_(this: &WaitAsyncResult) -> bool;

#[wasm_bindgen(method, getter, structural)]
Expand Down
200 changes: 100 additions & 100 deletions crates/js-sys/src/Temporal.rs

Large diffs are not rendered by default.

0 comments on commit 45030a1

Please sign in to comment.