Fix for missing space on return<operator>

input:
return ++i

expected:
return ++i

returned:
return++i
This commit is contained in:
Einar Lielmanis 2009-10-28 14:16:52 +02:00
parent 353bed2108
commit 6661c76c36
2 changed files with 17 additions and 0 deletions

View File

@ -217,6 +217,13 @@ function run_beautifier_tests(test_obj)
bt('{[x()[0]];indent;}', '{\n [x()[0]];\n indent;\n}');
bt('return ++i', 'return ++i');
bt('return !!x', 'return !!x');
bt('return !x', 'return !x');
bt('return [1,2]', 'return [1, 2]');
bt('return;', 'return;');
bt('return\nfunc', 'return\nfunc');
space_after_anon_function = true;
bt("// comment 1\n(function()", "// comment 1\n(function ()"); // typical greasemonkey start

View File

@ -498,6 +498,9 @@ function js_beautify(js_source_text, options)
if (last_type === 'TK_WORD' || last_text === ')') {
// this is array index specifier, break immediately
// a[x], fn()[x]
if (last_word === 'return' || last_word === 'throw') {
print_space();
}
set_mode('(EXPRESSION)');
print_token();
break;
@ -725,6 +728,13 @@ function js_beautify(js_source_text, options)
var_line_tainted = false;
}
if (last_text === 'return' || last_text === 'throw') {
// "return" had a special handling in TK_WORD. Now we need to return the favor
print_space();
print_token();
break;
}
if (token_text === ':' && in_case) {
print_token(); // colon really asks for separate treatment
print_newline();