|
@ -27,9 +27,23 @@ function isntReference ( id ) { |
|
|
return !( id instanceof Reference ); |
|
|
return !( id instanceof Reference ); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Prefix the argument with '_'.
|
|
|
// Returns a function that will prefix its argument with '_'
|
|
|
function underscorePrefix ( x ) { |
|
|
// and append a number if called with the same argument more than once.
|
|
|
return '_' + x; |
|
|
function underscorePrefix () { |
|
|
|
|
|
function number ( x ) { |
|
|
|
|
|
if ( !( x in map ) ) { |
|
|
|
|
|
map[ x ] = 0; |
|
|
|
|
|
return ''; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return map[ x ]++; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var map = blank(); |
|
|
|
|
|
|
|
|
|
|
|
return function ( x ) { |
|
|
|
|
|
return '_' + x + number( x ); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// ## Scope
|
|
|
// ## Scope
|
|
@ -51,7 +65,7 @@ export default class Scope { |
|
|
// Deconflict all names within the scope,
|
|
|
// Deconflict all names within the scope,
|
|
|
// using the given renaming function.
|
|
|
// using the given renaming function.
|
|
|
// If no function is supplied, `underscorePrefix` is used.
|
|
|
// If no function is supplied, `underscorePrefix` is used.
|
|
|
deconflict ( rename = underscorePrefix ) { |
|
|
deconflict ( rename = underscorePrefix() ) { |
|
|
const names = this.used; |
|
|
const names = this.used; |
|
|
|
|
|
|
|
|
this.ids.filter( ref => ref instanceof Reference ).forEach( ref => { |
|
|
this.ids.filter( ref => ref instanceof Reference ).forEach( ref => { |
|
|