wasm: prepend underscore for invalid EXPORT_NAMEs

JS identifiers may not start with a digit:

  em++: error: EXPORT_NAME is not a valid JS identifier: `2dpainting_entry`

Change the regex to match leading digits as well (note it is
inverted).

Prepend an underscore instead of replacing the invalid character;
this makes sure we don't create new conflicts between for example
"2dpainting" and "3dpainting".

Change-Id: If78a87e7ed352b88bc99aee7c5829facf1fc35a0
Reviewed-by: Piotr Wierciński <piotr.wiercinski@qt.io>
(cherry picked from commit a3ab79ec8cab51255b108646f475c5796448d1a1)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Morten Sørvig 2024-05-30 14:57:00 +02:00 committed by Qt Cherry-pick Bot
parent fd1066ad41
commit 56d0227a73

View File

@ -135,9 +135,13 @@ function(_qt_internal_wasm_export_name_for_target out target)
if(export_name)
set(${out} "${export_name}" PARENT_SCOPE)
else()
string(REGEX REPLACE "[^a-zA-Z0-9_]" "_" target "${target}")
string(REGEX MATCH "[^a-zA-Z_]" has_invalid_char "${target}")
if(has_invalid_char)
set(${out} "_${target}_entry" PARENT_SCOPE)
else()
set(${out} "${target}_entry" PARENT_SCOPE)
endif()
endif()
endfunction()
function(_qt_internal_set_wasm_embind_option target)