File tree Expand file tree Collapse file tree 3 files changed +28
-6
lines changed
crates/cli-support/src/js Expand file tree Collapse file tree 3 files changed +28
-6
lines changed Original file line number Diff line number Diff line change @@ -2372,12 +2372,12 @@ impl<'a> Context<'a> {
2372
2372
impl < ' a , ' b > SubContext < ' a , ' b > {
2373
2373
pub fn generate ( & mut self ) -> Result < ( ) , Error > {
2374
2374
for m in self . program . local_modules . iter ( ) {
2375
- // All local modules we find should be unique, so assert such.
2376
- assert ! ( self
2377
- . cx
2378
- . local_modules
2379
- . insert ( m . identifier , m. contents)
2380
- . is_none ( ) ) ;
2375
+ // All local modules we find should be unique, but the same module
2376
+ // may have showed up in a few different blocks. If that's the case
2377
+ // all the same identifiers should have the same contents.
2378
+ if let Some ( prev ) = self . cx . local_modules . insert ( m . identifier , m . contents ) {
2379
+ assert_eq ! ( prev , m. contents) ;
2380
+ }
2381
2381
}
2382
2382
for f in self . program . exports . iter ( ) {
2383
2383
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