@@ -17,6 +17,15 @@ on local JS files.
17
17
}
18
18
```
19
19
20
+ * The ` inline_js ` attribute can now be used to import JS modules inline:
21
+
22
+ ``` rust
23
+ #[wasm_bindgen(inline_js = " export function foo() {}" )]
24
+ extern " C" {
25
+ fn foo ();
26
+ }
27
+ ```
28
+
20
29
* The ` --browser ` flag is repurposed to generate an ES module for the browser
21
30
and ` --no-modules ` is deprecated in favor of this flag.
22
31
@@ -71,26 +80,33 @@ here.
71
80
### New Syntactical Features
72
81
73
82
The most user-facing change proposed here is the reinterpretation of the
74
- ` module ` attribute inside of ` #[wasm_bindgen] ` . It can now be used to import
75
- local files like so:
83
+ ` module ` attribute inside of ` #[wasm_bindgen] ` and the addition of an
84
+ ` inline_js ` attribute. They can now be used to import local files and define
85
+ local imports like so:
76
86
77
87
``` rust
78
88
#[wasm_bindgen(module = " /js/foo.js" )]
79
89
extern " C" {
80
90
// ... definitions
81
91
}
92
+
93
+ #[wasm_bindgen(inline_js = " export function foo() {}" )]
94
+ extern " C" {
95
+ fn foo ();
96
+ }
82
97
```
83
98
84
- This declaration says that the block of functions and types and such are all
85
- imported from the ` /js/foo.js ` file, relative to the current file and rooted at
86
- the crate root. The following rules are proposed for interpreting a ` module `
87
- attribute.
99
+ The first declaration says that the block of functions and types and such are
100
+ all imported from the ` /js/foo.js ` file, relative to the current file and rooted
101
+ at the crate root. The second declaration lists the JS inline as a string
102
+ literal and the ` extern ` block describes the exports of the inline module.
103
+
104
+ The following rules are proposed for interpreting a ` module ` attribute.
88
105
89
106
* If the strings starts with the platform-specific representation of an absolute
90
107
path to the cargo build directory (identified by ` $OUT_DIR ` ) then the string
91
108
is interpreted as a file path in the output directory. This is intended for
92
- procedural macros or build scripts which generate JS files as part of the
93
- build.
109
+ build scripts which generate JS files as part of the build.
94
110
95
111
* If the string starts with ` / ` , ` ./ ` , or ` ../ ` then it's considered a path to a
96
112
local file. If not, then it's passed through verbatim as the ES module import.
@@ -104,6 +120,10 @@ attribute.
104
120
This will hopefully roughly match what programmers expect as well as preexisting
105
121
conventions in browsers and bundlers.
106
122
123
+ The ` inline_js ` attribute isn't really intended to be used for general-purpose
124
+ development, but rather a way for procedural macros which can't currently today
125
+ rely on the presence of ` $OUT_DIR ` to generate JS to import.
126
+
107
127
### Format of imported JS
108
128
109
129
All imported JS is required to written with ES module syntax. Initially the JS
0 commit comments