Permalink
Browse files

Fix #43

    if (x) {
        // ...
    }
    (function() {
        // ...
        setTimeout(arguments.callee, 5);
    })();

=>

    ...
    }(function() {
    ...
  • Loading branch information...
1 parent a6dd2d5 commit 8956e2a3d9fbc960c749e5992009d25ce6ae529a @einars einars committed Feb 29, 2012
Showing with 9 additions and 1 deletion.
  1. +3 −0 beautify.js
  2. +2 −1 python/jsbeautifier/__init__.py
  3. +1 −0 python/jsbeautifier/tests/testjsbeautifier.py
  4. +3 −0 tests/beautify-tests.js
View
@@ -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();
@@ -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':
@@ -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'")
View
@@ -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}");

0 comments on commit 8956e2a

Please sign in to comment.