Skip to content

Commit baa5581

Browse files
authored
Cleanup python-generated JS code. NFC (#25287)
We were not being consistent about newlines here. This change makes the output more readable.
1 parent e397e08 commit baa5581

File tree

3 files changed

+25
-25
lines changed

3 files changed

+25
-25
lines changed
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
{
2-
"hello_world.js": 54019,
3-
"hello_world.js.gz": 17072,
2+
"hello_world.js": 54020,
3+
"hello_world.js.gz": 17068,
44
"hello_world.wasm": 15127,
55
"hello_world.wasm.gz": 7450,
6-
"no_asserts.js": 26497,
7-
"no_asserts.js.gz": 8849,
6+
"no_asserts.js": 26498,
7+
"no_asserts.js.gz": 8848,
88
"no_asserts.wasm": 12227,
99
"no_asserts.wasm.gz": 6010,
10-
"strict.js": 52057,
11-
"strict.js.gz": 16407,
10+
"strict.js": 52058,
11+
"strict.js.gz": 16403,
1212
"strict.wasm": 15127,
1313
"strict.wasm.gz": 7447,
14-
"total": 175054,
15-
"total_gz": 63235
14+
"total": 175057,
15+
"total_gz": 63226
1616
}

test/other/codesize/test_codesize_minimal_O0.expected.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1304,7 +1304,10 @@ function assignWasmExports(wasmExports) {
13041304
__emscripten_stack_alloc = wasmExports['_emscripten_stack_alloc'];
13051305
_emscripten_stack_get_current = wasmExports['emscripten_stack_get_current'];
13061306
}
1307-
var _global_val = Module['_global_val'] = 65536;var wasmImports = {
1307+
1308+
var _global_val = Module['_global_val'] = 65536;
1309+
1310+
var wasmImports = {
13081311

13091312
};
13101313

tools/emscripten.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,7 @@ def create_sending(metadata, library_symbols):
853853
elems.append(f'{v} as {k}')
854854
elems = ',\n '.join(elems)
855855
exports = '// Export JS functions to the wasm module with demangled names.\n'
856-
exports += f"export {{\n {elems}\n}};\n\n"
856+
exports += f"export {{\n {elems}\n}};"
857857
return exports
858858

859859
prefix = ''
@@ -885,7 +885,7 @@ def create_reexports(metadata):
885885
wasm_exports.append(exp)
886886
elif demangled == 'main' and '__main_argc_argv' in settings.WASM_EXPORTS:
887887
wasm_exports.append('_main')
888-
exports += f"export {{ {', '.join(wasm_exports)} }};\n\n"
888+
exports += f"export {{ {', '.join(wasm_exports)} }};"
889889
return exports
890890

891891

@@ -936,7 +936,7 @@ def create_receiving(function_exports, tag_exports, library_symbols):
936936
receiving.append(f" dynCalls['{sig_str}'] = {sym};")
937937
receiving.append('}')
938938

939-
return '\n'.join(receiving) + '\n\n'
939+
return '\n'.join(receiving)
940940

941941
# When not declaring asm exports this section is empty and we instead programmatically export
942942
# symbols on the global object by calling exportWasmSymbols after initialization
@@ -994,18 +994,15 @@ def create_receiving(function_exports, tag_exports, library_symbols):
994994
receiving.append(f" {export_assignment}{dynCallAssignment}{mangled} = wasmExports['{sym}'];")
995995
receiving.append('}')
996996

997-
return '\n'.join(receiving) + '\n'
997+
return '\n'.join(receiving)
998998

999999

10001000
def create_module(metadata, function_exports, global_exports, tag_exports, library_symbols):
10011001
module = []
1002+
module.append(create_receiving(function_exports, tag_exports, library_symbols))
1003+
module.append(create_global_exports(global_exports))
10021004

1003-
receiving = create_receiving(function_exports, tag_exports, library_symbols)
1004-
receiving += create_global_exports(global_exports)
10051005
sending = create_sending(metadata, library_symbols)
1006-
1007-
module.append(receiving)
1008-
10091006
if settings.WASM_ESM_INTEGRATION:
10101007
module.append(sending)
10111008
else:
@@ -1015,13 +1012,12 @@ def create_module(metadata, function_exports, global_exports, tag_exports, libra
10151012
var wasmImports;
10161013
function assignWasmImports() {
10171014
wasmImports = %s;
1018-
}
1019-
''' % sending)
1015+
}''' % sending)
10201016
else:
1021-
module.append('var wasmImports = %s;\n' % sending)
1017+
module.append('var wasmImports = %s;' % sending)
10221018

10231019
if settings.SUPPORT_LONGJMP == 'emscripten' or not settings.DISABLE_EXCEPTION_CATCHING:
1024-
module.append(create_invoke_wrappers(metadata))
1020+
module += create_invoke_wrappers(metadata)
10251021
else:
10261022
assert not metadata.invoke_funcs, "invoke_ functions exported but exceptions and longjmp are both disabled"
10271023

@@ -1031,15 +1027,16 @@ def create_module(metadata, function_exports, global_exports, tag_exports, libra
10311027
if settings.WASM_ESM_INTEGRATION:
10321028
module.append(create_reexports(metadata))
10331029

1034-
return module
1030+
module = [chunk for chunk in module if chunk]
1031+
return '\n\n'.join(module) + '\n'
10351032

10361033

10371034
def create_invoke_wrappers(metadata):
10381035
"""Asm.js-style exception handling: invoke wrapper generation."""
1039-
invoke_wrappers = ''
1036+
invoke_wrappers = []
10401037
for invoke in metadata.invoke_funcs:
10411038
sig = removeprefix(invoke, 'invoke_')
1042-
invoke_wrappers += '\n' + js_manipulation.make_invoke(sig) + '\n'
1039+
invoke_wrappers.append(js_manipulation.make_invoke(sig))
10431040
return invoke_wrappers
10441041

10451042

0 commit comments

Comments
 (0)