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

Address getIndent TODO in lib/patcher.js #6

Closed
benjamn opened this issue Sep 22, 2012 · 0 comments
Closed

Address getIndent TODO in lib/patcher.js #6

benjamn opened this issue Sep 22, 2012 · 0 comments
Labels

Comments

@benjamn
Copy link
Owner

benjamn commented Sep 22, 2012

The appropriate indentation for a node is not necessarily the amount of leading whitespace on the line where the node starts, as this code naïvely assumes:

function getIndent(node) {
    // TODO Improve this.
    return lines.getIndentAt(node.loc.start.line);
}

The correct indentation for a node is something closer to the amount of leading whitespace on the line where the nearest Statement ancestor of the node begins.

@benjamn benjamn closed this as completed in 15d2aa7 Jun 7, 2013
benjamn added a commit that referenced this issue Jun 7, 2013
In order to reprint a node that originally appeared at a different
level of indentation, the patcher needs to de-indent the original
lines by their original indentation amount, then re-indent them by the
desired amount.

The previous heuristic for determining the original indentation amount
was easily fooled, but I put up with it because in practice it was
wrong rarely enough.

Here's an example of when it would be wrong:

    function foo(bar,
                 baz) {
        qux();
    }

The previous version of getIndent reported the indentation of the
BlockStatement beginning at the "{" as being equal to the identation
of the "baz" token, when really it should be equal to the indentation
of the "function" keyword.

The new strategy is to find the starting column of the first ancestor
node on a line with nothing before it but whitespace.

Closes #6.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant