Add namespace removing transform #140
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation: Updating old JavaScript code to ES6 can often have namespaces (related issue). e.g.
where you would prefer:
My first approach was to introduce this into the class transform, but I believe the approach in this PR separates the concerns a bit better by introducing a transform whose sole job is to remove namespaces.
Unfortunately this introduces an ordering dependency, where you need to run
no-namespace
transform before running theclass
transform. I'd like to hear feedback on this.The code submitted is really my first hacky attempt, without thorough testing. Hoping this PR generates some interest and maybe some ideas on how to add this pretty handy feature.
Edit: Oh and the
Error: {...} does not match type string
error was super annoying, I eventually commented outisString.assert(stmt);
inrecast/lib/printer.js
because I couldn't tell what was causing it. Maybe you will know :)Edit: More TODOs: Update usage throughout file, and preserve comments.