Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc bug fixes #397

Merged
merged 5 commits into from Apr 2, 2016
Merged

Misc bug fixes #397

merged 5 commits into from Apr 2, 2016

Commits on Oct 19, 2015

  1. Correctly indent multiply nested BlockStatement

    js2coffee was not correctly indenting code such as:
    
        while (true) {
              {
                    {
                            var a = 0;
                            var b = 1;
                    }
              }
        }
    
    In that case you'd get:
    
        loop
            a = 0
          b = 1
    
    The reason is that the code that emits 'BlockStatement' was
    unconditionally prepending the current indent to each of its children.
    In the preceding case, the code would add an indent to the top-level
    BlockStatement then an indent for each child "a = 0" and "b = 0", resulting
    in then output:
    
        ["loop", "\n", "  ", "  ", "a", "=", "0", "\n", " ", "b", "=", "0", "\n"]
    
    This code makes it so that the code that emits 'BlockStatement' only outputs
    an indent if the child isn't of type 'BlockStatement', effectively flattening
    the output.
    rianhunter committed Oct 19, 2015
    Configuration menu
    Copy the full SHA
    01b9bb2 View commit details
    Browse the repository at this point in the history
  2. Properly reset scope member after popStack

    The `scope` member in the transformer base was being set to
    the previously pushed scope on `popStack`, instead of the
    scope that was active that before the previously pushed scope
    was pushed. This resulted in code like:
    
        var a = 0;
        var foo = function () {
          var b = function () {
            return 0;
          };
          var a = 1;
        };
    
    Being compiled into:
    
        a = 0
        foo = ->
          b = ->
            `var a`
            0
          a = 1
          return
    
    The preceding example would happen because the duplicate
    VariableDeclaration for `a` would trigger js2coffee's variable shadowing
    handling code, automatically placing the `var a` at the the
    top of the current scope's body. The current scope was erroneously
    left as the last pushed scope, hence `var a` would be placed at the
    top of the "b" function.
    rianhunter committed Oct 19, 2015
    Configuration menu
    Copy the full SHA
    5375daf View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    f3b162d View commit details
    Browse the repository at this point in the history
  4. Don't mutate @scope body while we are traversing over it.

    The `estraverse` module iterates over a function's AST body
    using fixed indices stored when the function is first entered.
    If the body of a function is modified during those methods, it can cause
    unexpected outcomes during traversal. One outcome is the complete
    skipping of a sub-statement. This change fixes that.
    rianhunter committed Oct 19, 2015
    Configuration menu
    Copy the full SHA
    c1841b9 View commit details
    Browse the repository at this point in the history

Commits on Oct 20, 2015

  1. Configuration menu
    Copy the full SHA
    4cdb4be View commit details
    Browse the repository at this point in the history