Skip to content

Commit 2437331

Browse files
authored
Allow dollar sign in export names (#24367)
Fixes: #24363
1 parent 27e931c commit 2437331

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

test/test_other.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15936,6 +15936,14 @@ def test_invalid_export_name(self):
1593615936
err = self.expect_fail([EMCC, 'test.c'])
1593715937
self.assertContained('emcc: error: invalid export name: my.func', err)
1593815938

15939+
# GCC (and clang) and JavaScript also allow $ in symbol names
15940+
create_file('valid.c', '''
15941+
#include <emscripten.h>
15942+
EMSCRIPTEN_KEEPALIVE
15943+
void my$func() {}
15944+
''')
15945+
self.run_process([EMCC, 'valid.c'])
15946+
1593915947
@also_with_modularize
1594015948
def test_instantiate_wasm(self):
1594115949
create_file('pre.js', '''

tools/emscripten.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import subprocess
1717
import logging
1818
import pprint
19+
import re
1920
import shutil
2021
import sys
2122
import textwrap
@@ -455,6 +456,13 @@ def get_metadata(infile, outfile, modify_wasm, args):
455456
return metadata
456457

457458

459+
def is_valid_js_identifier(ident):
460+
# See https://developer.mozilla.org/en-US/docs/Glossary/Identifier
461+
if ident[0].isdigit():
462+
return False
463+
return re.fullmatch(r'[0-9a-zA-Z_\$]+', ident)
464+
465+
458466
def finalize_wasm(infile, outfile, js_syms):
459467
building.save_intermediate(infile, 'base.wasm')
460468
args = []
@@ -563,7 +571,7 @@ def finalize_wasm(infile, outfile, js_syms):
563571
# not known auto-generated system functions.
564572
unexpected_exports = [e for e in metadata.all_exports if shared.is_user_export(e)]
565573
for n in unexpected_exports:
566-
if not n.isidentifier():
574+
if not is_valid_js_identifier(n):
567575
exit_with_error(f'invalid export name: {n}')
568576
unexpected_exports = [asmjs_mangle(e) for e in unexpected_exports]
569577
unexpected_exports = [e for e in unexpected_exports if e not in expected_exports]

0 commit comments

Comments
 (0)