Skip to content

Commit

Permalink
Preserve opening brace position other than whitespace / indentation (b…
Browse files Browse the repository at this point in the history
  • Loading branch information
c32hedge committed Sep 27, 2014
1 parent 16e9cf0 commit 8f46982
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
12 changes: 9 additions & 3 deletions js/lib/beautify.js
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,8 @@
var empty_anonymous_function = empty_braces && flags.last_word === 'function' &&
last_type === 'TK_END_EXPR';

if (opt.brace_style === "expand") {
if (opt.brace_style === "expand" ||
(opt.brace_style === "none" && current_token.wanted_newline)) {
if (last_type !== 'TK_OPERATOR' &&
(empty_anonymous_function ||
last_type === 'TK_EQUALS' ||
Expand Down Expand Up @@ -852,7 +853,9 @@
if (!(current_token.type === 'TK_RESERVED' && in_array(current_token.text, ['else', 'catch', 'finally']))) {
prefix = 'NEWLINE';
} else {
if (opt.brace_style === "expand" || opt.brace_style === "end-expand") {
if (opt.brace_style === "expand" ||
opt.brace_style === "end-expand" ||
(opt.brace_style === "none" && current_token.wanted_newline)) {
prefix = 'NEWLINE';
} else {
prefix = 'SPACE';
Expand Down Expand Up @@ -886,7 +889,10 @@
}

if (current_token.type === 'TK_RESERVED' && in_array(current_token.text, ['else', 'catch', 'finally'])) {
if (last_type !== 'TK_END_BLOCK' || opt.brace_style === "expand" || opt.brace_style === "end-expand") {
if (last_type !== 'TK_END_BLOCK' ||
opt.brace_style === "expand" ||
opt.brace_style === "end-expand" ||
(opt.brace_style === "none" && current_token.wanted_newline)) {
print_newline();
} else {
output.trim(true);
Expand Down
4 changes: 2 additions & 2 deletions js/lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ var fs = require('fs'),
"jslint_happy": Boolean,
"space_after_anon_function": Boolean,
// TODO: expand-strict is obsolete, now identical to expand. Remove in future version
"brace_style": ["collapse", "expand", "end-expand", "expand-strict"],
"brace_style": ["collapse", "expand", "end-expand", "expand-strict", "none"],
"break_chained_methods": Boolean,
"keep_array_indentation": Boolean,
"unescape_strings": Boolean,
Expand Down Expand Up @@ -215,7 +215,7 @@ function usage(err) {
msg.push(' -E, --space-in-empty-paren Add a single space inside empty paren, ie. f( )');
msg.push(' -j, --jslint-happy Enable jslint-stricter mode');
msg.push(' -a, --space_after_anon_function Add a space before an anonymous function\'s parens, ie. function ()');
msg.push(' -b, --brace-style [collapse|expand|end-expand] ["collapse"]');
msg.push(' -b, --brace-style [collapse|expand|end-expand|none] ["collapse"]');
msg.push(' -B, --break-chained-methods Break chained method calls across subsequent lines');
msg.push(' -k, --keep-array-indentation Preserve array indentation');
msg.push(' -x, --unescape-strings Decode printable characters encoded in xNN notation');
Expand Down

0 comments on commit 8f46982

Please sign in to comment.