mirror of
https://github.com/beautifier/js-beautify.git
synced 2025-02-25 15:53:04 +00:00
Fix for missing space on return<operator>
input: return ++i expected: return ++i returned: return++i
This commit is contained in:
parent
353bed2108
commit
6661c76c36
@ -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
|
||||
|
10
beautify.js
10
beautify.js
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user