File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
guide/src/reference/attributes/on-js-imports Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -58,4 +58,30 @@ extern "C" {
58
58
}
59
59
```
60
60
61
+ The ` js_name ` attribute can also be used in situations where a JavaScript module uses
62
+ ` export default ` . In this case, setting the ` js_name ` attribute to "default" on the
63
+ ` type ` declaration, and the [ ` js_class ` attribute] [ jsclass ] to "default" on any methods
64
+ on the exported object will generate the correct imports.
65
+
66
+
67
+ For example, a module that would be imported directly in JavaScript:
68
+
69
+ ``` javascript
70
+ import Foo from " bar" ;
71
+
72
+ let f = new Foo ();
73
+ ```
74
+
75
+ Could be accessed using this definition in Rust:
76
+
77
+ ``` rust
78
+ #[wasm_bindgen(module = " bar" )]
79
+ extern " C" {
80
+ #[wasm_bindgen(js_name = default)
81
+ type Foo ;
82
+ #[wasm_bindgen(constructor, js_class = default)]
83
+ pub fn new () -> Foo ;
84
+ }
85
+ ```
86
+
61
87
[ jsclass ] : js_class.html
You can’t perform that action at this time.
0 commit comments