Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
    if (x) {
        // ...
    }
    (function() {
        // ...
        setTimeout(arguments.callee, 5);
    })();

=>

    ...
    }(function() {
    ...
  • Loading branch information
einars committed Feb 29, 2012
1 parent a6dd2d5 commit 8956e2a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions beautify.js
Expand Up @@ -706,6 +706,9 @@ function js_beautify(js_source_text, options) {
if (last_text === ';' || last_type === 'TK_START_BLOCK') {
print_newline();
} else if (last_type === 'TK_END_EXPR' || last_type === 'TK_START_EXPR' || last_type === 'TK_END_BLOCK' || last_text === '.') {
if (wanted_newline) {
print_newline();
}
// do nothing on (( and )( and ][ and ]( and .(
} else if (last_type !== 'TK_WORD' && last_type !== 'TK_OPERATOR') {
print_single_space();
Expand Down
3 changes: 2 additions & 1 deletion python/jsbeautifier/__init__.py
Expand Up @@ -664,7 +664,8 @@ def handle_start_expr(self, token_text):
self.append_newline()
elif self.last_type in ['TK_END_EXPR', 'TK_START_EXPR', 'TK_END_BLOCK'] or self.last_text == '.':
# do nothing on (( and )( and ][ and ]( and .(
pass
if self.wanted_newline:
self.append_newline();
elif self.last_type not in ['TK_WORD', 'TK_OPERATOR']:
self.append(' ')
elif self.last_word == 'function' or self.last_word == 'typeof':
Expand Down
1 change: 1 addition & 0 deletions python/jsbeautifier/tests/testjsbeautifier.py
Expand Up @@ -406,6 +406,7 @@ def test_beautifier(self):
bt('a = <%= external() %> ;');

test_fragment('roo = {\n /*\n ****\n FOO\n ****\n */\n BAR: 0\n};');
test_fragment("if (..) {\n // ....\n}\n(function");

bt('"foo""bar""baz"', '"foo"\n"bar"\n"baz"')
bt("'foo''bar''baz'", "'foo'\n'bar'\n'baz'")
Expand Down
3 changes: 3 additions & 0 deletions tests/beautify-tests.js
Expand Up @@ -460,6 +460,9 @@ function run_beautifier_tests(test_obj)
bt('"foo""bar""baz"', '"foo"\n"bar"\n"baz"');
bt("'foo''bar''baz'", "'foo'\n'bar'\n'baz'");


test_fragment("if (..) {\n // ....\n}\n(function");

bt("{\n get foo() {}\n}");
bt("{\n var a = get\n foo();\n}");
bt("{\n set foo() {}\n}");
Expand Down

0 comments on commit 8956e2a

Please sign in to comment.