diff --git a/build-aux/bootstrap/prebirth.js b/build-aux/bootstrap/prebirth.js index c16de94..83728b2 100644 --- a/build-aux/bootstrap/prebirth.js +++ b/build-aux/bootstrap/prebirth.js @@ -375,6 +375,12 @@ class Compiler /** * Generate ECMAScript-friendly name from the given id * + * A subset of special characters that are acceptable in Scheme are + * converted in an identifiable manner; others are simply converted to + * `$' in a catch-all and therefore could result in conflicts and cannot + * be reliably distinguished from one-another. Remember: this is + * temporary code. + * * @param {string} name source name * @param {boolean} global whether identifier should be globally unique * @@ -382,8 +388,31 @@ class Compiler */ _idFromName( name, global ) { - return ( global ? '$$' : '' ) - + name.replace( /[^a-zA-Z0-9_]/g, '$' ); + // just some common ones; will fall back to `$' below + const conv = { + '-': '$_$', + '?': '$7$', + '@': '$a$', + '!': '$b$', + '>': '$g$', + '#': '$h$', + '*': '$k$', + '<': '$l$', + '&': '$n$', + '%': '$o$', + '+': '$p$', + '=': '$q$', + '^': '$v$', + '/': '$w$', + '$': '$$', + }; + + if ( name === undefined ) { + throw SyntaxError( "Missing identifier name" ); + } + + return ( global ? '$$' : '' ) + + name.replace( /[^a-zA-Z0-9_]/g, c => conv[ c ] || '$' ); }