-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow web-sys to emit correct typescript declarations from webidl (#1998
) * Update to emit typescript names * Update to use NamedAnyref * Update incoming / outgoing * Remove added space * Remove comment * Add basic typescript tests for web-sys
- Loading branch information
1 parent
9d55978
commit ec1b945
Showing
14 changed files
with
140 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ pub mod opt_args_and_ret; | |
pub mod optional_fields; | ||
pub mod simple_fn; | ||
pub mod simple_struct; | ||
pub mod web_sys; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use wasm_bindgen::prelude::*; | ||
use web_sys::*; | ||
|
||
#[wasm_bindgen] | ||
pub struct DocStruct { | ||
doc: Document, | ||
} | ||
|
||
#[wasm_bindgen] | ||
impl DocStruct { | ||
pub fn new(doc: Document) -> Self { | ||
Self { doc } | ||
} | ||
|
||
pub fn get_doc(&self) -> Document { | ||
self.doc.clone() | ||
} | ||
|
||
pub fn append_element(&self, element: &HtmlElement) { | ||
self.doc.body().unwrap().append_child(element).unwrap(); | ||
} | ||
|
||
pub fn append_many(&self, _: &HtmlElement, _: &HtmlElement, _: &HtmlElement) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import * as wbg from "../pkg/typescript_tests"; | ||
|
||
const doc: Document = document; | ||
|
||
const docStruct = wbg.DocStruct.new(doc); | ||
|
||
const el: HTMLElement = document.createElement("a"); | ||
|
||
docStruct.append_element(el); | ||
docStruct.append_many(el, el, el); | ||
|
||
const newDoc = docStruct.get_doc(); | ||
|
||
// This test ensures that the correct Typescript types are | ||
// used. If "newDoc" is "any", then "event" will cause the | ||
// compilation to fail because of noImplicitAny. | ||
newDoc.addEventListener("load", event => { | ||
console.log(event); | ||
}); | ||
|
||
// Same as above, but testing that the param is a document. | ||
const listener: Parameters< | ||
Parameters<typeof wbg["DocStruct"]["new"]>[0]["addEventListener"] | ||
>[1] = event => console.log(event); | ||
|
||
newDoc.addEventListener("load", listener); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,7 @@ tys! { | |
SLICE | ||
VECTOR | ||
ANYREF | ||
NAMED_ANYREF | ||
ENUM | ||
RUST_STRUCT | ||
CHAR | ||
|