From 8f12fed3b9314439b02ef0d1e55c1c6d22795dca Mon Sep 17 00:00:00 2001 From: Jeremy Nguyen Date: Fri, 3 Apr 2026 01:42:36 -0700 Subject: [PATCH] Format snippet with f-string - Fixes #26589 - Replaces concatenation (which can error when snippet is an int) with f-string --- test/other/test_emit_tsd_integer.d.ts | 12 ++++++++++++ test/other/test_tsd_integer.ts | 6 ++++++ test/test_other.py | 11 +++++++++++ tools/emscripten.py | 2 +- 4 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 test/other/test_emit_tsd_integer.d.ts create mode 100644 test/other/test_tsd_integer.ts diff --git a/test/other/test_emit_tsd_integer.d.ts b/test/other/test_emit_tsd_integer.d.ts new file mode 100644 index 0000000000000..e03577216b80f --- /dev/null +++ b/test/other/test_emit_tsd_integer.d.ts @@ -0,0 +1,12 @@ +// TypeScript bindings for emscripten-generated code. Automatically generated at compile time. +declare namespace RuntimeExports { + let POINTER_SIZE: number; +} +interface WasmModule { + _fooVoid(): void; + _fooInt(_0: number, _1: number): number; + _main(_0: number, _1: number): number; +} + +export type MainModule = WasmModule & typeof RuntimeExports; +export default function MainModuleFactory (options?: unknown): Promise; diff --git a/test/other/test_tsd_integer.ts b/test/other/test_tsd_integer.ts new file mode 100644 index 0000000000000..e2eae0825f698 --- /dev/null +++ b/test/other/test_tsd_integer.ts @@ -0,0 +1,6 @@ +import moduleFactory from './test_emit_tsd_integer.js'; + +async function go() { + const module = await moduleFactory(); + module.POINTER_SIZE; +} diff --git a/test/test_other.py b/test/test_other.py index f5fab92327817..2db19713c18c5 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -3748,6 +3748,17 @@ def test_emit_tsd_sync_compilation(self): cmd = shared.get_npm_cmd('tsc') + [test_file('other/test_tsd_sync.ts'), '--noEmit'] shared.check_call(cmd) + @requires_dev_dependency('typescript') + def test_emit_tsd_integer(self): + self.run_process([EMCC, test_file('other/test_emit_tsd.c'), + '--emit-tsd', 'test_emit_tsd_integer.d.ts', '-sEXPORT_ES6', + '-sMODULARIZE', '-sEXPORTED_RUNTIME_METHODS=POINTER_SIZE', + '-Wno-experimental', '-o', 'test_emit_tsd_integer.js'] + + self.get_cflags()) + self.assertFileContents(test_file('other/test_emit_tsd_integer.d.ts'), read_file('test_emit_tsd_integer.d.ts')) + cmd = shared.get_npm_cmd('tsc') + [test_file('other/test_tsd_integer.ts'), '--noEmit'] + shared.check_call(cmd) + def test_emit_tsd_wasm_only(self): expected = 'Wasm only output is not compatible with --emit-tsd' self.assert_fail([EMCC, test_file('other/test_emit_tsd.c'), '--emit-tsd', 'test_emit_tsd_wasm_only.d.ts', '-o', 'out.wasm'], expected) diff --git a/tools/emscripten.py b/tools/emscripten.py index d9e7384a0c934..82c623aeecc27 100644 --- a/tools/emscripten.py +++ b/tools/emscripten.py @@ -643,7 +643,7 @@ def create_tsd_exported_runtime_methods(metadata): if name in metadata.library_definitions: definition = metadata.library_definitions[name] if definition['snippet']: - snippet = ' = ' + definition['snippet'] + snippet = f' = {definition["snippet"]}' # Clear the doc so the type is either computed from the snippet or # defined by the definition below. docs = ''