wasm: fix handling of invalid EXPORT_NAMEs

Commit a3ab79ec8 fixed the "leading digit" case, but
broke the original "replace invalid chars" case.

Fix regexp usage. Use "^[0-9]" for matching a leading
digit and then "[^a-zA-Z0-9_]" for matching all chars
not valid in a JavaScript identifier.

Change-Id: I2ab2dcb73b201a996c38b0cab55a049eb39d8b2b
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
(cherry picked from commit ba42c48dd460110d02b078c1460be0e268624faa)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Morten Sørvig 2024-06-21 14:52:39 +02:00 committed by Qt Cherry-pick Bot
parent 72e07e1c0f
commit b64373a997

View File

@ -135,12 +135,21 @@ function(_qt_internal_wasm_export_name_for_target out target)
if(export_name)
set(${out} "${export_name}" PARENT_SCOPE)
else()
string(REGEX MATCH "[^a-zA-Z_]" has_invalid_char "${target}")
if(has_invalid_char)
set(${out} "_${target}_entry" PARENT_SCOPE)
# Modify target name to remove characters which are not valid in
# JavaScript identifiers.
# Prefix leading digit with '_' (2dpaint -> _2dpaint)
if("${target}" MATCHES "^[0-9]")
set(targ "_${target}")
else()
set(${out} "${target}_entry" PARENT_SCOPE)
set(targ "${target}")
endif()
# Replace remaining non-legal chars with '_' (target-foo -> target_foo)
string(REGEX REPLACE "[^a-zA-Z0-9_]" "_" targ "${targ}")
# Append "_entry" and return
set(${out} "${targ}_entry" PARENT_SCOPE)
endif()
endfunction()