prebirth: Distinguishable id generation
* build-aux/bootstrap/prebirth.js (Compiler#_idFromName): Distinguish between certain types of characters.master
parent
6a736a8fcd
commit
61f6ba1470
|
@ -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 ] || '$' );
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue