facebook / regenerator

Source transformer enabling ECMAScript 6 generator functions in JavaScript-of-today.
http://facebook.github.io/regenerator/
MIT License
3.83k stars 1.16k forks source link

Custom UID generator #159

Open sebmck opened 9 years ago

sebmck commented 9 years ago

It'd be great to be able to override the path.scope.declareTemporary calls used in visit.js with a custom function to generate identifiers.

benjamn commented 9 years ago

This involves https://github.com/benjamn/ast-types/blob/master/lib/scope.js more than Regenerator itself, I'd say.

sebmck commented 9 years ago

@benjamn Not really. Regenerator is the one that delegates it to ast-types. I know it seems incredibly pedantic to want to change it but I'm pretty set on 6to5 code output consistency which is what this feature would be used for.

benjamn commented 9 years ago

Ah, I see what you mean now. What do you want the temporaries to look like?

Note that .declareTemporary adds unique-ifying suffixes (the argument you provide is just a prefix), so this may require changes to .declareTemporary after all, depending on what you're looking for.

sebmck commented 9 years ago

@benjamn 6to5 has a generateUid method which is basically the direct equivalent. You provide it a prefix and it prepends it with an underscore and checks to see if there are any variables declared within the current scope to avoid collisions and appends a number.

I'd be willing to submit a PR to demonstrate what I mean but I'm unsure of how to structure it since transform options aren't accessible from the visitor.

ghost commented 9 years ago

Thank you for reporting this issue and appreciate your patience. We've notified the core team for an update on this issue. We're looking for a response within the next 30 days or the issue may be closed.