treycordova / nativejsx

JSX to native DOM API transpilation. :yellow_heart: <div> ⟹ document.createElement('div')!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Uses the same variable name over and over.

benderTheCrime opened this issue · comments

It looks like the compiler is outputting the same variable name over and over again:

    return function () {
        var $$a = document.createElement('div');
        // ...
        var $$a = document.createElement('select');
        $$a.appendChild($$a);
        return $$a;
    }();

I looked at the code for allocator, it seems to be doing what it should be. Perhaps there is an issue somewhere else in the middle?

This seems to be the culprit:
https://github.com/treycordova/nativejsx/blob/master/source/walkers.js#L109

Commenting it out, the code works fine. This also seems to have some allocator implications.

Really, there was an incorrect assumption that a single allocator could be used across all closures and reset per closure. In reality, each closure requires a unique allocator, otherwise the variable naming will be wiped for subsequent allocations in the closure preceding it.

Either that, or we allow a global allocator that resets when the entire file is finished. I think that sounds more ideal and easier to follow from a debugging standpoint (variable shadowing is awfully confusing).

Nice catch, @benderTheCrime. I'll get out a fix immediately.

awesome, @treycordova, thanks 👍

I've released https://github.com/treycordova/nativejsx/releases/tag/3.0.2 with the fix in place. From my observations, it seems to be working. I'll continue to poke around just to be sure.

Seems like all is well. Going to close this!