From 0b2b41d380485a6b72654a6f788aa4c0dc39fe82 Mon Sep 17 00:00:00 2001 From: Jeremy Nguyen Date: Thu, 23 Jul 2026 20:16:36 -0700 Subject: [PATCH] Fix compiler error when exporting integers while emitting tsd - Fixes #26589 - Replaces concatenation (which can error when snippet is an int) with f-string - Update test_other.py to include POINTER_SIZE --- test/other/test_emit_tsd.d.ts | 1 + test/other/test_emit_tsd_jspi.d.ts | 1 + test/other/test_tsd.ts | 1 + test/test_other.py | 2 +- tools/emscripten.py | 2 +- 5 files changed, 5 insertions(+), 2 deletions(-) diff --git a/test/other/test_emit_tsd.d.ts b/test/other/test_emit_tsd.d.ts index 06dec92fbe350..a8e7f28cb400a 100644 --- a/test/other/test_emit_tsd.d.ts +++ b/test/other/test_emit_tsd.d.ts @@ -1,5 +1,6 @@ // TypeScript bindings for emscripten-generated code. Automatically generated at compile time. declare namespace RuntimeExports { + let POINTER_SIZE: number; /** * Given a pointer 'idx' to a null-terminated UTF8-encoded string in the given * array that contains uint8 values, returns a copy of that string as a diff --git a/test/other/test_emit_tsd_jspi.d.ts b/test/other/test_emit_tsd_jspi.d.ts index 8124730e69a29..4c9e03dd61703 100644 --- a/test/other/test_emit_tsd_jspi.d.ts +++ b/test/other/test_emit_tsd_jspi.d.ts @@ -1,5 +1,6 @@ // TypeScript bindings for emscripten-generated code. Automatically generated at compile time. declare namespace RuntimeExports { + let POINTER_SIZE: number; /** * Given a pointer 'idx' to a null-terminated UTF8-encoded string in the given * array that contains uint8 values, returns a copy of that string as a diff --git a/test/other/test_tsd.ts b/test/other/test_tsd.ts index ce1de1569d31c..133e200e4604d 100644 --- a/test/other/test_tsd.ts +++ b/test/other/test_tsd.ts @@ -5,4 +5,5 @@ async function go() { module._fooVoid(); let result = module._fooInt(7, 8); module.UTF8ArrayToString([], 99); + module.POINTER_SIZE; } diff --git a/test/test_other.py b/test/test_other.py index 09df84c0ed5c5..6e68482d7ee0c 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -3825,7 +3825,7 @@ def test_emit_tsd(self, args, postfix): self.require_jspi() self.run_process([EMCC, test_file('other/test_emit_tsd.c'), '--emit-tsd', f'test_emit_tsd{postfix}.d.ts', '-sEXPORT_ES6', - '-sMODULARIZE', '-sEXPORTED_RUNTIME_METHODS=UTF8ArrayToString,wasmTable', + '-sMODULARIZE', '-sEXPORTED_RUNTIME_METHODS=POINTER_SIZE,UTF8ArrayToString,wasmTable', '-o', f'test_emit_tsd{postfix}.js'] + args + self.get_cflags()) self.assertFilesMatch(test_file(f'other/test_emit_tsd{postfix}.d.ts'), f'test_emit_tsd{postfix}.d.ts') diff --git a/tools/emscripten.py b/tools/emscripten.py index 54adaa8aa8756..82d8563214dbe 100644 --- a/tools/emscripten.py +++ b/tools/emscripten.py @@ -648,7 +648,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 = ''