File tree 3 files changed +28
-6
lines changed
crates/cli-support/src/js
3 files changed +28
-6
lines changed Original file line number Diff line number Diff line change @@ -2378,12 +2378,12 @@ impl<'a> Context<'a> {
2378
2378
impl < ' a , ' b > SubContext < ' a , ' b > {
2379
2379
pub fn generate ( & mut self ) -> Result < ( ) , Error > {
2380
2380
for m in self . program . local_modules . iter ( ) {
2381
- // All local modules we find should be unique, so assert such.
2382
- assert ! ( self
2383
- . cx
2384
- . local_modules
2385
- . insert ( m . identifier , m. contents)
2386
- . is_none ( ) ) ;
2381
+ // All local modules we find should be unique, but the same module
2382
+ // may have showed up in a few different blocks. If that's the case
2383
+ // all the same identifiers should have the same contents.
2384
+ if let Some ( prev ) = self . cx . local_modules . insert ( m . identifier , m . contents ) {
2385
+ assert_eq ! ( prev , m. contents) ;
2386
+ }
2387
2387
}
2388
2388
for f in self . program . exports . iter ( ) {
2389
2389
self . generate_export ( f) . with_context ( |_| {
Original file line number Diff line number Diff line change @@ -4,13 +4,29 @@ use wasm_bindgen_test::*;
4
4
#[ wasm_bindgen( module = "/tests/headless/snippets1.js" ) ]
5
5
extern {
6
6
fn get_two ( ) -> u32 ;
7
+ #[ wasm_bindgen( js_name = get_stateful) ]
8
+ fn get_stateful1 ( ) -> u32 ;
9
+ }
10
+
11
+ #[ wasm_bindgen( module = "/tests/headless/snippets1.js" ) ]
12
+ extern {
13
+ #[ wasm_bindgen( js_name = get_stateful) ]
14
+ fn get_stateful2 ( ) -> u32 ;
7
15
}
8
16
9
17
#[ wasm_bindgen_test]
10
18
fn test_get_two ( ) {
11
19
assert_eq ! ( get_two( ) , 2 ) ;
12
20
}
13
21
22
+ #[ wasm_bindgen_test]
23
+ fn stateful_deduplicated ( ) {
24
+ assert_eq ! ( get_stateful1( ) , 1 ) ;
25
+ assert_eq ! ( get_stateful2( ) , 2 ) ;
26
+ assert_eq ! ( get_stateful1( ) , 3 ) ;
27
+ assert_eq ! ( get_stateful2( ) , 4 ) ;
28
+ }
29
+
14
30
#[ wasm_bindgen( inline_js = "export function get_three() { return 3; }" ) ]
15
31
extern {
16
32
fn get_three ( ) -> u32 ;
Original file line number Diff line number Diff line change 1
1
export function get_two ( ) {
2
2
return 2 ;
3
3
}
4
+
5
+ let a = 0 ;
6
+ export function get_stateful ( ) {
7
+ a += 1 ;
8
+ return a ;
9
+ }
You can’t perform that action at this time.
0 commit comments