Skip to content

Commit af6fd41

Browse files
Improved temporary variable names in generated JS
1 parent fe5d89f commit af6fd41

File tree

9 files changed

+213
-190
lines changed

9 files changed

+213
-190
lines changed

crates/cli-support/src/js/binding.rs

Lines changed: 154 additions & 161 deletions
Large diffs are not rendered by default.

crates/cli/tests/reference/getter-setter.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,9 @@ export class Foo {
170170
* @param {string | undefined} [value]
171171
*/
172172
set weird(value) {
173-
var ptr0 = isLikeNone(value) ? 0 : passStringToWasm0(value, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
174-
var len0 = WASM_VECTOR_LEN;
175-
wasm.foo_set_weird(this.__wbg_ptr, ptr0, len0);
173+
const ptr = isLikeNone(value) ? 0 : passStringToWasm0(value, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
174+
const len = WASM_VECTOR_LEN;
175+
wasm.foo_set_weird(this.__wbg_ptr, ptr, len);
176176
}
177177
/**
178178
* There can be static getters and setters too, and they can even have the

crates/cli/tests/reference/result.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,19 @@ function takeObject(idx) {
5656
* @returns {string}
5757
*/
5858
export function result_string() {
59-
let deferred2_0;
60-
let deferred2_1;
6159
try {
6260
const ret = wasm.result_string();
63-
var ptr1 = ret[0];
64-
var len1 = ret[1];
61+
var ptr = ret[0];
62+
var len = ret[1];
6563
if (ret[3]) {
66-
ptr1 = 0; len1 = 0;
64+
ptr = 0; len = 0;
6765
throw takeObject(ret[2]);
6866
}
69-
deferred2_0 = ptr1;
70-
deferred2_1 = len1;
71-
return getStringFromWasm0(ptr1, len1);
67+
var deferred0 = ptr;
68+
var deferred1 = len;
69+
return getStringFromWasm0(ptr, len);
7270
} finally {
73-
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
71+
wasm.__wbindgen_free(deferred0, deferred1, 1);
7472
}
7573
}
7674

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/* tslint:disable */
22
/* eslint-disable */
33
export function foo(a: string): void;
4+
export function bar(a: string, b: string, ptr: number, len: number): string;

crates/cli/tests/reference/string-arg.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,31 @@ function passStringToWasm0(arg, malloc, realloc) {
8585
* @param {string} a
8686
*/
8787
export function foo(a) {
88-
const ptr0 = passStringToWasm0(a, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
89-
const len0 = WASM_VECTOR_LEN;
90-
wasm.foo(ptr0, len0);
88+
const ptr = passStringToWasm0(a, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
89+
const len = WASM_VECTOR_LEN;
90+
wasm.foo(ptr, len);
91+
}
92+
93+
/**
94+
* @param {string} a
95+
* @param {string} b
96+
* @param {number} ptr
97+
* @param {number} len
98+
* @returns {string}
99+
*/
100+
export function bar(a, b, ptr, len) {
101+
try {
102+
const ptr1 = passStringToWasm0(a, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
103+
const len2 = WASM_VECTOR_LEN;
104+
const ptr3 = passStringToWasm0(b, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
105+
const len4 = WASM_VECTOR_LEN;
106+
const ret = wasm.bar(ptr1, len2, ptr3, len4, ptr, len);
107+
var deferred0 = ret[0];
108+
var deferred1 = ret[1];
109+
return getStringFromWasm0(ret[0], ret[1]);
110+
} finally {
111+
wasm.__wbindgen_free(deferred0, deferred1, 1);
112+
}
91113
}
92114

93115
export function __wbindgen_throw(arg0, arg1) {

crates/cli/tests/reference/string-arg.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@ use wasm_bindgen::prelude::*;
44
pub fn foo(a: &str) {
55
drop(a);
66
}
7+
8+
#[wasm_bindgen]
9+
pub fn bar(a: &str, b: String, ptr: u32, len: u32) -> String {
10+
b
11+
}
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
(module $reference_test.wasm
22
(type (;0;) (func (param i32 i32)))
33
(type (;1;) (func (param i32 i32) (result i32)))
4-
(type (;2;) (func (param i32 i32 i32 i32) (result i32)))
5-
(func $__wbindgen_realloc (;0;) (type 2) (param i32 i32 i32 i32) (result i32))
4+
(type (;2;) (func (param i32 i32 i32)))
5+
(type (;3;) (func (param i32 i32 i32 i32) (result i32)))
6+
(type (;4;) (func (param i32 i32 i32 i32 i32 i32) (result i32 i32)))
7+
(func $__wbindgen_realloc (;0;) (type 3) (param i32 i32 i32 i32) (result i32))
68
(func $__wbindgen_malloc (;1;) (type 1) (param i32 i32) (result i32))
79
(func $foo (;2;) (type 0) (param i32 i32))
10+
(func $__wbindgen_free (;3;) (type 2) (param i32 i32 i32))
11+
(func $"bar multivalue shim" (;4;) (type 4) (param i32 i32 i32 i32 i32 i32) (result i32 i32))
812
(memory (;0;) 17)
913
(export "memory" (memory 0))
1014
(export "foo" (func $foo))
15+
(export "bar" (func $"bar multivalue shim"))
1116
(export "__wbindgen_malloc" (func $__wbindgen_malloc))
1217
(export "__wbindgen_realloc" (func $__wbindgen_realloc))
18+
(export "__wbindgen_free" (func $__wbindgen_free))
1319
(@custom "target_features" (after code) "\04+\0amultivalue+\0fmutable-globals+\0freference-types+\08sign-ext")
1420
)
1521

crates/cli/tests/reference/wasm-export-types.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,15 @@ function passStringToWasm0(arg, malloc, realloc) {
8181
* @returns {string}
8282
*/
8383
export function example(a, b, c, d) {
84-
let deferred2_0;
85-
let deferred2_1;
8684
try {
87-
const ptr0 = passStringToWasm0(d, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
88-
const len0 = WASM_VECTOR_LEN;
89-
const ret = wasm.example(a, b, c, ptr0, len0);
90-
deferred2_0 = ret[0];
91-
deferred2_1 = ret[1];
85+
const ptr = passStringToWasm0(d, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
86+
const len = WASM_VECTOR_LEN;
87+
const ret = wasm.example(a, b, c, ptr, len);
88+
var deferred0 = ret[0];
89+
var deferred1 = ret[1];
9290
return getStringFromWasm0(ret[0], ret[1]);
9391
} finally {
94-
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
92+
wasm.__wbindgen_free(deferred0, deferred1, 1);
9593
}
9694
}
9795

crates/cli/tests/reference/web-sys.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,10 @@ export function __wbg_new_561a91ce53f10a66() { return handleError(function (arg0
217217

218218
export function __wbindgen_debug_string(arg0, arg1) {
219219
const ret = debugString(getObject(arg1));
220-
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
221-
const len1 = WASM_VECTOR_LEN;
222-
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
223-
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
220+
const ptr = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
221+
const len = WASM_VECTOR_LEN;
222+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len, true);
223+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr, true);
224224
};
225225

226226
export function __wbindgen_object_drop_ref(arg0) {

0 commit comments

Comments
 (0)