diff -Nru rust-wasm-bindgen-backend-0.2.58/Cargo.toml rust-wasm-bindgen-backend-0.2.78/Cargo.toml --- rust-wasm-bindgen-backend-0.2.58/Cargo.toml 2020-01-07 19:48:40.000000000 +0000 +++ rust-wasm-bindgen-backend-0.2.78/Cargo.toml 1970-01-01 00:00:01.000000000 +0000 @@ -3,17 +3,16 @@ # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies -# to registry (e.g., crates.io) dependencies +# to registry (e.g., crates.io) dependencies. # -# If you believe there's an error in this file please file an -# issue against the rust-lang/cargo repository. If you're -# editing this file be aware that the upstream Cargo.toml -# will likely look very different (and much more reasonable) +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. [package] edition = "2018" name = "wasm-bindgen-backend" -version = "0.2.58" +version = "0.2.78" authors = ["The wasm-bindgen Developers"] description = "Backend code generation of the wasm-bindgen tool\n" homepage = "https://rustwasm.github.io/wasm-bindgen/" @@ -24,7 +23,7 @@ version = "3.0.0" [dependencies.lazy_static] -version = "1.0.0" +version = "1.0.2" [dependencies.log] version = "0.4" @@ -40,7 +39,7 @@ features = ["full"] [dependencies.wasm-bindgen-shared] -version = "=0.2.58" +version = "=0.2.78" [features] extra-traits = ["syn/extra-traits"] diff -Nru rust-wasm-bindgen-backend-0.2.58/Cargo.toml.orig rust-wasm-bindgen-backend-0.2.78/Cargo.toml.orig --- rust-wasm-bindgen-backend-0.2.58/Cargo.toml.orig 2020-01-07 17:34:55.000000000 +0000 +++ rust-wasm-bindgen-backend-0.2.78/Cargo.toml.orig 1973-11-29 21:33:09.000000000 +0000 @@ -1,6 +1,6 @@ [package] name = "wasm-bindgen-backend" -version = "0.2.58" +version = "0.2.78" authors = ["The wasm-bindgen Developers"] license = "MIT/Apache-2.0" repository = "https://github.com/rustwasm/wasm-bindgen/tree/master/crates/backend" @@ -17,9 +17,9 @@ [dependencies] bumpalo = "3.0.0" -lazy_static = "1.0.0" +lazy_static = "1.0.2" log = "0.4" proc-macro2 = "1.0" quote = '1.0' syn = { version = '1.0', features = ['full'] } -wasm-bindgen-shared = { path = "../shared", version = "=0.2.58" } +wasm-bindgen-shared = { path = "../shared", version = "=0.2.78" } diff -Nru rust-wasm-bindgen-backend-0.2.58/debian/cargo-checksum.json rust-wasm-bindgen-backend-0.2.78/debian/cargo-checksum.json --- rust-wasm-bindgen-backend-0.2.58/debian/cargo-checksum.json 2020-01-08 14:05:31.000000000 +0000 +++ rust-wasm-bindgen-backend-0.2.78/debian/cargo-checksum.json 2022-01-08 11:44:22.000000000 +0000 @@ -1 +1 @@ -{"package":"11cdb95816290b525b32587d76419facd99662a07e59d3cdb560488a819d9a45","files":{}} +{"package":"a317bf8f9fba2476b4b2c85ef4c4af8ff39c3c7f0cdfeed4f82c34a880aa837b","files":{}} diff -Nru rust-wasm-bindgen-backend-0.2.58/debian/changelog rust-wasm-bindgen-backend-0.2.78/debian/changelog --- rust-wasm-bindgen-backend-0.2.58/debian/changelog 2020-01-08 14:05:31.000000000 +0000 +++ rust-wasm-bindgen-backend-0.2.78/debian/changelog 2022-01-08 11:44:22.000000000 +0000 @@ -1,3 +1,10 @@ +rust-wasm-bindgen-backend (0.2.78-1) unstable; urgency=medium + + * Team upload. + * Package wasm-bindgen-backend 0.2.78 from crates.io using debcargo 2.5.0 + + -- Peter Michael Green Sat, 08 Jan 2022 11:44:22 +0000 + rust-wasm-bindgen-backend (0.2.58-1) unstable; urgency=medium * Package wasm-bindgen-backend 0.2.58 from crates.io using debcargo 2.4.0 diff -Nru rust-wasm-bindgen-backend-0.2.58/debian/compat rust-wasm-bindgen-backend-0.2.78/debian/compat --- rust-wasm-bindgen-backend-0.2.58/debian/compat 2020-01-08 14:05:31.000000000 +0000 +++ rust-wasm-bindgen-backend-0.2.78/debian/compat 2022-01-08 11:44:22.000000000 +0000 @@ -1 +1 @@ -11 +12 diff -Nru rust-wasm-bindgen-backend-0.2.58/debian/control rust-wasm-bindgen-backend-0.2.78/debian/control --- rust-wasm-bindgen-backend-0.2.58/debian/control 2020-01-08 14:05:31.000000000 +0000 +++ rust-wasm-bindgen-backend-0.2.78/debian/control 2022-01-08 11:44:22.000000000 +0000 @@ -1,27 +1,28 @@ Source: rust-wasm-bindgen-backend Section: rust Priority: optional -Build-Depends: debhelper (>= 11), - dh-cargo (>= 18), +Build-Depends: debhelper (>= 12), + dh-cargo (>= 25), cargo:native , rustc:native , libstd-rust-dev , librust-bumpalo-3+default-dev , - librust-lazy-static-1+default-dev , + librust-lazy-static-1+default-dev (>= 1.0.2-~~) , librust-log-0.4+default-dev , librust-proc-macro2-1+default-dev , librust-quote-1+default-dev , librust-syn-1+default-dev , librust-syn-1+full-dev , - librust-wasm-bindgen-shared-0.2.58+default-dev + librust-wasm-bindgen-shared-0.2.78+default-dev Maintainer: Debian Rust Maintainers Uploaders: Wolfgang Silbermayr , kpcyrd -Standards-Version: 4.2.0 +Standards-Version: 4.5.1 Vcs-Git: https://salsa.debian.org/rust-team/debcargo-conf.git [src/wasm-bindgen-backend] Vcs-Browser: https://salsa.debian.org/rust-team/debcargo-conf/tree/master/src/wasm-bindgen-backend Homepage: https://rustwasm.github.io/wasm-bindgen/ +Rules-Requires-Root: no Package: librust-wasm-bindgen-backend-dev Architecture: any @@ -29,13 +30,13 @@ Depends: ${misc:Depends}, librust-bumpalo-3+default-dev, - librust-lazy-static-1+default-dev, + librust-lazy-static-1+default-dev (>= 1.0.2-~~), librust-log-0.4+default-dev, librust-proc-macro2-1+default-dev, librust-quote-1+default-dev, librust-syn-1+default-dev, librust-syn-1+full-dev, - librust-wasm-bindgen-shared-0.2.58+default-dev + librust-wasm-bindgen-shared-0.2.78+default-dev Suggests: librust-wasm-bindgen-backend+extra-traits-dev (= ${binary:Version}) Provides: @@ -47,9 +48,9 @@ librust-wasm-bindgen-backend-0.2-dev (= ${binary:Version}), librust-wasm-bindgen-backend-0.2+default-dev (= ${binary:Version}), librust-wasm-bindgen-backend-0.2+spans-dev (= ${binary:Version}), - librust-wasm-bindgen-backend-0.2.58-dev (= ${binary:Version}), - librust-wasm-bindgen-backend-0.2.58+default-dev (= ${binary:Version}), - librust-wasm-bindgen-backend-0.2.58+spans-dev (= ${binary:Version}) + librust-wasm-bindgen-backend-0.2.78-dev (= ${binary:Version}), + librust-wasm-bindgen-backend-0.2.78+default-dev (= ${binary:Version}), + librust-wasm-bindgen-backend-0.2.78+spans-dev (= ${binary:Version}) Description: Backend code generation of the wasm-bindgen tool - Rust source code This package contains the source for the Rust wasm-bindgen-backend crate, packaged by debcargo for use with cargo and dh-cargo. @@ -64,7 +65,7 @@ Provides: librust-wasm-bindgen-backend-0+extra-traits-dev (= ${binary:Version}), librust-wasm-bindgen-backend-0.2+extra-traits-dev (= ${binary:Version}), - librust-wasm-bindgen-backend-0.2.58+extra-traits-dev (= ${binary:Version}) + librust-wasm-bindgen-backend-0.2.78+extra-traits-dev (= ${binary:Version}) Description: Backend code generation of the wasm-bindgen tool - feature "extra-traits" This metapackage enables feature "extra-traits" for the Rust wasm-bindgen- backend crate, by pulling in any additional dependencies needed by diff -Nru rust-wasm-bindgen-backend-0.2.58/debian/copyright rust-wasm-bindgen-backend-0.2.78/debian/copyright --- rust-wasm-bindgen-backend-0.2.58/debian/copyright 2020-01-08 14:05:31.000000000 +0000 +++ rust-wasm-bindgen-backend-0.2.78/debian/copyright 2022-01-08 11:44:22.000000000 +0000 @@ -4,12 +4,12 @@ Source: https://github.com/rustwasm/wasm-bindgen/tree/master/crates/backend Files: * -Copyright: 2018-2020 The wasm-bindgen Developers +Copyright: 2018-2021 The wasm-bindgen Developers License: MIT or Apache-2.0 Files: debian/* Copyright: - 2019-2020 Debian Rust Maintainers + 2019-2022 Debian Rust Maintainers 2019-2020 Wolfgang Silbermayr License: MIT or Apache-2.0 diff -Nru rust-wasm-bindgen-backend-0.2.58/debian/copyright.debcargo.hint rust-wasm-bindgen-backend-0.2.78/debian/copyright.debcargo.hint --- rust-wasm-bindgen-backend-0.2.58/debian/copyright.debcargo.hint 2020-01-08 14:05:31.000000000 +0000 +++ rust-wasm-bindgen-backend-0.2.78/debian/copyright.debcargo.hint 2022-01-08 11:44:22.000000000 +0000 @@ -12,11 +12,18 @@ be correct information so you should review and fix this before uploading to the archive. +Files: ./LICENSE-MIT +Copyright: 2014 Alex Crichton +License: UNKNOWN-LICENSE; FIXME (overlay) +Comment: + FIXME (overlay): These notices are extracted from files. Please review them + before uploading to the archive. + Files: debian/* Copyright: - 2019-2020 Debian Rust Maintainers - 2019-2020 Wolfgang Silbermayr - 2019-2020 kpcyrd + 2019-2022 Debian Rust Maintainers + 2019-2022 Wolfgang Silbermayr + 2019-2022 kpcyrd License: MIT or Apache-2.0 License: Apache-2.0 diff -Nru rust-wasm-bindgen-backend-0.2.58/debian/librust-wasm-bindgen-backend+extra-traits-dev.lintian-overrides rust-wasm-bindgen-backend-0.2.78/debian/librust-wasm-bindgen-backend+extra-traits-dev.lintian-overrides --- rust-wasm-bindgen-backend-0.2.58/debian/librust-wasm-bindgen-backend+extra-traits-dev.lintian-overrides 1970-01-01 00:00:00.000000000 +0000 +++ rust-wasm-bindgen-backend-0.2.78/debian/librust-wasm-bindgen-backend+extra-traits-dev.lintian-overrides 2022-01-08 11:44:22.000000000 +0000 @@ -0,0 +1 @@ +librust-wasm-bindgen-backend+extra-traits-dev binary: empty-rust-library-declares-provides * \ No newline at end of file diff -Nru rust-wasm-bindgen-backend-0.2.58/debian/tests/control rust-wasm-bindgen-backend-0.2.78/debian/tests/control --- rust-wasm-bindgen-backend-0.2.58/debian/tests/control 2020-01-08 14:05:31.000000000 +0000 +++ rust-wasm-bindgen-backend-0.2.78/debian/tests/control 2022-01-08 11:44:22.000000000 +0000 @@ -1,11 +1,24 @@ -Test-Command: /usr/share/cargo/bin/cargo-auto-test wasm-bindgen-backend 0.2.58 --all-targets --all-features +Test-Command: /usr/share/cargo/bin/cargo-auto-test wasm-bindgen-backend 0.2.78 --all-targets --all-features +Features: test-name=rust-wasm-bindgen-backend:@ Depends: dh-cargo (>= 18), @ Restrictions: allow-stderr, skip-not-installable -Test-Command: /usr/share/cargo/bin/cargo-auto-test wasm-bindgen-backend 0.2.58 --all-targets --no-default-features -Depends: dh-cargo (>= 18), librust-wasm-bindgen-backend-dev +Test-Command: /usr/share/cargo/bin/cargo-auto-test wasm-bindgen-backend 0.2.78 --all-targets +Features: test-name=librust-wasm-bindgen-backend-dev:default +Depends: dh-cargo (>= 18), @ +Restrictions: allow-stderr, skip-not-installable + +Test-Command: /usr/share/cargo/bin/cargo-auto-test wasm-bindgen-backend 0.2.78 --all-targets --no-default-features --features spans +Features: test-name=librust-wasm-bindgen-backend-dev:spans +Depends: dh-cargo (>= 18), @ Restrictions: allow-stderr, skip-not-installable -Test-Command: /usr/share/cargo/bin/cargo-auto-test wasm-bindgen-backend 0.2.58 --all-targets --features extra-traits -Depends: dh-cargo (>= 18), librust-wasm-bindgen-backend+extra-traits-dev +Test-Command: /usr/share/cargo/bin/cargo-auto-test wasm-bindgen-backend 0.2.78 --all-targets --no-default-features +Features: test-name=librust-wasm-bindgen-backend-dev: +Depends: dh-cargo (>= 18), @ +Restrictions: allow-stderr, skip-not-installable + +Test-Command: /usr/share/cargo/bin/cargo-auto-test wasm-bindgen-backend 0.2.78 --all-targets --no-default-features --features extra-traits +Features: test-name=librust-wasm-bindgen-backend+extra-traits-dev:extra-traits +Depends: dh-cargo (>= 18), @ Restrictions: allow-stderr, skip-not-installable diff -Nru rust-wasm-bindgen-backend-0.2.58/debian/watch rust-wasm-bindgen-backend-0.2.78/debian/watch --- rust-wasm-bindgen-backend-0.2.58/debian/watch 2020-01-08 14:05:31.000000000 +0000 +++ rust-wasm-bindgen-backend-0.2.78/debian/watch 2022-01-08 11:44:22.000000000 +0000 @@ -2,4 +2,3 @@ opts=filenamemangle=s/.*\/(.*)\/download/wasm-bindgen-backend-$1\.tar\.gz/g,\ uversionmangle=s/(\d)[_\.\-\+]?((RC|rc|pre|dev|beta|alpha)\d*)$/$1~$2/ \ https://qa.debian.org/cgi-bin/fakeupstream.cgi?upstream=crates.io/wasm-bindgen-backend .*/crates/wasm-bindgen-backend/@ANY_VERSION@/download - diff -Nru rust-wasm-bindgen-backend-0.2.58/LICENSE-APACHE rust-wasm-bindgen-backend-0.2.78/LICENSE-APACHE --- rust-wasm-bindgen-backend-0.2.58/LICENSE-APACHE 1970-01-01 00:00:00.000000000 +0000 +++ rust-wasm-bindgen-backend-0.2.78/LICENSE-APACHE 1973-11-29 21:33:09.000000000 +0000 @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + +Copyright [yyyy] [name of copyright owner] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff -Nru rust-wasm-bindgen-backend-0.2.58/LICENSE-MIT rust-wasm-bindgen-backend-0.2.78/LICENSE-MIT --- rust-wasm-bindgen-backend-0.2.58/LICENSE-MIT 1970-01-01 00:00:00.000000000 +0000 +++ rust-wasm-bindgen-backend-0.2.78/LICENSE-MIT 1973-11-29 21:33:09.000000000 +0000 @@ -0,0 +1,25 @@ +Copyright (c) 2014 Alex Crichton + +Permission is hereby granted, free of charge, to any +person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the +Software without restriction, including without +limitation the rights to use, copy, modify, merge, +publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software +is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice +shall be included in all copies or substantial portions +of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF +ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED +TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT +SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR +IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. diff -Nru rust-wasm-bindgen-backend-0.2.58/src/ast.rs rust-wasm-bindgen-backend-0.2.78/src/ast.rs --- rust-wasm-bindgen-backend-0.2.58/src/ast.rs 2019-12-03 17:18:15.000000000 +0000 +++ rust-wasm-bindgen-backend-0.2.78/src/ast.rs 1973-11-29 21:33:09.000000000 +0000 @@ -1,3 +1,7 @@ +//! A representation of the Abstract Syntax Tree of a Rust program, +//! with all the added metadata necessary to generate WASM bindings +//! for it. + use crate::Diagnostic; use proc_macro2::{Ident, Span}; use std::hash::{Hash, Hasher}; @@ -17,18 +21,24 @@ pub enums: Vec, /// rust structs pub structs: Vec, - /// rust consts - pub consts: Vec, - /// "dictionaries", generated for WebIDL, which are basically just "typed - /// objects" in the sense that they represent a JS object with a particular - /// shape in JIT parlance. - pub dictionaries: Vec, /// custom typescript sections to be included in the definition file pub typescript_custom_sections: Vec, /// Inline JS snippets pub inline_js: Vec, } +impl Program { + /// Returns true if the Program is empty + pub fn is_empty(&self) -> bool { + self.exports.is_empty() + && self.imports.is_empty() + && self.enums.is_empty() + && self.structs.is_empty() + && self.typescript_custom_sections.is_empty() + && self.inline_js.is_empty() + } +} + /// A rust to js interface. Allows interaction with rust objects/functions /// from javascript. #[cfg_attr(feature = "extra-traits", derive(Debug))] @@ -65,20 +75,29 @@ RefShared, } +/// Things imported from a JS module (in an `extern` block) #[cfg_attr(feature = "extra-traits", derive(Debug))] #[derive(Clone)] pub struct Import { + /// The type of module being imported from pub module: ImportModule, - pub js_namespace: Option, + /// The namespace to access the item through, if any + pub js_namespace: Option>, + /// The type of item being imported pub kind: ImportKind, } +/// The possible types of module to import from #[cfg_attr(feature = "extra-traits", derive(Debug))] #[derive(Clone)] pub enum ImportModule { + /// No module / import from global scope None, + /// Import from the named module, with relative paths interpreted Named(String, Span), + /// Import from the named module, without interpreting paths RawNamed(String, Span), + /// Import from an inline JS snippet Inline(usize, Span), } @@ -104,90 +123,149 @@ } } +/// The type of item being imported #[cfg_attr(feature = "extra-traits", derive(Debug))] #[derive(Clone)] pub enum ImportKind { + /// Importing a function Function(ImportFunction), + /// Importing a static value Static(ImportStatic), + /// Importing a type/class Type(ImportType), + /// Importing a JS enum Enum(ImportEnum), } +/// A function being imported from JS #[cfg_attr(feature = "extra-traits", derive(Debug))] #[derive(Clone)] pub struct ImportFunction { + /// The full signature of the function pub function: Function, + /// The name rust code will use pub rust_name: Ident, + /// The type being returned pub js_ret: Option, + /// Whether to catch JS exceptions pub catch: bool, + /// Whether the function is variadic on the JS side pub variadic: bool, + /// Whether the function should use structural type checking pub structural: bool, + /// Causes the Builder (See cli-support::js::binding::Builder) to error out if + /// it finds itself generating code for a function with this signature pub assert_no_shim: bool, + /// The kind of function being imported pub kind: ImportFunctionKind, + /// The shim name to use in the generated code. The 'shim' is a function that appears in + /// the generated JS as a wrapper around the actual function to import, performing any + /// necessary conversions (EG adding a try/catch to change a thrown error into a Result) pub shim: Ident, + /// The doc comment on this import, if one is provided pub doc_comment: Option, } +/// The type of a function being imported #[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq))] #[derive(Clone)] pub enum ImportFunctionKind { + /// A class method Method { + /// The name of the class for this method, in JS class: String, + /// The type of the class for this method, in Rust ty: syn::Type, + /// The kind of method this is kind: MethodKind, }, + /// A standard function Normal, } +/// The type of a method #[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq))] #[derive(Clone)] pub enum MethodKind { + /// A class constructor Constructor, + /// Any other kind of method Operation(Operation), } +/// The operation performed by a class method #[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq))] #[derive(Clone)] pub struct Operation { + /// Whether this method is static pub is_static: bool, + /// The internal kind of this Operation pub kind: OperationKind, } +/// The kind of operation performed by a method #[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq))] #[derive(Clone)] pub enum OperationKind { + /// A standard method, nothing special Regular, + /// A method for getting the value of the provided Ident Getter(Option), + /// A method for setting the value of the provided Ident Setter(Option), + /// A dynamically intercepted getter IndexingGetter, + /// A dynamically intercepted setter IndexingSetter, + /// A dynamically intercepted deleter IndexingDeleter, } +/// The type of a static being imported #[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq))] #[derive(Clone)] pub struct ImportStatic { + /// The visibility of this static in Rust pub vis: syn::Visibility, + /// The type of static being imported pub ty: syn::Type, + /// The name of the shim function used to access this static pub shim: Ident, + /// The name of this static on the Rust side pub rust_name: Ident, + /// The name of this static on the JS side pub js_name: String, } +/// The metadata for a type being imported #[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq))] #[derive(Clone)] pub struct ImportType { + /// The visibility of this type in Rust pub vis: syn::Visibility, + /// The name of this type on the Rust side pub rust_name: Ident, + /// The name of this type on the JS side pub js_name: String, + /// The custom attributes to apply to this type pub attrs: Vec, + /// The TS definition to generate for this type + pub typescript_type: Option, + /// The doc comment applied to this type, if one exists pub doc_comment: Option, + /// The name of the shim to check instanceof for this type pub instanceof_shim: String, + /// The name of the remote function to use for the generated is_type_of pub is_type_of: Option, + /// The list of classes this extends, if any pub extends: Vec, + /// A custom prefix to add and attempt to fall back to, if the type isn't found pub vendor_prefixes: Vec, + /// If present, don't generate a `Deref` impl + pub no_deref: bool, } +/// The metadata for an Enum being imported #[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq))] #[derive(Clone)] pub struct ImportEnum { @@ -203,113 +281,128 @@ pub rust_attrs: Vec, } +/// Information about a function being imported or exported #[cfg_attr(feature = "extra-traits", derive(Debug))] #[derive(Clone)] pub struct Function { + /// The name of the function pub name: String, + /// The span of the function's name in Rust code pub name_span: Span, + /// Whether the function has a js_name attribute pub renamed_via_js_name: bool, + /// The arguments to the function pub arguments: Vec, + /// The return type of the function, if provided pub ret: Option, + /// Any custom attributes being applied to the function pub rust_attrs: Vec, + /// The visibility of this function in Rust pub rust_vis: syn::Visibility, + /// Whether this is an `async` function pub r#async: bool, + /// Whether to generate a typescript definition for this function + pub generate_typescript: bool, } +/// Information about a Struct being exported #[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq))] #[derive(Clone)] pub struct Struct { + /// The name of the struct in Rust code pub rust_name: Ident, + /// The name of the struct in JS code pub js_name: String, + /// All the fields of this struct to export pub fields: Vec, + /// The doc comments on this struct, if provided pub comments: Vec, + /// Whether this struct is inspectable (provides toJSON/toString properties to JS) pub is_inspectable: bool, + /// Whether to generate a typescript definition for this struct + pub generate_typescript: bool, } +/// The field of a struct #[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq))] #[derive(Clone)] pub struct StructField { - pub name: syn::Member, + /// The name of the field in Rust code + pub rust_name: syn::Member, + /// The name of the field in JS code + pub js_name: String, + /// The name of the struct this field is part of pub struct_name: Ident, + /// Whether this value is read-only to JS pub readonly: bool, + /// The type of this field pub ty: syn::Type, + /// The name of the getter shim for this field pub getter: Ident, + /// The name of the setter shim for this field pub setter: Ident, + /// The doc comments on this field, if any pub comments: Vec, + /// Whether to generate a typescript definition for this field + pub generate_typescript: bool, + /// Whether to use .clone() in the auto-generated getter for this field + pub getter_with_clone: bool, } +/// Information about an Enum being exported #[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq))] #[derive(Clone)] pub struct Enum { - pub name: Ident, + /// The name of this enum in Rust code + pub rust_name: Ident, + /// The name of this enum in JS code + pub js_name: String, + /// The variants provided by this enum pub variants: Vec, + /// The doc comments on this enum, if any pub comments: Vec, + /// The value to use for a `none` variant of the enum pub hole: u32, + /// Whether to generate a typescript definition for this enum + pub generate_typescript: bool, } +/// The variant of an enum #[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq))] #[derive(Clone)] pub struct Variant { + /// The name of this variant pub name: Ident, + /// The backing value of this variant pub value: u32, + /// The doc comments on this variant, if any + pub comments: Vec, } +/// Unused, the type of an argument to / return from a function #[derive(Copy, Clone, Debug, PartialEq, Eq)] pub enum TypeKind { + /// A by-reference arg, EG `&T` ByRef, + /// A by-mutable-reference arg, EG `&mut T` ByMutRef, + /// A by-value arg, EG `T` ByValue, } +/// Unused, the location of a type for a function argument (import/export, argument/ret) #[derive(Copy, Clone, Debug, PartialEq, Eq)] pub enum TypeLocation { + /// An imported argument (JS side type) ImportArgument, + /// An imported return ImportRet, + /// An exported argument (Rust side type) ExportArgument, + /// An exported return ExportRet, } -#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq))] -#[derive(Clone)] -pub struct Const { - pub vis: syn::Visibility, - pub name: Ident, - pub class: Option, - pub ty: syn::Type, - pub value: ConstValue, -} - -#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq))] -#[derive(Clone)] -/// same as webidl::ast::ConstValue -pub enum ConstValue { - BooleanLiteral(bool), - FloatLiteral(f64), - SignedIntegerLiteral(i64), - UnsignedIntegerLiteral(u64), - Null, -} - -#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq))] -#[derive(Clone)] -pub struct Dictionary { - pub name: Ident, - pub fields: Vec, - pub ctor: bool, - pub doc_comment: Option, - pub ctor_doc_comment: Option, -} - -#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq))] -#[derive(Clone)] -pub struct DictionaryField { - pub rust_name: Ident, - pub js_name: String, - pub required: bool, - pub ty: syn::Type, - pub doc_comment: Option, -} - impl Export { /// Mangles a rust -> javascript export, so that the created Ident will be unique over function /// name and class name, if the function belongs to a javascript class. @@ -360,12 +453,6 @@ pub fn infer_setter_property(&self) -> Result { let name = self.name.to_string(); - // if `#[wasm_bindgen(js_name = "...")]` is used then that explicitly - // because it was hand-written anyway. - if self.renamed_via_js_name { - return Ok(name); - } - // Otherwise we infer names based on the Rust function name. if !name.starts_with("set_") { bail_span!( diff -Nru rust-wasm-bindgen-backend-0.2.58/src/codegen.rs rust-wasm-bindgen-backend-0.2.78/src/codegen.rs --- rust-wasm-bindgen-backend-0.2.58/src/codegen.rs 2020-01-07 16:16:45.000000000 +0000 +++ rust-wasm-bindgen-backend-0.2.78/src/codegen.rs 1973-11-29 21:33:09.000000000 +0000 @@ -4,15 +4,19 @@ use crate::Diagnostic; use proc_macro2::{Ident, Literal, Span, TokenStream}; use quote::{quote, ToTokens}; -use std::collections::HashSet; +use std::collections::{HashMap, HashSet}; use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::Mutex; use syn; use wasm_bindgen_shared as shared; +/// A trait for converting AST structs into Tokens and adding them to a TokenStream, +/// or providing a diagnostic if conversion fails. pub trait TryToTokens { + /// Attempt to convert a `Self` into tokens and add it to the `TokenStream` fn try_to_tokens(&self, tokens: &mut TokenStream) -> Result<(), Diagnostic>; + /// Attempt to convert a `Self` into a new `TokenStream` fn try_to_token_stream(&self) -> Result { let mut tokens = TokenStream::new(); self.try_to_tokens(&mut tokens)?; @@ -32,28 +36,31 @@ for s in self.structs.iter() { s.to_tokens(tokens); } - let mut types = HashSet::new(); + let mut types = HashMap::new(); for i in self.imports.iter() { if let ast::ImportKind::Type(t) = &i.kind { - types.insert(t.rust_name.clone()); + types.insert(t.rust_name.to_string(), t.rust_name.clone()); } } for i in self.imports.iter() { - DescribeImport(&i.kind).to_tokens(tokens); + DescribeImport { kind: &i.kind }.to_tokens(tokens); // If there is a js namespace, check that name isn't a type. If it is, // this import might be a method on that type. - if let Some(ns) = &i.js_namespace { - if types.contains(ns) && i.kind.fits_on_impl() { - let kind = match i.kind.try_to_token_stream() { - Ok(kind) => kind, - Err(e) => { - errors.push(e); - continue; - } - }; - (quote! { impl #ns { #kind } }).to_tokens(tokens); - continue; + if let Some(nss) = &i.js_namespace { + // When the namespace is `A.B`, the type name should be `B`. + if let Some(ns) = nss.last().and_then(|t| types.get(t)) { + if i.kind.fits_on_impl() { + let kind = match i.kind.try_to_token_stream() { + Ok(kind) => kind, + Err(e) => { + errors.push(e); + continue; + } + }; + (quote! { impl #ns { #kind } }).to_tokens(tokens); + continue; + } } } @@ -64,12 +71,6 @@ for e in self.enums.iter() { e.to_tokens(tokens); } - for c in self.consts.iter() { - c.to_tokens(tokens); - } - for d in self.dictionaries.iter() { - d.to_tokens(tokens); - } Diagnostic::from_vec(errors)?; @@ -219,7 +220,7 @@ #[doc(hidden)] #[allow(clippy::all)] pub unsafe extern "C" fn #free_fn(ptr: u32) { - <#name as wasm_bindgen::convert::FromWasmAbi>::from_abi(ptr); + drop(<#name as wasm_bindgen::convert::FromWasmAbi>::from_abi(ptr)); } #[allow(clippy::all)] @@ -267,14 +268,25 @@ impl ToTokens for ast::StructField { fn to_tokens(&self, tokens: &mut TokenStream) { - let name = &self.name; + let rust_name = &self.rust_name; let struct_name = &self.struct_name; let ty = &self.ty; let getter = &self.getter; let setter = &self.setter; - let assert_copy = quote! { assert_copy::<#ty>() }; - let assert_copy = respan(assert_copy, ty); + let maybe_assert_copy = if self.getter_with_clone { + quote! {} + } else { + quote! { assert_copy::<#ty>() } + }; + let maybe_assert_copy = respan(maybe_assert_copy, ty); + + let maybe_clone = if self.getter_with_clone { + quote! { .clone() } + } else { + quote! {} + }; + (quote! { #[doc(hidden)] #[allow(clippy::all)] @@ -286,22 +298,23 @@ use wasm_bindgen::convert::IntoWasmAbi; fn assert_copy(){} - #assert_copy; + #maybe_assert_copy; let js = js as *mut WasmRefCell<#struct_name>; assert_not_null(js); - let val = (*js).borrow().#name; + let val = (*js).borrow().#rust_name#maybe_clone; <#ty as IntoWasmAbi>::into_abi(val) } }) .to_tokens(tokens); - Descriptor( - &getter, - quote! { + Descriptor { + ident: &getter, + inner: quote! { <#ty as WasmDescribe>::describe(); }, - ) + attrs: vec![], + } .to_tokens(tokens); if self.readonly { @@ -323,7 +336,7 @@ let js = js as *mut WasmRefCell<#struct_name>; assert_not_null(js); let val = <#ty as FromWasmAbi>::from_abi(val); - (*js).borrow_mut().#name = val; + (*js).borrow_mut().#rust_name = val; } }) .to_tokens(tokens); @@ -446,10 +459,11 @@ // For an `async` function we always run it through `future_to_promise` // since we're returning a promise to JS, and this will implicitly // require that the function returns a `Future>` - let (ret_ty, ret_expr) = if self.function.r#async { + let (ret_ty, inner_ret_ty, ret_expr) = if self.function.r#async { if self.start { ( quote! { () }, + quote! { () }, quote! { wasm_bindgen_futures::spawn_local(async move { <#syn_ret as wasm_bindgen::__rt::Start>::start(#ret.await); @@ -459,6 +473,7 @@ } else { ( quote! { wasm_bindgen::JsValue }, + quote! { #syn_ret }, quote! { wasm_bindgen_futures::future_to_promise(async move { <#syn_ret as wasm_bindgen::__rt::IntoJsResult>::into_js_result(#ret.await) @@ -469,16 +484,18 @@ } else if self.start { ( quote! { () }, + quote! { () }, quote! { <#syn_ret as wasm_bindgen::__rt::Start>::start(#ret) }, ) } else { - (quote! { #syn_ret }, quote! { #ret }) + (quote! { #syn_ret }, quote! { #syn_ret }, quote! { #ret }) }; let projection = quote! { <#ret_ty as wasm_bindgen::convert::ReturnWasmAbi> }; let convert_ret = quote! { #projection::return_abi(#ret_expr) }; let describe_ret = quote! { <#ret_ty as WasmDescribe>::describe(); + <#inner_ret_ty as WasmDescribe>::describe(); }; let nargs = self.function.arguments.len() as u32; let attrs = &self.function.rust_attrs; @@ -528,16 +545,17 @@ // this, but the tl;dr; is that this is stripped from the final wasm // binary along with anything it references. let export = Ident::new(&export_name, Span::call_site()); - Descriptor( - &export, - quote! { + Descriptor { + ident: &export, + inner: quote! { inform(FUNCTION); inform(0); inform(#nargs); #(<#argtys as WasmDescribe>::describe();)* #describe_ret }, - ) + attrs: attrs.clone(), + } .to_tokens(into); Ok(()) @@ -579,6 +597,21 @@ } }; + let description = if let Some(typescript_type) = &self.typescript_type { + let typescript_type_len = typescript_type.len() as u32; + let typescript_type_chars = typescript_type.chars().map(|c| c as u32); + quote! { + use wasm_bindgen::describe::*; + inform(NAMED_EXTERNREF); + inform(#typescript_type_len); + #(inform(#typescript_type_chars);)* + } + } else { + quote! { + JsValue::describe() + } + }; + let is_type_of = self.is_type_of.as_ref().map(|is_type_of| { quote! { #[inline] @@ -589,6 +622,8 @@ } }); + let no_deref = self.no_deref; + (quote! { #[allow(bad_style)] #(#attrs)* @@ -606,21 +641,12 @@ use wasm_bindgen::convert::{OptionIntoWasmAbi, OptionFromWasmAbi}; use wasm_bindgen::convert::RefFromWasmAbi; use wasm_bindgen::describe::WasmDescribe; - use wasm_bindgen::{JsValue, JsCast}; + use wasm_bindgen::{JsValue, JsCast, JsObject}; use wasm_bindgen::__rt::core; impl WasmDescribe for #rust_name { fn describe() { - JsValue::describe(); - } - } - - impl core::ops::Deref for #rust_name { - type Target = #internal_obj; - - #[inline] - fn deref(&self) -> &#internal_obj { - &self.obj + #description } } @@ -743,11 +769,28 @@ } } + impl JsObject for #rust_name {} + () }; }) .to_tokens(tokens); + if !no_deref { + (quote! { + #[allow(clippy::all)] + impl core::ops::Deref for #rust_name { + type Target = #internal_obj; + + #[inline] + fn deref(&self) -> &#internal_obj { + &self.obj + } + } + }) + .to_tokens(tokens); + } + for superclass in self.extends.iter() { (quote! { #[allow(clippy::all)] @@ -817,61 +860,69 @@ #[allow(clippy::all)] impl #name { - #vis fn from_js_value(obj: &wasm_bindgen::JsValue) -> Option<#name> { - obj.as_string().and_then(|obj_str| match obj_str.as_str() { + fn from_str(s: &str) -> Option<#name> { + match s { #(#variant_strings => Some(#variant_paths_ref),)* _ => None, - }) + } + } + + fn to_str(&self) -> &'static str { + match self { + #(#variant_paths_ref => #variant_strings,)* + #name::__Nonexhaustive => panic!(#expect_string), + } + } + + #vis fn from_js_value(obj: &wasm_bindgen::JsValue) -> Option<#name> { + obj.as_string().and_then(|obj_str| Self::from_str(obj_str.as_str())) } } + // It should really be using &str for all of these, but that requires some major changes to cli-support #[allow(clippy::all)] impl wasm_bindgen::describe::WasmDescribe for #name { fn describe() { - wasm_bindgen::JsValue::describe() + ::describe() } } #[allow(clippy::all)] impl wasm_bindgen::convert::IntoWasmAbi for #name { - type Abi = ::Abi; + type Abi = ::Abi; #[inline] fn into_abi(self) -> Self::Abi { - wasm_bindgen::JsValue::from(self).into_abi() + ::into_abi(self.into()) } } #[allow(clippy::all)] impl wasm_bindgen::convert::FromWasmAbi for #name { - type Abi = ::Abi; + type Abi = ::Abi; unsafe fn from_abi(js: Self::Abi) -> Self { - #name::from_js_value(&wasm_bindgen::JsValue::from_abi(js)).unwrap_or(#name::__Nonexhaustive) + let s = ::from_abi(js); + #name::from_js_value(&s).unwrap_or(#name::__Nonexhaustive) } } #[allow(clippy::all)] impl wasm_bindgen::convert::OptionIntoWasmAbi for #name { #[inline] - fn none() -> Self::Abi { Object::none() } + fn none() -> Self::Abi { <::js_sys::Object as wasm_bindgen::convert::OptionIntoWasmAbi>::none() } } #[allow(clippy::all)] impl wasm_bindgen::convert::OptionFromWasmAbi for #name { #[inline] - fn is_none(abi: &Self::Abi) -> bool { Object::is_none(abi) } + fn is_none(abi: &Self::Abi) -> bool { <::js_sys::Object as wasm_bindgen::convert::OptionFromWasmAbi>::is_none(abi) } } #[allow(clippy::all)] impl From<#name> for wasm_bindgen::JsValue { fn from(obj: #name) -> wasm_bindgen::JsValue { - match obj { - #(#variant_paths_ref => wasm_bindgen::JsValue::from_str(#variant_strings),)* - #name::__Nonexhaustive => panic!(#expect_string), - } + wasm_bindgen::JsValue::from(obj.to_str()) } } }).to_tokens(tokens); @@ -949,22 +1000,54 @@ ); } Some(ref ty) => { - abi_ret = quote! { - <#ty as wasm_bindgen::convert::FromWasmAbi>::Abi - }; - convert_ret = quote! { - <#ty as wasm_bindgen::convert::FromWasmAbi> - ::from_abi(#ret_ident) - }; + if self.function.r#async { + abi_ret = + quote! { ::Abi }; + let future = quote! { + wasm_bindgen_futures::JsFuture::from( + + ::from_abi(#ret_ident) + ).await + }; + convert_ret = if self.catch { + quote! { Ok(#future?) } + } else { + quote! { #future.expect("unexpected exception") } + }; + } else { + abi_ret = quote! { + <#ty as wasm_bindgen::convert::FromWasmAbi>::Abi + }; + convert_ret = quote! { + <#ty as wasm_bindgen::convert::FromWasmAbi> + ::from_abi(#ret_ident) + }; + } } None => { - abi_ret = quote! { () }; - convert_ret = quote! { () }; + if self.function.r#async { + abi_ret = + quote! { ::Abi }; + let future = quote! { + wasm_bindgen_futures::JsFuture::from( + + ::from_abi(#ret_ident) + ).await + }; + convert_ret = if self.catch { + quote! { #future?; Ok(()) } + } else { + quote! { #future.expect("uncaught exception"); } + }; + } else { + abi_ret = quote! { () }; + convert_ret = quote! { () }; + } } } let mut exceptional_ret = quote!(); - if self.catch { + if self.catch && !self.function.r#async { convert_ret = quote! { Ok(#convert_ret) }; exceptional_ret = quote! { wasm_bindgen::__rt::take_last_exception()?; @@ -1005,6 +1088,7 @@ // the best we can in the meantime. let extern_fn = respan( quote! { + #(#attrs)* #[link(wasm_import_module = "__wbindgen_placeholder__")] #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] extern "C" { @@ -1022,12 +1106,17 @@ &self.rust_name, ); + let maybe_async = if self.function.r#async { + Some(quote! {async}) + } else { + None + }; let invocation = quote! { #(#attrs)* #[allow(bad_style)] #[doc = #doc_comment] #[allow(clippy::all)] - #vis fn #rust_name(#me #(#arguments),*) #ret { + #vis #maybe_async fn #rust_name(#me #(#arguments),*) #ret { #extern_fn unsafe { @@ -1057,11 +1146,13 @@ } // See comment above in ast::Export for what's going on here. -struct DescribeImport<'a>(&'a ast::ImportKind); +struct DescribeImport<'a> { + kind: &'a ast::ImportKind, +} impl<'a> ToTokens for DescribeImport<'a> { fn to_tokens(&self, tokens: &mut TokenStream) { - let f = match *self.0 { + let f = match *self.kind { ast::ImportKind::Function(ref f) => f, ast::ImportKind::Static(_) => return, ast::ImportKind::Type(_) => return, @@ -1071,26 +1162,30 @@ let nargs = f.function.arguments.len() as u32; let inform_ret = match &f.js_ret { Some(ref t) => quote! { <#t as WasmDescribe>::describe(); }, + // async functions always return a JsValue, even if they say to return () + None if f.function.r#async => quote! { ::describe(); }, None => quote! { <() as WasmDescribe>::describe(); }, }; - Descriptor( - &f.shim, - quote! { + Descriptor { + ident: &f.shim, + inner: quote! { inform(FUNCTION); inform(0); inform(#nargs); #(<#argtys as WasmDescribe>::describe();)* #inform_ret + #inform_ret }, - ) + attrs: f.function.rust_attrs.clone(), + } .to_tokens(tokens); } } impl ToTokens for ast::Enum { fn to_tokens(&self, into: &mut TokenStream) { - let enum_name = &self.name; + let enum_name = &self.rust_name; let hole = &self.hole; let cast_clauses = self.variants.iter().map(|variant| { let variant_name = &variant.name; @@ -1181,254 +1276,24 @@ }) .to_tokens(into); - Descriptor( - &shim_name, - quote! { + Descriptor { + ident: &shim_name, + inner: quote! { <#ty as WasmDescribe>::describe(); }, - ) - .to_tokens(into); - } -} - -impl ToTokens for ast::Const { - fn to_tokens(&self, tokens: &mut TokenStream) { - use crate::ast::ConstValue::*; - - let vis = &self.vis; - let name = &self.name; - let ty = &self.ty; - - let value: TokenStream = match self.value { - BooleanLiteral(false) => quote!(false), - BooleanLiteral(true) => quote!(true), - // the actual type is unknown because of typedefs - // so we cannot use std::fxx::INFINITY - // but we can use type inference - FloatLiteral(f) if f.is_infinite() && f.is_sign_positive() => quote!(1.0 / 0.0), - FloatLiteral(f) if f.is_infinite() && f.is_sign_negative() => quote!(-1.0 / 0.0), - FloatLiteral(f) if f.is_nan() => quote!(0.0 / 0.0), - // again no suffix - // panics on +-inf, nan - FloatLiteral(f) => { - let f = Literal::f64_suffixed(f); - quote!(#f) - } - SignedIntegerLiteral(i) => { - let i = Literal::i64_suffixed(i); - quote!(#i) - } - UnsignedIntegerLiteral(i) => { - let i = Literal::u64_suffixed(i); - quote!(#i) - } - Null => unimplemented!(), - }; - - let declaration = quote!(#vis const #name: #ty = #value as #ty;); - - if let Some(class) = &self.class { - (quote! { - impl #class { - #declaration - } - }) - .to_tokens(tokens); - } else { - declaration.to_tokens(tokens); - } - } -} - -impl ToTokens for ast::Dictionary { - fn to_tokens(&self, tokens: &mut TokenStream) { - let name = &self.name; - let mut methods = TokenStream::new(); - for field in self.fields.iter() { - field.to_tokens(&mut methods); + attrs: vec![], } - let required_names = &self - .fields - .iter() - .filter(|f| f.required) - .map(|f| &f.rust_name) - .collect::>(); - let required_types = &self - .fields - .iter() - .filter(|f| f.required) - .map(|f| &f.ty) - .collect::>(); - let required_names2 = required_names; - let required_names3 = required_names; - let doc_comment = match &self.doc_comment { - None => "", - Some(doc_string) => doc_string, - }; - - let ctor = if self.ctor { - let doc_comment = match &self.ctor_doc_comment { - None => "", - Some(doc_string) => doc_string, - }; - quote! { - #[doc = #doc_comment] - pub fn new(#(#required_names: #required_types),*) -> #name { - let mut _ret = #name { obj: ::js_sys::Object::new() }; - #(_ret.#required_names2(#required_names3);)* - return _ret - } - } - } else { - quote! {} - }; - - let const_name = Ident::new(&format!("_CONST_{}", name), Span::call_site()); - (quote! { - #[derive(Clone, Debug)] - #[repr(transparent)] - #[allow(clippy::all)] - #[doc = #doc_comment] - pub struct #name { - obj: ::js_sys::Object, - } - - #[allow(clippy::all)] - impl #name { - #ctor - #methods - } - - #[allow(bad_style)] - #[allow(clippy::all)] - const #const_name: () = { - use js_sys::Object; - use wasm_bindgen::describe::WasmDescribe; - use wasm_bindgen::convert::*; - use wasm_bindgen::{JsValue, JsCast}; - use wasm_bindgen::__rt::core::mem::ManuallyDrop; - - // interop w/ JsValue - impl From<#name> for JsValue { - #[inline] - fn from(val: #name) -> JsValue { - val.obj.into() - } - } - impl AsRef for #name { - #[inline] - fn as_ref(&self) -> &JsValue { self.obj.as_ref() } - } - - // Boundary conversion impls - impl WasmDescribe for #name { - fn describe() { - Object::describe(); - } - } - - impl IntoWasmAbi for #name { - type Abi = ::Abi; - #[inline] - fn into_abi(self) -> Self::Abi { - self.obj.into_abi() - } - } - - impl<'a> IntoWasmAbi for &'a #name { - type Abi = <&'a Object as IntoWasmAbi>::Abi; - #[inline] - fn into_abi(self) -> Self::Abi { - (&self.obj).into_abi() - } - } - - impl FromWasmAbi for #name { - type Abi = ::Abi; - #[inline] - unsafe fn from_abi(abi: Self::Abi) -> Self { - #name { obj: Object::from_abi(abi) } - } - } - - impl OptionIntoWasmAbi for #name { - #[inline] - fn none() -> Self::Abi { Object::none() } - } - impl<'a> OptionIntoWasmAbi for &'a #name { - #[inline] - fn none() -> Self::Abi { <&'a Object>::none() } - } - impl OptionFromWasmAbi for #name { - #[inline] - fn is_none(abi: &Self::Abi) -> bool { Object::is_none(abi) } - } - - impl RefFromWasmAbi for #name { - type Abi = ::Abi; - type Anchor = ManuallyDrop<#name>; - - #[inline] - unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor { - let tmp = ::ref_from_abi(js); - ManuallyDrop::new(#name { - obj: ManuallyDrop::into_inner(tmp), - }) - } - } - - impl JsCast for #name { - #[inline] - fn instanceof(val: &JsValue) -> bool { - Object::instanceof(val) - } - - #[inline] - fn unchecked_from_js(val: JsValue) -> Self { - #name { obj: Object::unchecked_from_js(val) } - } - - #[inline] - fn unchecked_from_js_ref(val: &JsValue) -> &Self { - unsafe { &*(val as *const JsValue as *const #name) } - } - } - }; - }) - .to_tokens(tokens); - } -} - -impl ToTokens for ast::DictionaryField { - fn to_tokens(&self, tokens: &mut TokenStream) { - let rust_name = &self.rust_name; - let js_name = &self.js_name; - let ty = &self.ty; - let doc_comment = match &self.doc_comment { - None => "", - Some(doc_string) => doc_string, - }; - (quote! { - #[allow(clippy::all)] - #[doc = #doc_comment] - pub fn #rust_name(&mut self, val: #ty) -> &mut Self { - use wasm_bindgen::JsValue; - let r = ::js_sys::Reflect::set( - self.obj.as_ref(), - &JsValue::from(#js_name), - &JsValue::from(val), - ); - debug_assert!(r.is_ok(), "setting properties should never fail on our dictionary objects"); - let _ = r; - self - } - }).to_tokens(tokens); + .to_tokens(into); } } /// Emits the necessary glue tokens for "descriptor", generating an appropriate /// symbol name as well as attributes around the descriptor function itself. -struct Descriptor<'a, T>(&'a Ident, T); +struct Descriptor<'a, T> { + ident: &'a Ident, + inner: T, + attrs: Vec, +} impl<'a, T: ToTokens> ToTokens for Descriptor<'a, T> { fn to_tokens(&self, tokens: &mut TokenStream) { @@ -1443,17 +1308,22 @@ lazy_static::lazy_static! { static ref DESCRIPTORS_EMITTED: Mutex> = Default::default(); } + + let ident = self.ident; + if !DESCRIPTORS_EMITTED .lock() .unwrap() - .insert(self.0.to_string()) + .insert(ident.to_string()) { return; } - let name = Ident::new(&format!("__wbindgen_describe_{}", self.0), self.0.span()); - let inner = &self.1; + let name = Ident::new(&format!("__wbindgen_describe_{}", ident), ident.span()); + let inner = &self.inner; + let attrs = &self.attrs; (quote! { + #(#attrs)* #[no_mangle] #[allow(non_snake_case)] #[doc(hidden)] diff -Nru rust-wasm-bindgen-backend-0.2.58/src/defined.rs rust-wasm-bindgen-backend-0.2.78/src/defined.rs --- rust-wasm-bindgen-backend-0.2.58/src/defined.rs 2019-08-13 19:12:38.000000000 +0000 +++ rust-wasm-bindgen-backend-0.2.78/src/defined.rs 1970-01-01 00:00:00.000000000 +0000 @@ -1,403 +0,0 @@ -use crate::ast; -use proc_macro2::Ident; -use syn; - -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub enum ImportedTypeKind { - /// The definition of an imported type. - Definition, - /// A reference to an imported type. - Reference, -} - -impl ImportedTypes for Option -where - T: ImportedTypes, -{ - fn imported_types(&self, f: &mut F) - where - F: FnMut(&Ident, ImportedTypeKind), - { - if let Some(inner) = self { - inner.imported_types(f); - } - } -} - -/// Iterate over definitions of and references to imported types in the AST. -pub trait ImportedTypes { - fn imported_types(&self, f: &mut F) - where - F: FnMut(&Ident, ImportedTypeKind); -} - -/// Iterate over definitions of imported types in the AST. -pub trait ImportedTypeDefinitions { - fn imported_type_definitions(&self, f: &mut F) - where - F: FnMut(&Ident); -} - -impl ImportedTypeDefinitions for T -where - T: ImportedTypes, -{ - fn imported_type_definitions(&self, f: &mut F) - where - F: FnMut(&Ident), - { - self.imported_types(&mut |id, kind| { - if let ImportedTypeKind::Definition = kind { - f(id); - } - }); - } -} - -/// Iterate over references to imported types in the AST. -pub trait ImportedTypeReferences { - fn imported_type_references(&self, f: &mut F) - where - F: FnMut(&Ident); -} - -impl ImportedTypeReferences for T -where - T: ImportedTypes, -{ - fn imported_type_references(&self, f: &mut F) - where - F: FnMut(&Ident), - { - self.imported_types(&mut |id, kind| { - if let ImportedTypeKind::Reference = kind { - f(id); - } - }); - } -} - -impl<'a, T: ImportedTypes> ImportedTypes for &'a T { - fn imported_types(&self, f: &mut F) - where - F: FnMut(&Ident, ImportedTypeKind), - { - (*self).imported_types(f) - } -} - -impl ImportedTypes for ast::Program { - fn imported_types(&self, f: &mut F) - where - F: FnMut(&Ident, ImportedTypeKind), - { - self.imports.imported_types(f); - self.consts.imported_types(f); - self.dictionaries.imported_types(f); - } -} - -impl ImportedTypes for Vec -where - T: ImportedTypes, -{ - fn imported_types(&self, f: &mut F) - where - F: FnMut(&Ident, ImportedTypeKind), - { - for x in self { - x.imported_types(f); - } - } -} - -impl ImportedTypes for ast::Import { - fn imported_types(&self, f: &mut F) - where - F: FnMut(&Ident, ImportedTypeKind), - { - self.kind.imported_types(f) - } -} - -impl ImportedTypes for ast::ImportKind { - fn imported_types(&self, f: &mut F) - where - F: FnMut(&Ident, ImportedTypeKind), - { - match self { - ast::ImportKind::Static(s) => s.imported_types(f), - ast::ImportKind::Function(fun) => fun.imported_types(f), - ast::ImportKind::Type(ty) => ty.imported_types(f), - ast::ImportKind::Enum(enm) => enm.imported_types(f), - } - } -} - -impl ImportedTypes for ast::ImportStatic { - fn imported_types(&self, f: &mut F) - where - F: FnMut(&Ident, ImportedTypeKind), - { - self.ty.imported_types(f); - } -} - -impl ImportedTypes for syn::Type { - fn imported_types(&self, f: &mut F) - where - F: FnMut(&Ident, ImportedTypeKind), - { - match self { - syn::Type::Reference(ref r) => r.imported_types(f), - syn::Type::Path(ref p) => p.imported_types(f), - _ => {} - } - } -} - -impl ImportedTypes for syn::TypeReference { - fn imported_types(&self, f: &mut F) - where - F: FnMut(&Ident, ImportedTypeKind), - { - self.elem.imported_types(f); - } -} - -impl ImportedTypes for syn::TypePath { - fn imported_types(&self, f: &mut F) - where - F: FnMut(&Ident, ImportedTypeKind), - { - self.qself.imported_types(f); - self.path.imported_types(f); - } -} - -impl ImportedTypes for syn::QSelf { - fn imported_types(&self, _: &mut F) - where - F: FnMut(&Ident, ImportedTypeKind), - { - // TODO - } -} - -impl ImportedTypes for syn::Path { - fn imported_types(&self, f: &mut F) - where - F: FnMut(&Ident, ImportedTypeKind), - { - for seg in self.segments.iter() { - seg.arguments.imported_types(f); - } - f( - &self.segments.last().unwrap().ident, - ImportedTypeKind::Reference, - ); - } -} - -impl ImportedTypes for syn::PathArguments { - fn imported_types(&self, f: &mut F) - where - F: FnMut(&Ident, ImportedTypeKind), - { - match self { - syn::PathArguments::AngleBracketed(data) => { - for arg in data.args.iter() { - arg.imported_types(f); - } - } - //TOCHECK - syn::PathArguments::Parenthesized(data) => { - for input in data.inputs.iter() { - input.imported_types(f); - } - // TODO do we need to handle output here? - // https://docs.rs/syn/0.14.0/syn/struct.ParenthesizedGenericArguments.html - } - syn::PathArguments::None => {} - } - } -} - -impl ImportedTypes for syn::GenericArgument { - fn imported_types(&self, f: &mut F) - where - F: FnMut(&Ident, ImportedTypeKind), - { - match self { - syn::GenericArgument::Lifetime(_) => {} - syn::GenericArgument::Type(ty) => ty.imported_types(f), - syn::GenericArgument::Binding(_) => {} // TODO - syn::GenericArgument::Const(_) => {} // TODO - syn::GenericArgument::Constraint(_) => {} // TODO - } - } -} - -impl ImportedTypes for ast::ImportFunction { - fn imported_types(&self, f: &mut F) - where - F: FnMut(&Ident, ImportedTypeKind), - { - self.function.imported_types(f); - self.kind.imported_types(f); - } -} - -impl ImportedTypes for ast::ImportFunctionKind { - fn imported_types(&self, f: &mut F) - where - F: FnMut(&Ident, ImportedTypeKind), - { - match self { - ast::ImportFunctionKind::Method { ty, .. } => ty.imported_types(f), - ast::ImportFunctionKind::Normal => {} - } - } -} - -impl ImportedTypes for ast::Function { - fn imported_types(&self, f: &mut F) - where - F: FnMut(&Ident, ImportedTypeKind), - { - self.arguments.imported_types(f); - if let Some(ref r) = self.ret { - r.imported_types(f); - } - } -} - -impl ImportedTypes for syn::FnArg { - fn imported_types(&self, f: &mut F) - where - F: FnMut(&Ident, ImportedTypeKind), - { - match self { - syn::FnArg::Receiver(_) => {} - syn::FnArg::Typed(p) => p.imported_types(f), - } - } -} - -impl ImportedTypes for syn::PatType { - fn imported_types(&self, f: &mut F) - where - F: FnMut(&Ident, ImportedTypeKind), - { - self.ty.imported_types(f) - } -} - -impl ImportedTypes for ast::ImportType { - fn imported_types(&self, f: &mut F) - where - F: FnMut(&Ident, ImportedTypeKind), - { - f(&self.rust_name, ImportedTypeKind::Definition); - for class in self.extends.iter() { - class.imported_types(f); - } - } -} - -impl ImportedTypes for ast::ImportEnum { - fn imported_types(&self, f: &mut F) - where - F: FnMut(&Ident, ImportedTypeKind), - { - f(&self.name, ImportedTypeKind::Definition); - } -} - -impl ImportedTypes for ast::Const { - fn imported_types(&self, f: &mut F) - where - F: FnMut(&Ident, ImportedTypeKind), - { - self.ty.imported_types(f); - } -} - -impl ImportedTypes for ast::Dictionary { - fn imported_types(&self, f: &mut F) - where - F: FnMut(&Ident, ImportedTypeKind), - { - f(&self.name, ImportedTypeKind::Definition); - for field in self.fields.iter() { - field.imported_types(f); - } - } -} - -impl ImportedTypes for ast::DictionaryField { - fn imported_types(&self, f: &mut F) - where - F: FnMut(&Ident, ImportedTypeKind), - { - self.ty.imported_types(f); - } -} - -/// Remove any methods, statics, &c, that reference types that are *not* -/// defined. -pub trait RemoveUndefinedImports { - fn remove_undefined_imports(&mut self, is_defined: &F) -> bool - where - F: Fn(&Ident) -> bool; -} - -impl RemoveUndefinedImports for ast::Program { - fn remove_undefined_imports(&mut self, is_defined: &F) -> bool - where - F: Fn(&Ident) -> bool, - { - let mut changed = self.imports.remove_undefined_imports(is_defined); - changed = self.consts.remove_undefined_imports(is_defined) || changed; - - for dictionary in self.dictionaries.iter_mut() { - let num_required = - |dict: &ast::Dictionary| dict.fields.iter().filter(|f| f.required).count(); - let before = num_required(dictionary); - changed = dictionary.fields.remove_undefined_imports(is_defined) || changed; - - // If a required field was removed we can no longer construct this - // dictionary so disable the constructor. - if before != num_required(dictionary) { - dictionary.ctor = false; - } - } - - changed - } -} - -impl RemoveUndefinedImports for Vec -where - T: ImportedTypeReferences, -{ - fn remove_undefined_imports(&mut self, is_defined: &F) -> bool - where - F: Fn(&Ident) -> bool, - { - let before = self.len(); - self.retain(|x| { - let mut all_defined = true; - x.imported_type_references(&mut |id| { - if all_defined { - if !is_defined(id) { - log::info!("removing due to {} not being defined", id); - all_defined = false; - } - } - }); - all_defined - }); - before != self.len() - } -} diff -Nru rust-wasm-bindgen-backend-0.2.58/src/encode.rs rust-wasm-bindgen-backend-0.2.78/src/encode.rs --- rust-wasm-bindgen-backend-0.2.58/src/encode.rs 2020-01-06 19:17:34.000000000 +0000 +++ rust-wasm-bindgen-backend-0.2.78/src/encode.rs 1973-11-29 21:33:09.000000000 +0000 @@ -205,19 +205,22 @@ .collect::>(); Function { arg_names, + asyncness: func.r#async, name: &func.name, + generate_typescript: func.generate_typescript, } } fn shared_enum<'a>(e: &'a ast::Enum, intern: &'a Interner) -> Enum<'a> { Enum { - name: intern.intern(&e.name), + name: &e.js_name, variants: e .variants .iter() .map(|v| shared_variant(v, intern)) .collect(), comments: e.comments.iter().map(|s| &**s).collect(), + generate_typescript: e.generate_typescript, } } @@ -225,6 +228,7 @@ EnumVariant { name: intern.intern(&v.name), value: v.value, + comments: v.comments.iter().map(|s| &**s).collect(), } } @@ -238,7 +242,7 @@ ast::ImportModule::Inline(idx, _) => ImportModule::Inline(*idx as u32), ast::ImportModule::None => ImportModule::None, }, - js_namespace: i.js_namespace.as_ref().map(|s| intern.intern(s)), + js_namespace: i.js_namespace.clone(), kind: shared_import_kind(&i.kind, intern)?, }) } @@ -307,17 +311,16 @@ .collect(), comments: s.comments.iter().map(|s| &**s).collect(), is_inspectable: s.is_inspectable, + generate_typescript: s.generate_typescript, } } -fn shared_struct_field<'a>(s: &'a ast::StructField, intern: &'a Interner) -> StructField<'a> { +fn shared_struct_field<'a>(s: &'a ast::StructField, _intern: &'a Interner) -> StructField<'a> { StructField { - name: match &s.name { - syn::Member::Named(ident) => intern.intern(ident), - syn::Member::Unnamed(index) => intern.intern_str(&index.index.to_string()), - }, + name: &s.js_name, readonly: s.readonly, comments: s.comments.iter().map(|s| &**s).collect(), + generate_typescript: s.generate_typescript, } } diff -Nru rust-wasm-bindgen-backend-0.2.58/src/error.rs rust-wasm-bindgen-backend-0.2.78/src/error.rs --- rust-wasm-bindgen-backend-0.2.58/src/error.rs 2019-09-23 15:02:22.000000000 +0000 +++ rust-wasm-bindgen-backend-0.2.78/src/error.rs 1973-11-29 21:33:09.000000000 +0000 @@ -2,6 +2,7 @@ use quote::{ToTokens, TokenStreamExt}; use syn::parse::Error; +/// Provide a Diagnostic with the given span and message #[macro_export] macro_rules! err_span { ($span:expr, $($msg:tt)*) => ( @@ -9,6 +10,7 @@ ) } +/// Immediately fail and return an Err, with the arguments passed to err_span! #[macro_export] macro_rules! bail_span { ($($t:tt)*) => ( @@ -16,6 +18,7 @@ ) } +/// A struct representing a diagnostic to emit to the end-user as an error. #[derive(Debug)] pub struct Diagnostic { inner: Repr, @@ -34,6 +37,7 @@ } impl Diagnostic { + /// Generate a `Diagnostic` from an informational message with no Span pub fn error>(text: T) -> Diagnostic { Diagnostic { inner: Repr::Single { @@ -43,6 +47,7 @@ } } + /// Generate a `Diagnostic` from a Span and an informational message pub fn span_error>(span: Span, text: T) -> Diagnostic { Diagnostic { inner: Repr::Single { @@ -52,6 +57,7 @@ } } + /// Generate a `Diagnostic` from the span of any tokenizable object and a message pub fn spanned_error>(node: &dyn ToTokens, text: T) -> Diagnostic { Diagnostic { inner: Repr::Single { @@ -61,6 +67,8 @@ } } + /// Attempt to generate a `Diagnostic` from a vector of other `Diagnostic` instances. + /// If the `Vec` is empty, returns `Ok(())`, otherwise returns the new `Diagnostic` pub fn from_vec(diagnostics: Vec) -> Result<(), Diagnostic> { if diagnostics.len() == 0 { Ok(()) @@ -71,6 +79,7 @@ } } + /// Immediately trigger a panic from this `Diagnostic` #[allow(unconditional_recursion)] pub fn panic(&self) -> ! { match &self.inner { diff -Nru rust-wasm-bindgen-backend-0.2.58/src/lib.rs rust-wasm-bindgen-backend-0.2.78/src/lib.rs --- rust-wasm-bindgen-backend-0.2.58/src/lib.rs 2019-09-26 17:33:47.000000000 +0000 +++ rust-wasm-bindgen-backend-0.2.78/src/lib.rs 1973-11-29 21:33:09.000000000 +0000 @@ -1,5 +1,31 @@ +//! A common backend for bindgen crates. +//! +//! This (internal) crate provides functionality common to multiple bindgen +//! dependency crates. There are 4 main things exported from this crate: +//! +//! 1. [**`TryToTokens`**](./trait.TryToTokens.html) +//! +//! Provides the ability to attempt conversion from an AST struct +//! into a TokenStream +//! +//! 2. [**`Diagnostic`**](./struct.Diagnostic.html) +//! +//! A struct used to provide diagnostic responses for failures of said +//! tokenization +//! +//! 3. [**`ast`**](./ast/index.html) +//! +//! Abstract Syntax Tree types used to represent a Rust program, with +//! the necessary metadata to generate bindings for it +//! +//! 4. [**`util`**](./util/index.html) +//! +//! Common utilities for manipulating parsed types from syn +//! + #![recursion_limit = "256"] #![cfg_attr(feature = "extra-traits", deny(missing_debug_implementations))] +#![deny(missing_docs)] #![doc(html_root_url = "https://docs.rs/wasm-bindgen-backend/0.2")] pub use crate::codegen::TryToTokens; @@ -10,6 +36,5 @@ pub mod ast; mod codegen; -pub mod defined; mod encode; pub mod util; diff -Nru rust-wasm-bindgen-backend-0.2.58/src/util.rs rust-wasm-bindgen-backend-0.2.78/src/util.rs --- rust-wasm-bindgen-backend-0.2.58/src/util.rs 2019-06-05 21:58:54.000000000 +0000 +++ rust-wasm-bindgen-backend-0.2.78/src/util.rs 1973-11-29 21:33:09.000000000 +0000 @@ -1,3 +1,6 @@ +//! Common utility function for manipulating syn types and +//! handling parsed values + use std::collections::hash_map::DefaultHasher; use std::env; use std::fmt; @@ -11,6 +14,7 @@ use proc_macro2::{self, Ident}; use syn; +/// Check whether a given `&str` is a Rust keyword fn is_rust_keyword(name: &str) -> bool { match name { "abstract" | "alignof" | "as" | "become" | "box" | "break" | "const" | "continue" @@ -24,7 +28,7 @@ } } -// Create an `Ident`, possibly mangling it if it conflicts with a Rust keyword. +/// Create an `Ident`, possibly mangling it if it conflicts with a Rust keyword. pub fn rust_ident(name: &str) -> Ident { if name == "" { panic!("tried to create empty Ident (from \"\")"); @@ -57,8 +61,8 @@ } } -// Create an `Ident` without checking to see if it conflicts with a Rust -// keyword. +/// Create an `Ident` without checking to see if it conflicts with a Rust +/// keyword. pub fn raw_ident(name: &str) -> Ident { Ident::new(name, proc_macro2::Span::call_site()) } @@ -108,10 +112,12 @@ .into() } +/// Create a path type with a single segment from a given Identifier pub fn ident_ty(ident: Ident) -> syn::Type { simple_path_ty(Some(ident)) } +/// Convert an ImportFunction into the more generic Import type, wrapping the provided function pub fn wrap_import_function(function: ast::ImportFunction) -> ast::Import { ast::Import { module: ast::ImportModule::None,